productAttrList.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <template> 
  2. <div class="app-container">
  3. <el-card class="operate-container" shadow="never">
  4. <i class="el-icon-tickets" style="margin-top: 5px"></i>
  5. <span style="margin-top: 5px">数据列表</span>
  6. <el-button
  7. class="btn-add"
  8. @click="addProductAttr()"
  9. size="mini">
  10. 添加
  11. </el-button>
  12. </el-card>
  13. <div class="table-container">
  14. <el-table ref="productAttrTable"
  15. :data="list"
  16. style="width: 100%"
  17. @selection-change="handleSelectionChange"
  18. v-loading="listLoading"
  19. border>
  20. <el-table-column type="selection" width="60" align="center"></el-table-column>
  21. <el-table-column label="编号" width="100" align="center">
  22. <template slot-scope="scope">{{scope.row.id}}</template>
  23. </el-table-column>
  24. <el-table-column label="属性名称" width="140" align="center">
  25. <template slot-scope="scope">{{scope.row.name}}</template>
  26. </el-table-column>
  27. <el-table-column label="商品类型" width="140" align="center">
  28. <template slot-scope="scope">{{$route.query.cname}}</template>
  29. </el-table-column>
  30. <el-table-column label="属性是否可选" width="120" align="center">
  31. <template slot-scope="scope">{{scope.row.selectType|selectTypeFilter}}</template>
  32. </el-table-column>
  33. <el-table-column label="属性值的录入方式" width="150" align="center">
  34. <template slot-scope="scope">{{scope.row.inputType|inputTypeFilter}}</template>
  35. </el-table-column>
  36. <el-table-column label="可选值列表" align="center">
  37. <template slot-scope="scope">{{scope.row.inputList}}</template>
  38. </el-table-column>
  39. <el-table-column label="排序" width="100" align="center">
  40. <template slot-scope="scope">{{scope.row.sort}}</template>
  41. </el-table-column>
  42. <el-table-column label="操作" width="200" align="center">
  43. <template slot-scope="scope">
  44. <el-button
  45. size="mini"
  46. @click="handleUpdate(scope.$index, scope.row)">编辑
  47. </el-button>
  48. <el-button
  49. size="mini"
  50. type="danger"
  51. @click="handleDelete(scope.$index, scope.row)">删除
  52. </el-button>
  53. </template>
  54. </el-table-column>
  55. </el-table>
  56. </div>
  57. <div class="batch-operate-container">
  58. <el-select
  59. size="small"
  60. v-model="operateType" placeholder="批量操作">
  61. <el-option
  62. v-for="item in operates"
  63. :key="item.value"
  64. :label="item.label"
  65. :value="item.value">
  66. </el-option>
  67. </el-select>
  68. <el-button
  69. style="margin-left: 20px"
  70. class="search-button"
  71. @click="handleBatchOperate()"
  72. type="primary"
  73. size="small">
  74. 确定
  75. </el-button>
  76. </div>
  77. <div class="pagination-container">
  78. <el-pagination
  79. background
  80. @size-change="handleSizeChange"
  81. @current-change="handleCurrentChange"
  82. layout="total, sizes,prev, pager, next,jumper"
  83. :page-size="listQuery.pageSize"
  84. :page-sizes="[5,10,15]"
  85. :current-page.sync="listQuery.pageNum"
  86. :total="total">
  87. </el-pagination>
  88. </div>
  89. </div>
  90. </template>
  91. <script>
  92. import {fetchList, deleteProductAttr} from '@/api/productAttr'
  93. export default {
  94. name: 'productAttrList',
  95. data() {
  96. return {
  97. list: null,
  98. total: null,
  99. listLoading: true,
  100. listQuery: {
  101. pageNum: 1,
  102. pageSize: 5,
  103. type: this.$route.query.type
  104. },
  105. operateType: null,
  106. multipleSelection: [],
  107. operates: [
  108. {
  109. label: "删除",
  110. value: "deleteProductAttr"
  111. }
  112. ]
  113. }
  114. },
  115. created() {
  116. this.getList();
  117. },
  118. methods: {
  119. getList() {
  120. this.listLoading = true;
  121. fetchList(this.$route.query.cid, this.listQuery).then(response => {
  122. this.listLoading = false;
  123. this.list = response.data.list;
  124. this.total = response.data.total;
  125. });
  126. },
  127. addProductAttr() {
  128. this.$router.push({path:'/pms/addProductAttr',query:{cid:this.$route.query.cid,type:this.$route.query.type}});
  129. },
  130. handleSelectionChange(val) {
  131. this.multipleSelection = val;
  132. },
  133. handleBatchOperate() {
  134. if (this.multipleSelection < 1) {
  135. this.$message({
  136. message: '请选择一条记录',
  137. type: 'warning',
  138. duration: 1000
  139. });
  140. return;
  141. }
  142. if (this.operateType !== 'deleteProductAttr') {
  143. this.$message({
  144. message: '请选择批量操作类型',
  145. type: 'warning',
  146. duration: 1000
  147. });
  148. return;
  149. }
  150. let ids = [];
  151. for (let i = 0; i < this.multipleSelection.length; i++) {
  152. ids.push(this.multipleSelection[i].id);
  153. }
  154. this.handleDeleteProductAttr(ids);
  155. },
  156. handleSizeChange(val) {
  157. this.listQuery.pageNum = 1;
  158. this.listQuery.pageSize = val;
  159. this.getList();
  160. },
  161. handleCurrentChange(val) {
  162. this.listQuery.pageNum = val;
  163. this.getList();
  164. },
  165. handleUpdate(index, row) {
  166. this.$router.push({path:'/pms/updateProductAttr',query:{id:row.id}});
  167. },
  168. handleDeleteProductAttr(ids) {
  169. this.$confirm('是否要删除该属性', '提示', {
  170. confirmButtonText: '确定',
  171. cancelButtonText: '取消',
  172. type: 'warning'
  173. }).then(() => {
  174. // let data = new URLSearchParams();
  175. // data.append("ids", ids);
  176. let obj = {
  177. ids:ids.join(',')
  178. }
  179. deleteProductAttr(obj).then(response => {
  180. this.$message({
  181. message: '删除成功',
  182. type: 'success',
  183. duration: 1000
  184. });
  185. this.getList();
  186. });
  187. });
  188. },
  189. handleDelete(index, row) {
  190. let ids = [];
  191. ids.push(row.id);
  192. this.handleDeleteProductAttr(ids);
  193. },
  194. },
  195. filters: {
  196. inputTypeFilter(value) {
  197. if (value === 1) {
  198. return '从列表中选取';
  199. } else {
  200. return '手工录入'
  201. }
  202. },
  203. selectTypeFilter(value) {
  204. if (value === 1) {
  205. return '单选';
  206. } else if (value === 2) {
  207. return '多选';
  208. } else {
  209. return '唯一'
  210. }
  211. },
  212. }
  213. }
  214. </script>
  215. <style rel="stylesheet/scss" lang="scss" scoped>
  216. </style>