index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <div id="">
  3. <search-box-new
  4. ref="searchBox"
  5. :formData="formData"
  6. :formList="formList"
  7. @search="search"
  8. @init="init"
  9. />
  10. <table-list
  11. rowKey="categoryId"
  12. ref="tableList"
  13. :tableSets="tableSet"
  14. :tableData="tableData"
  15. :navText="navText"
  16. :loading="loading"
  17. @addClick="addClick"
  18. >
  19. <template slot="customize">
  20. <el-button type="warning" @click="remove"> 批量删除 </el-button>
  21. </template>
  22. <template slot="status" slot-scope="props">
  23. <el-switch
  24. v-model="props.scope.row.status"
  25. active-color="#13ce66"
  26. inactive-color="#ff4949"
  27. :active-value="1"
  28. :inactive-value="0"
  29. @change="statusChange($event, props.scope.row)"
  30. >
  31. </el-switch>
  32. </template>
  33. <template slot="btn" slot-scope="props">
  34. <el-button type="text" @click="addClick(props.scope.row, 1)"
  35. >编辑</el-button
  36. ><el-button type="text" @click="addClick(props.scope.row, 2)"
  37. >添加</el-button
  38. ><el-button type="text" @click="del(props.scope.row)">删除</el-button>
  39. </template>
  40. </table-list>
  41. <pagination
  42. :total="total"
  43. :pageSize.sync="formData.pageSize"
  44. :currentPage.sync="formData.pageNum"
  45. @search="search"
  46. />
  47. <dislog
  48. :dialogVisible.sync="dialogVisible"
  49. @search="search"
  50. :treeData="treeData"
  51. ></dislog>
  52. </div>
  53. </template>
  54. <script>
  55. import { mapGetters } from "vuex";
  56. import dislog from "./dislog.vue";
  57. import searchBoxNew from "@/components/searchBoxNew";
  58. import tableList from "@/components/tableList";
  59. import pagination from "@/components/pagination";
  60. export default {
  61. name: "GoodsClassification",
  62. components: { searchBoxNew, tableList, pagination, dislog },
  63. data() {
  64. return {
  65. loading: false,
  66. navText: {
  67. title: "商品分类",
  68. index: 0,
  69. ch: "条",
  70. num: true,
  71. choice: true,
  72. addHide: false,
  73. custom: false,
  74. openCheckMore: true,
  75. },
  76. formList: [
  77. {
  78. prop: "merId",
  79. placeholder: "请选择合作商户",
  80. scope: "merList",
  81. },
  82. {
  83. prop: "storeId",
  84. placeholder: "请选择商户店铺",
  85. scope: "storeList",
  86. },
  87. {
  88. prop: "storeName",
  89. placeholder: "输入分类名称",
  90. },
  91. ],
  92. formData: {},
  93. tableSet: [
  94. {
  95. label: "分类名称",
  96. prop: "categoryName",
  97. hidden: true,
  98. },
  99. {
  100. label: "合作商户",
  101. prop: "merName",
  102. hidden: true,
  103. },
  104. {
  105. label: "商户店铺",
  106. prop: "storeName",
  107. hidden: true,
  108. },
  109. {
  110. label: "启用状态",
  111. prop: "status",
  112. hidden: true,
  113. scope: "slot",
  114. slotName: "status",
  115. },
  116. {
  117. label: "创建时间",
  118. prop: "createTime",
  119. hidden: true,
  120. scope: "aTimeList",
  121. },
  122. ],
  123. tableData: [],
  124. total: 0,
  125. dialogVisible: false,
  126. treeData: {},
  127. };
  128. },
  129. created() {
  130. this.search(2);
  131. },
  132. methods: {
  133. remove() {
  134. if (this.$refs.tableList.allCheckData.length === 0) {
  135. this.$message.error("请勾选数据");
  136. return;
  137. }
  138. this.$confirm("确定批量删除选中的数据吗?", "提示", {
  139. confirmButtonText: "确定",
  140. cancelButtonText: "取消",
  141. type: "warning",
  142. })
  143. .then(() => {
  144. this.$api
  145. .mallgoodscategorybatchdel(
  146. this.$refs.tableList.allCheckData.map((i) => i.categoryId)
  147. )
  148. .then(() => {
  149. this.$message.success("批量删除成功");
  150. this.$store.commit("CATEGORYTREELIST");
  151. this.search(3);
  152. });
  153. })
  154. .catch(() => {});
  155. },
  156. addClick(data, status) {
  157. if (data) {
  158. var datas = JSON.parse(JSON.stringify(data));
  159. if (status === 2) {
  160. datas.parentId = datas.categoryId;
  161. datas.categoryId = null;
  162. datas.categoryName = null;
  163. datas.status = 1;
  164. }
  165. this.treeData = datas;
  166. } else {
  167. this.treeData = {
  168. merId: "",
  169. storeId: "",
  170. parentId: "",
  171. categoryName: "",
  172. status: 1,
  173. };
  174. }
  175. this.dialogVisible = true;
  176. },
  177. search(v) {
  178. this.loading = true;
  179. if (v === 2) {
  180. this.formData = {
  181. pageSize: 10,
  182. pageNum: 1,
  183. status: "0,1",
  184. };
  185. this.$nextTick(() => {
  186. this.$refs.tableList.clearMoreActive();
  187. });
  188. }
  189. if (v === 3) {
  190. this.$nextTick(() => {
  191. this.$refs.tableList.clearMoreActive();
  192. });
  193. }
  194. this.$api
  195. .mallgoodscategorylist(this.formData)
  196. .then((res) => {
  197. this.tableData = res.rows;
  198. this.total = res.total;
  199. this.navText.index = res.total;
  200. })
  201. .finally(() => {
  202. this.loading = false;
  203. });
  204. },
  205. statusChange(e, row) {
  206. this.$api
  207. .editmallgoodscategorysave({ categoryId: row.categoryId, status: e })
  208. .then((res) => {
  209. this.$message.success("操作成功");
  210. this.$store.commit("CATEGORYTREELIST");
  211. row.status = e;
  212. })
  213. .catch(() => {
  214. return (row.status = e ? 0 : 1);
  215. });
  216. },
  217. init() {
  218. this.search(2);
  219. },
  220. del(v) {
  221. this.$confirm("确定删除此内容?", "提示", {
  222. confirmButtonText: "确定",
  223. cancelButtonText: "取消",
  224. type: "warning",
  225. })
  226. .then(() => {
  227. this.$api.mallgoodscategorybatchdel([v.categoryId]).then((res) => {
  228. this.$message.success("删除成功");
  229. this.$store.commit("CATEGORYTREELIST");
  230. this.search(3);
  231. });
  232. })
  233. .catch(() => {});
  234. },
  235. },
  236. };
  237. </script>
  238. <style lang="scss" scoped></style>