Commit f0fda03e authored by jingnan's avatar jingnan 👀

架次关联站位编号组件修改

parent f996da98
<template>
<div class="generalLinkageSelect-select">
<el-select ref="selectCom" v-model="selVal" placeholder="请选择" size="mini" :disabled="disabledVal" @change="changeVal">
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</div>
</template>
<script>
import http from '@/utils/http'
import config from './config'
import _get from 'lodash.get'
export default {
componentName: '通用联动属性配置',
name: 'GeneralLinkageSelectSelect', // name写在组件的最前方,自定义组件为必填
components: {},
mixins: [config],
props: {
item: {
type: Object,
default: () => {
return {}
}
},
form: {
type: Object,
default: () => {}
},
middleForm: {
type: Object,
default: () => {}
},
value: {
type: [Number, String, Object],
default: () => ''
}
},
data() {
return {
options: [],
selVal: '',
disabledVal: false,
linkageValue: ''
}
},
computed: {},
watch: {
form: {
immediate: true,
deep: true,
handler(val) {
if (val) {
if (!this.item.linkageAttr) {
return
}
const _val = _get(this.form, this.item.linkageAttr)
if (_val !== this.linkageValue) {
this.options = []
this.selVal = ''
this.linkageValue = _val
this.getData(_val)
}
}
}
},
item: {
immediate: true,
deep: true,
handler(v) {
if (v.component.hasOwnProperty('disabled')) {
this.disabledVal = v.component.disabled
}
}
},
value: {
immediate: true,
deep: true,
handler(v) {
if (v) {
this.selVal = this.value
}
}
}
},
created() {
// 初始化数据
},
methods: {
getData(val) {
var requestURL = ''
var requestParameters = {}
if (this.item.requestURL) {
try {
let fun
eval(`fun = function (obtainedParams, functionParams){${this.item.requestURL}}`) // eslint-disable-line
fun.apply(this)// eslint-disable-line
} catch (error) {
console.error(error)
}
}
if (this.item.requestParameters) {
try {
let fun1
eval(`fun1 = function (obtainedParams, functionParams){${this.item.requestParameters}}`) // eslint-disable-line
fun1.apply(this)// eslint-disable-line
} catch (error) {
console.error(error)
}
}
http[this.item.requestMethod](requestURL, requestParameters).then(res => {
let responseData = []
if (this.item.formateResponse) {
try {
let fun2
eval(`fun2 = function (obtainedParams, functionParams){${this.item.formateResponse}}`) // eslint-disable-line
fun2.apply(this)// eslint-disable-line
} catch (error) {
console.error(error)
}
} else {
responseData = res.items.content.map(row => {
return {
value: row.id,
label: row.name
}
})
}
this.options = responseData
})
},
changeVal() {
this.$emit('input', this.selVal)
}
}
}
</script>
<style lang='scss'>
</style>
export default {
props: {},
layoutConfigData: [
{
title: '高级组件配置',
data: [
{
key: 'bindKey',
title: '绑定属性',
disabled: true,
component: {
defaultValue: 'positionNumber',
name: 'el-input'
}
},
{
key: 'relatedAttribute',
title: '受关联属性',
disabled: true,
component: {
defaultValue: '',
name: 'el-input'
}
}
]
}
],
data() {
return {
}
},
created() {
},
computed: {
},
methods: {
}
}
<template> <template>
<div> <div>
<el-select <el-select
:value="value" :value="selVal"
:loading="loading" :loading="loading"
filterable filterable
remote remote
...@@ -22,10 +22,11 @@ ...@@ -22,10 +22,11 @@
</template> </template>
<script> <script>
import config from './config'
export default { export default {
name: 'StationSelect', name: 'StationSelect',
componentName: '架次关联站位编号', componentName: '架次关联站位编号',
mixins: [config],
props: { props: {
value: { value: {
type: [String, Number], type: [String, Number],
...@@ -47,20 +48,35 @@ export default { ...@@ -47,20 +48,35 @@ export default {
data() { data() {
return { return {
loading: false, loading: false,
options: [] options: [],
// linkageValue: '',
selVal: ''
} }
}, },
computed: {}, computed: {},
watch: { watch: {
'form.sorties': { 'form.sorties': {
immediate: true, immediate: true,
deep: true, // deep: true,
handler(val) { handler(val) {
// if (val !== this.linkageValue) {
if (this.item.key !== 'position') { if (this.item.key !== 'position') {
// this.linkageValue = val
this.$set(this.form, 'positionNumber', '') this.$set(this.form, 'positionNumber', '')
this.selVal = ''
} }
// }
val && this.getOptions() val && this.getOptions()
} }
},
value: {
immediate: true,
deep: true,
handler(v) {
if (v) {
this.selVal = this.value
}
}
} }
}, },
methods: { methods: {
...@@ -104,6 +120,15 @@ export default { ...@@ -104,6 +120,15 @@ export default {
}, },
change(val) { change(val) {
this.$emit('input', val) this.$emit('input', val)
this.clearRelativeAttr()
},
clearRelativeAttr() {
if (this.item.relatedAttribute) {
const attributes = this.item.relatedAttribute.split(',') || []
attributes.forEach(el => {
el && this.$set(this.form, el, '')
})
}
}, },
clear() { clear() {
this.$emit('input') this.$emit('input')
......
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