index.vue 7.4 KB

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