<template>
|
<GlobalWindow
|
:title="title"
|
:visible.sync="visible"
|
:confirm-working="isWorking"
|
@confirm="confirm"
|
>
|
<el-form :model="form" ref="form" :rules="rules">
|
<el-form-item label="分类类型:" prop="cateType">
|
<el-select v-model="form.cateType" placeholder="请选择分类类型" filterable clearable @change="seletType">
|
<el-option
|
v-for="item in types"
|
:key="item.id"
|
:label="item.name"
|
:value="item.id">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="所属大类:" prop="cateBigId">
|
<el-select v-model="form.cateBigId" @visible-change="visibleChange" placeholder="请选择" clearable filterable @change="selectBig">
|
<el-option
|
v-for="item in cateBig"
|
:key="item.value"
|
:label="item.name"
|
:value="item.id">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="所属中类:" prop="cateMiddleId">
|
<el-select v-model="form.cateMiddleId" placeholder="请选择" clearable filterable @change="selectMiddle">
|
<el-option
|
v-for="item in cateMiddle"
|
:key="item.value"
|
:label="item.name"
|
:value="item.id"
|
>
|
</el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="所属小类:" prop="cateSmallId">
|
<el-select v-model="form.cateSmallId" placeholder="请选择" clearable filterable @change="selectSmall">
|
<el-option
|
v-for="item in cateSmall"
|
:key="item.value"
|
:label="item.name"
|
:value="item.id">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="组合名称:" prop="combinationName">
|
<el-input v-model="form.combinationName" disabled placeholder="根据类型生产" v-trim/>
|
</el-form-item>
|
</el-form>
|
</GlobalWindow>
|
</template>
|
|
<script>
|
import BaseOpera from '@/components/base/BaseOpera'
|
import GlobalWindow from '@/components/common/GlobalWindow'
|
import { getListByType } from '@/api/ext/categoryExt'
|
export default {
|
name: 'OperaCategoryUnionExtWindow',
|
extends: BaseOpera,
|
components: { GlobalWindow },
|
data () {
|
return {
|
types: [
|
{ name: '物料', id: 0 },
|
{ name: '客户', id: 1 },
|
// { name: '工装器具', id: 2 },
|
// { name: '不良原因', id: 3 }
|
],
|
cateBig: [],
|
cateMiddle: [],
|
cateSmall: [],
|
// 表单数据
|
form: {
|
id: '',
|
cateType: 0,
|
cateBigId: '',
|
cateMiddleId: '',
|
cateSmallId: '',
|
combinationName: ''
|
},
|
// 验证规则
|
rules: {
|
cateType: [{ required: true, message: '请选择类型', trigger: 'chanage' }],
|
cateBigId: [{ required: true, message: '请选择大类', trigger: 'chnage' }]
|
// combinationName: [{ required: true, message: '', trigger: 'chnage' }]
|
}
|
}
|
},
|
created () {
|
this.config({
|
api: '/ext/categoryUnionExt',
|
'field.id': 'id'
|
})
|
this.getCategory(0)
|
},
|
methods: {
|
visibleChange(e) {
|
if (e) {
|
this.getCategory(0)
|
}
|
},
|
open (title, target) {
|
this.title = title
|
this.visible = true
|
// 新建
|
if (target == null) {
|
this.$nextTick(() => {
|
this.$refs.form.resetFields()
|
this.form[this.configData['field.id']] = null
|
})
|
return
|
}
|
// 编辑
|
this.$nextTick(() => {
|
for (const key in this.form) {
|
this.form[key] = target[key]
|
}
|
this.form.cateType = parseInt(target.unionCateType)
|
this.getCategory(0)
|
if (this.form.cateBigId) {
|
this.getCategory(1, this.form.cateBigId)
|
}
|
if (this.form.cateMiddleId) {
|
this.getCategory(2, this.form.cateMiddleId)
|
}
|
})
|
},
|
getCategory (type, id) {
|
let qurey = '?cateType=' + this.form.cateType + '&type=' + type
|
if (id) {
|
qurey = qurey + '&id=' + id
|
}
|
getListByType(
|
qurey
|
).then(res => {
|
// console.log(res)
|
switch (type) {
|
case 0: {
|
this.cateBig = res
|
break
|
}
|
case 1: {
|
this.cateMiddle = res
|
break
|
}
|
case 2: {
|
this.cateSmall = res
|
break
|
}
|
default: break
|
}
|
this.parent = res
|
}).catch(err => {
|
console.log(err)
|
})
|
},
|
seletType (v) {
|
this.getCategory(0)
|
this.cateBig = []
|
this.cateMiddle = []
|
this.cateSmall = []
|
this.form.cateBigId = ''
|
this.form.cateMiddleId = ''
|
this.form.cateSmallId = ''
|
this.form.combinationName = ''
|
},
|
selectBig (v) {
|
this.getCategory(1, v)
|
this.cateMiddle = []
|
this.cateSmall = []
|
this.form.cateMiddleId = ''
|
this.form.cateSmallId = ''
|
for (const item of this.cateBig) {
|
if (item.id === v) {
|
this.form.combinationName = item.name
|
}
|
}
|
},
|
selectMiddle (v) {
|
// console.log('中类选择', v)
|
this.cateSmall = []
|
this.form.cateSmallId = ''
|
if (!v) {
|
const categories = this.form.combinationName.split('_')
|
this.form.combinationName = categories[0]
|
return
|
}
|
this.getCategory(2, v)
|
for (const item of this.cateMiddle) {
|
if (item.id === v) {
|
const categories = this.form.combinationName.split('_')
|
const nCategories = []
|
nCategories.push(categories[0])
|
nCategories.push(item.name)
|
this.form.combinationName = nCategories.join('_')
|
}
|
}
|
},
|
selectSmall (v) {
|
if (!v) {
|
const categories = this.form.combinationName.split('_')
|
categories.pop()
|
this.form.combinationName = categories.join('_')
|
return
|
}
|
for (const item of this.cateSmall) {
|
if (item.id === v) {
|
const categories = this.form.combinationName.split('_')
|
categories[2] = item.name
|
this.form.combinationName = categories.join('_')
|
}
|
}
|
}
|
}
|
}
|
</script>
|