shopCategory.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <div class="m-container">
  3. <h2>
  4. <div class="squrt"></div>
  5. 商品分类管理
  6. </h2>
  7. <div class="m-core">
  8. <el-button
  9. v-permission="'category/upset'"
  10. @click="openTypes('create')"
  11. type="primary"
  12. style="margin-bottom:20px"
  13. >
  14. 添加
  15. </el-button>
  16. <!-- 列表 -->
  17. <div class="tableWrap">
  18. <el-table
  19. :data="tableList"
  20. :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
  21. >
  22. <el-table-column align="center" prop="name" label="分类名称">
  23. </el-table-column>
  24. <el-table-column align="center" label="声部属性">
  25. <template slot-scope="scope">
  26. <overflow-text
  27. width="100%"
  28. :text="scope.row.subjectName | joinArray(',')"
  29. ></overflow-text>
  30. </template>
  31. </el-table-column>
  32. <el-table-column align="center" label="操作">
  33. <template slot-scope="scope">
  34. <el-button
  35. @click="openTypes('update', scope.row)"
  36. v-permission="'category/upset'"
  37. type="text"
  38. >修改</el-button
  39. >
  40. <el-button
  41. @click="onTypesDelOpeation(scope.row)"
  42. v-permission="'category/del'"
  43. type="text"
  44. >删除</el-button
  45. >
  46. </template>
  47. </el-table-column>
  48. </el-table>
  49. <pagination
  50. sync
  51. :total.sync="pageInfo.total"
  52. :page.sync="pageInfo.page"
  53. :limit.sync="pageInfo.limit"
  54. :page-sizes="pageInfo.page_size"
  55. @pagination="getList"
  56. />
  57. </div>
  58. </div>
  59. <el-dialog
  60. :title="formTitle[formActionTitle]"
  61. :visible.sync="typeStatus"
  62. @close="onFormClose('ruleForm')"
  63. width="500px"
  64. >
  65. <el-form :model="form" :rules="rules" ref="ruleForm">
  66. <el-form-item
  67. label="商品分类名称"
  68. prop="name"
  69. :label-width="formLabelWidth"
  70. >
  71. <el-input v-model.trim="form.name" autocomplete="off"></el-input>
  72. </el-form-item>
  73. <el-form-item
  74. label="声部属性"
  75. v-if="form.classGroupType != 'MIX'"
  76. prop="subjectIds"
  77. :label-width="formLabelWidth"
  78. >
  79. <select-all
  80. v-model.trim="form.subjectIds"
  81. clearable
  82. filterable
  83. multiple
  84. >
  85. <!-- <el-select > -->
  86. <el-option-group
  87. v-for="group in subjectList"
  88. :key="group.id"
  89. :label="group.label"
  90. >
  91. <el-option
  92. v-for="item in group.options"
  93. :key="item.value"
  94. :label="item.label"
  95. :value="item.value"
  96. >
  97. </el-option>
  98. </el-option-group>
  99. </select-all>
  100. <!-- </el-select> -->
  101. </el-form-item>
  102. </el-form>
  103. <span slot="footer" class="dialog-footer">
  104. <el-button @click="typeStatus = false">取 消</el-button>
  105. <el-button type="primary" @click="onTypesSubmit('ruleForm')"
  106. >确 定</el-button
  107. >
  108. </span>
  109. </el-dialog>
  110. </div>
  111. </template>
  112. <script>
  113. import pagination from "@/components/Pagination/index";
  114. import store from "@/store";
  115. import { subjectListTree } from "@/api/specialSetting";
  116. import {
  117. categoryListTree,
  118. categoryUpSet,
  119. categoryUpSetDel
  120. } from "@/api/businessManager";
  121. export default {
  122. components: { pagination },
  123. name: "shopCategory",
  124. data() {
  125. return {
  126. tableList: [],
  127. subjectList: [], // 声部列表
  128. formActionTitle: "create",
  129. formTitle: {
  130. create: "添加商品分类",
  131. update: "修改商品分类"
  132. },
  133. typeStatus: false, // 添加教学点
  134. formLabelWidth: "120px",
  135. form: {
  136. name: null, // 训练模块名称
  137. subjectIds: []
  138. },
  139. rules: {
  140. name: [{ required: true, message: "请输入类型名称", trigger: "blur" }],
  141. subjectIds: [
  142. { required: true, message: "请选择声部组合", trigger: "change" }
  143. ]
  144. },
  145. pageInfo: {
  146. // 分页规则
  147. limit: 10, // 限制显示条数
  148. page: 1, // 当前页
  149. total: 0, // 总条数
  150. page_size: [10, 20, 40, 50] // 选择限制显示条数
  151. }
  152. };
  153. },
  154. mounted() {
  155. this.getList();
  156. this.getSubjectTree();
  157. },
  158. methods: {
  159. onTypesDelOpeation(row) {
  160. this.$confirm("您确定删除该分类?", "提示", {
  161. confirmButtonText: "确定",
  162. cancelButtonText: "取消",
  163. type: "warning"
  164. }).then(() => {
  165. categoryUpSetDel({ id: row.id }).then(res => {
  166. this.messageTips("删除", res);
  167. });
  168. });
  169. },
  170. onTypesSubmit(formName) {
  171. // 添加数据
  172. this.$refs[formName].validate(valid => {
  173. if (valid) {
  174. if (this.formActionTitle == "create") {
  175. if (this.form.id) {
  176. // 判断有没有Id,如果有则删除
  177. delete this.form.id;
  178. }
  179. categoryUpSet(this.form).then(res => {
  180. this.messageTips("添加", res);
  181. });
  182. } else if (this.formActionTitle == "update") {
  183. categoryUpSet(this.form).then(res => {
  184. this.messageTips("修改", res);
  185. });
  186. }
  187. } else {
  188. return false;
  189. }
  190. });
  191. },
  192. messageTips(title, res) {
  193. if (res.code == 200) {
  194. this.$message.success(title + "成功");
  195. this.typeStatus = false;
  196. this.getList();
  197. } else {
  198. this.$message.error(res.msg);
  199. }
  200. },
  201. getList() {
  202. categoryListTree({
  203. delFlag: 0,
  204. rows: this.pageInfo.limit,
  205. page: this.pageInfo.page
  206. }).then(res => {
  207. let result = res.data;
  208. if (res.code == 200) {
  209. result.rows.forEach(row => {
  210. let subjectname = [],
  211. subjectIds = [];
  212. (row.subjects || []).forEach(item => {
  213. subjectname.push(item.name);
  214. subjectIds.push(item.id);
  215. });
  216. row.subjectName = subjectname;
  217. row.subjectIds = subjectIds;
  218. });
  219. this.tableList = result.rows;
  220. this.pageInfo.total = result.total;
  221. }
  222. });
  223. },
  224. openTypes(type, row) {
  225. this.typeStatus = true;
  226. this.formActionTitle = type;
  227. // 修改的时候赋值
  228. if (type == "update") {
  229. this.form = {
  230. id: row.id,
  231. name: row.name,
  232. subjectIds: row.subjectIds
  233. };
  234. }
  235. },
  236. onFormClose(formName) {
  237. // 关闭弹窗重置验证
  238. this.form = {
  239. name: null, // 训练模块名称
  240. subjectIds: []
  241. };
  242. this.$refs[formName].resetFields();
  243. },
  244. getSubjectTree() {
  245. // 获取声部列表
  246. subjectListTree({
  247. delFlag: 0,
  248. rows: 9999
  249. }).then(res => {
  250. let result = res.data;
  251. if (res.code == 200) {
  252. let tempArray = [];
  253. result.rows.forEach((item, index) => {
  254. let subject = [];
  255. (item.subjects || []).forEach(s => {
  256. subject.push({
  257. value: s.id,
  258. label: s.name
  259. });
  260. });
  261. tempArray[index] = {
  262. label: item.name,
  263. options: subject
  264. };
  265. });
  266. this.subjectList = tempArray;
  267. }
  268. });
  269. }
  270. }
  271. };
  272. </script>
  273. <style lang="scss" scoped>
  274. ::v-deep .el-date-editor.el-input {
  275. width: 100% !important;
  276. }
  277. ::v-deep .el-select {
  278. width: 100% !important;
  279. }
  280. </style>