Browse Source

门类判断类型 是否可创建 类型可选

master
xuhuajiao 3 years ago
parent
commit
683cef586f
  1. 36
      src/views/category/form.vue
  2. 11
      src/views/category/index.vue

36
src/views/category/form.vue

@ -10,7 +10,7 @@
</el-form-item> </el-form-item>
<el-form-item label="门类类型" prop="isType"> <el-form-item label="门类类型" prop="isType">
<el-select v-model="form.isType" style="width: 370px;" :disabled="crud.status.edit === 1" @change="changeType"> <el-select v-model="form.isType" style="width: 370px;" :disabled="crud.status.edit === 1" @change="changeType">
<el-option v-for="item in selectOptions" :key="item.value" :label="item.label" :value="item.value" />
<el-option v-for="item in selectOptions" :key="item.value" :label="item.label" :value="item.value" :disabled="item.typeState" />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item v-if="crud.status.add === 1" label="选择模板" prop="dicExplain"> <el-form-item v-if="crud.status.add === 1" label="选择模板" prop="dicExplain">
@ -30,7 +30,7 @@
<script> <script>
import { getCategoryTree, getCategoryType } from '@/api/category/category' import { getCategoryTree, getCategoryType } from '@/api/category/category'
import { form } from '@crud/crud'
import CRUD, { form } from '@crud/crud'
import Treeselect from '@riophae/vue-treeselect' import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css' import '@riophae/vue-treeselect/dist/vue-treeselect.css'
@ -42,6 +42,14 @@ export default {
return Object.assign({ pid: this.pid }, defaultForm) return Object.assign({ pid: this.pid }, defaultForm)
}) })
], ],
props: {
selectedCategory: {
type: Object,
default: function() {
return {}
}
}
},
data() { data() {
return { return {
pid: null, pid: null,
@ -58,6 +66,27 @@ export default {
this.getSelectOptions() this.getSelectOptions()
}, },
methods: { methods: {
// option
[CRUD.HOOK.beforeToAdd]() {
this.form.isType = null
this.selectOptions.forEach(item => {
if (this.selectedCategory.isType === 2) {
if (item.value !== 3) {
item.typeState = true
}
} else if (this.selectedCategory.isType === 3) {
if (item.value !== 4) {
item.typeState = true
}
}
})
},
//
[CRUD.HOOK.beforeAddCancel]() {
this.selectOptions.forEach(item => {
item.typeState = false
})
},
changeType() { changeType() {
if (this.form.isType === 6) { if (this.form.isType === 6) {
// this.crudDict.getDicts() // this.crudDict.getDicts()
@ -74,7 +103,8 @@ export default {
for (const key in res) { for (const key in res) {
this.selectOptions.push({ this.selectOptions.push({
value: Number(key), value: Number(key),
label: res[key]
label: res[key],
typeState: false
}) })
} }
}) })

11
src/views/category/index.vue

@ -1,7 +1,7 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<!--修改新增表单组件--> <!--修改新增表单组件-->
<eForm ref="eform" />
<eForm ref="eform" :selected-category="selectedCategory" />
<el-dialog title="确认删除" :visible.sync="deleteVisible" :before-close="handleClose"> <el-dialog title="确认删除" :visible.sync="deleteVisible" :before-close="handleClose">
<span class="dialog-right-top" /> <span class="dialog-right-top" />
<span class="dialog-left-bottom" /> <span class="dialog-left-bottom" />
@ -195,9 +195,18 @@ export default {
if (val.isType === 1 || val.isType === 2) { if (val.isType === 1 || val.isType === 2) {
this.changeActiveTab(0) this.changeActiveTab(0)
} }
//
localStorage.setItem('currentCategoryKey', JSON.stringify(val)) localStorage.setItem('currentCategoryKey', JSON.stringify(val))
} }
}, },
// - /
[CRUD.HOOK.beforeToAdd](crud, form, btn) {
const isCanAddKey = JSON.parse(localStorage.getItem('currentCategoryKey'))
if (isCanAddKey.isType === 4 || isCanAddKey.isType === 5) {
this.$message.error('此门类下不可新建门类')
return false
}
},
updateKeyChildren(data) { updateKeyChildren(data) {
const oldDatas = this.$refs.tree.getCurrentNode().children const oldDatas = this.$refs.tree.getCurrentNode().children
if (oldDatas) { if (oldDatas) {

Loading…
Cancel
Save