Authored by 张文文

更新省份城市问题修改

... ... @@ -71,9 +71,9 @@
<div class="wrapper-del">
<Radio
class="radio"
:label="{text: '设为默认地址', value: 'Y'}"
:label="{text: '设为默认地址', value: true}"
style="flex: 0 1 100%;"
checked="model.tagType === 'Y'"
checked="model.defaultType"
v-model="model.defaultType"
></Radio>
<div v-if="isUpdate" class="del-address" @click="delAddress">删除地址</div>
... ... @@ -81,7 +81,14 @@
<div :class="submitClass" @touchend="onSubmit">确定</div>
</div>
<AddressAct v-show="isShowPop" @popHidden="popHidden" @modifyAddressAct="modifyAddressAct"></AddressAct>
<AddressAct
v-show="isShowPop"
:areaId="model.areaCode"
:areaTitle="model.receiverArea"
@popHidden="popHidden"
@modifyAddressAct="modifyAddressAct"
></AddressAct>
</LayoutApp>
</template>
... ... @@ -118,7 +125,7 @@ export default {
receiverArea: "",
receiverAddress: "",
tagType: "",
defaultType: "N"
defaultType: false
}
};
},
... ... @@ -158,12 +165,6 @@ export default {
return;
}
this.toast = this.$createToast({
type: "loading",
txt: "正在提交中",
mask: true
}).show();
let result = {};
if (this.isUpdate) {
... ... @@ -173,11 +174,13 @@ export default {
result = await this.addUserAddress(data);
}
await this.sleep(1000);
this.toast && this.toast.hide();
if (result && result.code === 200) {
this.$createToast({
type: "txt",
txt: result.message
}).show();
await this.sleep(1000);
this.$router.go(-1);
} else {
this.$createToast({
... ... @@ -187,13 +190,6 @@ export default {
}).show();
}
},
sleep(n) {
return new Promise(resolve => {
setTimeout(() => {
resolve();
}, n);
});
},
validator() {
let info = this.model;
let username = info.receiverName.replace(/(^\s+)|(\s+$)/g, "");
... ... @@ -209,9 +205,18 @@ export default {
return false;
}
let reg = this.isUpdate
? /^[0123456789*]{1,30}$/
: /^[0123456789]{1,30}$/;
if (!info.receiverMobile) {
this.showToast("手机号不能为空");
return false;
} else {
if (!reg.test(info.receiverMobile)) {
this.showToast("手机号码输入不正确");
return;
}
}
if (!info.areaCode || !info.receiverArea) {
... ... @@ -230,15 +235,14 @@ export default {
area_code: info.areaCode,
area: info.receiverArea,
address: info.receiverAddress,
is_default: info.defaultType,
is_default: info.defaultType ? "Y" : "N",
tag_code: info.tagType
};
},
showToast(tip) {
this.toast = this.$createToast({
type: "error",
txt: tip,
mask: true
this.$createToast({
type: "txt",
txt: tip
}).show();
},
chooseArea() {
... ... @@ -258,6 +262,12 @@ export default {
async delAddress() {
const result = await this.deleteUserAddress(this.model.addressId);
if (result && result.code === 200) {
this.$createToast({
type: "txt",
txt: result.message
}).show();
await this.sleep(1000);
this.$router.go(-1);
} else {
this.$createToast({
... ... @@ -266,8 +276,16 @@ export default {
mask: true
}).show();
}
},
sleep(n) {
return new Promise(resolve => {
setTimeout(() => {
resolve();
}, n);
});
}
},
mounted() {
this.fetchAddressTags();
... ... @@ -284,7 +302,7 @@ export default {
that.model.receiverArea = item.area;
that.model.receiverAddress = item.address;
that.model.tagType = item.tag_code;
that.model.defaultType = item.is_default;
that.model.defaultType = item.is_default === "Y" ? true : false;
}
}
}
... ...
... ... @@ -79,6 +79,25 @@ const { mapState, mapMutations, mapActions } = createNamespacedHelpers(
"address/address"
);
export default {
props: {
areaTitle: {
type: String,
default() {
return "";
}
},
areaId: {
type: String,
default() {
return "";
}
}
},
watch: {
areaTitle: function(newVal, oldVal) {
newVal && this.handleAreaTitle();
}
},
data() {
return {
supportChangeProvince: true, // 是否支持修改省
... ... @@ -125,6 +144,63 @@ export default {
methods: {
...mapMutations({}),
...mapActions(["fetchAddressProvinces"]),
/* 处理父组件传递的区域 */
async handleAreaTitle() {
let areaId = this.areaId;
let areaCaption = this.areaTitle;
let returnTitle = this.returnTitle();
if (returnTitle.length > 0) {
return;
}
let arrList = areaCaption.trim().split(" ");
if (!areaId) {
areaId = 0;
}
this.province.id = areaId.substring(0, 2);
this.province.allTitle = arrList[0];
this.province.title = this.titleHandle(arrList[0]);
const provinceResult = await this.fetchAddressProvinces(0);
this.provinces = provinceResult.data;
this.city.id = areaId.substring(0, 4);
this.city.allTitle = arrList[1];
this.city.title = this.titleHandle(arrList[1]);
const cityResult = await this.fetchAddressProvinces(
areaId.substring(0, 2)
);
this.citys = cityResult.data;
this.area.id = areaId.substring(0, 6);
this.area.allTitle = arrList[2];
this.area.title = this.titleHandle(arrList[2]);
const areaResult = await this.fetchAddressProvinces(
areaId.substring(0, 4)
);
this.areas = areaResult.data;
this.street.id = areaId;
this.street.allTitle = arrList[3];
this.street.title = this.titleHandle(arrList[3]);
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;
this.common.titleActive = false;
this.area.titleActive = true;
//根据前6位请求显示列表
const result = await this.fetchAddressProvinces(areaId.substring(0, 6));
this.streets = result.data;
},
/* 返回标题处理 */
returnTitle() {
let getTitle = "";
... ... @@ -141,8 +217,8 @@ export default {
this.city.allTitle + this.area.allTitle + this.street.allTitle;
}
if (getTitle.length > 11) {
returnTitle = getTitle.substr(0, 5) + "..." + getTitle.substr(-5);
if (getTitle.length > 18) {
returnTitle = getTitle.substr(0, 8) + "..." + getTitle.substr(-8);
} else {
returnTitle = getTitle;
}
... ... @@ -152,7 +228,7 @@ export default {
/* 标题长度处理 */
titleHandle(caption) {
if (caption.length > 3) {
if (caption && caption.length > 3) {
return caption.substring(0, 3) + "...";
} else {
return caption;
... ... @@ -218,7 +294,7 @@ export default {
let resultData = result.data;
//length小于1时弹窗消失并传数据给上层
if (resultData.length < 1) {
if (resultData && resultData.length < 1) {
let returnTitle = this.returnTitle();
this.$emit("popHidden");
... ... @@ -248,7 +324,7 @@ export default {
/* 关闭地址选择组件 */
closeAddBox() {
this.$emit("hidden");
this.$emit("popHidden");
},
/* 点击地址标题时的处理 */
... ...
... ... @@ -24,7 +24,6 @@
</slot>
</div>
</div>
<div class="add-btn" :data-add="1" @click="toEditorPage">添加地址</div>
</CubeScroll>
</template>
... ... @@ -66,6 +65,18 @@ export default {
let isAdd = !!parseInt(event.currentTarget.dataset.add);
let item = event.currentTarget.dataset.item || {};
if (isAdd) {
if (this.list.length >= 5) {
this.toast = this.$createToast({
type: "error",
txt: "地址不能超过5个",
mask: true
}).show();
return;
}
}
this.$router.push({
name: "addressEdit",
params: {
... ...
... ... @@ -10,7 +10,7 @@ export default {
commit
}) {
const result = await this.$api.get('/api/address/gethidden', {
uid: '500031912',
uid: '500031912'
});
if (result.code === 200) {
... ... @@ -25,7 +25,7 @@ export default {
commit
}) {
const result = await this.$api.get('/api/address/getTags', {
uid: '500031912',
uid: '500031912'
});
if (result.code === 200) {
... ... @@ -53,34 +53,20 @@ export default {
return result;
},
// 设置默认地址, post请求
async setDefaultAddress({
commit
}) {
const result = await this.$api.post('/api/address/setDefaultAddress');
if (result.code === 200) {
commit(Types.SET_DEFAULT_ADDRESS);
}
return result || {};
},
// 添加、更新、删除地址,post请求
async addUserAddress({
commit
}, data) {
const result = await this.$api.post(
'/api/address/addAddress', {
uid: '500031912',
address: data.address,
area_code: data.area_code,
consignee: data.consignee,
mobile: data.mobile,
tag_code: data.tag_code,
is_default: data.is_default,
debug: 'XYZ'
});
const result = await this.$api.post('/api/address/addAddress', {
uid: '500031912',
address: data.address,
area_code: data.area_code,
consignee: data.consignee,
mobile: data.mobile,
tag_code: data.tag_code,
is_default: data.is_default,
debug: 'XYZ'
});
return result || {};
},
... ... @@ -114,4 +100,17 @@ export default {
return result || {};
},
// 设置默认地址, post请求 ---- 暂时用不到这个
async setDefaultAddress({
commit
}) {
const result = await this.$api.post('/api/address/setDefaultAddress');
if (result.code === 200) {
commit(Types.SET_DEFAULT_ADDRESS);
}
return result || {};
},
};
... ...
... ... @@ -7,11 +7,7 @@ export default function () {
state: {
addressList: [],
addressTags: [],
provincesList: [],
addStatus: -1,
updateStatus: -1,
delStatus: -1,
setDefaultStatus: -1
provincesList: []
},
actions,
mutations,
... ...
... ... @@ -15,10 +15,5 @@ export default {
list
}) {
state.provincesList = list;
},
[Types.ADD_USER_ADDRESS_INFO](state, {
status,
}) {
state.addStatus = status;
},
}
};
... ...
export const FETCH_USER_ADDRESS_LIST = 'FETCH_USER_ADDRESS_LIST';
export const FETCH_ADDRESS_TAGS = 'FETCH_ADDRESS_TAGS';
export const ADD_USER_ADDRESS_INFO = 'ADD_USER_ADDRESS_INFO';
export const UPDATE_USER_ADDRESS_INFO = 'UPDATE_USER_ADDRESS_INFO';
export const DELETE_USER_ADDRESS_INFO = 'DELETE_USER_ADDRESS_INFO';
export const FETCH_ADDRESS_PROVINCES = 'FETCH_ADDRESS_PROVINCES';
export const ADD_USER_ADDRESSINFO_SUCCESS = 'ADD_USER_ADDRESSINFO_SUCCESS';
export const UPDATE_USER_ADDRESSINFO_SUCCESS = 'UPDATE_USER_ADDRESSINFO_SUCCESS';
export const DELETE_USER_ADDRESSINFO_SUCCESS = 'DELETE_USER_ADDRESSINFO_SUCCESS';
export const SET_DEFAULT_ADDRESS = 'SET_DEFAULT_ADDRESS';
... ...