Commit 96897531 authored by wangxl's avatar wangxl

333

parent 797b83de
...@@ -25,15 +25,14 @@ const mutations = { ...@@ -25,15 +25,14 @@ const mutations = {
} }
} }
const actions = { const actions = {
getDict: ({ commit, state }, type) => { async getDictByType ({ dispatch, state }, type) {
return state.dict
},
getDictByType: ({ dispatch, state }, type) => {
/** /**
* 闭包特性。返回一个函数,该函数接收一个type参数。 * 闭包特性。返回一个函数,该函数接收一个type参数。
* 同时由于闭包还持有state对象,故可以返回需要的值。 * 同时由于闭包还持有state对象,故可以返回需要的值。
*/ */
return state.dict[type] await dispatch('dict', type)
var obj = JSON.parse(JSON.stringify(state.dict[type]))
return obj
}, },
// 缓存字典内容 // 缓存字典内容
dict ({ commit, state }, type) { dict ({ commit, state }, type) {
......
<template>
<div style=" width:auto; display:inline-block !important; display:inline;z-index:100">
<a-select :style="{width: width + 'px'}" v-model="parSelected" @change="parentChange($event)" :key="0">
<a-select-option v-for="item in parArray" :key="item.key" :value="item.key" select>{{ item.title }}</a-select-option>
</a-select>
<a-select :style="{width: width + 'px'}" v-model="selected" @change="childChange($event)" :key="1">
<a-select-option v-for="item in chArray" :key="item.key" :value="item.key" select>{{ item.title }}</a-select-option>
</a-select>
</div>
</template>
<script>
export default {
//用法 <para-multi-select v-model="formData.projClass" :typeId="52" />
name: "paraMultiSelect",
data () {
return {
parArray: [],
chArray: [],
parSelected: '',
selected: '',
defaultAll: {
title: "--请选择" + this.title + "--",
key: "",
children: [{
title: "--请先选择上级-",
key: "",
}]
},
loading: false
};
},
props: {
value: {
type: String,
default () {
return null
}
},
typeId: {
type: Number,
default () {
return 0
}
},
width: {
type: Number,
default () {
return 180
}
},
title: {
type: String,
default () {
return ''
}
},
},
created () {
this.load(this.value)
},
methods: {
async load (value) {
if (!!!this.parArray || this.parArray.length == 0) {
this.parArray = await this.$store.dispatch('cache/getDictByType', 6)
this.parArray.unshift(this.defaultAll)
this.chArray = this.parArray[0].children
this.parSelected = ''
this.selected = ''
}
if (!!value) {
var show = this.getParIndex(this.parArray, value)
this.chArray = this.parArray[show].children
this.parSelected = this.parArray[show].key
this.selected = value
}
},
parentChange (value) {
this.childArray = [];
this.childArray.unshift(this.defaultChild)
this.childValue = ''
if (value != '') {
let pars2 = { typeId: this.typeId, parentId: value };
this.$api.parameter.getParameterList(pars2).then(({ data = {} }) => {
if (data) {
this.childArray = data.data
this.childArray.unshift(this.defaultChild)
}
}).catch(() => { });
}
else {
this.childArray = [this.defaultChild]
this.childValue = ''
this.$emit("input", null);
this.$emit("change");
}
this.$emit('parentChange', value)
this.$emit("change");
},
childChange (value) {
this.$emit("input", value);
var newArr = this.childArray.filter(x => x.key == value);
if (!!newArr && newArr.length > 0) {
var text = !!value ? newArr[0].title : ''
this.$emit('changeTitle', text)
}
this.$emit("change");
},
getParIndex (list, value) {
var show = 0
if (!!list && list.length > 0) {
for (var i = 0; i < list.length; i++) {
for (var j = 0; j < list[i].children.length; j++) {
if (list[i].children[j].key == value) {
show = i
break
}
}
}
}
return show
}
},
watch: {
value: {
handler (value) {
if (!!value && !this.loading) {
this.loading = true
this.load(value)
}
},
},
}
}
</script>
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
<a-form-item> <a-form-item>
<base-select v-model="searchForm.projState" :title="'状态'" :type="1" :isAll="true" :width="160" /> <base-select v-model="searchForm.projState" :title="'状态'" :type="1" :isAll="true" :width="160" />
</a-form-item> </a-form-item>
<para-multi-select2 :typeId="6" />
<a-form-item> <a-form-item>
<a-button type="primary" icon="search" @click="search">搜索</a-button> <a-button type="primary" icon="search" @click="search">搜索</a-button>
<a-button icon="reload" style="margin-left: 10px" @click="reset" class="bt-normal">重置</a-button> <a-button icon="reload" style="margin-left: 10px" @click="reset" class="bt-normal">重置</a-button>
......
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