"use strict"; const common_vendor = require("../../common/vendor.js"); const utils_globalState = require("../../utils/globalState.js"); const api_index = require("../../api/index.js"); const utils_session = require("../../utils/session.js"); if (!Math) { AppIcon(); } const AppIcon = () => "../../components/AppIcon.js"; const _sfc_main = { __name: "Store", emits: ["change-page"], setup(__props) { const storeInfo = utils_session.getStoreSession(); const navSafeStyle = (() => { var _a, _b, _c, _d; const statusBarHeight = ((_b = (_a = common_vendor.index).getSystemInfoSync) == null ? void 0 : _b.call(_a).statusBarHeight) || 20; let navHeight = statusBarHeight + 44; const menuRect = (_d = (_c = common_vendor.index).getMenuButtonBoundingClientRect) == null ? void 0 : _d.call(_c); if (menuRect && menuRect.top && menuRect.height) { const verticalGap = Math.max(menuRect.top - statusBarHeight, 4); navHeight = statusBarHeight + verticalGap * 2 + menuRect.height; } return `padding-top:${statusBarHeight}px;height:${navHeight}px;`; })(); const saving = common_vendor.ref(false); const pickingLocation = common_vendor.ref(false); const form = common_vendor.ref({ name: "", phone: "", address: "", intro: "", latitude: null, longitude: null }); const hasMapPin = common_vendor.computed(() => form.value.latitude != null && form.value.longitude != null); const toCoord = (v) => { if (v == null || v === "") return null; const n = typeof v === "number" ? v : parseFloat(v); return Number.isFinite(n) ? n : null; }; const pickAddress = () => { pickingLocation.value = true; common_vendor.index.chooseLocation({ success: (res) => { const name = res.name || ""; const addr = res.address || ""; form.value.address = [name, addr].filter(Boolean).join(" · ") || addr || name; form.value.latitude = toCoord(res.latitude); form.value.longitude = toCoord(res.longitude); }, fail: (err) => { const msg = err && err.errMsg || ""; if (/cancel|取消/i.test(msg)) return; common_vendor.index.showToast({ title: "无法打开选点,请手动填写", icon: "none" }); }, complete: () => { pickingLocation.value = false; } }); }; const saveStore = async () => { saving.value = true; const res = await api_index.updateStore({ id: storeInfo.id, ...form.value }); saving.value = false; if (res.code === 200) { common_vendor.index.showToast({ title: "保存成功", icon: "success" }); const merged = res.data ? { ...storeInfo, ...res.data } : { ...storeInfo, ...form.value }; utils_session.setStoreSession(merged); } else { common_vendor.index.showToast({ title: res.message || "保存失败", icon: "none" }); } }; common_vendor.onMounted(() => { form.value = { name: storeInfo.name || "", phone: storeInfo.phone || "", address: storeInfo.address || "", intro: storeInfo.intro || "", latitude: toCoord(storeInfo.latitude), longitude: toCoord(storeInfo.longitude) }; }); return (_ctx, _cache) => { return common_vendor.e({ a: common_vendor.p({ name: "back", size: 18, color: "#ffffff" }), b: common_vendor.o(($event) => common_vendor.unref(utils_globalState.navigateTo)("mine")), c: common_vendor.s(common_vendor.unref(navSafeStyle)), d: common_vendor.p({ name: "store", size: 22, color: "#15803d" }), e: common_vendor.p({ name: "store", size: 15, color: "#475569" }), f: form.value.name, g: common_vendor.o(($event) => form.value.name = $event.detail.value), h: common_vendor.p({ name: "phone", size: 15, color: "#475569" }), i: form.value.phone, j: common_vendor.o(($event) => form.value.phone = $event.detail.value), k: common_vendor.p({ name: "pin", size: 15, color: "#475569" }), l: form.value.address, m: common_vendor.o(($event) => form.value.address = $event.detail.value), n: pickingLocation.value, o: common_vendor.o(pickAddress), p: hasMapPin.value }, hasMapPin.value ? {} : {}, { q: common_vendor.p({ name: "report", size: 15, color: "#475569" }), r: form.value.intro, s: common_vendor.o(($event) => form.value.intro = $event.detail.value), t: saving.value, v: common_vendor.o(saveStore) }); }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-195de84b"]]); wx.createPage(MiniProgramPage);