From f64155f6ad27c50451bb7d4a15f553bc72ead7de Mon Sep 17 00:00:00 2001
From: WXL <wl_5969728@163.com>
Date: 星期五, 12 九月 2025 14:35:26 +0800
Subject: [PATCH] 年龄计算相关
---
src/components/Address/index.vue | 126 ++++++++++++++++++++++++-----------------
1 files changed, 74 insertions(+), 52 deletions(-)
diff --git a/src/components/Address/index.vue b/src/components/Address/index.vue
index 4056a0c..8e36b2d 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,56 @@
methods: {
getAddressData() {
var that = this;
- 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;
- }
+ console.log(store.getters.addressArray,'addressArray');
+ 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 +161,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