|
|
@@ -1,5 +1,6 @@
|
|
|
import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
|
|
|
-import smart from "address-smart-parse";
|
|
|
+// import parseAddress from "../../../../utils/address-parse";
|
|
|
+import AddressParse from "address-parse";
|
|
|
import tickleBehavior, {
|
|
|
getTickleContext,
|
|
|
} from "../../../../core/behavior/tickle.behavior";
|
|
|
@@ -51,7 +52,6 @@ Page({
|
|
|
this.setData({ detail: "" });
|
|
|
},
|
|
|
onRegionConfirm(e: any) {
|
|
|
- console.log(e.detail.values, "onRegionConfirm");
|
|
|
this.setData({
|
|
|
region:
|
|
|
e.detail.values[0].name +
|
|
|
@@ -68,11 +68,8 @@ Page({
|
|
|
"formData.areaCode": e.detail.values[2].code,
|
|
|
"formData.areaName": e.detail.values[2].name,
|
|
|
});
|
|
|
-
|
|
|
- console.log(this.data.region, "onRegionConfirm");
|
|
|
},
|
|
|
onRegionCancel(e: any) {
|
|
|
- console.log(e, "onRegionCancel");
|
|
|
this.setData({
|
|
|
regionPickerVisible: false,
|
|
|
});
|
|
|
@@ -129,14 +126,12 @@ Page({
|
|
|
// 添加地址
|
|
|
async onAddress(params: any) {
|
|
|
const res = await addAddressMethod(params);
|
|
|
- console.log(res, "添加地址");
|
|
|
- wx.showToast({ title: "添加地址成功", icon: "success" });
|
|
|
+ wx.showToast({ title: "添加成功", icon: "success" });
|
|
|
},
|
|
|
// 更新地址
|
|
|
async onUpdate(params: any) {
|
|
|
const res = await updateAddressMethod(params);
|
|
|
- console.log(res, "更新地址");
|
|
|
- wx.showToast({ title: "保存成功", icon: "success" });
|
|
|
+ wx.showToast({ title: "更新成功", icon: "success" });
|
|
|
},
|
|
|
// 保存
|
|
|
async onSave() {
|
|
|
@@ -168,7 +163,7 @@ Page({
|
|
|
this.setData({
|
|
|
"formData.tagList": [this.data.selectedTag],
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
this.setData({ saving: true });
|
|
|
if (this.data.id) {
|
|
|
this.data.formData.id = this.data.id;
|
|
|
@@ -177,31 +172,32 @@ Page({
|
|
|
await this.onAddress(this.data.formData);
|
|
|
}
|
|
|
this.setData({ saving: false });
|
|
|
- if (this.data.type === "orderDetail") {
|
|
|
- // 订单详情页
|
|
|
-
|
|
|
- }
|
|
|
- // 返回上一页
|
|
|
- const pages = getCurrentPages();
|
|
|
- console.log(pages, "保存地址pages");
|
|
|
+ // if (this.data.type === "orderDetail") {
|
|
|
+ // // 订单详情页
|
|
|
+ // wx.redirectTo({
|
|
|
+ // url: "/module/article/pages/order-detail/order-detail",
|
|
|
+ // });
|
|
|
+ // } else if (this.data.type === "orderList") {
|
|
|
+ // // 订单列表页
|
|
|
+ // wx.redirectTo({
|
|
|
+ // url: "/module/article/pages/order-list/order-list",
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // 返回上一页
|
|
|
+ const pages = getCurrentPages();
|
|
|
if (pages.length > 1) {
|
|
|
const prevPage = pages[pages.length - 2];
|
|
|
- console.log(prevPage.route, "prevPage");
|
|
|
if (
|
|
|
prevPage.route ===
|
|
|
"module/article/pages/manage-address/manage-address"
|
|
|
) {
|
|
|
- console.log(prevPage.route, "上一页面");
|
|
|
wx.redirectTo({
|
|
|
url: "/module/article/pages/manage-address/manage-address",
|
|
|
});
|
|
|
- } else {
|
|
|
- // wx.navigateBack();
|
|
|
}
|
|
|
}
|
|
|
// 保存成功后可自动跳转或提示
|
|
|
} catch (error: any) {
|
|
|
- console.log("保存失败", error);
|
|
|
wx.showToast({ title: error.errMsg, icon: "none" });
|
|
|
this.setData({ saving: false }); // 无论成功失败都重置
|
|
|
}
|
|
|
@@ -238,7 +234,7 @@ Page({
|
|
|
this.setData({ smartPasteValue: "" });
|
|
|
},
|
|
|
// 获取省市区编码
|
|
|
- getCodeByName(list, name) {
|
|
|
+ getCodeByName(list: any, name: any) {
|
|
|
for (const code in list) {
|
|
|
if (list[code] === name) {
|
|
|
return code;
|
|
|
@@ -249,7 +245,6 @@ Page({
|
|
|
// 删除地址
|
|
|
async onDelete() {
|
|
|
const that = this;
|
|
|
- console.log(that.data.id, "6666");
|
|
|
wx.showModal({
|
|
|
title: "确定删除地址?",
|
|
|
content: "删除后地址不可恢复",
|
|
|
@@ -259,14 +254,9 @@ Page({
|
|
|
confirmText: "删除",
|
|
|
success: async (res) => {
|
|
|
if (res.confirm) {
|
|
|
- console.log(that.data.id, "删除地址的id");
|
|
|
const res = await deleteAddressMethod(that.data.id);
|
|
|
- console.log(res, "删除地址");
|
|
|
wx.showToast({ title: "删除成功", icon: "success" });
|
|
|
wx.navigateBack();
|
|
|
- // setTimeout(() => {
|
|
|
- // wx.navigateBack();
|
|
|
- // }, 1500);
|
|
|
}
|
|
|
},
|
|
|
});
|
|
|
@@ -289,15 +279,17 @@ Page({
|
|
|
value = value.replace(name, ",");
|
|
|
}
|
|
|
// 5. 用智能库进一步解析省市区
|
|
|
- let result = smart(this.data.smartPasteValue);
|
|
|
- console.log(result, "识别的result");
|
|
|
+ let [result] = AddressParse.parse(this.data.smartPasteValue);
|
|
|
result = {
|
|
|
...result,
|
|
|
- name: result.name || name,
|
|
|
- phone: result.phone || phone,
|
|
|
- detailAddress: result.address,
|
|
|
+ name: result.name,
|
|
|
+ phone: result.phone || result.mobile,
|
|
|
+ detailAddress: result.details,
|
|
|
+ county: result.area,
|
|
|
+ provinceCode: result.provinceCode,
|
|
|
+ cityCode: result.cityCode,
|
|
|
+ areaCode: result.areaCode,
|
|
|
};
|
|
|
-
|
|
|
// 6. 校验
|
|
|
if (!result.name || !result.phone) {
|
|
|
wx.showToast({ title: "请按照提示输入正确的地址信息", icon: "none" });
|
|
|
@@ -310,7 +302,6 @@ Page({
|
|
|
// 7. 省市区识别
|
|
|
const { province, city, county } = result;
|
|
|
const { province_list, city_list, county_list } = this.data.areaList;
|
|
|
-
|
|
|
if (province && city) {
|
|
|
const provinceCode = this.getCodeByName(province_list, province);
|
|
|
const cityCode = this.getCodeByName(city_list, city);
|
|
|
@@ -322,7 +313,7 @@ Page({
|
|
|
"formData.provinceCode": provinceCode,
|
|
|
"formData.cityCode": cityCode,
|
|
|
"formData.areaCode": areaCode,
|
|
|
- "formData.detailAddress": result.address,
|
|
|
+ "formData.detailAddress": result.details,
|
|
|
region: `${province},${city}${county ? "," + county : ""}`,
|
|
|
});
|
|
|
} else {
|
|
|
@@ -331,7 +322,7 @@ Page({
|
|
|
// 其他字段(如姓名、手机号、详细地址)可以单独 setData,不受省市影响
|
|
|
this.setData({
|
|
|
"formData.liaison": result.name,
|
|
|
- "formData.phone": result.phone,
|
|
|
+ "formData.phone": result.phone || result.mobile,
|
|
|
});
|
|
|
wx.showToast({ title: "已识别", icon: "success" });
|
|
|
},
|
|
|
@@ -339,7 +330,6 @@ Page({
|
|
|
async getAddressDetail(id: string) {
|
|
|
try {
|
|
|
const res = await getAddressDetailByPatientIdMethod(id);
|
|
|
- console.log(res.data, "获取地址详情");
|
|
|
if (res && res.data) {
|
|
|
this.setData({
|
|
|
"formData.isDefault": res.data.isDefault,
|
|
|
@@ -374,5 +364,32 @@ Page({
|
|
|
if (options.type) {
|
|
|
this.setData({ type: options.type });
|
|
|
}
|
|
|
+ if (options.imported) {
|
|
|
+ const imported = JSON.parse(decodeURIComponent(options.imported));
|
|
|
+ const { provinceName, cityName, areaName } = imported;
|
|
|
+ const { province_list, city_list, county_list } = this.data.areaList;
|
|
|
+ if (provinceName && cityName) {
|
|
|
+ const provinceCode = this.getCodeByName(province_list, provinceName);
|
|
|
+ const cityCode = this.getCodeByName(city_list, cityName);
|
|
|
+ const areaCode = this.getCodeByName(county_list, areaName);
|
|
|
+ this.setData({
|
|
|
+ "formData.isDefault": imported.isDefault || "N",
|
|
|
+ "formData.liaison": imported.liaison,
|
|
|
+ "formData.phone": imported.phone,
|
|
|
+ "formData.detailAddress": imported.detailAddress,
|
|
|
+ "formData.provinceName": imported.provinceName,
|
|
|
+ "formData.cityName": imported.cityName,
|
|
|
+ "formData.areaName": imported.areaName,
|
|
|
+ "formData.provinceCode": provinceCode,
|
|
|
+ "formData.cityCode": cityCode,
|
|
|
+ "formData.areaCode": areaCode,
|
|
|
+ region: imported.region,
|
|
|
+ });
|
|
|
+ this.setData({
|
|
|
+ selectedTag: "",
|
|
|
+ type: "imported",
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
});
|