"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; }; const common_vendor = require("../../../common/vendor.js"); const hooks_useColPickerData = require("../../../hooks/useColPickerData.js"); if (!Array) { const _easycom_wd_input2 = common_vendor.resolveComponent("wd-input"); const _easycom_wd_picker2 = common_vendor.resolveComponent("wd-picker"); const _easycom_wd_col_picker2 = common_vendor.resolveComponent("wd-col-picker"); const _easycom_wd_form2 = common_vendor.resolveComponent("wd-form"); (_easycom_wd_input2 + _easycom_wd_picker2 + _easycom_wd_col_picker2 + _easycom_wd_form2)(); } const _easycom_wd_input = () => "../../../node-modules/wot-design-uni/components/wd-input/wd-input.js"; const _easycom_wd_picker = () => "../../../node-modules/wot-design-uni/components/wd-picker/wd-picker.js"; const _easycom_wd_col_picker = () => "../../../node-modules/wot-design-uni/components/wd-col-picker/wd-col-picker.js"; const _easycom_wd_form = () => "../../../node-modules/wot-design-uni/components/wd-form/wd-form.js"; if (!Math) { (_easycom_wd_input + _easycom_wd_picker + _easycom_wd_col_picker + _easycom_wd_form)(); } const _sfc_main = { __name: "AddAddress", props: { initialAddress: { type: Object, default: () => ({ name: "", phone: "", address: "", detailAddress: "", type: "", customType: "" }) } }, emits: ["save-address"], setup(__props, { emit: __emit }) { const { colPickerData, findChildrenByCode } = hooks_useColPickerData.useColPickerData(); const value = common_vendor.ref([]); const props = __props; common_vendor.ref([]); const area = common_vendor.ref([ colPickerData.map((item) => { return { value: item.value, label: item.text }; }) ]); const typeOptions = common_vendor.ref(["家", "公司", "自定义"]); const isCustomType = common_vendor.ref(false); const columnChange = ({ selectedItem, resolve, finish }) => { const areaData = findChildrenByCode(colPickerData, selectedItem.value); if (areaData && areaData.length) { resolve(areaData.map((item) => ({ value: item.value, label: item.text }))); } else { finish(); } }; const displayFormat = (selectedItems) => { return selectedItems.map((v) => v.label).join("-"); }; function handleConfirm({ value: value2, selectedItems }) { address.value.address = selectedItems.map((v) => v.label).join("-"); console.log(address.value.address); } function handleTypeChange({ value: value2 }) { isCustomType.value = value2 === "自定义"; if (!isCustomType.value) { address.value.customType = ""; } } const emit = __emit; const address = common_vendor.ref(__spreadValues({}, props.initialAddress)); common_vendor.watch( () => props.initialAddress, (newVal) => { address.value = __spreadValues({}, newVal); isCustomType.value = newVal.type === "自定义"; } ); const submitAddress = () => { if (address.value.name && address.value.phone && address.value.detailAddress && (address.value.type !== "自定义" || address.value.customType)) { emit("save-address", address.value); resetForm(); } else { common_vendor.index.showToast({ title: "请填写完整的地址信息", icon: "error" }); } }; const resetForm = () => { address.value = { name: "", phone: "", address: "", detailAddress: "", type: "", customType: "" }; value.value = []; isCustomType.value = false; }; return (_ctx, _cache) => { return common_vendor.e({ a: common_vendor.o(($event) => address.value.name = $event), b: common_vendor.p({ label: "姓名", required: true, modelValue: address.value.name }), c: common_vendor.o(($event) => address.value.phone = $event), d: common_vendor.p({ label: "电话", required: true, type: "tel", modelValue: address.value.phone }), e: common_vendor.o(handleTypeChange), f: common_vendor.o(($event) => address.value.type = $event), g: common_vendor.p({ columns: typeOptions.value, label: "地址类型", modelValue: address.value.type }), h: isCustomType.value }, isCustomType.value ? { i: common_vendor.o(($event) => address.value.customType = $event), j: common_vendor.p({ label: "自定义类型", required: true, modelValue: address.value.customType }) } : {}, { k: common_vendor.o(handleConfirm), l: common_vendor.o(($event) => value.value = $event), m: common_vendor.p({ label: "选择地址", columns: area.value, ["column-change"]: columnChange, ["display-format"]: displayFormat, modelValue: value.value }), n: address.value.address.length && address.value.address && !value.value.length }, address.value.address.length && address.value.address && !value.value.length ? { o: common_vendor.t(address.value.address) } : {}, { p: common_vendor.o(($event) => address.value.detailAddress = $event), q: common_vendor.p({ label: "详细地址", required: true, modelValue: address.value.detailAddress }), r: common_vendor.o(submitAddress), s: common_vendor.sr("addressForm", "fb0a64f0-0") }); }; } }; const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-fb0a64f0"]]); wx.createComponent(Component); //# sourceMappingURL=AddAddress.js.map