handlesGetAreaFirst(params) {
this.apiGetAreas(params, "province_list")
.then((data1) => {
if (data1.length <= 0) {
return Promise.resolve([]);
}
const parentId = data1[0].id;
return this.apiGetAreas({ parentId }, "city_list")
.then((data2) => {
if (data2.length <= 0) {
return Promise.resolve([]);
}
const parentId = data2[0].id;
return this.apiGetAreas({ parentId }, "county_list");
})
.catch(() => {});
})
.catch(() => {});
},
apiGetAreas(params = {}, level) {
return cantonService.find({ ...params, stateId: 1 }).then(({ result }) => {
const key = `apiAreas.${level}`;
const value = {};
if (result && result.length > 0) {
result.forEach((item) => {
value[item.id] = item.cantonName;
});
}
this.setData({
[key]: value,
});
return result;
});
},
Promise坑点:省市区三级联动
最新推荐文章于 2024-07-26 20:46:33 发布