123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- <template>
- <zj-tab-page ref="tabPage" :defaultActives="[{ key: 'list', label: $route.meta.title+'-列表', essential: true }]">
- <template slot-scope="{activeKey, data}">
- <div v-if="activeKey == 'list'" class="app-container">
- <div class="mymain-container">
- <div class="btn-group clearfix">
- <div class="fl">
- <el-button v-if="$restrict('add')" size="small" type="primary" icon="el-icon-plus"
- @click="openForm('add1')">添加</el-button>
- </div>
- </div>
- <div class="table">
- <el-table :data="dataList" row-key="categoryId" border default-expand-all :tree-props="{ children: 'child' }">
- <el-table-column prop="categoryName" label="分类名称" min-width="150"></el-table-column>
- <el-table-column align="center" label="状态" class-name="status-col">
- <template slot-scope="scope">
- <el-tag :type="scope.row.status ? 'success' : 'danger'">{{ ({ ON: '启用', OFF: '禁用' })[scope.row.status]
- }}</el-tag>
- </template>
- </el-table-column>
- <el-table-column align="center" prop="sort" label="排序"></el-table-column>
- <el-table-column align="right" label="操作" width="120" fixed="right">
- <template slot-scope="scope">
- <el-button v-if="scope.row.parentCategoryId == 0 && $restrict('add')" type="primary" size="mini"
- icon="el-icon-plus" @click="openForm('add2',scope.row)"></el-button>
- <el-button v-if="$restrict('edit')" type="primary" size="mini" icon="el-icon-edit"
- @click="openForm(scope.row.parentCategoryId == 0?'edit1':'edit2',scope.row)"></el-button>
- </template>
- </el-table-column>
- </el-table>
- </div>
- </div>
- </div>
- <div v-if="~['add1', 'add2', 'edit1', 'edit2'].indexOf(activeKey)">
- <zj-form-container ref="formRef" :form-data="formData" :styleSwitch="false">
- <zj-form-module :title="formDialogTitles[formDialogType]" label-width="100px" :showPackUp="false"
- :form-data="formData" :form-items="formItems">
- </zj-form-module>
- </zj-form-container>
- <div slot="footer" class="dialog-footer">
- <el-button size="mini" @click="formCancel;data.removeTab()">取 消</el-button>
- <el-button size="mini" @click="formConfirm(data.removeTab)" type="primary">确 定</el-button>
- </div>
- </div>
- </template>
- </zj-tab-page>
- </template>
- <script>
- import { getToken } from '@/utils/auth'
- import { getClassifyList, addClassify, editClassify, deleteClassify, getClassifyDetail, getSmallType } from '@/api/goods'
- import { ORDER_MAIN_TYPE } from "@/utils/select_data";
- import { materialCategoryList, materialCategoryAdd, materialCategoryUpdate, materialCategoryTree } from "@/api/auxiliaryMaterialClass";
- import { required, mobileRequired, mobile } from '@/components/template/rules_verify.js'
- export default {
- data() {
- return {
- dataList: [], // 列表数据
- screenForm: { // 筛选表单数据
- keyword: '', // 关键词
- },
- formDialogType: 0,
- formDialogTitles: ["新增", "编辑"],
- formDialog: false,
- formData: {
- companyWechatName: JSON.parse(localStorage.getItem('greemall_user')).companyName,
- status: "ON",
- parentCategoryId: "",
- categoryName: "",
- sort: "",
- categoryLevel: 2
- },
- materialCategoryList: [],
- formType: 'add',
- formVisible: false,
- }
- },
- computed: {
- // 更多参数
- moreParameters() {
- return []
- },
- formItems() {
- return [
- {
- md: 6,
- isShow: true,
- name: 'el-input',
- attributes: { placeholder: '请输入', disabled: true },
- formItemAttributes: {
- label: '所属商户',
- prop: 'companyWechatName',
- rules: []
- }
- },
- ...(() => {
- if (this.formData.categoryLevel == 2) {
- return [{
- md: 6,
- isShow: true,
- name: 'el-select',
- options: [...this.materialCategoryList, { categoryName: "无", categoryId: "0" }],
- labelKey: "categoryName",
- valueKey: "categoryId",
- attributes: { placeholder: '请输入', disabled: this.formDialogType != 0 },
- formItemAttributes: {
- label: '父级分类',
- prop: 'parentCategoryId',
- rules: []
- },
- events: {
- change: (val) => {
- if (val && val != 0) {
- this.formData.parentCategoryName = this.materialCategoryList.find(item => item.categoryId == val).categoryName
- } else {
- this.formData.parentCategoryName = ""
- }
- console.log(val)
- }
- }
- }]
- }
- return []
- })(),
- {
- md: 6,
- isShow: true,
- name: 'el-input',
- attributes: { placeholder: '请输入' },
- formItemAttributes: {
- label: '分类名称',
- prop: 'categoryName',
- rules: [...required]
- }
- }, {
- md: 6,
- isShow: true,
- name: 'el-radio',
- options: [{ label: "启用", value: "ON" }, { label: "禁用", value: "OFF" }],
- attributes: {},
- formItemAttributes: {
- label: '状态',
- prop: 'status',
- rules: [...required]
- },
- }, {
- md: 6,
- isShow: true,
- name: 'el-input',
- attributes: { placeholder: '请输入' },
- formItemAttributes: {
- label: '排序',
- prop: 'sort',
- rules: []
- }
- },
- ]
- }
- },
- created() {
- this.getList();
- },
- methods: {
- getList() {
- materialCategoryTree().then(res => {
- this.dataList = res.data
- })
- },
- openForm(type,row) {
- this.$refs.tabPage.addTab({
- // 对应显示的模块
- activeKey: type,
- // 唯一标识
- key: type,
- // 页签名称
- label: ({ edit1: "编辑一级分类", add1: "添加一级分类", edit2: "编辑二级分类", add2: "添加二级分类" })[type],
- // 打开时事件
- triggerEvent: () => {
-
- this.$nextTick(()=>{
- this.formType = type
- this.formVisible = true
- Promise.all([
- materialCategoryList({ "pageNum": 1, "pageSize": -1, "params": [{ "param": "a.status", "compare": "=", "value": "ON" }, { "param": "a.category_level", "compare": "=", "value": "1" }] })
- ]).then(([res1]) => {
- this.materialCategoryList = res1.data.records
- this.formDialog = true;
- })
- if(type == 'add1'){
- this.formDialogType = 0
- }else if(type == 'add2'){
- Object.assign(this.formData, {
- parentCategoryId: row.categoryId
- })
- }else if(type == 'edit1'){
- Object.assign(this.formData, row)
- this.formDialogType = 1
- }else if(type == 'edit2'){
- Object.assign(this.formData, row)
- this.formDialogType = 1
- }
- })
- },
- // 关闭时事件
- closeEvent: () => {
- this.formCancel()
- }
- })
- },
- formCancel() {
- this.formVisible = false
- this.$refs?.formRef?.resetFields()
- this.$data.formData = this.$options.data().formData
- },
- formConfirm(cancel) {
- this.$refs.formRef.validate((valid, invalidFields, errLabels) => {
- if (valid) {
- ([materialCategoryAdd, materialCategoryUpdate][this.formDialogType])({
- ...this.formData,
- categoryLevel: !this.formData.parentCategoryId || this.formData.parentCategoryId == 0 ? 1 : 2
- }).then(res => {
- this.$message({ type: 'success', message: `${this.formDialogTitles[this.formDialogType]}成功!` })
- cancel('list')
- this.getList();
- })
- }
- })
- }
- }
- }
- </script>
- <style scoped lang="scss"></style>
- <style lang="scss">
- .el-image-viewer__wrapper .el-icon-circle-close {
- color: #ffffff !important;
- font-size: 60px;
- }
- .el-table__row.expanded {
- background: #f5f5f5;
- }
- th:first-child,
- th:last-child {
- text-align: center !important;
- }
- </style>
|