Commit 126a7be0 authored by arvin's avatar arvin

修改组件

parent cf072ca2
export default {
props: {},
layoutConfigData: [
{
title: '高级组件配置',
data: [
{
key: 'linkageAttr',
title: '联动属性',
component: {
defaultValue: 'extProductAreaId',
name: 'el-input'
}
},
{
key: 'syncOutAttr',
title: '同步输出',
component: {
defaultValue: 'extWorkCenteName:extname',
name: 'el-input'
}
}
]
}
],
data() {
return {
}
},
created() {
},
computed: {
},
methods: {
}
}
<template> <template>
<div>
<el-select v-model="form.extWorkCenterId"> <el-select v-model="cloneValue" @change="change">
<el-option <el-option
v-for="(item,i) in warehouseOptions" v-for="(item,i) in warehouseOptions"
:key="i" :key="i"
:label="item.extname" :label="item.extname"
:value="item.id" :value="item.id"
/> />
</el-select> </el-select>
</div>
</template> </template>
<script> <script>
import config from './config'
import _get from 'lodash.get'
import _set from 'lodash.set'
export default { export default {
componentName: '库房', componentName: '库房',
name: 'Warehouse', name: 'Warehouse',
components: {}, mixins: [config],
props: { props: {
form: {} itemObj: {
type: Object,
default: null
},
form: {
type: Object,
default: () => {}
},
value: {
type: [Number, String, Object],
default: () => ''
}
}, },
data() { data() {
return { return {
warehouseOptions: [], warehouseOptions: [],
areaList: [], areaList: [],
cloneValue: '',
linkageValue: '',
dataType: 'string',
isFirst: true isFirst: true
} }
}, },
computed: {}, computed: {},
watch: { watch: {
async 'form.extProductArea.id'() { 'value': {
this.$set(this.form, 'extWorkCenterId', this.form.extWorkCenterId || '') immediate: true,
if (!this.isFirst) { handler(val) {
this.$set(this.form, 'extWorkCenterId', '') if (!val) {
this.cloneValue = ''
return
}
if (typeof (val) === 'object') {
this.cloneValue = val.id
this.dataType = 'object'
} else {
this.cloneValue = val
this.dataType = 'string'
}
} }
if (this.areaList.length) { },
this.findWarehouse() form: {
} else { immediate: true,
await this.searchApi() deep: true,
handler() {
if (!this.itemObj.linkageAttr) {
return
}
const _val = _get(this.form, this.itemObj.linkageAttr)
if (_val !== this.linkageValue) {
this.linkageValue = _val
this.linkageValue && this.searchApi()
if (this.linkageValue) {
this.cloneValue = ''
this.update()
}
}
} }
} }
}, },
...@@ -51,17 +90,47 @@ export default { ...@@ -51,17 +90,47 @@ export default {
mounted() { mounted() {
}, },
methods: { methods: {
async searchApi() { validate() {
this.isFirst = false return !!this.cloneValue
const params = { 'openProps': [{ 'name': 'extDxProductWorkCenters' }] } },
await this.$api.searchApi('ExtDxProductArea', params).then(res => { searchApi() {
this.areaList = res.items.content const params = { 'openProps': [{ 'name': 'extDxProductWorkCenters' }],
this.findWarehouse() searchItems: {
items: [{ 'fieldName': 'id', operator: 'EQ', value: this.linkageValue }],
operator: 'AND'
}
}
this.$api.searchApi('ExtDxProductArea', params).then(res => {
this.warehouseOptions = res.items.content[0].extDxProductWorkCenters
})
},
update() {
let item = null
if (this.dataType === 'string') {
this.$emit('input', this.cloneValue)
this.$emit('change', this.cloneValue)
} else {
item = this.warehouseOptions.find(r => r.id === this.cloneValue)
this.$emit('input', item)
this.$emit('change', item)
}
this.syncOut(item)
},
syncOut(obj) {
if (!this.itemObj.syncOutAttr) {
return
}
const list = this.itemObj.syncOutAttr.split(',')
list.forEach(r => {
const keyname = r.split(':')
if (keyname.length === 2) {
const val = obj ? _get(obj, keyname[1]) : ''
_set(this.form, keyname[0], val)
}
}) })
}, },
findWarehouse() { change() {
const warehouse = this.areaList.find(item => item.id === this.form.extProductArea.id) this.update()
this.warehouseOptions = warehouse.extDxProductWorkCenters
} }
} }
} }
......
...@@ -7,11 +7,21 @@ const privateComponents = [] ...@@ -7,11 +7,21 @@ const privateComponents = []
requireComponent.keys().forEach(fileName => { requireComponent.keys().forEach(fileName => {
const comp = requireComponent(fileName) const comp = requireComponent(fileName)
if (comp.default.componentName) { if (comp.default.componentName) {
let layoutConfigData = comp.default.layoutConfigData
if (!layoutConfigData && comp.default.mixins) {
const hasLayoutConfigData = comp.default.mixins.find(el => {
return el.layoutConfigData
})
if (hasLayoutConfigData) {
layoutConfigData = hasLayoutConfigData.layoutConfigData
}
}
privateComponents.push( privateComponents.push(
{ {
componentName: comp.default.componentName, componentName: comp.default.componentName,
name: comp.default.name, name: comp.default.name,
path: fileName.slice(1) path: fileName.slice(1),
layoutConfigData: layoutConfigData || []
} }
) )
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment