index.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <div id="app" v-cloak>
  2. <el-card shadow="never" style="border:0;" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  3. <div slot="header">
  4. <div>
  5. <span>规格列表</span>
  6. </div>
  7. </div>
  8. <div class="table-body">
  9. <!-- <el-form
  10. :inline="true"
  11. :model="searchData"
  12. size="mini"
  13. >
  14. <el-row>
  15. <el-form-item label="会员ID">
  16. <el-input v-model="searchData.user_id" placeholder="会员ID"></el-input>
  17. </el-form-item>
  18. </el-row>
  19. <el-row>
  20. <el-form-item>
  21. <el-button type="primary" @click="onSubmit">查询</el-button>
  22. <el-button @click="resetForm">重置</el-button>
  23. </el-form-item>
  24. </el-row>
  25. </el-form> -->
  26. <!-- 订单信息 -->
  27. <template>
  28. <el-row>
  29. <el-button type="success" size="mini" @click="addAttr">添加规格</el-button>
  30. </el-row>
  31. <el-table ref="multipleTable" :data="list" @selection-change="handleSelectionChange">
  32. <!-- 空数据 -->
  33. <template slot="empty">
  34. <el-empty description="暂无规格"></el-empty>
  35. </template>
  36. <!-- 数据 -->
  37. <el-table-column type="selection"></el-table-column>
  38. <el-table-column prop="id" align="center" label="ID"></el-table-column>
  39. <el-table-column prop="name" align="center" label="规格名"></el-table-column>
  40. <el-table-column prop="values" align="center" label="规格值">
  41. <template slot-scope="scope">
  42. <el-tag class="tag-item" size="mini" v-for="(value, i) in scope.row.values" v-if="i < tagLimit">
  43. {{ value }}
  44. </el-tag>
  45. <span v-if="tagIsLimit(scope.row.values)">...</span>
  46. </template>
  47. </el-table-column>
  48. <el-table-column prop="created_at" align="center" label="创建时间">
  49. <template slot-scope="scope">
  50. {{ scope.row.created_at|dateTimeFormat('Y-m-d H:i:s') }}
  51. </template>
  52. </el-table-column>
  53. <el-table-column prop="right_button" align="center" label="操作">
  54. <template slot-scope="scope">
  55. <el-button size="mini" type="primary" @click="editSpecs(scope.row)" v-loading="btnLoading">
  56. 编辑
  57. </el-button>
  58. <el-button size="mini" type="danger" @click="delSpecs(scope.row.id)" v-loading="btnLoading">
  59. 删除
  60. </el-button>
  61. </template>
  62. </el-table-column>
  63. </el-table>
  64. </template>
  65. <!-- 分页 -->
  66. <el-row type="flex" class="page" justify="end" style="margin-top: 15px">
  67. <el-pagination
  68. @current-change="pagination"
  69. background
  70. layout="prev, pager, next"
  71. :page-count="pageCount"
  72. v-if="list"
  73. ></el-pagination>
  74. </el-row>
  75. </div>
  76. </el-card>
  77. <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="30%" :close-on-click-modal="false">
  78. <el-form
  79. :inline="true"
  80. :model="attr"
  81. size="mini"
  82. :rules="rules"
  83. ref="elForm"
  84. >
  85. <el-row>
  86. <el-form-item label="规格名" prop="name">
  87. <el-input v-model="attr.name" placeholder="规格名"></el-input>
  88. </el-form-item>
  89. </el-row>
  90. <el-row>
  91. <el-form-item label="规格值" prop="values">
  92. <div class="attrs-item" v-for="(item, index) in attr.values">
  93. <el-input v-model="attr.values[index]" placeholder="规格值"></el-input>
  94. <div class="item-button">
  95. <el-button type="danger" @click="delItem(index)" icon="el-icon-delete" v-if="isDel(index)"></el-button>
  96. <el-button type="success" @click="addItem" icon="el-icon-plus" v-if="isAdd(index)"></el-button>
  97. </div>
  98. </div>
  99. </el-form-item>
  100. </el-row>
  101. </el-form>
  102. <span slot="footer" class="dialog-footer">
  103. <el-button @click="submit" v-loading="btnLoading">提交</el-button>
  104. </span>
  105. </el-dialog>
  106. </div>
  107. <script>
  108. const app = new Vue({
  109. el: '#app',
  110. data() {
  111. var validateAttr = (rule, value, callback) => {
  112. for (let index = 0; index < value.length; index++) {
  113. const element = value[index];
  114. if (element == '') {
  115. callback(new Error('规格值内容不能为空'));
  116. }
  117. }
  118. callback()
  119. }
  120. return {
  121. dialogTitle: '添加规格',
  122. // 规格值显示上限
  123. tagLimit: 5,
  124. limit: 20,
  125. searchData: {
  126. user_id : undefined,
  127. user_keyword : undefined,
  128. order_no : undefined,
  129. time : [],
  130. },
  131. list: [],
  132. pageCount: 0,
  133. page: 1,
  134. currentPage: null,
  135. listLoading: false,
  136. btnLoading: false,
  137. dialogVisible: false,
  138. rules: {
  139. name: [
  140. {
  141. required: true,
  142. message: '规格名不能为空',
  143. }
  144. ],
  145. values: [
  146. {
  147. required: true,
  148. },
  149. {
  150. validator: validateAttr,
  151. }
  152. ],
  153. },
  154. attr: {
  155. name: '',
  156. values: [
  157. ''
  158. ],
  159. },
  160. };
  161. },
  162. methods: {
  163. handleSelectionChange(val) {
  164. this.select_order = val
  165. },
  166. // 全选
  167. allSelect() {
  168. if (this.checked) {
  169. this.goods_list.forEach(function(item, index) {
  170. if (!item.storage) {
  171. item.is_select = true
  172. }
  173. })
  174. } else {
  175. this.goods_list.forEach(function(item, index) {
  176. item.is_select = false
  177. })
  178. }
  179. },
  180. //搜索
  181. onSubmit() {
  182. this.page = 1
  183. this.getAttrList()
  184. },
  185. pagination(currentPage) {
  186. this.page = currentPage
  187. this.getAttrList()
  188. },
  189. getAttrList() {
  190. this.listLoading = true;
  191. request({
  192. params: {
  193. r: 'store/client/specs/index',
  194. page: this.page,
  195. limit: this.limit
  196. },
  197. method: 'get',
  198. data: this.searchData,
  199. }).then(e => {
  200. if (e.data.code === 0) {
  201. this.list = e.data.data.list
  202. this.pageCount = e.data.data.page_count
  203. this.currentPage = e.data.data.pagination.current_page
  204. } else {
  205. this.$message.error(e.data.msg)
  206. }
  207. this.listLoading = false
  208. }).catch(e => {
  209. this.listLoading = false
  210. })
  211. },
  212. //重置
  213. resetForm() {
  214. this.searchData = {
  215. user_id : undefined,
  216. }
  217. },
  218. // 添加规格
  219. addAttr() {
  220. this.dialogTitle = '添加规格'
  221. this.attr = {
  222. name: '',
  223. values: [
  224. ''
  225. ],
  226. },
  227. this.dialogVisible = true
  228. },
  229. // 是否删除button
  230. isDel(i) {
  231. return this.attr.values.length - 1 != i
  232. // return true
  233. // return this.attr.values.length > 1
  234. },
  235. // 是否添加button
  236. isAdd(i) {
  237. return this.attr.values.length - 1 == i
  238. },
  239. // 添加
  240. addItem() {
  241. this.attr.values.push(
  242. ''
  243. )
  244. },
  245. // 删除
  246. delItem(i) {
  247. this.attr.values = this.attr.values.filter((item, index) => {
  248. return index != i
  249. })
  250. },
  251. // 规格提交
  252. submit() {
  253. this.$refs['elForm'].validate(valid => {
  254. if (valid) {
  255. this.btnLoading = true
  256. request({
  257. params: {
  258. r: 'store/client/specs/add',
  259. },
  260. method: 'post',
  261. data: this.attr,
  262. }).then(e => {
  263. if (e.data.code === 0) {
  264. this.$message.success(e.data.msg)
  265. setTimeout(() => {
  266. this.dialogVisible = false
  267. this.getAttrList()
  268. }, 1500)
  269. } else {
  270. this.$message.error(e.data.msg)
  271. }
  272. this.btnLoading = false
  273. }).catch(e => {
  274. this.btnLoading = false
  275. })
  276. }
  277. })
  278. },
  279. tagIsLimit(values) {
  280. return values.length > this.tagLimit
  281. },
  282. editSpecs(row) {
  283. this.dialogTitle = '编辑规格'
  284. // this.btnLoading = true
  285. this.attr = row
  286. this.dialogVisible = true
  287. },
  288. delSpecs(id) {
  289. this.$confirm('此操作将永久删除, 是否继续?', '提示', {
  290. confirmButtonText: '确定',
  291. cancelButtonText: '取消',
  292. type: 'warning'
  293. }).then(() => {
  294. this.btnLoading = true
  295. request({
  296. params: {
  297. r: 'store/client/specs/del',
  298. id: id
  299. },
  300. method: 'get',
  301. }).then(e => {
  302. if (e.data.code === 0) {
  303. this.$message.success(e.data.msg)
  304. setTimeout(() => {
  305. this.getAttrList()
  306. }, 1500)
  307. } else {
  308. this.$message.error(e.data.msg)
  309. }
  310. this.btnLoading = false
  311. }).catch(e => {
  312. this.btnLoading = false
  313. })
  314. })
  315. },
  316. },
  317. mounted: function() {
  318. this.page = getQuery('page') ? getQuery('page') : 1
  319. this.limit = getQuery('limit') ? getQuery('limit') : 20
  320. this.getAttrList()
  321. }
  322. });
  323. </script>
  324. <style>
  325. .el-dialog__body {
  326. padding: 30px 20px;
  327. }
  328. .attrs-item + .attrs-item {
  329. margin-top: 5px;
  330. }
  331. .attrs-item {
  332. display: flex;
  333. align-items: center;
  334. }
  335. .item-button {
  336. margin-left: 5px;
  337. }
  338. .tag-item + .tag-item {
  339. margin-left: 3px;
  340. }
  341. </style>