"use strict"; var __defProp = Object.defineProperty; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; var __async = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { step(generator.next(value)); } catch (e) { reject(e); } }; var rejected = (value) => { try { step(generator.throw(value)); } catch (e) { reject(e); } }; var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); step((generator = generator.apply(__this, __arguments)).next()); }); }; const common_vendor = require("../../common/vendor.js"); const utils_http = require("../../utils/http.js"); if (!Array) { const _easycom_wd_icon2 = common_vendor.resolveComponent("wd-icon"); const _easycom_wd_status_tip2 = common_vendor.resolveComponent("wd-status-tip"); const _easycom_wd_popup2 = common_vendor.resolveComponent("wd-popup"); const _component_layout_default_uni = common_vendor.resolveComponent("layout-default-uni"); (_easycom_wd_icon2 + _easycom_wd_status_tip2 + _easycom_wd_popup2 + _component_layout_default_uni)(); } const _easycom_wd_icon = () => "../../node-modules/wot-design-uni/components/wd-icon/wd-icon.js"; const _easycom_wd_status_tip = () => "../../node-modules/wot-design-uni/components/wd-status-tip/wd-status-tip.js"; const _easycom_wd_popup = () => "../../node-modules/wot-design-uni/components/wd-popup/wd-popup.js"; if (!Math) { (_easycom_wd_icon + _easycom_wd_status_tip + AddAddress + _easycom_wd_popup)(); } const AddAddress = () => "./components/AddAddress.js"; const _sfc_main = { __name: "index", setup(__props) { const addresses = common_vendor.ref([]); const currentAddress = common_vendor.ref({ id: null, name: "", phone: "", address: "" }); const showPopup = common_vendor.ref(false); const fetchAddresses = () => __async(this, null, function* () { const res = yield utils_http.httpPost("/china-address/page"); addresses.value = res.records; }); common_vendor.onMounted(() => { fetchAddresses(); }); const addAddress = () => { currentAddress.value = { id: null, name: "", phone: "", address: "" }; showPopup.value = true; }; const editAddress = (index) => { const address = addresses.value[index]; addresses.value[index].address = `${address.province}-${address.city}-${address.district}`; currentAddress.value = __spreadValues({}, addresses.value[index]); showPopup.value = true; }; const saveAddress = (address) => __async(this, null, function* () { let res; if (address.address != "") { const addressList = address.address.split("-"); address.province = addressList[0]; address.city = addressList[1]; address.district = addressList[2]; } if (address.id) { res = yield utils_http.httpPost("/china-address/modify", address); } else { res = yield utils_http.httpPost("/china-address/add", address); } if (res.code == 200) { common_vendor.index.showToast({ title: "操作成功", icon: "" }); fetchAddresses(); showPopup.value = false; } }); const deleteAddress = (index) => __async(this, null, function* () { const addressId = addresses.value[index].id; common_vendor.index.showModal({ title: "确认删除", content: "你确定要删除这个地址吗?", success: (res) => __async(this, null, function* () { if (res.confirm) { const deleteRes = yield utils_http.httpGet(`/china-address/remove/${addressId}`); if (deleteRes.code === 200) { common_vendor.index.showToast({ title: "删除成功", icon: "success" }); fetchAddresses(); } } }) }); }); return (_ctx, _cache) => { return common_vendor.e({ a: common_vendor.f(addresses.value, (address, index, i0) => { return { a: common_vendor.t(address.type), b: common_vendor.t(address.name), c: common_vendor.t(address.phone), d: common_vendor.t(`${address["province"]}-${address["city"]}-${address["district"]}`), e: common_vendor.o(($event) => editAddress(index), index), f: "15db8353-1-" + i0 + ",15db8353-0", g: common_vendor.o(($event) => deleteAddress(index), index), h: "15db8353-2-" + i0 + ",15db8353-0", i: index }; }), b: common_vendor.p({ name: "edit", size: "20px" }), c: common_vendor.p({ name: "delete", size: "20px" }), d: addresses.value.length == 0 }, addresses.value.length == 0 ? { e: common_vendor.p({ image: "content", tip: "暂无内容" }) } : {}, { f: common_vendor.o(addAddress), g: common_vendor.o(saveAddress), h: common_vendor.p({ initialAddress: currentAddress.value }), i: common_vendor.o(_ctx.handleClose), j: common_vendor.o(($event) => showPopup.value = $event), k: common_vendor.p({ position: "bottom", ["custom-style"]: "height: 60%; width: 100%;", modelValue: showPopup.value }) }); }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-15db8353"]]); wx.createPage(MiniProgramPage); //# sourceMappingURL=index.js.map