"use strict"; var common_vendor = require("../common/vendor.js"); var api_common = require("../api/common.js"); var api_userAddress = require("../api/userAddress.js"); require("../common/request.js"); const _sfc_main = { components: {}, data() { return { content: null, type: null, addressId: null, isDefault: false, addressList: [[], [], []], multiIndex: [0, 0, 0], address: [], form: { realName: null, phone: null, detail: null, address: null, isDefault: 0 } }; }, onLoad(option) { this.type = option.type; if (this.type == "edit") { common_vendor.index.setNavigationBarTitle({ title: "\u4FEE\u6539\u6536\u8D27\u5730\u5740" }); this.addressId = option.addressId; this.getAddressById(); } else { common_vendor.index.setNavigationBarTitle({ title: "\u65B0\u589E\u6536\u8D27\u5730\u5740" }); } this.getCitys(); }, methods: { parseAddress() { if (this.content == null || this.content == "") { common_vendor.index.showToast({ icon: "none", title: "\u8BF7\u8F93\u5165\u5730\u5740\u4FE1\u606F" }); return; } var data = { content: this.content }; api_userAddress.parseAddress(data).then((res) => { if (res.code == 200) { this.form.realName = res.data.name; this.form.phone = res.data.mobile; this.form.address = res.data.provinceName + res.data.cityName + res.data.expAreaName; this.form.province = res.data.provinceName; this.form.city = res.data.cityName; this.form.district = res.data.expAreaName; this.form.detail = res.data.streetName + res.data.address; this.form.detail = this.form.detail.replace(/\s+/g, ""); } else { common_vendor.index.showToast({ icon: "none", title: res.msg }); } }, (rej) => { }); }, getAddressById() { var data = { addressId: this.addressId }; api_userAddress.getAddressById(data).then((res) => { if (res.code == 200) { this.form = res.data; this.isDefault = this.form.isDefault == 1 ? true : false; this.form.address = this.form.province + this.form.city + this.form.district; } else { common_vendor.index.showToast({ icon: "none", title: res.msg }); } }, (rej) => { }); }, submit() { if (this.type == "add") { this.addAddress(); } else if (this.type == "edit") { this.editAddress(); } }, editAddress() { this.form.isDefault = this.isDefault ? 1 : 0; api_userAddress.editAddress(this.form).then((res) => { if (res.code == 200) { common_vendor.index.showToast({ icon: "success", title: "\u64CD\u4F5C\u6210\u529F" }); setTimeout(function() { common_vendor.index.$emit("refreshAddress"); common_vendor.index.navigateBack({ delta: 1 }); }, 500); } else { common_vendor.index.showToast({ icon: "none", title: res.msg }); } }, (rej) => { }); }, addAddress() { this.form.isDefault = this.isDefault ? 1 : 0; api_userAddress.addAddress(this.form).then((res) => { if (res.code == 200) { common_vendor.index.showToast({ icon: "success", title: "\u64CD\u4F5C\u6210\u529F" }); setTimeout(function() { common_vendor.index.$emit("refreshAddress"); common_vendor.index.navigateBack({ delta: 1 }); }, 500); } else { common_vendor.index.showToast({ icon: "none", title: res.msg }); } }, (rej) => { }); }, pickerChange(e) { this.multiIndex = e.detail.value; this.form.address = this.addressList[0][this.multiIndex[0]].n + this.addressList[1][this.multiIndex[1]].n + this.addressList[2][this.multiIndex[2]].n; this.form.province = this.addressList[0][this.multiIndex[0]].n; this.form.city = this.addressList[1][this.multiIndex[1]].n; this.form.district = this.addressList[2][this.multiIndex[2]].n; this.form.cityId = this.addressList[1][this.multiIndex[1]].v; }, pickerColumnchange(e) { if (e.detail.column === 0) { this.multiIndex[0] = e.detail.value; this.addressList[1] = this.address[this.multiIndex[0]].c; this.addressList[2] = this.address[this.multiIndex[0]].c[0].c; this.multiIndex.splice(1, 1, 0); this.multiIndex.splice(2, 1, 0); } if (e.detail.column === 1) { this.multiIndex[1] = e.detail.value; this.addressList[2] = this.address[this.multiIndex[0]].c[this.multiIndex[1]].c; this.multiIndex.splice(2, 1, 0); } if (e.detail.column === 2) { this.multiIndex[2] = e.detail.value; } }, getCitys() { api_common.getCitys().then((res) => { if (res.code == 200) { this.address = res.data; for (var i = 0; i < this.address.length; i++) { this.addressList[0].push(this.address[i]); } for (var i = 0; i < this.address[0].c.length; i++) { this.addressList[1].push(this.address[0].c[i]); } for (var i = 0; i < this.address[0].c[0].c.length; i++) { this.addressList[2].push(this.address[0].c[0].c[i]); } } else { common_vendor.index.showToast({ icon: "none", title: "\u8BF7\u6C42\u5931\u8D25" }); } }, (rej) => { }); } } }; if (!Array) { const _easycom_u_switch2 = common_vendor.resolveComponent("u-switch"); _easycom_u_switch2(); } const _easycom_u_switch = () => "../uni_modules/uview-plus/components/u-switch/u-switch.js"; if (!Math) { _easycom_u_switch(); } function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return { a: $data.form.realName, b: common_vendor.o(($event) => $data.form.realName = $event.detail.value), c: $data.form.phone, d: common_vendor.o(($event) => $data.form.phone = $event.detail.value), e: $data.form.address, f: common_vendor.o(($event) => $data.form.address = $event.detail.value), g: $data.multiIndex, h: $data.addressList, i: common_vendor.o((...args) => $options.pickerChange && $options.pickerChange(...args)), j: common_vendor.o((...args) => $options.pickerColumnchange && $options.pickerColumnchange(...args)), k: $data.form.detail, l: common_vendor.o(($event) => $data.form.detail = $event.detail.value), m: $data.content, n: common_vendor.o(($event) => $data.content = $event.detail.value), o: common_vendor.o(($event) => $options.parseAddress()), p: common_vendor.o(($event) => $data.isDefault = $event), q: common_vendor.p({ activeColor: "#C39A58", modelValue: $data.isDefault }), r: common_vendor.o(($event) => $options.submit()) }; } var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "E:/Project/2023/\u95EE\u8BCA\u5E73\u53F0/his_user_miniapp/pages_user/addEditAddress.vue"]]); wx.createPage(MiniProgramPage);