//省市区通过code回显text
|
export function getAddressText(array, obj) {
|
let [pText, cText, aText] = ['', '', ''];
|
console.log(array, "=====")
|
if (Object.keys(obj).length) {
|
if (obj.pCode) {
|
//省
|
let _pObj = getCurObj(array, obj.pCode)
|
if (_pObj) {
|
pText = _pObj.label;
|
//市
|
let _cObj = getCurObj(_pObj.children, obj.cCode);
|
if (_cObj) {
|
cText = _cObj.label;
|
//区
|
let _aObj = getCurObj(_cObj.children, obj.aCode);
|
aText = _aObj ? _aObj.label : '';
|
}
|
}
|
}
|
}
|
return `${pText}${cText}${aText}`;
|
}
|
//获取当前地址项
|
function getCurObj(array, code) {
|
let obj = {};
|
if (array.length) {
|
obj = array.find((item) => item.value === code);
|
}
|
return obj;
|
}
|