style: 统一全仓代码格式
This commit is contained in:
1 parent
d811478d0f
commit
8033cabff9
30 files changed
+1183
-187
No files matched your search
@@ -1,31 +1,92 @@
|
||||
const { request, customerRequest } = require('../../utils/request');
|
||||
const { getTemplate } = require('../../utils/templates');
|
||||
const { request, customerRequest } = require("../../utils/request");
|
||||
const { getTemplate } = require("../../utils/templates");
|
||||
Page({
|
||||
data: { service: {}, form: {}, serviceId: '', quantity: 1, fulfillment: 'pickup', submitting: false, template: getTemplate('personal') },
|
||||
onLoad(query) { Promise.all([request('/public/services'), request('/public/brand')]).then(([services, brand]) => { const list = Array.isArray(services) ? services : []; const service = list.find((item) => item.id === query.serviceId) || list.find((item) => item.priceAmount !== null) || {}; this.setData({ service, serviceId: service.id || '', template: getTemplate(brand.templateKey) }); }).catch(() => wx.showToast({ title: '服务加载失败', icon: 'none' })); },
|
||||
input(event) { this.setData({ ['form.' + event.currentTarget.dataset.key]: event.detail.value }); },
|
||||
chooseFulfillment(event) { this.setData({ fulfillment: event.currentTarget.dataset.value }); },
|
||||
increase() { if (this.data.quantity < 50) this.setData({ quantity: this.data.quantity + 1 }); },
|
||||
decrease() { if (this.data.quantity > 1) this.setData({ quantity: this.data.quantity - 1 }); },
|
||||
data: {
|
||||
service: {},
|
||||
form: {},
|
||||
serviceId: "",
|
||||
quantity: 1,
|
||||
fulfillment: "pickup",
|
||||
submitting: false,
|
||||
template: getTemplate("personal"),
|
||||
},
|
||||
onLoad(query) {
|
||||
Promise.all([request("/public/services"), request("/public/brand")])
|
||||
.then(([services, brand]) => {
|
||||
const list = Array.isArray(services) ? services : [];
|
||||
const service =
|
||||
list.find((item) => item.id === query.serviceId) ||
|
||||
list.find((item) => item.priceAmount !== null) ||
|
||||
{};
|
||||
this.setData({
|
||||
service,
|
||||
serviceId: service.id || "",
|
||||
template: getTemplate(brand.templateKey),
|
||||
});
|
||||
})
|
||||
.catch(() => wx.showToast({ title: "服务加载失败", icon: "none" }));
|
||||
},
|
||||
input(event) {
|
||||
this.setData({ ["form." + event.currentTarget.dataset.key]: event.detail.value });
|
||||
},
|
||||
chooseFulfillment(event) {
|
||||
this.setData({ fulfillment: event.currentTarget.dataset.value });
|
||||
},
|
||||
increase() {
|
||||
if (this.data.quantity < 50) this.setData({ quantity: this.data.quantity + 1 });
|
||||
},
|
||||
decrease() {
|
||||
if (this.data.quantity > 1) this.setData({ quantity: this.data.quantity - 1 });
|
||||
},
|
||||
submit() {
|
||||
const form = this.data.form;
|
||||
if (!this.data.serviceId) return wx.showToast({ title: '请先选择服务', icon: 'none' });
|
||||
if (!form.customerName || !form.wechatId) return wx.showToast({ title: '请填写称呼和联系方式', icon: 'none' });
|
||||
if (this.data.fulfillment === 'delivery' && !form.deliveryAddress) return wx.showToast({ title: '请填写' + this.data.template.locationLabel, icon: 'none' });
|
||||
if (!this.data.serviceId) return wx.showToast({ title: "请先选择服务", icon: "none" });
|
||||
if (!form.customerName || !form.wechatId)
|
||||
return wx.showToast({ title: "请填写称呼和联系方式", icon: "none" });
|
||||
if (this.data.fulfillment === "delivery" && !form.deliveryAddress)
|
||||
return wx.showToast({ title: "请填写" + this.data.template.locationLabel, icon: "none" });
|
||||
this.setData({ submitting: true });
|
||||
const send = () => customerRequest('/customer/bookings', {
|
||||
method: 'POST',
|
||||
data: { requestType: this.data.template.requestType, customerName: form.customerName, wechatId: form.wechatId, contactPreference: 'wechat', fulfillmentType: this.data.fulfillment, deliveryAddress: form.deliveryAddress, requestedTime: form.requestedTime, note: form.note, items: [{ serviceId: this.data.serviceId, quantity: this.data.quantity }] },
|
||||
}).then(() => {
|
||||
this.setData({ submitting: false });
|
||||
wx.showToast({ title: '预约已提交' });
|
||||
setTimeout(() => wx.navigateTo({ url: '/pages/bookings/index' }), 500);
|
||||
}).catch((error) => {
|
||||
this.setData({ submitting: false });
|
||||
wx.showToast({ title: error.message || '提交失败', icon: 'none' });
|
||||
});
|
||||
const token = wx.getStorageSync('customerToken');
|
||||
const send = () =>
|
||||
customerRequest("/customer/bookings", {
|
||||
method: "POST",
|
||||
data: {
|
||||
requestType: this.data.template.requestType,
|
||||
customerName: form.customerName,
|
||||
wechatId: form.wechatId,
|
||||
contactPreference: "wechat",
|
||||
fulfillmentType: this.data.fulfillment,
|
||||
deliveryAddress: form.deliveryAddress,
|
||||
requestedTime: form.requestedTime,
|
||||
note: form.note,
|
||||
items: [{ serviceId: this.data.serviceId, quantity: this.data.quantity }],
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
this.setData({ submitting: false });
|
||||
wx.showToast({ title: "预约已提交" });
|
||||
setTimeout(() => wx.navigateTo({ url: "/pages/bookings/index" }), 500);
|
||||
})
|
||||
.catch((error) => {
|
||||
this.setData({ submitting: false });
|
||||
wx.showToast({ title: error.message || "提交失败", icon: "none" });
|
||||
});
|
||||
const token = wx.getStorageSync("customerToken");
|
||||
if (token) return send();
|
||||
wx.login({ success: (login) => request('/customer/session/wechat', { method: 'POST', data: { code: login.code } }).then((result) => { wx.setStorageSync('customerToken', result.token); send(); }).catch((error) => { this.setData({ submitting: false }); wx.showToast({ title: error.message || '微信登录失败', icon: 'none' }); }), fail: (error) => { this.setData({ submitting: false }); wx.showToast({ title: error.errMsg || '微信登录失败', icon: 'none' }); } });
|
||||
wx.login({
|
||||
success: (login) =>
|
||||
request("/customer/session/wechat", { method: "POST", data: { code: login.code } })
|
||||
.then((result) => {
|
||||
wx.setStorageSync("customerToken", result.token);
|
||||
send();
|
||||
})
|
||||
.catch((error) => {
|
||||
this.setData({ submitting: false });
|
||||
wx.showToast({ title: error.message || "微信登录失败", icon: "none" });
|
||||
}),
|
||||
fail: (error) => {
|
||||
this.setData({ submitting: false });
|
||||
wx.showToast({ title: error.errMsg || "微信登录失败", icon: "none" });
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -1 +1,5 @@
|
||||
{"navigationBarTitleText":"提交需求","navigationBarBackgroundColor":"#FBF7F1","navigationBarTextStyle":"black"}
|
||||
{
|
||||
"navigationBarTitleText": "提交需求",
|
||||
"navigationBarBackgroundColor": "#FBF7F1",
|
||||
"navigationBarTextStyle": "black"
|
||||
}
|
||||
@@ -1,2 +1,138 @@
|
||||
.page{min-height:100vh;padding:24rpx 32rpx 60rpx;background:#FBF7F1;color:#2B2B2B}.product{display:flex;align-items:center;gap:20rpx;padding:20rpx;background:#F4EBD9;border-radius:16rpx}.product-image{width:220rpx;height:180rpx;overflow:hidden;border-radius:12rpx;flex:none}.product-image image,.dish-placeholder{width:100%;height:100%;display:block;background:#c79555}.product-copy{flex:1}.name{display:block;font-size:34rpx;font-weight:700}.price{display:block;margin-top:18rpx;color:#B54A2C;font-size:38rpx}.available{color:#7A4A2B;font-size:26rpx;white-space:nowrap;align-self:flex-start;margin-top:14rpx}.quantity,.fulfillment{margin-top:20rpx;padding:28rpx;background:#F4EBD9;border-radius:16rpx;font-size:32rpx}.stepper{float:right;display:flex;align-items:center;gap:18rpx}.stepper button{width:56rpx;height:56rpx;line-height:52rpx;padding:0;border-radius:50%;background:#fff;color:#B54A2C}.field-title{font-weight:700}.choices{display:flex;gap:16rpx;margin-top:18rpx}.choice{flex:1;border-radius:12rpx;background:#7A4A2B;color:#fff}.choice.active{background:#B54A2C}.form{margin-top:20rpx;background:#fff;border-radius:16rpx;padding:8rpx 28rpx}.form label{display:flex;justify-content:space-between;gap:20rpx;padding:28rpx 0;border-bottom:1rpx solid #eee;font-size:30rpx}.form input,.form textarea{flex:1;text-align:right}.form textarea{min-height:100rpx}.notice{margin:20rpx 0;padding:24rpx;background:#F4EBD9;border-radius:16rpx;color:#7A4A2B}.submit{background:#B54A2C;color:#fff;border-radius:12rpx;font-size:34rpx}
|
||||
.stepper button{display:flex;width:64rpx;height:64rpx;align-items:center;justify-content:center;padding:0;border:0;border-radius:16rpx;background:#fff;color:#B54A2C;font-size:40rpx;line-height:1}
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
padding: 24rpx 32rpx 60rpx;
|
||||
background: #fbf7f1;
|
||||
color: #2b2b2b;
|
||||
}
|
||||
.product {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20rpx;
|
||||
padding: 20rpx;
|
||||
background: #f4ebd9;
|
||||
border-radius: 16rpx;
|
||||
}
|
||||
.product-image {
|
||||
width: 220rpx;
|
||||
height: 180rpx;
|
||||
overflow: hidden;
|
||||
border-radius: 12rpx;
|
||||
flex: none;
|
||||
}
|
||||
.product-image image,
|
||||
.dish-placeholder {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: block;
|
||||
background: #c79555;
|
||||
}
|
||||
.product-copy {
|
||||
flex: 1;
|
||||
}
|
||||
.name {
|
||||
display: block;
|
||||
font-size: 34rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
.price {
|
||||
display: block;
|
||||
margin-top: 18rpx;
|
||||
color: #b54a2c;
|
||||
font-size: 38rpx;
|
||||
}
|
||||
.available {
|
||||
color: #7a4a2b;
|
||||
font-size: 26rpx;
|
||||
white-space: nowrap;
|
||||
align-self: flex-start;
|
||||
margin-top: 14rpx;
|
||||
}
|
||||
.quantity,
|
||||
.fulfillment {
|
||||
margin-top: 20rpx;
|
||||
padding: 28rpx;
|
||||
background: #f4ebd9;
|
||||
border-radius: 16rpx;
|
||||
font-size: 32rpx;
|
||||
}
|
||||
.stepper {
|
||||
float: right;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 18rpx;
|
||||
}
|
||||
.stepper button {
|
||||
width: 56rpx;
|
||||
height: 56rpx;
|
||||
line-height: 52rpx;
|
||||
padding: 0;
|
||||
border-radius: 50%;
|
||||
background: #fff;
|
||||
color: #b54a2c;
|
||||
}
|
||||
.field-title {
|
||||
font-weight: 700;
|
||||
}
|
||||
.choices {
|
||||
display: flex;
|
||||
gap: 16rpx;
|
||||
margin-top: 18rpx;
|
||||
}
|
||||
.choice {
|
||||
flex: 1;
|
||||
border-radius: 12rpx;
|
||||
background: #7a4a2b;
|
||||
color: #fff;
|
||||
}
|
||||
.choice.active {
|
||||
background: #b54a2c;
|
||||
}
|
||||
.form {
|
||||
margin-top: 20rpx;
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 8rpx 28rpx;
|
||||
}
|
||||
.form label {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 20rpx;
|
||||
padding: 28rpx 0;
|
||||
border-bottom: 1rpx solid #eee;
|
||||
font-size: 30rpx;
|
||||
}
|
||||
.form input,
|
||||
.form textarea {
|
||||
flex: 1;
|
||||
text-align: right;
|
||||
}
|
||||
.form textarea {
|
||||
min-height: 100rpx;
|
||||
}
|
||||
.notice {
|
||||
margin: 20rpx 0;
|
||||
padding: 24rpx;
|
||||
background: #f4ebd9;
|
||||
border-radius: 16rpx;
|
||||
color: #7a4a2b;
|
||||
}
|
||||
.submit {
|
||||
background: #b54a2c;
|
||||
color: #fff;
|
||||
border-radius: 12rpx;
|
||||
font-size: 34rpx;
|
||||
}
|
||||
.stepper button {
|
||||
display: flex;
|
||||
width: 64rpx;
|
||||
height: 64rpx;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: 16rpx;
|
||||
background: #fff;
|
||||
color: #b54a2c;
|
||||
font-size: 40rpx;
|
||||
line-height: 1;
|
||||
}
|
||||
Reference in new issue
Block a user