index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. v-if="createproductCategory"
  8. class="btn-add"
  9. @click="handleAddProductCate()"
  10. size="mini">
  11. 添加
  12. </el-button>
  13. </el-card>
  14. <div class="table-container">
  15. <el-table ref="productCateTable"
  16. style="width: 100%"
  17. :data="list"
  18. v-loading="listLoading" border>
  19. <el-table-column label="编号" width="100" align="center">
  20. <template slot-scope="scope">{{scope.row.id}}</template>
  21. </el-table-column>
  22. <el-table-column label="分类名称" align="center">
  23. <template slot-scope="scope">{{scope.row.name}}</template>
  24. </el-table-column>
  25. <el-table-column label="级别" width="100" align="center">
  26. <template slot-scope="scope">{{scope.row.level | levelFilter}}</template>
  27. </el-table-column>
  28. <el-table-column label="商品数量" width="100" align="center">
  29. <template slot-scope="scope">{{scope.row.productCount }}</template>
  30. </el-table-column>
  31. <el-table-column label="数量单位" width="100" align="center">
  32. <template slot-scope="scope">{{scope.row.productUnit }}</template>
  33. </el-table-column>
  34. <el-table-column label="导航栏" width="100" align="center">
  35. <template slot-scope="scope">
  36. <el-switch
  37. @change="handleNavStatusChange(scope.$index, scope.row)"
  38. :active-value="1"
  39. :inactive-value="0"
  40. v-model="scope.row.navStatus">
  41. </el-switch>
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="是否显示" width="100" align="center">
  45. <template slot-scope="scope">
  46. <el-switch
  47. @change="handleShowStatusChange(scope.$index, scope.row)"
  48. :active-value="1"
  49. :inactive-value="0"
  50. v-model="scope.row.showStatus">
  51. </el-switch>
  52. </template>
  53. </el-table-column>
  54. <el-table-column label="排序" width="100" align="center">
  55. <template slot-scope="scope">{{scope.row.sort }}</template>
  56. </el-table-column>
  57. <el-table-column label="设置" width="200" align="center">
  58. <template slot-scope="scope">
  59. <el-button
  60. size="mini"
  61. :disabled="scope.row.level | disableNextLevel"
  62. @click="handleShowNextLevel(scope.$index, scope.row)">查看下级
  63. </el-button>
  64. <!-- <el-button
  65. size="mini"
  66. @click="handleTransferProduct(scope.$index, scope.row)">转移商品
  67. </el-button> -->
  68. </template>
  69. </el-table-column>
  70. <el-table-column label="操作" width="200" align="center">
  71. <template slot-scope="scope">
  72. <el-button
  73. v-if="updateproductCategory"
  74. size="mini"
  75. @click="handleUpdate(scope.$index, scope.row)">编辑
  76. </el-button>
  77. <el-button
  78. v-if="deleteproductCategory"
  79. size="mini"
  80. type="danger"
  81. @click="handleDelete(scope.$index, scope.row)">删除
  82. </el-button>
  83. </template>
  84. </el-table-column>
  85. </el-table>
  86. </div>
  87. <div class="pagination-container">
  88. <el-pagination
  89. background
  90. @size-change="handleSizeChange"
  91. @current-change="handleCurrentChange"
  92. layout="total, sizes,prev, pager, next,jumper"
  93. :page-size="listQuery.pageSize"
  94. :page-sizes="[5,10,15]"
  95. :current-page.sync="listQuery.pageNum"
  96. :total="total">
  97. </el-pagination>
  98. </div>
  99. </div>
  100. </template>
  101. <script>
  102. import {fetchList,deleteProductCate,updateShowStatus,updateNavStatus} from '@/api/productCate'
  103. import {createproductCategory,deleteproductCategory,updateproductCategory} from '@/api/permissions'
  104. export default {
  105. name: "productCateList",
  106. data() {
  107. return {
  108. createproductCategory,
  109. deleteproductCategory,
  110. updateproductCategory,
  111. list: null,
  112. total: null,
  113. listLoading: true,
  114. listQuery: {
  115. pageNum: 1,
  116. pageSize: 5
  117. },
  118. parentId: 0
  119. }
  120. },
  121. created() {
  122. this.resetParentId();
  123. this.getList();
  124. },
  125. watch: {
  126. $route(route) {
  127. this.resetParentId();
  128. this.getList();
  129. }
  130. },
  131. methods: {
  132. resetParentId(){
  133. this.listQuery.pageNum = 1;
  134. if (this.$route.query.parentId != null) {
  135. this.parentId = this.$route.query.parentId;
  136. } else {
  137. this.parentId = 0;
  138. }
  139. },
  140. handleAddProductCate() {
  141. this.$router.push('/pms/addProductCate');
  142. },
  143. getList() {
  144. this.listLoading = true;
  145. fetchList(this.parentId, this.listQuery).then(response => {
  146. this.listLoading = false;
  147. this.list = response.data.list;
  148. this.total = response.data.total;
  149. });
  150. },
  151. handleSizeChange(val) {
  152. this.listQuery.pageNum = 1;
  153. this.listQuery.pageSize = val;
  154. this.getList();
  155. },
  156. handleCurrentChange(val) {
  157. this.listQuery.pageNum = val;
  158. this.getList();
  159. },
  160. handleNavStatusChange(index, row) {
  161. let data = new URLSearchParams();
  162. let ids=[];
  163. ids.push(row.id)
  164. data.append('ids',ids);
  165. data.append('navStatus',row.navStatus);
  166. updateNavStatus(data).then(response=>{
  167. this.$message({
  168. message: '修改成功',
  169. type: 'success',
  170. duration: 1000
  171. });
  172. });
  173. },
  174. handleShowStatusChange(index, row) {
  175. let data = new URLSearchParams();
  176. let ids=[];
  177. ids.push(row.id)
  178. data.append('ids',ids);
  179. data.append('showStatus',row.showStatus);
  180. updateShowStatus(data).then(response=>{
  181. this.$message({
  182. message: '修改成功',
  183. type: 'success',
  184. duration: 1000
  185. });
  186. });
  187. },
  188. handleShowNextLevel(index, row) {
  189. this.$router.push({path: '/pms/productCate', query: {parentId: row.id}})
  190. },
  191. handleTransferProduct(index, row) {
  192. console.log('handleAddProductCate');
  193. },
  194. handleUpdate(index, row) {
  195. this.$router.push({path:'/pms/updateProductCate',query:{id:row.id}});
  196. },
  197. handleDelete(index, row) {
  198. this.$confirm('是否要删除该品牌', '提示', {
  199. confirmButtonText: '确定',
  200. cancelButtonText: '取消',
  201. type: 'warning'
  202. }).then(() => {
  203. deleteProductCate(row.id).then(response => {
  204. this.$message({
  205. message: '删除成功',
  206. type: 'success',
  207. duration: 1000
  208. });
  209. this.getList();
  210. });
  211. });
  212. }
  213. },
  214. filters: {
  215. levelFilter(value) {
  216. if (value === 0) {
  217. return '一级';
  218. } else if (value === 1) {
  219. return '二级';
  220. }
  221. },
  222. disableNextLevel(value) {
  223. if (value === 0) {
  224. return false;
  225. } else {
  226. return true;
  227. }
  228. }
  229. }
  230. }
  231. </script>
  232. <style scoped>
  233. </style>