|
|
<template>
|
|
|
<div class="address-select-component" v-show="true">
|
|
|
<div class="address-select-component">
|
|
|
<div class="address-select-box">
|
|
|
<div class="component-title">
|
|
|
<span class="title">所在地区</span>
|
|
|
<span class="iconfont close" @click="closeAddBox"></span>
|
|
|
<span class="icon-close close" @click="closeAddBox"></span>
|
|
|
</div>
|
|
|
|
|
|
<ul class="head-address-ul">
|
|
|
<li
|
|
|
v-if="province.title"
|
...
|
...
|
@@ -23,6 +24,7 @@ |
|
|
>{{area.title}}</li>
|
|
|
<li v-if="street.title" :class="{ 'head-address-li': area.titleActive }">{{street.title}}</li>
|
|
|
</ul>
|
|
|
|
|
|
<div class="address-container">
|
|
|
<div class="address-content">
|
|
|
<ul v-if="province.showList" class="address-ul">
|
...
|
...
|
@@ -32,10 +34,7 @@ |
|
|
@click="switchAddress(pprovince.id, pprovince.caption)"
|
|
|
>
|
|
|
{{pprovince.caption}}
|
|
|
<span
|
|
|
v-if="pprovince.id === province.id"
|
|
|
class="iconfont icon-v"
|
|
|
></span>
|
|
|
<span v-if="pprovince.id === province.id" class="icon-check"></span>
|
|
|
</li>
|
|
|
</ul>
|
|
|
<ul v-if="city.showList" class="address-ul">
|
...
|
...
|
@@ -45,7 +44,7 @@ |
|
|
@click="switchAddress(pcity.id, pcity.caption)"
|
|
|
>
|
|
|
{{pcity.caption}}
|
|
|
<span v-if="pcity.id === city.id" class="iconfont icon-v"></span>
|
|
|
<span v-if="pcity.id === city.id" class="icon-check"></span>
|
|
|
</li>
|
|
|
</ul>
|
|
|
<ul v-if="area.showList" class="address-ul">
|
...
|
...
|
@@ -55,7 +54,7 @@ |
|
|
@click="switchAddress(parea.id, parea.caption)"
|
|
|
>
|
|
|
{{parea.caption}}
|
|
|
<span v-if="parea.id === area.id" class="iconfont icon-v"></span>
|
|
|
<span v-if="parea.id === area.id" class="icon-check"></span>
|
|
|
</li>
|
|
|
</ul>
|
|
|
<ul v-if="street.showList" class="address-ul">
|
...
|
...
|
@@ -65,7 +64,7 @@ |
|
|
@click="switchAddress(pstreet.id, pstreet.caption)"
|
|
|
>
|
|
|
{{pstreet.caption}}
|
|
|
<span v-if="pstreet.id === street.id" class="iconfont icon-v"></span>
|
|
|
<span v-if="pstreet.id === street.id" class="icon-check"></span>
|
|
|
</li>
|
|
|
</ul>
|
|
|
</div>
|
...
|
...
|
@@ -75,6 +74,10 @@ |
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import { createNamespacedHelpers } from "vuex";
|
|
|
const { mapState, mapMutations, mapActions } = createNamespacedHelpers(
|
|
|
"address/address"
|
|
|
);
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
...
|
...
|
@@ -83,7 +86,6 @@ export default { |
|
|
citys: [],
|
|
|
areas: [],
|
|
|
streets: [],
|
|
|
show: false,
|
|
|
common: {
|
|
|
titleActive: true
|
|
|
},
|
...
|
...
|
@@ -116,175 +118,173 @@ export default { |
|
|
titleActive: false
|
|
|
}
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
|
...mapState(["provincesList"])
|
|
|
},
|
|
|
methods: {
|
|
|
...mapMutations({}),
|
|
|
...mapActions(["fetchAddressProvinces"]),
|
|
|
/* 返回标题处理 */
|
|
|
returnTitle() {
|
|
|
let getTitle = "";
|
|
|
let returnTitle = "";
|
|
|
|
|
|
if (this.supportChangeProvince) {
|
|
|
getTitle =
|
|
|
this.province.allTitle +
|
|
|
this.city.allTitle +
|
|
|
this.area.allTitle +
|
|
|
this.street.allTitle;
|
|
|
} else {
|
|
|
getTitle =
|
|
|
this.city.allTitle + this.area.allTitle + this.street.allTitle;
|
|
|
}
|
|
|
|
|
|
if (getTitle.length > 11) {
|
|
|
returnTitle = getTitle.substr(0, 5) + "..." + getTitle.substr(-5);
|
|
|
} else {
|
|
|
returnTitle = getTitle;
|
|
|
}
|
|
|
|
|
|
return returnTitle;
|
|
|
},
|
|
|
|
|
|
/* 标题长度处理 */
|
|
|
titleHandle(caption) {
|
|
|
if (caption.length > 3) {
|
|
|
return caption.substring(0, 3) + "...";
|
|
|
} else {
|
|
|
return caption;
|
|
|
}
|
|
|
},
|
|
|
|
|
|
/* 选择地址后的显示控制 */
|
|
|
changeShow(id, caption) {
|
|
|
switch ((id + "").length) {
|
|
|
case 2:
|
|
|
this.province.id = id;
|
|
|
this.province.allTitle = caption;
|
|
|
this.province.title = this.titleHandle(caption);
|
|
|
this.city.title = "请选择";
|
|
|
this.city.showList = this.province.titleActive = true;
|
|
|
this.province.showList = this.area.showList = this.street.showList = false;
|
|
|
this.common.titleActive = this.city.titleActive = this.area.titleActive = this.street.titleActive = false;
|
|
|
break;
|
|
|
case 4:
|
|
|
this.city.id = id;
|
|
|
this.city.allTitle = caption;
|
|
|
this.city.title = this.titleHandle(caption);
|
|
|
this.area.title = "请选择";
|
|
|
this.area.showList = this.city.titleActive = true;
|
|
|
this.province.showList = this.city.showList = this.street.showList = false;
|
|
|
this.province.titleActive = this.area.titleActive = this.street.titleActive = false;
|
|
|
break;
|
|
|
case 6:
|
|
|
this.area.id = id;
|
|
|
this.area.allTitle = caption;
|
|
|
this.area.title = this.titleHandle(caption);
|
|
|
this.street.title = "请选择";
|
|
|
this.street.showList = this.area.titleActive = true;
|
|
|
this.province.showList = this.city.showList = this.area.showList = false;
|
|
|
this.province.titleActive = this.city.titleActive = this.street.titleActive = false;
|
|
|
break;
|
|
|
case 9:
|
|
|
this.street.id = id;
|
|
|
this.street.allTitle = caption;
|
|
|
this.street.title = this.titleHandle(caption);
|
|
|
this.street.showList = this.street.titleActive = true;
|
|
|
this.province.showList = this.city.showList = this.area.showList = false;
|
|
|
this.province.titleActive = this.city.titleActive = this.area.titleActive = false;
|
|
|
break;
|
|
|
default:
|
|
|
this.province.title = "请选择";
|
|
|
this.province.showList = this.province.titleActive = true;
|
|
|
this.city.showList = this.area.showList = this.street.showList = false;
|
|
|
this.city.titleActive = this.area.titleActive = this.street.titleActive = false;
|
|
|
break;
|
|
|
}
|
|
|
},
|
|
|
|
|
|
/* 获取地址数据绑定 */
|
|
|
async switchAddress(id, caption) {
|
|
|
if (!id) {
|
|
|
id = 0;
|
|
|
}
|
|
|
|
|
|
this.changeShow(id, caption);
|
|
|
|
|
|
const result = await this.fetchAddressProvinces(id);
|
|
|
let resultData = result.data;
|
|
|
|
|
|
//length小于1时弹窗消失并传数据给上层
|
|
|
if (resultData.length < 1) {
|
|
|
let returnTitle = this.returnTitle();
|
|
|
|
|
|
this.$emit("popHidden");
|
|
|
|
|
|
this.$emit("modifyAddressAct", {
|
|
|
code: id,
|
|
|
area: returnTitle
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/* 数据绑定 */
|
|
|
switch ((id + "").length) {
|
|
|
case 2:
|
|
|
this.citys = resultData;
|
|
|
break;
|
|
|
case 4:
|
|
|
this.areas = resultData;
|
|
|
break;
|
|
|
case 6:
|
|
|
this.streets = resultData;
|
|
|
break;
|
|
|
default:
|
|
|
this.provinces = resultData;
|
|
|
break;
|
|
|
}
|
|
|
},
|
|
|
|
|
|
/* 关闭地址选择组件 */
|
|
|
closeAddBox() {
|
|
|
this.$emit("hidden");
|
|
|
},
|
|
|
|
|
|
/* 点击地址标题时的处理 */
|
|
|
clickTitle(type) {
|
|
|
switch (type) {
|
|
|
case "province":
|
|
|
if (!this.supportChangeProvince) {
|
|
|
return false;
|
|
|
}
|
|
|
if (this.provinces.length < 1) {
|
|
|
this.switchAddress();
|
|
|
}
|
|
|
this.province.titleActive = this.province.showList = true;
|
|
|
this.city.titleActive = this.area.titleActive = this.street.titleActive = false;
|
|
|
this.city.title = this.area.title = this.street.title = "";
|
|
|
break;
|
|
|
case "city":
|
|
|
this.city.titleActive = this.city.showList = true;
|
|
|
this.province.titleActive = this.area.titleActive = this.street.titleActive = false;
|
|
|
this.province.showList = this.area.showList = this.street.showList = false;
|
|
|
this.area.title = this.street.title = "";
|
|
|
break;
|
|
|
case "area":
|
|
|
this.area.titleActive = this.area.showList = true;
|
|
|
this.province.titleActive = this.city.titleActive = this.street.titleActive = false;
|
|
|
this.province.showList = this.city.showList = this.street.showList = false;
|
|
|
this.street.title = "";
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
created: function() {
|
|
|
this.switchAddress();
|
|
|
}
|
|
|
// methods: {
|
|
|
// /* 返回标题处理 */
|
|
|
// returnTitle() {
|
|
|
// let getTitle = "";
|
|
|
// let returnTitle = "";
|
|
|
|
|
|
// if (this.supportChangeProvince) {
|
|
|
// getTitle =
|
|
|
// this.province.allTitle +
|
|
|
// this.city.allTitle +
|
|
|
// this.area.allTitle +
|
|
|
// this.street.allTitle;
|
|
|
// } else {
|
|
|
// getTitle =
|
|
|
// this.city.allTitle + this.area.allTitle + this.street.allTitle;
|
|
|
// }
|
|
|
|
|
|
// if (getTitle.length > 11) {
|
|
|
// returnTitle = getTitle.substr(0, 5) + "..." + getTitle.substr(-5);
|
|
|
// } else {
|
|
|
// returnTitle = getTitle;
|
|
|
// }
|
|
|
|
|
|
// return returnTitle;
|
|
|
// },
|
|
|
|
|
|
// /* 标题长度处理 */
|
|
|
// titleHandle(caption) {
|
|
|
// if (caption.length > 3) {
|
|
|
// return caption.substring(0, 3) + "...";
|
|
|
// } else {
|
|
|
// return caption;
|
|
|
// }
|
|
|
// },
|
|
|
|
|
|
// /* 选择地址后的显示控制 */
|
|
|
// changeShow(id, caption) {
|
|
|
// switch ((id + "").length) {
|
|
|
// case 2:
|
|
|
// this.province.id = id;
|
|
|
// this.province.allTitle = caption;
|
|
|
// this.province.title = this.titleHandle(caption);
|
|
|
// this.city.title = "请选择";
|
|
|
// this.city.showList = this.province.titleActive = true;
|
|
|
// this.province.showList = this.area.showList = this.street.showList = false;
|
|
|
// this.common.titleActive = this.city.titleActive = this.area.titleActive = this.street.titleActive = false;
|
|
|
// break;
|
|
|
// case 4:
|
|
|
// this.city.id = id;
|
|
|
// this.city.allTitle = caption;
|
|
|
// this.city.title = this.titleHandle(caption);
|
|
|
// this.area.title = "请选择";
|
|
|
// this.area.showList = this.city.titleActive = true;
|
|
|
// this.province.showList = this.city.showList = this.street.showList = false;
|
|
|
// this.province.titleActive = this.area.titleActive = this.street.titleActive = false;
|
|
|
// break;
|
|
|
// case 6:
|
|
|
// this.area.id = id;
|
|
|
// this.area.allTitle = caption;
|
|
|
// this.area.title = this.titleHandle(caption);
|
|
|
// this.street.title = "请选择";
|
|
|
// this.street.showList = this.area.titleActive = true;
|
|
|
// this.province.showList = this.city.showList = this.area.showList = false;
|
|
|
// this.province.titleActive = this.city.titleActive = this.street.titleActive = false;
|
|
|
// break;
|
|
|
// case 9:
|
|
|
// this.street.id = id;
|
|
|
// this.street.allTitle = caption;
|
|
|
// this.street.title = this.titleHandle(caption);
|
|
|
// this.street.showList = this.street.titleActive = true;
|
|
|
// this.province.showList = this.city.showList = this.area.showList = false;
|
|
|
// this.province.titleActive = this.city.titleActive = this.area.titleActive = false;
|
|
|
// break;
|
|
|
// default:
|
|
|
// this.province.title = "请选择";
|
|
|
// this.province.showList = this.province.titleActive = true;
|
|
|
// this.city.showList = this.area.showList = this.street.showList = false;
|
|
|
// this.city.titleActive = this.area.titleActive = this.street.titleActive = false;
|
|
|
// break;
|
|
|
// }
|
|
|
// },
|
|
|
|
|
|
// /* 获取地址数据绑定 */
|
|
|
// switchAddress(id, caption) {
|
|
|
// if (!id) {
|
|
|
// id = 0;
|
|
|
// }
|
|
|
|
|
|
// this.changeShow(id, caption);
|
|
|
|
|
|
// $.get(
|
|
|
// "/home/getaddress.json",
|
|
|
// {
|
|
|
// id: id
|
|
|
// },
|
|
|
// resultData => {
|
|
|
// /* 结果返回 */
|
|
|
// if (resultData.length < 1) {
|
|
|
// areaCode.val(id);
|
|
|
// let returnTitle = this.returnTitle();
|
|
|
|
|
|
// area.val(returnTitle);
|
|
|
// this.show = false;
|
|
|
|
|
|
// // this.$emit("modify.addressAct", {
|
|
|
// // code: id,
|
|
|
// // area: returnTitle
|
|
|
// // });
|
|
|
// }
|
|
|
|
|
|
// /* 数据绑定 */
|
|
|
// switch ((id + "").length) {
|
|
|
// case 2:
|
|
|
// this.citys = resultData;
|
|
|
// break;
|
|
|
// case 4:
|
|
|
// this.areas = resultData;
|
|
|
// break;
|
|
|
// case 6:
|
|
|
// this.streets = resultData;
|
|
|
// break;
|
|
|
// default:
|
|
|
// this.provinces = resultData;
|
|
|
// break;
|
|
|
// }
|
|
|
// }
|
|
|
// );
|
|
|
// },
|
|
|
|
|
|
// /* 关闭地址选择组件 */
|
|
|
// closeAddBox() {
|
|
|
// this.show = false;
|
|
|
// },
|
|
|
|
|
|
// /* 点击地址标题时的处理 */
|
|
|
// clickTitle(type) {
|
|
|
// switch (type) {
|
|
|
// case "province":
|
|
|
// if (!this.supportChangeProvince) {
|
|
|
// return false;
|
|
|
// }
|
|
|
// if (this.provinces.length < 1) {
|
|
|
// this.switchAddress();
|
|
|
// }
|
|
|
// this.province.titleActive = this.province.showList = true;
|
|
|
// this.city.titleActive = this.area.titleActive = this.street.titleActive = false;
|
|
|
// this.city.title = this.area.title = this.street.title = "";
|
|
|
// break;
|
|
|
// case "city":
|
|
|
// this.city.titleActive = this.city.showList = true;
|
|
|
// this.province.titleActive = this.area.titleActive = this.street.titleActive = false;
|
|
|
// this.province.showList = this.area.showList = this.street.showList = false;
|
|
|
// this.area.title = this.street.title = "";
|
|
|
// break;
|
|
|
// case "area":
|
|
|
// this.area.titleActive = this.area.showList = true;
|
|
|
// this.province.titleActive = this.city.titleActive = this.street.titleActive = false;
|
|
|
// this.province.showList = this.city.showList = this.street.showList = false;
|
|
|
// this.street.title = "";
|
|
|
// break;
|
|
|
// default:
|
|
|
// break;
|
|
|
// }
|
|
|
// }
|
|
|
// },
|
|
|
// created: function() {
|
|
|
// this.switchAddress();
|
|
|
// }
|
|
|
};
|
|
|
</script>
|
|
|
|
...
|
...
|
@@ -293,10 +293,6 @@ export default { |
|
|
color: #a6a6a6;
|
|
|
}
|
|
|
|
|
|
.icon-v:before {
|
|
|
content: "\e6ea";
|
|
|
}
|
|
|
|
|
|
.address-select-component {
|
|
|
position: fixed;
|
|
|
bottom: 0;
|
...
|
...
|
@@ -322,6 +318,14 @@ export default { |
|
|
.close {
|
|
|
float: right;
|
|
|
}
|
|
|
|
|
|
.icon-close {
|
|
|
height: 40px;
|
|
|
width: 40px;
|
|
|
margin-top: 20px;
|
|
|
background: url("~statics/image/address/close.png");
|
|
|
background-size: cover;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
.head-address-ul {
|
...
|
...
|
@@ -402,9 +406,13 @@ export default { |
|
|
position: relative;
|
|
|
overflow: hidden;
|
|
|
|
|
|
span {
|
|
|
color: #f23030;
|
|
|
font-size: 14px;
|
|
|
.icon-check {
|
|
|
display: inline-block;
|
|
|
margin-left: 10px;
|
|
|
height: 30px;
|
|
|
width: 30px;
|
|
|
background: url("~statics/image/address/check.png");
|
|
|
background-size: cover;
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|