index.vue 7.2 KB

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