index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <zj-tab-page ref="tabPage" :defaultActives="[{ key: 'list', label: $route.meta.title+'-列表', essential: true }]">
  3. <template slot-scope="{activeKey, data}">
  4. <div v-if="activeKey == 'list'" class="app-container">
  5. <div class="mymain-container">
  6. <div class="btn-group clearfix">
  7. <div class="fl">
  8. <el-button v-if="$restrict('add')" size="small" type="primary" icon="el-icon-plus"
  9. @click="openForm('add1')">添加</el-button>
  10. </div>
  11. </div>
  12. <div class="table">
  13. <el-table :data="dataList" row-key="categoryId" border default-expand-all :tree-props="{ children: 'child' }">
  14. <el-table-column prop="categoryName" label="分类名称" min-width="150"></el-table-column>
  15. <el-table-column align="center" label="状态" class-name="status-col">
  16. <template slot-scope="scope">
  17. <el-tag :type="scope.row.status ? 'success' : 'danger'">{{ ({ ON: '启用', OFF: '禁用' })[scope.row.status]
  18. }}</el-tag>
  19. </template>
  20. </el-table-column>
  21. <el-table-column align="center" prop="sort" label="排序"></el-table-column>
  22. <el-table-column align="right" label="操作" width="120" fixed="right">
  23. <template slot-scope="scope">
  24. <el-button v-if="scope.row.parentCategoryId == 0 && $restrict('add')" type="primary" size="mini"
  25. icon="el-icon-plus" @click="openForm('add2',scope.row)"></el-button>
  26. <el-button v-if="$restrict('edit')" type="primary" size="mini" icon="el-icon-edit"
  27. @click="openForm(scope.row.parentCategoryId == 0?'edit1':'edit2',scope.row)"></el-button>
  28. </template>
  29. </el-table-column>
  30. </el-table>
  31. </div>
  32. </div>
  33. </div>
  34. <div v-if="~['add1', 'add2', 'edit1', 'edit2'].indexOf(activeKey)">
  35. <zj-form-container ref="formRef" :form-data="formData" :styleSwitch="false">
  36. <zj-form-module :title="formDialogTitles[formDialogType]" label-width="100px" :showPackUp="false"
  37. :form-data="formData" :form-items="formItems">
  38. </zj-form-module>
  39. </zj-form-container>
  40. <div slot="footer" class="dialog-footer">
  41. <el-button size="mini" @click="formCancel;data.removeTab()">取 消</el-button>
  42. <el-button size="mini" @click="formConfirm(data.removeTab)" type="primary">确 定</el-button>
  43. </div>
  44. </div>
  45. </template>
  46. </zj-tab-page>
  47. </template>
  48. <script>
  49. import { getToken } from '@/utils/auth'
  50. import { getClassifyList, addClassify, editClassify, deleteClassify, getClassifyDetail, getSmallType } from '@/api/goods'
  51. import { ORDER_MAIN_TYPE } from "@/utils/select_data";
  52. import { materialCategoryList, materialCategoryAdd, materialCategoryUpdate, materialCategoryTree } from "@/api/auxiliaryMaterialClass";
  53. import { required, mobileRequired, mobile } from '@/components/template/rules_verify.js'
  54. export default {
  55. data() {
  56. return {
  57. dataList: [], // 列表数据
  58. screenForm: { // 筛选表单数据
  59. keyword: '', // 关键词
  60. },
  61. formDialogType: 0,
  62. formDialogTitles: ["新增", "编辑"],
  63. formDialog: false,
  64. formData: {
  65. companyWechatName: JSON.parse(localStorage.getItem('greemall_user')).companyName,
  66. status: "ON",
  67. parentCategoryId: "",
  68. categoryName: "",
  69. sort: "",
  70. categoryLevel: 2
  71. },
  72. materialCategoryList: [],
  73. formType: 'add',
  74. formVisible: false,
  75. }
  76. },
  77. computed: {
  78. // 更多参数
  79. moreParameters() {
  80. return []
  81. },
  82. formItems() {
  83. return [
  84. {
  85. md: 6,
  86. isShow: true,
  87. name: 'el-input',
  88. attributes: { placeholder: '请输入', disabled: true },
  89. formItemAttributes: {
  90. label: '所属商户',
  91. prop: 'companyWechatName',
  92. rules: []
  93. }
  94. },
  95. ...(() => {
  96. if (this.formData.categoryLevel == 2) {
  97. return [{
  98. md: 6,
  99. isShow: true,
  100. name: 'el-select',
  101. options: [...this.materialCategoryList, { categoryName: "无", categoryId: "0" }],
  102. labelKey: "categoryName",
  103. valueKey: "categoryId",
  104. attributes: { placeholder: '请输入', disabled: this.formDialogType != 0 },
  105. formItemAttributes: {
  106. label: '父级分类',
  107. prop: 'parentCategoryId',
  108. rules: []
  109. },
  110. events: {
  111. change: (val) => {
  112. if (val && val != 0) {
  113. this.formData.parentCategoryName = this.materialCategoryList.find(item => item.categoryId == val).categoryName
  114. } else {
  115. this.formData.parentCategoryName = ""
  116. }
  117. console.log(val)
  118. }
  119. }
  120. }]
  121. }
  122. return []
  123. })(),
  124. {
  125. md: 6,
  126. isShow: true,
  127. name: 'el-input',
  128. attributes: { placeholder: '请输入' },
  129. formItemAttributes: {
  130. label: '分类名称',
  131. prop: 'categoryName',
  132. rules: [...required]
  133. }
  134. }, {
  135. md: 6,
  136. isShow: true,
  137. name: 'el-radio',
  138. options: [{ label: "启用", value: "ON" }, { label: "禁用", value: "OFF" }],
  139. attributes: {},
  140. formItemAttributes: {
  141. label: '状态',
  142. prop: 'status',
  143. rules: [...required]
  144. },
  145. }, {
  146. md: 6,
  147. isShow: true,
  148. name: 'el-input',
  149. attributes: { placeholder: '请输入' },
  150. formItemAttributes: {
  151. label: '排序',
  152. prop: 'sort',
  153. rules: []
  154. }
  155. },
  156. ]
  157. }
  158. },
  159. created() {
  160. this.getList();
  161. },
  162. methods: {
  163. getList() {
  164. materialCategoryTree().then(res => {
  165. this.dataList = res.data
  166. })
  167. },
  168. openForm(type,row) {
  169. this.$refs.tabPage.addTab({
  170. // 对应显示的模块
  171. activeKey: type,
  172. // 唯一标识
  173. key: type,
  174. // 页签名称
  175. label: ({ edit1: "编辑一级分类", add1: "添加一级分类", edit2: "编辑二级分类", add2: "添加二级分类" })[type],
  176. // 打开时事件
  177. triggerEvent: () => {
  178. this.$nextTick(()=>{
  179. this.formType = type
  180. this.formVisible = true
  181. Promise.all([
  182. materialCategoryList({ "pageNum": 1, "pageSize": -1, "params": [{ "param": "a.status", "compare": "=", "value": "ON" }, { "param": "a.category_level", "compare": "=", "value": "1" }] })
  183. ]).then(([res1]) => {
  184. this.materialCategoryList = res1.data.records
  185. this.formDialog = true;
  186. })
  187. if(type == 'add1'){
  188. this.formDialogType = 0
  189. }else if(type == 'add2'){
  190. Object.assign(this.formData, {
  191. parentCategoryId: row.categoryId
  192. })
  193. }else if(type == 'edit1'){
  194. Object.assign(this.formData, row)
  195. this.formDialogType = 1
  196. }else if(type == 'edit2'){
  197. Object.assign(this.formData, row)
  198. this.formDialogType = 1
  199. }
  200. })
  201. },
  202. // 关闭时事件
  203. closeEvent: () => {
  204. this.formCancel()
  205. }
  206. })
  207. },
  208. formCancel() {
  209. this.formVisible = false
  210. this.$refs?.formRef?.resetFields()
  211. this.$data.formData = this.$options.data().formData
  212. },
  213. formConfirm(cancel) {
  214. this.$refs.formRef.validate((valid, invalidFields, errLabels) => {
  215. if (valid) {
  216. ([materialCategoryAdd, materialCategoryUpdate][this.formDialogType])({
  217. ...this.formData,
  218. categoryLevel: !this.formData.parentCategoryId || this.formData.parentCategoryId == 0 ? 1 : 2
  219. }).then(res => {
  220. this.$message({ type: 'success', message: `${this.formDialogTitles[this.formDialogType]}成功!` })
  221. cancel('list')
  222. this.getList();
  223. })
  224. }
  225. })
  226. }
  227. }
  228. }
  229. </script>
  230. <style scoped lang="scss"></style>
  231. <style lang="scss">
  232. .el-image-viewer__wrapper .el-icon-circle-close {
  233. color: #ffffff !important;
  234. font-size: 60px;
  235. }
  236. .el-table__row.expanded {
  237. background: #f5f5f5;
  238. }
  239. th:first-child,
  240. th:last-child {
  241. text-align: center !important;
  242. }
  243. </style>