feat:"完成页面接口的对接"
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
"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 {
|
||||
@@ -11,7 +10,8 @@ class FormData extends UTS.UTSType {
|
||||
userName: { type: String, optional: false },
|
||||
phone: { type: String, optional: false },
|
||||
address: { type: String, optional: false },
|
||||
sofaType: { type: String, optional: false },
|
||||
serviceId: { type: Number, optional: false },
|
||||
appointmentDate: { type: String, optional: false },
|
||||
problem: { type: String, optional: false }
|
||||
};
|
||||
},
|
||||
@@ -24,29 +24,36 @@ class FormData extends UTS.UTSType {
|
||||
this.userName = this.__props__.userName;
|
||||
this.phone = this.__props__.phone;
|
||||
this.address = this.__props__.address;
|
||||
this.sofaType = this.__props__.sofaType;
|
||||
this.serviceId = this.__props__.serviceId;
|
||||
this.appointmentDate = this.__props__.appointmentDate;
|
||||
this.problem = this.__props__.problem;
|
||||
delete this.__props__;
|
||||
}
|
||||
}
|
||||
class SofaType extends UTS.UTSType {
|
||||
class ServiceItem extends UTS.UTSType {
|
||||
static get$UTSMetadata$() {
|
||||
return {
|
||||
kind: 2,
|
||||
get fields() {
|
||||
return {
|
||||
id: { type: String, optional: false },
|
||||
name: { type: String, optional: false }
|
||||
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: "SofaType"
|
||||
name: "ServiceItem"
|
||||
};
|
||||
}
|
||||
constructor(options, metadata = SofaType.get$UTSMetadata$(), isJSONParse = false) {
|
||||
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__;
|
||||
}
|
||||
}
|
||||
@@ -57,24 +64,65 @@ const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
||||
userName: "",
|
||||
phone: "",
|
||||
address: "",
|
||||
sofaType: "",
|
||||
serviceId: 0,
|
||||
appointmentDate: "",
|
||||
problem: ""
|
||||
}));
|
||||
const imageList = common_vendor.ref([]);
|
||||
const sofaTypes = common_vendor.ref([]);
|
||||
const serviceList = 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 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 selectSofaType = (id) => {
|
||||
formData.value.sofaType = id;
|
||||
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({
|
||||
@@ -119,6 +167,20 @@ const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
||||
});
|
||||
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 = () => {
|
||||
@@ -129,19 +191,28 @@ const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
||||
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 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);
|
||||
const result = res.data;
|
||||
common_vendor.index.__f__("log", "at pages/booking/index.uvue:356", "预约提交结果:", res);
|
||||
common_vendor.index.showModal(new UTSJSONObject({
|
||||
title: "预约成功",
|
||||
content: result["message"],
|
||||
content: "我们会尽快与您联系,请保持电话畅通",
|
||||
showCancel: false,
|
||||
success: () => {
|
||||
common_vendor.index.navigateBack(new UTSJSONObject({
|
||||
@@ -154,17 +225,14 @@ const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
||||
}
|
||||
}));
|
||||
} catch (e) {
|
||||
common_vendor.index.__f__("error", "at pages/booking/index.uvue:270", "提交预约失败", e);
|
||||
common_vendor.index.showToast({
|
||||
title: "提交失败,请重试",
|
||||
icon: "none"
|
||||
});
|
||||
common_vendor.index.__f__("error", "at pages/booking/index.uvue:375", "提交预约异常:", e);
|
||||
}
|
||||
submitting.value = false;
|
||||
});
|
||||
};
|
||||
common_vendor.onLoad(() => {
|
||||
initSofaTypes();
|
||||
initMinDate();
|
||||
loadServices();
|
||||
});
|
||||
return (_ctx, _cache) => {
|
||||
"raw js";
|
||||
@@ -181,23 +249,30 @@ const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
||||
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) => {
|
||||
g: common_vendor.f(common_vendor.unref(serviceList), (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 : "",
|
||||
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 selectSofaType(item.id);
|
||||
return selectService(item.id);
|
||||
}, item.id)
|
||||
};
|
||||
}),
|
||||
h: common_vendor.unref(formData).problem,
|
||||
i: common_vendor.o(($event) => {
|
||||
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;
|
||||
}),
|
||||
j: common_vendor.t(common_vendor.unref(formData).problem.length),
|
||||
k: common_vendor.f(common_vendor.unref(imageList), (item, index, i0) => {
|
||||
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) => {
|
||||
@@ -206,12 +281,12 @@ const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
||||
c: index
|
||||
};
|
||||
}),
|
||||
l: common_vendor.unref(imageList).length < 9
|
||||
q: common_vendor.unref(imageList).length < 9
|
||||
}, common_vendor.unref(imageList).length < 9 ? {
|
||||
m: common_vendor.o(chooseImage)
|
||||
r: common_vendor.o(chooseImage)
|
||||
} : {}, {
|
||||
n: common_vendor.o(handleSubmit),
|
||||
o: common_vendor.sei(common_vendor.gei(_ctx, ""), "view")
|
||||
s: common_vendor.o(handleSubmit),
|
||||
t: common_vendor.sei(common_vendor.gei(_ctx, ""), "view")
|
||||
});
|
||||
return __returned__;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user