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__;
|
||||
};
|
||||
|
||||
@@ -1 +1 @@
|
||||
<view id="{{o}}" change:eS="{{uV.sS}}" eS="{{$eS[o]}}" change:eA="{{uV.sA}}" eA="{{$eA[o]}}" class="{{['page', virtualHostClass]}}" style="{{virtualHostStyle}}" hidden="{{virtualHostHidden || false}}"><scroll-view class="page-scroll" scroll-y enable-flex="true" enhanced="true"><view class="header-section"><text class="header-title">预约翻新服务</text><text class="header-desc">填写以下信息,我们会尽快与您联系</text></view><view class="form-section"><view class="form-item"><text class="form-label"><text class="required">*</text> 您的姓名 </text><input class="form-input" type="text" placeholder="请输入您的姓名" placeholder-class="placeholder" value="{{a}}" bindinput="{{b}}"/></view><view class="form-item"><text class="form-label"><text class="required">*</text> 联系电话 </text><input class="form-input" type="number" placeholder="请输入您的手机号" placeholder-class="placeholder" maxlength="11" value="{{c}}" bindinput="{{d}}"/></view><view class="form-item"><text class="form-label"><text class="required">*</text> 您的地址 </text><input class="form-input" type="text" placeholder="请输入详细地址" placeholder-class="placeholder" value="{{e}}" bindinput="{{f}}"/></view><view class="form-item"><text class="form-label">沙发类型</text><view class="type-grid"><view wx:for="{{g}}" wx:for-item="item" wx:key="d" class="{{['type-item', item.c && 'type-active']}}" bindtap="{{item.e}}"><text class="{{['type-text', item.b && 'type-text-active']}}">{{item.a}}</text></view></view></view><view class="form-item"><text class="form-label">问题描述</text><block wx:if="{{r0}}"><textarea class="form-textarea" placeholder="请描述沙发的问题(如:皮面开裂、褪色、塌陷等)" placeholder-class="placeholder" maxlength="500" value="{{h}}" bindinput="{{i}}"></textarea></block><text class="textarea-count">{{j}}/500</text></view><view class="form-item"><text class="form-label">上传图片(可选)</text><view class="upload-grid"><view wx:for="{{k}}" wx:for-item="item" wx:key="c" class="upload-item"><image class="upload-image" src="{{item.a}}" mode="aspectFill"></image><view class="upload-delete" bindtap="{{item.b}}"><text class="delete-icon">×</text></view></view><view wx:if="{{l}}" class="upload-add" bindtap="{{m}}"><text class="add-icon">+</text><text class="add-text">添加图片</text></view></view><text class="upload-tip">最多可上传9张图片</text></view></view><view class="bottom-space"></view></scroll-view><view class="submit-bar"><view class="submit-btn" bindtap="{{n}}"><text class="submit-text">提交预约</text></view></view></view><wxs src="/common/uniView.wxs" module="uV"/>
|
||||
<view id="{{t}}" change:eS="{{uV.sS}}" eS="{{$eS[t]}}" change:eA="{{uV.sA}}" eA="{{$eA[t]}}" class="{{['page', virtualHostClass]}}" style="{{virtualHostStyle}}" hidden="{{virtualHostHidden || false}}"><scroll-view class="page-scroll" scroll-y enable-flex="true" enhanced="true"><view class="header-section"><text class="header-title">预约翻新服务</text><text class="header-desc">填写以下信息,我们会尽快与您联系</text></view><view class="form-section"><view class="form-item"><text class="form-label"><text class="required">*</text> 您的姓名 </text><input class="form-input" type="text" placeholder="请输入您的姓名" placeholder-class="placeholder" value="{{a}}" bindinput="{{b}}"/></view><view class="form-item"><text class="form-label"><text class="required">*</text> 联系电话 </text><input class="form-input" type="number" placeholder="请输入您的手机号" placeholder-class="placeholder" maxlength="11" value="{{c}}" bindinput="{{d}}"/></view><view class="form-item"><text class="form-label"><text class="required">*</text> 您的地址 </text><input class="form-input" type="text" placeholder="请输入详细地址" placeholder-class="placeholder" value="{{e}}" bindinput="{{f}}"/></view><view class="form-item"><text class="form-label"><text class="required">*</text> 服务类型 </text><view class="type-grid"><view wx:for="{{g}}" wx:for-item="item" wx:key="d" class="{{['type-item', item.c && 'type-active']}}" bindtap="{{item.e}}"><text class="{{['type-text', item.b && 'type-text-active']}}">{{item.a}}</text></view></view></view><view class="form-item"><text class="form-label"><text class="required">*</text> 预约时间 </text><picker mode="date" value="{{j}}" start="{{k}}" bindchange="{{l}}"><view class="picker-value"><text wx:if="{{h}}" class="picker-text">{{i}}</text><text wx:else class="picker-placeholder">请选择预约日期</text></view></picker></view><view class="form-item"><text class="form-label">问题描述</text><block wx:if="{{r0}}"><textarea class="form-textarea" placeholder="请描述沙发的问题(如:皮面开裂、褪色、塌陷等)" placeholder-class="placeholder" maxlength="500" value="{{m}}" bindinput="{{n}}"></textarea></block><text class="textarea-count">{{o}}/500</text></view><view class="form-item"><text class="form-label">上传图片(可选)</text><view class="upload-grid"><view wx:for="{{p}}" wx:for-item="item" wx:key="c" class="upload-item"><image class="upload-image" src="{{item.a}}" mode="aspectFill"></image><view class="upload-delete" bindtap="{{item.b}}"><text class="delete-icon">×</text></view></view><view wx:if="{{q}}" class="upload-add" bindtap="{{r}}"><text class="add-icon">+</text><text class="add-text">添加图片</text></view></view><text class="upload-tip">提示:当前仅支持预览,图片暂不会上传到服务器</text></view></view><view class="bottom-space"></view></scroll-view><view class="submit-bar"><view class="submit-btn" bindtap="{{s}}"><text class="submit-text">提交预约</text></view></view></view><wxs src="/common/uniView.wxs" module="uV"/>
|
||||
|
||||
@@ -80,6 +80,23 @@
|
||||
color: #C0C4CC;
|
||||
}
|
||||
|
||||
/* 日期选择器 */
|
||||
.picker-value {
|
||||
background-color: #f5f5f5;
|
||||
border-radius: 12rpx;
|
||||
padding: 24rpx;
|
||||
height: 40px;
|
||||
justify-content: center;
|
||||
}
|
||||
.picker-text {
|
||||
font-size: 28rpx;
|
||||
color: #303133;
|
||||
}
|
||||
.picker-placeholder {
|
||||
font-size: 28rpx;
|
||||
color: #C0C4CC;
|
||||
}
|
||||
|
||||
/* 沙发类型选择 */
|
||||
.type-grid {
|
||||
flex-direction: row;
|
||||
|
||||
Reference in New Issue
Block a user