提交 25ac6660 编写于 作者: tony001's avatar tony001

单位、部门选择器无label字段

上级 b7bbbd1f
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<script lang="ts"> <script lang="ts">
import { Vue, Component, Watch, Prop, Model } from 'vue-property-decorator'; import { Vue, Component, Watch, Prop, Model } from 'vue-property-decorator';
import CodeListService from '@/service/app/codelist-service';
@Component({ @Component({
}) })
export default class AppDepartmentSelect extends Vue { export default class AppDepartmentSelect extends Vue {
...@@ -18,6 +19,20 @@ export default class AppDepartmentSelect extends Vue { ...@@ -18,6 +19,20 @@ export default class AppDepartmentSelect extends Vue {
*/ */
@Prop() public url?: any; @Prop() public url?: any;
/**
* 代码表标识
*
* @memberof AppDepartmentSelect
*/
@Prop() public tag?:string;
/**
* 代码表类型
*
* @memberof AppDepartmentSelect
*/
@Prop() public codelistType?:string;
/** /**
* 过滤项 * 过滤项
* *
...@@ -121,14 +136,14 @@ export default class AppDepartmentSelect extends Vue { ...@@ -121,14 +136,14 @@ export default class AppDepartmentSelect extends Vue {
} }
this.oldurl = _url; this.oldurl = _url;
// 缓存机制 // 缓存机制
const result:any = this.$store.getters.getDepData(_url); const result:any = this.$store.getters.getDepData(this.filter);
if(result){ if(result){
this.Nodesdata = result; this.Nodesdata = result;
return; return;
} }
this.$http.get(_url).then((response: any) => { this.$http.get(_url).then((response: any) => {
this.Nodesdata = response.data; this.Nodesdata = response.data;
this.$store.commit('addDepData', { srfkey: this.filter, orgData: response.data }); this.$store.commit('addDepData', { srfkey: this.filter, depData: response.data });
}).catch((response: any) => { }).catch((response: any) => {
if (!response || !response.status || !response.data) { if (!response || !response.status || !response.data) {
this.$Notice.error({ title: (this.$t('app.commonWords.error') as string), desc: (this.$t('app.commonWords.sysException') as string) }); this.$Notice.error({ title: (this.$t('app.commonWords.error') as string), desc: (this.$t('app.commonWords.sysException') as string) });
...@@ -163,13 +178,19 @@ export default class AppDepartmentSelect extends Vue { ...@@ -163,13 +178,19 @@ export default class AppDepartmentSelect extends Vue {
// 单选 // 单选
if(!this.multiple){ if(!this.multiple){
if(this.fillMap && Object.keys(this.fillMap).length >0){ if(this.fillMap && Object.keys(this.fillMap).length >0){
let templateValue = {}; let templateValue:any = {};
Object.keys(this.fillMap).forEach((item:any) =>{ Object.keys(this.fillMap).forEach((item:any) =>{
if(this.data && this.data[this.fillMap[item]]){ if(this.data && this.data[this.fillMap[item]]){
Object.assign(templateValue,{[item]:this.data[this.fillMap[item]]}); Object.assign(templateValue,{[item]:this.data[this.fillMap[item]]});
} }
}) })
this.selectTreeValue = JSON.stringify([templateValue]); if(!templateValue.label && templateValue.id && this.tag && this.codelistType && Object.is(this.codelistType,"DYNAMIC")){
this.fillLabel(templateValue,templateValue.id,(templateValue:any) =>{
this.selectTreeValue = JSON.stringify([templateValue]);
});
}else{
this.selectTreeValue = JSON.stringify([templateValue]);
}
} }
}else{ }else{
// 多选 // 多选
...@@ -188,8 +209,30 @@ export default class AppDepartmentSelect extends Vue { ...@@ -188,8 +209,30 @@ export default class AppDepartmentSelect extends Vue {
}) })
} }
}) })
this.selectTreeValue = JSON.stringify(tempArray); let tempflag:boolean = false;
if(tempArray.length >0 && tempArray.length >0){
tempArray.forEach((item:any) =>{
if(!item.label) tempflag = true;
})
} }
if(tempflag && this.tag && this.codelistType && Object.is(this.codelistType,"DYNAMIC")){
let tempStatus:number = 0;
tempArray.forEach((item:any) =>{
if(!item.label){
tempStatus += 1;
this.fillLabel(item,item.id,(result:any) =>{
item = result;
tempStatus -= 1;
if(tempStatus === 0){
this.selectTreeValue = JSON.stringify(tempArray);
}
})
}
})
}else{
this.selectTreeValue = JSON.stringify(tempArray);
}
}
} }
} }
...@@ -208,10 +251,35 @@ export default class AppDepartmentSelect extends Vue { ...@@ -208,10 +251,35 @@ export default class AppDepartmentSelect extends Vue {
let _name = this.fillMap[attribute]; let _name = this.fillMap[attribute];
let values = selectArr.map((item:any) => item[attribute]); let values = selectArr.map((item:any) => item[attribute]);
let _value = $event === "[]" ? null : values.join(","); let _value = $event === "[]" ? null : values.join(",");
this.$emit('select-change',{name: this.fillMap[attribute], value: _value}) setTimeout(() => {
this.$emit('select-change',{name: this.fillMap[attribute], value: _value});
},0);
}); });
} }
} }
/**
* 填充label
*
* @memberof AppOrgSelect
*/
public fillLabel(tempObject:any,valueItem:any,callback:any){
if(!tempObject.label && tempObject.id && this.tag && this.codelistType && Object.is(this.codelistType,"DYNAMIC")){
let codeListService:CodeListService = new CodeListService();
codeListService.getItems(this.tag).then((items:any) =>{
if(items && items.length >0){
let result:any = items.find((item:any) =>{
return item.id === valueItem;
})
Object.assign(tempObject,{label:result.label});
}
callback(tempObject);
}).catch((error:any) =>{
console.log(error);
})
}
}
} }
</script> </script>
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
<script lang = 'ts'> <script lang = 'ts'>
import { Vue, Component, Prop, Watch } from "vue-property-decorator"; import { Vue, Component, Prop, Watch } from "vue-property-decorator";
import { Http } from '@/utils'; import { Http } from '@/utils';
import CodeListService from "@service/app/codelist-service";
import { observable } from 'rxjs';
@Component({}) @Component({})
export default class AppOrgSelect extends Vue { export default class AppOrgSelect extends Vue {
...@@ -37,6 +39,20 @@ export default class AppOrgSelect extends Vue { ...@@ -37,6 +39,20 @@ export default class AppOrgSelect extends Vue {
*/ */
@Prop() public filter?:string; @Prop() public filter?:string;
/**
* 代码表标识
*
* @memberof AppOrgSelect
*/
@Prop() public tag?:string;
/**
* 代码表类型
*
* @memberof AppOrgSelect
*/
@Prop() public codelistType?:string;
/** /**
* 是否多选 * 是否多选
* *
...@@ -138,13 +154,19 @@ export default class AppOrgSelect extends Vue { ...@@ -138,13 +154,19 @@ export default class AppOrgSelect extends Vue {
// 单选 // 单选
if(!this.multiple){ if(!this.multiple){
if(this.fillMap && Object.keys(this.fillMap).length >0){ if(this.fillMap && Object.keys(this.fillMap).length >0){
let templateValue = {}; let templateValue:any = {};
Object.keys(this.fillMap).forEach((item:any) =>{ Object.keys(this.fillMap).forEach((item:any) =>{
if(this.data && this.data[this.fillMap[item]]){ if(this.data && this.data[this.fillMap[item]]){
Object.assign(templateValue,{[item]:this.data[this.fillMap[item]]}); Object.assign(templateValue,{[item]:this.data[this.fillMap[item]]});
}
})
if(!templateValue.label && templateValue.id && this.tag && this.codelistType && Object.is(this.codelistType,"DYNAMIC")){
this.fillLabel(templateValue,templateValue.id,(templateValue:any) =>{
this.selectTreeValue = JSON.stringify([templateValue]);
});
}else{
this.selectTreeValue = JSON.stringify([templateValue]);
} }
})
this.selectTreeValue = JSON.stringify([templateValue]);
} }
}else{ }else{
// 多选 // 多选
...@@ -163,8 +185,30 @@ export default class AppOrgSelect extends Vue { ...@@ -163,8 +185,30 @@ export default class AppOrgSelect extends Vue {
}) })
} }
}) })
this.selectTreeValue = JSON.stringify(tempArray); let tempflag:boolean = false;
if(tempArray.length >0 && tempArray.length >0){
tempArray.forEach((item:any) =>{
if(!item.label) tempflag = true;
})
}
if(tempflag && this.tag && this.codelistType && Object.is(this.codelistType,"DYNAMIC")){
let tempStatus:number = 0;
tempArray.forEach((item:any) =>{
if(!item.label){
tempStatus += 1;
this.fillLabel(item,item.id,(result:any) =>{
item = result;
tempStatus -= 1;
if(tempStatus === 0){
this.selectTreeValue = JSON.stringify(tempArray);
}
})
}
})
}else{
this.selectTreeValue = JSON.stringify(tempArray);
} }
}
} }
} }
...@@ -209,7 +253,9 @@ export default class AppOrgSelect extends Vue { ...@@ -209,7 +253,9 @@ export default class AppOrgSelect extends Vue {
tempValue.forEach((value:any,index:number) =>{ tempValue.forEach((value:any,index:number) =>{
tempResult += index>0?`,${value[item]}`:`${value[item]}`; tempResult += index>0?`,${value[item]}`:`${value[item]}`;
}) })
this.emitValue(this.fillMap[item],tempResult); setTimeout(() => {
this.emitValue(this.fillMap[item],tempResult);
}, 0);
}) })
} }
}else{ }else{
...@@ -225,7 +271,9 @@ export default class AppOrgSelect extends Vue { ...@@ -225,7 +271,9 @@ export default class AppOrgSelect extends Vue {
const tempValue:any = JSON.parse($event)[0]; const tempValue:any = JSON.parse($event)[0];
if(this.fillMap && Object.keys(this.fillMap).length >0){ if(this.fillMap && Object.keys(this.fillMap).length >0){
Object.keys(this.fillMap).forEach((item:any) =>{ Object.keys(this.fillMap).forEach((item:any) =>{
this.emitValue(this.fillMap[item],tempValue[item]); setTimeout(() => {
this.emitValue(this.fillMap[item],tempValue[item]);
}, 0);
}) })
} }
}else{ }else{
...@@ -247,6 +295,28 @@ export default class AppOrgSelect extends Vue { ...@@ -247,6 +295,28 @@ export default class AppOrgSelect extends Vue {
this.$emit('select-change',{name:name,value:value}); this.$emit('select-change',{name:name,value:value});
} }
/**
* 填充label
*
* @memberof AppOrgSelect
*/
public fillLabel(tempObject:any,valueItem:any,callback:any){
if(!tempObject.label && tempObject.id && this.tag && this.codelistType && Object.is(this.codelistType,"DYNAMIC")){
let codeListService:CodeListService = new CodeListService();
codeListService.getItems(this.tag).then((items:any) =>{
if(items && items.length >0){
let result:any = items.find((item:any) =>{
return item.id === valueItem;
})
Object.assign(tempObject,{label:result.label});
}
callback(tempObject);
}).catch((error:any) =>{
console.log(error);
})
}
}
} }
</script> </script>
......
...@@ -100,10 +100,11 @@ export default class CodeListService { ...@@ -100,10 +100,11 @@ export default class CodeListService {
if(items.length >0) resolve(items); if(items.length >0) resolve(items);
} }
const callback:Function = (tag:string,promise:Promise<any>) =>{ const callback:Function = (tag:string,promise:Promise<any>) =>{
promise.then((result:any) =>{ promise.then((res:any) =>{
if(result.length > 0){ let result:any = res.data;
CodeListService.codelistCached.set(`${tag}`,{items:result}); if(result.items && result.items.length > 0){
return resolve(result); CodeListService.codelistCached.set(`${tag}`,{items:result.items});
return resolve(result.items);
}else{ }else{
return resolve([]); return resolve([]);
} }
...@@ -137,6 +138,12 @@ export default class CodeListService { ...@@ -137,6 +138,12 @@ export default class CodeListService {
} }
return new Promise((resolve:any,reject:any) =>{ return new Promise((resolve:any,reject:any) =>{
this.getService(tag).then((codelist:any) =>{ this.getService(tag).then((codelist:any) =>{
if(Object.is(codelist.predefinedType,"RUNTIME")){
this.getPredefinedItems(tag).then((res:any) =>{
resolve(res);
})
return;
}
let isEnableCache:boolean = codelist.isEnableCache; let isEnableCache:boolean = codelist.isEnableCache;
let cacheTimeout:any = codelist.cacheTimeout; let cacheTimeout:any = codelist.cacheTimeout;
// 启用缓存 // 启用缓存
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册