acdr-ui/dist/dev/mp-weixin/modules/mall/user/address/edit.js

292 lines
11 KiB
JavaScript
Raw Permalink Normal View History

2024-09-19 07:20:14 +08:00
"use strict";
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
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 __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
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");
2024-10-01 09:15:35 +08:00
const modules_mall_sheep_index = require("../../sheep/index.js");
const modules_mall_sheep_validate_form = require("../../sheep/validate/form.js");
const modules_mall_sheep_api_system_area = require("../../sheep/api/system/area.js");
const modules_mall_sheep_api_member_address = require("../../sheep/api/member/address.js");
2024-09-19 07:20:14 +08:00
if (!Array) {
const _easycom_uni_easyinput2 = common_vendor.resolveComponent("uni-easyinput");
const _easycom_uni_forms_item2 = common_vendor.resolveComponent("uni-forms-item");
const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
const _easycom_su_switch2 = common_vendor.resolveComponent("su-switch");
const _easycom_uni_forms2 = common_vendor.resolveComponent("uni-forms");
const _easycom_su_fixed2 = common_vendor.resolveComponent("su-fixed");
const _easycom_su_region_picker2 = common_vendor.resolveComponent("su-region-picker");
const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
const _component_layout_default_uni = common_vendor.resolveComponent("layout-default-uni");
(_easycom_uni_easyinput2 + _easycom_uni_forms_item2 + _easycom_uni_icons2 + _easycom_su_switch2 + _easycom_uni_forms2 + _easycom_su_fixed2 + _easycom_su_region_picker2 + _easycom_s_layout2 + _component_layout_default_uni)();
}
const _easycom_uni_easyinput = () => "../../../../uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.js";
const _easycom_uni_forms_item = () => "../../../../uni_modules/uni-forms/components/uni-forms-item/uni-forms-item.js";
const _easycom_uni_icons = () => "../../../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
2024-10-01 09:15:35 +08:00
const _easycom_su_switch = () => "../../sheep/ui/su-switch/su-switch.js";
2024-09-19 07:20:14 +08:00
const _easycom_uni_forms = () => "../../../../uni_modules/uni-forms/components/uni-forms/uni-forms.js";
2024-10-01 09:15:35 +08:00
const _easycom_su_fixed = () => "../../sheep/ui/su-fixed/su-fixed.js";
const _easycom_su_region_picker = () => "../../sheep/ui/su-region-picker/su-region-picker.js";
const _easycom_s_layout = () => "../../sheep/components/s-layout/s-layout.js";
2024-09-19 07:20:14 +08:00
if (!Math) {
(_easycom_uni_easyinput + _easycom_uni_forms_item + _easycom_uni_icons + _easycom_su_switch + _easycom_uni_forms + _easycom_su_fixed + _easycom_su_region_picker + _easycom_s_layout)();
}
const _sfc_main = {
__name: "edit",
setup(__props) {
const addressFormRef = common_vendor.ref(null);
const state = common_vendor.reactive({
showRegion: false,
model: {
name: "",
mobile: "",
detailAddress: "",
defaultStatus: false,
areaName: ""
},
rules: {}
});
const rules = {
name: {
rules: [
{
required: true,
errorMessage: "请输入收货人姓名"
}
]
},
2024-10-01 09:15:35 +08:00
mobile: modules_mall_sheep_validate_form.mobile,
2024-09-19 07:20:14 +08:00
detailAddress: {
rules: [
{
required: true,
errorMessage: "请输入详细地址"
}
]
},
areaName: {
rules: [
{
required: true,
errorMessage: "请选择您的位置"
}
]
}
};
const onRegionConfirm = (e) => {
state.model.areaName = `${e.province_name} ${e.city_name} ${e.district_name}`;
state.model.areaId = e.district_id;
state.showRegion = false;
};
const getAreaData = () => {
if (common_vendor.lodash.isEmpty(common_vendor.index.getStorageSync("areaData"))) {
2024-10-01 09:15:35 +08:00
modules_mall_sheep_api_system_area.AreaApi.getAreaTree().then((res) => {
2024-09-19 07:20:14 +08:00
if (res.code === 0) {
common_vendor.index.setStorageSync("areaData", res.data);
}
});
}
};
const onSave = () => __async(this, null, function* () {
const validate = yield common_vendor.unref(addressFormRef).validate().catch((error) => {
console.log("error: ", error);
});
if (!validate) {
return;
}
const formData = __spreadValues({}, state.model);
2024-10-01 09:15:35 +08:00
const { code } = state.model.id > 0 ? yield modules_mall_sheep_api_member_address.AddressApi.updateAddress(formData) : yield modules_mall_sheep_api_member_address.AddressApi.createAddress(formData);
2024-09-19 07:20:14 +08:00
if (code === 0) {
2024-10-01 09:15:35 +08:00
modules_mall_sheep_index.sheep.$router.back();
2024-09-19 07:20:14 +08:00
}
});
const onDelete = () => {
common_vendor.index.showModal({
title: "提示",
content: "确认删除此收货地址吗?",
success: function(res) {
return __async(this, null, function* () {
if (!res.confirm) {
return;
}
2024-10-01 09:15:35 +08:00
const { code } = yield modules_mall_sheep_api_member_address.AddressApi.deleteAddress(state.model.id);
2024-09-19 07:20:14 +08:00
if (code === 0) {
2024-10-01 09:15:35 +08:00
modules_mall_sheep_index.sheep.$router.back();
2024-09-19 07:20:14 +08:00
}
});
}
});
};
common_vendor.onLoad((options) => __async(this, null, function* () {
getAreaData();
if (options.id) {
2024-10-01 09:15:35 +08:00
const { code, data } = yield modules_mall_sheep_api_member_address.AddressApi.getAddress(options.id);
2024-09-19 07:20:14 +08:00
if (code !== 0) {
return;
}
state.model = data;
}
if (options.data) {
const data = JSON.parse(options.data);
const areaData = common_vendor.index.getStorageSync("areaData");
const findAreaByName = (areas, name) => areas.find((item) => item.name === name);
const provinceObj = findAreaByName(areaData, data.province_name);
const cityObj = provinceObj ? findAreaByName(provinceObj.children, data.city_name) : void 0;
const districtObj = cityObj ? findAreaByName(cityObj.children, data.district_name) : void 0;
const areaId = (districtObj || cityObj || provinceObj).id;
state.model = __spreadProps(__spreadValues({}, state.model), {
areaId,
areaName: [data.province_name, data.city_name, data.district_name].filter(Boolean).join(" "),
defaultStatus: false,
detailAddress: data.address,
mobile: data.mobile,
name: data.consignee
});
}
}));
return (_ctx, _cache) => {
return common_vendor.e({
a: common_vendor.o(($event) => state.model.name = $event),
b: common_vendor.p({
placeholder: "请填写收货人姓名",
inputBorder: false,
placeholderStyle: "color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal",
modelValue: state.model.name
}),
c: common_vendor.p({
name: "name",
label: "收货人"
}),
d: common_vendor.o(($event) => state.model.mobile = $event),
e: common_vendor.p({
type: "number",
placeholder: "请输入手机号",
inputBorder: false,
placeholderStyle: "color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal",
modelValue: state.model.mobile
}),
f: common_vendor.p({
name: "mobile",
label: "手机号"
}),
g: common_vendor.p({
type: "right"
}),
h: common_vendor.o(($event) => state.model.areaName = $event),
i: common_vendor.p({
disabled: true,
inputBorder: false,
styles: {
disableColor: "#fff",
color: "#333"
},
placeholderStyle: "color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal",
placeholder: "请选择省市区",
modelValue: state.model.areaName
}),
j: common_vendor.o(($event) => state.showRegion = true),
k: common_vendor.p({
name: "areaName",
label: "省市区"
}),
l: common_vendor.o(($event) => state.model.detailAddress = $event),
m: common_vendor.p({
inputBorder: false,
type: "textarea",
placeholderStyle: "color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal",
placeholder: "请输入详细地址",
clearable: true,
modelValue: state.model.detailAddress
}),
n: common_vendor.p({
name: "detailAddress",
label: "详细地址",
formItemStyle: {
alignItems: "flex-start"
},
labelStyle: {
lineHeight: "5em"
}
}),
o: common_vendor.o(($event) => state.model.defaultStatus = $event),
p: common_vendor.p({
modelValue: state.model.defaultStatus
}),
q: common_vendor.sr(addressFormRef, "67eb3955-2,67eb3955-1", {
"k": "addressFormRef"
}),
r: common_vendor.o(($event) => state.model = $event),
s: common_vendor.p({
rules,
validateTrigger: "bind",
labelWidth: "160",
labelAlign: "left",
border: true,
labelStyle: {
fontWeight: "bold"
},
modelValue: state.model
}),
t: common_vendor.o(onSave),
v: state.model.id
}, state.model.id ? {
w: common_vendor.o(onDelete)
} : {}, {
x: common_vendor.p({
bottom: true,
opacity: false,
bg: "",
placeholder: true,
noFixed: false,
index: 10
}),
y: common_vendor.o(($event) => state.showRegion = false),
z: common_vendor.o(onRegionConfirm),
A: common_vendor.p({
show: state.showRegion
}),
B: common_vendor.p({
title: state.model.id ? "编辑地址" : "新增地址"
})
});
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-67eb3955"]]);
wx.createPage(MiniProgramPage);