fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//省市区通过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;
}