"use strict"; const common_vendor = require("../../common/vendor.js"); const api_index = require("../../api/index.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 }, serviceId: { type: Number, optional: false }, appointmentDate: { 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.serviceId = this.__props__.serviceId; this.appointmentDate = this.__props__.appointmentDate; this.problem = this.__props__.problem; delete this.__props__; } } class ServiceItem extends UTS.UTSType { static get$UTSMetadata$() { return { kind: 2, get fields() { return { id: { type: Number, optional: false }, name: { type: String, optional: false }, type: { type: String, optional: false }, description: { type: String, optional: false }, price: { type: Number, optional: false } }; }, name: "ServiceItem" }; } constructor(options, metadata = ServiceItem.get$UTSMetadata$(), isJSONParse = false) { super(); this.__props__ = UTS.UTSType.initProps(options, metadata, isJSONParse); this.id = this.__props__.id; this.name = this.__props__.name; this.type = this.__props__.type; this.description = this.__props__.description; this.price = this.__props__.price; delete this.__props__; } } const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({ __name: "index", setup(__props) { const formData = common_vendor.ref(new FormData({ userName: "", phone: "", address: "", serviceId: 0, appointmentDate: "", problem: "" })); const imageList = common_vendor.ref([]); const serviceList = common_vendor.ref([]); const submitting = common_vendor.ref(false); const minDate = common_vendor.ref(""); const loadServices = () => { return common_vendor.__awaiter(this, void 0, void 0, function* () { try { const res = yield api_index.getActiveServices(); common_vendor.index.__f__("log", "at pages/booking/index.uvue:196", "服务列表响应:", res); if (res.code == 0 && res.data != null) { const data = res.data; let list = []; if (Array.isArray(data)) { list = data; } else { list = data["list"] || []; } common_vendor.index.__f__("log", "at pages/booking/index.uvue:206", "解析的服务列表:", list); serviceList.value = list.map((item) => { const basePrice = item["basePrice"] || "0"; return new ServiceItem({ id: item["id"], name: item["name"], type: item["type"], description: item["description"], price: parseFloat(basePrice) }); }); common_vendor.index.__f__("log", "at pages/booking/index.uvue:217", "最终服务列表:", serviceList.value); } else { common_vendor.index.__f__("error", "at pages/booking/index.uvue:219", "服务列表响应异常,code:", res.code, "data:", res.data); } } catch (e) { common_vendor.index.__f__("error", "at pages/booking/index.uvue:222", "加载服务列表失败", e); } }); }; const initMinDate = () => { const now = /* @__PURE__ */ new Date(); const year = now.getFullYear(); const month = String(now.getMonth() + 1).padStart(2, "0"); const day = String(now.getDate()).padStart(2, "0"); minDate.value = `${year}-${month}-${day}`; const tomorrow = /* @__PURE__ */ new Date(); tomorrow.setDate(tomorrow.getDate() + 1); const tYear = tomorrow.getFullYear(); const tMonth = String(tomorrow.getMonth() + 1).padStart(2, "0"); const tDay = String(tomorrow.getDate()).padStart(2, "0"); formData.value.appointmentDate = `${tYear}-${tMonth}-${tDay}`; }; const selectService = (id) => { formData.value.serviceId = id; }; const onDateChange = (e = null) => { formData.value.appointmentDate = e.detail.value; }; 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; } if (formData.value.serviceId == 0) { common_vendor.index.showToast({ title: "请选择服务类型", icon: "none" }); return false; } if (formData.value.appointmentDate == "") { 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 validImages = imageList.value.filter((url) => { return url.startsWith("http://") || url.startsWith("https://"); }); if (imageList.value.length > 0 && validImages.length === 0) { common_vendor.index.__f__("log", "at pages/booking/index.uvue:340", "警告:图片为微信临时路径,暂不支持上传"); } const data = new UTSJSONObject({ serviceId: formData.value.serviceId, contactName: formData.value.userName, contactPhone: formData.value.phone, address: formData.value.address, appointmentTime: formData.value.appointmentDate + "T10:00:00.000Z", requirements: formData.value.problem, images: validImages // 只提交有效的URL }); common_vendor.index.__f__("log", "at pages/booking/index.uvue:354", "提交预约数据:", data); const res = yield api_index.submitBooking(data); common_vendor.index.__f__("log", "at pages/booking/index.uvue:356", "预约提交结果:", res); common_vendor.index.showModal(new UTSJSONObject({ title: "预约成功", content: "我们会尽快与您联系,请保持电话畅通", 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:375", "提交预约异常:", e); } submitting.value = false; }); }; common_vendor.onLoad(() => { initMinDate(); loadServices(); }); 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(serviceList), (item, k0, i0) => { return { a: common_vendor.t(item.name), b: common_vendor.unref(formData).serviceId == item.id ? 1 : "", c: common_vendor.unref(formData).serviceId == item.id ? 1 : "", d: item.id, e: common_vendor.o(($event) => { return selectService(item.id); }, item.id) }; }), h: common_vendor.unref(formData).appointmentDate }, common_vendor.unref(formData).appointmentDate ? { i: common_vendor.t(common_vendor.unref(formData).appointmentDate) } : {}, { j: common_vendor.unref(formData).appointmentDate, k: common_vendor.unref(minDate), l: common_vendor.o(onDateChange), m: common_vendor.unref(formData).problem, n: common_vendor.o(($event) => { return common_vendor.unref(formData).problem = $event.detail.value; }), o: common_vendor.t(common_vendor.unref(formData).problem.length), p: common_vendor.f(common_vendor.unref(imageList), (item, index, i0) => { return { a: item, b: common_vendor.o(($event) => { return deleteImage(index); }, index), c: index }; }), q: common_vendor.unref(imageList).length < 9 }, common_vendor.unref(imageList).length < 9 ? { r: common_vendor.o(chooseImage) } : {}, { s: common_vendor.o(handleSubmit), t: common_vendor.sei(common_vendor.gei(_ctx, ""), "view") }); return __returned__; }; } }); wx.createPage(_sfc_main); //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/booking/index.js.map