From 8022f7036945b75f82f2dfc43055623f81ed98f6 Mon Sep 17 00:00:00 2001 From: yxh <172933527@qq.com> Date: 星期五, 23 五月 2025 22:42:56 +0800 Subject: [PATCH] yxh --- src/components/Address/index.vue | 126 +++++++++++++++++++++++++----------------- 1 files changed, 75 insertions(+), 51 deletions(-) diff --git a/src/components/Address/index.vue b/src/components/Address/index.vue index 4056a0c..a26d5b4 100644 --- a/src/components/Address/index.vue +++ b/src/components/Address/index.vue @@ -50,18 +50,20 @@ <script> // 浣跨敤璇存槑锛歷-model鏃讹紝蹇呴』浼犲甫鏈夊甫鏈夌渷锛屽競锛屽尯鎷奸煶鐨勫瓧娈� -import request from '@/utils/request' +import request from "@/utils/request"; +import store from "@/store"; + export default { name: "li_area_select", //閫氳繃 model 閫夐」閰嶇疆瀛愮粍浠舵帴鏀剁殑 prop 鍚嶄互鍙婃淳鍙戠殑浜嬩欢鍚� model: { prop: "caddress", - event: "change", + event: "change" }, props: { caddress: { - type: Object, - }, + type: Object + } }, data() { return { @@ -69,7 +71,7 @@ //areaJson: './../address.json', addressArray: [], //鎵�鏈夋暟鎹� cityArray: [], - areaArray: [], + areaArray: [] }; }, created() { @@ -78,34 +80,58 @@ methods: { getAddressData() { var that = this; - request({ - url: that.areaJson, - method: "get", - }).then(function (response) { - if (response.code === 200) { - //鑾峰彇鍦板潃 + console.log(store.getters.addressArray,'addressArray'); - that.addressArray = response.data; - //榛樿鍊艰祴鍊艰幏鍙栧煄甯傛暟缁� - if (that.caddress.sheng) { - for (let ad of that.addressArray) { - if (ad.areaname === that.caddress.sheng) { - that.cityArray = ad.subarea; - //--- - //榛樿璧嬪�艰幏鍙栧尯鍩熸暟缁� - if (that.caddress.shi) { - for (let area of that.cityArray) { - if (area.areaname === that.caddress.shi) { - that.areaArray = area.subarea; - break; - } + if (store.getters.addressArray.length) { + that.addressArray = store.getters.addressArray.length; + //榛樿鍊艰祴鍊艰幏鍙栧煄甯傛暟缁� + if (that.caddress.sheng) { + for (let ad of that.addressArray) { + if (ad.areaname === that.caddress.sheng) { + that.cityArray = ad.subarea; + //--- + //榛樿璧嬪�艰幏鍙栧尯鍩熸暟缁� + if (that.caddress.shi) { + for (let area of that.cityArray) { + if (area.areaname === that.caddress.shi) { + that.areaArray = area.subarea; + break; } } } } } } - }); + } else { + request({ + url: that.areaJson, + method: "get" + }).then(function(response) { + if (response.code === 200) { + //鑾峰彇鍦板潃 + + that.addressArray = response.data; + //榛樿鍊艰祴鍊艰幏鍙栧煄甯傛暟缁� + if (that.caddress.sheng) { + for (let ad of that.addressArray) { + if (ad.areaname === that.caddress.sheng) { + that.cityArray = ad.subarea; + //--- + //榛樿璧嬪�艰幏鍙栧尯鍩熸暟缁� + if (that.caddress.shi) { + for (let area of that.cityArray) { + if (area.areaname === that.caddress.shi) { + that.areaArray = area.subarea; + break; + } + } + } + } + } + } + } + }); + } }, //閫夋嫨鐪佷唤 getCityData(val) { @@ -137,41 +163,39 @@ this.$forceUpdate(); }, - getSheng(){ - let list= this.addressArray.filter(r=>r.areaname == this.caddress.sheng); - if(list.length>0){ + getSheng() { + let list = this.addressArray.filter( + r => r.areaname == this.caddress.sheng + ); + if (list.length > 0) { return list[0].areacode; - } - else{ - return ''; + } else { + return ""; } }, - getShi(){ - let list= this.cityArray.filter(r=>r.areaname == this.caddress.shi); - if(list.length>0){ + getShi() { + let list = this.cityArray.filter(r => r.areaname == this.caddress.shi); + if (list.length > 0) { return list[0].areacode; - } - else{ - return ''; + } else { + return ""; } }, - getQu(){ - let list= this.areaArray.filter(r=>r.areaname == this.caddress.qu); - if(list.length>0){ + getQu() { + let list = this.areaArray.filter(r => r.areaname == this.caddress.qu); + if (list.length > 0) { return list[0].areacode; + } else { + return ""; } - else{ - return ''; - } }, - clean(){ - this.caddress.sheng=""; - this.caddress.shi=""; - this.caddress.qu=""; + clean() { + this.caddress.sheng = ""; + this.caddress.shi = ""; + this.caddress.qu = ""; } - }, + } }; </script> -<style scoped> -</style> \ No newline at end of file +<style scoped></style> -- Gitblit v1.9.3