Files
ShaFaFanXin/前端/unpackage/dist/dev/mp-weixin/pages/booking/index.js
2026-01-27 18:06:04 +08:00

222 lines
7.1 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const api_index = require("../../api/index.js");
const utils_config = require("../../utils/config.js");
class FormData extends UTS.UTSType {
static get$UTSMetadata$() {
return {
kind: 2,
get fields() {
return {
userName: { type: String, optional: false },
phone: { type: String, optional: false },
address: { type: String, optional: false },
sofaType: { type: String, optional: false },
problem: { type: String, optional: false }
};
},
name: "FormData"
};
}
constructor(options, metadata = FormData.get$UTSMetadata$(), isJSONParse = false) {
super();
this.__props__ = UTS.UTSType.initProps(options, metadata, isJSONParse);
this.userName = this.__props__.userName;
this.phone = this.__props__.phone;
this.address = this.__props__.address;
this.sofaType = this.__props__.sofaType;
this.problem = this.__props__.problem;
delete this.__props__;
}
}
class SofaType extends UTS.UTSType {
static get$UTSMetadata$() {
return {
kind: 2,
get fields() {
return {
id: { type: String, optional: false },
name: { type: String, optional: false }
};
},
name: "SofaType"
};
}
constructor(options, metadata = SofaType.get$UTSMetadata$(), isJSONParse = false) {
super();
this.__props__ = UTS.UTSType.initProps(options, metadata, isJSONParse);
this.id = this.__props__.id;
this.name = this.__props__.name;
delete this.__props__;
}
}
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
__name: "index",
setup(__props) {
const formData = common_vendor.ref(new FormData({
userName: "",
phone: "",
address: "",
sofaType: "",
problem: ""
}));
const imageList = common_vendor.ref([]);
const sofaTypes = common_vendor.ref([]);
const submitting = common_vendor.ref(false);
const initSofaTypes = () => {
sofaTypes.value = utils_config.SOFA_CATEGORIES.filter((item) => {
return item.id != "all";
}).map((item) => {
return new SofaType({
id: item.id,
name: item.name
});
});
};
const selectSofaType = (id) => {
formData.value.sofaType = id;
};
const chooseImage = () => {
common_vendor.index.chooseImage(new UTSJSONObject({
count: 9 - imageList.value.length,
sizeType: ["compressed"],
sourceType: ["album", "camera"],
success: (res) => {
imageList.value = [...imageList.value, ...res.tempFilePaths];
}
}));
};
const deleteImage = (index) => {
imageList.value.splice(index, 1);
};
const validateForm = () => {
if (formData.value.userName.trim() == "") {
common_vendor.index.showToast({
title: "请输入您的姓名",
icon: "none"
});
return false;
}
const phone = formData.value.phone.trim();
if (phone == "") {
common_vendor.index.showToast({
title: "请输入联系电话",
icon: "none"
});
return false;
}
if (phone.length != 11) {
common_vendor.index.showToast({
title: "请输入正确的手机号",
icon: "none"
});
return false;
}
if (formData.value.address.trim() == "") {
common_vendor.index.showToast({
title: "请输入您的地址",
icon: "none"
});
return false;
}
return true;
};
const handleSubmit = () => {
return common_vendor.__awaiter(this, void 0, void 0, function* () {
if (!validateForm())
return Promise.resolve(null);
if (submitting.value)
return Promise.resolve(null);
submitting.value = true;
try {
const data = new UTSJSONObject({
userName: formData.value.userName,
phone: formData.value.phone,
address: formData.value.address,
sofaType: formData.value.sofaType,
problem: formData.value.problem,
images: imageList.value
});
const res = yield api_index.submitBooking(data);
const result = res.data;
common_vendor.index.showModal(new UTSJSONObject({
title: "预约成功",
content: result["message"],
showCancel: false,
success: () => {
common_vendor.index.navigateBack(new UTSJSONObject({
fail: () => {
common_vendor.index.switchTab({
url: "/pages/index/index"
});
}
}));
}
}));
} catch (e) {
common_vendor.index.__f__("error", "at pages/booking/index.uvue:270", "提交预约失败", e);
common_vendor.index.showToast({
title: "提交失败,请重试",
icon: "none"
});
}
submitting.value = false;
});
};
common_vendor.onLoad(() => {
initSofaTypes();
});
return (_ctx, _cache) => {
"raw js";
const __returned__ = common_vendor.e({
a: common_vendor.unref(formData).userName,
b: common_vendor.o(($event) => {
return common_vendor.unref(formData).userName = $event.detail.value;
}),
c: common_vendor.unref(formData).phone,
d: common_vendor.o(($event) => {
return common_vendor.unref(formData).phone = $event.detail.value;
}),
e: common_vendor.unref(formData).address,
f: common_vendor.o(($event) => {
return common_vendor.unref(formData).address = $event.detail.value;
}),
g: common_vendor.f(common_vendor.unref(sofaTypes), (item, k0, i0) => {
return {
a: common_vendor.t(item.name),
b: common_vendor.unref(formData).sofaType == item.id ? 1 : "",
c: common_vendor.unref(formData).sofaType == item.id ? 1 : "",
d: item.id,
e: common_vendor.o(($event) => {
return selectSofaType(item.id);
}, item.id)
};
}),
h: common_vendor.unref(formData).problem,
i: common_vendor.o(($event) => {
return common_vendor.unref(formData).problem = $event.detail.value;
}),
j: common_vendor.t(common_vendor.unref(formData).problem.length),
k: common_vendor.f(common_vendor.unref(imageList), (item, index, i0) => {
return {
a: item,
b: common_vendor.o(($event) => {
return deleteImage(index);
}, index),
c: index
};
}),
l: common_vendor.unref(imageList).length < 9
}, common_vendor.unref(imageList).length < 9 ? {
m: common_vendor.o(chooseImage)
} : {}, {
n: common_vendor.o(handleSubmit),
o: common_vendor.sei(common_vendor.gei(_ctx, ""), "view")
});
return __returned__;
};
}
});
wx.createPage(_sfc_main);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/booking/index.js.map