Commit ee0e968f by 前端

修复bug

1 parent 26496c93
...@@ -4,9 +4,10 @@ ...@@ -4,9 +4,10 @@
:options="areaList" :options="areaList"
v-model="areas" v-model="areas"
:props="cascaderProps" :props="cascaderProps"
@change="handleAsycChange"
@expand-change="handleAsycChange"
placeholder="请选择" placeholder="请选择"
:key="areasKeys"
@change="onChange"
@expand-change="onChange"
/> />
</template> </template>
<script> <script>
...@@ -25,11 +26,12 @@ export default { ...@@ -25,11 +26,12 @@ export default {
areas: [], areas: [],
cascaderProps: { cascaderProps: {
label: "areaName", label: "areaName",
value: "areaCode", value: "id",
children: "children", children: "children",
lazy: true, // lazy: true,
lazyLoad: this.loadProvince, // lazyLoad: this.loadProvince,
}, },
areasKeys: "",
}; };
}, },
watch: { watch: {
...@@ -37,7 +39,7 @@ export default { ...@@ -37,7 +39,7 @@ export default {
handler: function (n, o) { handler: function (n, o) {
if (n && n != o) { if (n && n != o) {
this.areas = n; this.areas = n;
this.fillDistrict(n); this.fillProvince(n);
} }
}, },
immediate: true, immediate: true,
...@@ -69,61 +71,80 @@ export default { ...@@ -69,61 +71,80 @@ export default {
}); });
}, },
// 动态加载 // 填充省市区
async loadProvince(node, resolve) { fillProvince(codes) {
console.log("触发加载...."); let _this = this;
const { level, data } = node; this.getList(0).then((res) => {
if (!node.children || node.children.length <= 0) { _this.getCity(codes);
resolve([]); });
return false;
}
let res = await this.getList(data ? data.areaCode : 0);
resolve(res);
}, },
// 省市区 // 根据省份code 获取城市列表
handleAsycChange(val) { getCity(codes) {
if (val && val.length == 3) { let _this = this;
this.$emit("input", val); let list = this.areaList || [];
} let params = {};
var newPro = new Promise((resolve) => { params.id = codes[0];
var riVal = val[val.length - 1]; params.type = "children";
this.getList(riVal).then((response) => { getAddress(params).then((response) => {
this.areaList.map((item) => { let arr = response.data || [];
if (item.id == riVal) { let idx = list.findIndex((k) => k.areaCode == codes[0]);
item.children = response; let province = list[idx];
} else if (item.children && item.children.length > 0) {
// console.log('active item:', response); arr.map((k) => {
item.children.map((citem) => { k.children = [];
if (citem.id == riVal) { return k;
if (val.length < 2) {
citem.children = response;
} else {
response.map((ccitem) => {
ccitem.children = null;
});
citem.children = response;
}
}
});
}
});
resolve();
}); });
province.children = arr;
_this.$set(_this.areaList, idx, province);
if (codes.length > 2) {
_this.getArea(codes);
}
}); });
return newPro;
}, },
// 填充省市区 // 根据城市code 获取地区列表
fillDistrict(districtArr) { getArea(codes) {
let _this = this; let _this = this;
_this.$nextTick(() => { let list = this.areaList || [];
if (districtArr.length !== 3) return; let params = {};
_this.handleAsycChange([districtArr[0]]).then(() => { params.id = codes[1];
_this.handleAsycChange([districtArr[0], districtArr[1]]) params.type = "children";
getAddress(params).then((response) => {
let arr = response.data || [];
let province = list.find((k) => k.areaCode == codes[0]);
let idx = (province.children || []).findIndex(
(k) => k.areaCode == codes[1]
);
let city = province.children[idx];
arr.map((k) => {
delete k.children;
return k;
}); });
city.children = arr;
_this.$set(_this.areaList, idx, province);
// _this.areas = codes;
if (codes.length == 3) {
_this.areasKeys = Math.random();
}
}); });
}, },
// 监听编号
onChange(node) {
console.log(";555555555");
console.log(node);
// 切换省份
if (node.length == 1) {
this.getCity(node);
}
// 切换城市
if (node.length == 2) {
this.getArea(node);
}
},
}, },
}; };
</script> </script>
\ No newline at end of file \ No newline at end of file
...@@ -104,7 +104,7 @@ ...@@ -104,7 +104,7 @@
</el-form-item> </el-form-item>
</div> </div>
<el-form-item label="邮寄地址:"> <el-form-item label="邮寄地址:">
<!-- <area-cascader v-model="ruleForm.returnDistrict" /> --> <area-cascader v-model="ruleForm.returnDistrict" />
</el-form-item> </el-form-item>
<el-form-item label="详细地址:"> <el-form-item label="详细地址:">
<el-input v-model="ruleForm.returnAddress" /> <el-input v-model="ruleForm.returnAddress" />
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!