order.js
11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
"use strict";
const common_vendor = require("../../common/vendor.js");
const common_hotel = require("../../common/hotel.js");
require("../../common/login.js");
require("../../common/request.js");
require("../../config.js");
require("../../common/api.js");
if (!Array) {
const _easycom_uni_number_box2 = common_vendor.resolveComponent("uni-number-box");
const _easycom_uni_datetime_picker2 = common_vendor.resolveComponent("uni-datetime-picker");
const _easycom_uni_forms_item2 = common_vendor.resolveComponent("uni-forms-item");
const _easycom_uni_easyinput2 = common_vendor.resolveComponent("uni-easyinput");
const _easycom_uni_forms2 = common_vendor.resolveComponent("uni-forms");
const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
(_easycom_uni_number_box2 + _easycom_uni_datetime_picker2 + _easycom_uni_forms_item2 + _easycom_uni_easyinput2 + _easycom_uni_forms2 + _easycom_uni_icons2 + _easycom_uni_popup2)();
}
const _easycom_uni_number_box = () => "../../uni_modules/uni-number-box/components/uni-number-box/uni-number-box.js";
const _easycom_uni_datetime_picker = () => "../../uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.js";
const _easycom_uni_forms_item = () => "../../uni_modules/uni-forms/components/uni-forms-item/uni-forms-item.js";
const _easycom_uni_easyinput = () => "../../uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.js";
const _easycom_uni_forms = () => "../../uni_modules/uni-forms/components/uni-forms/uni-forms.js";
const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
const _easycom_uni_popup = () => "../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
if (!Math) {
(_easycom_uni_number_box + _easycom_uni_datetime_picker + _easycom_uni_forms_item + _easycom_uni_easyinput + _easycom_uni_forms + _easycom_uni_icons + _easycom_uni_popup)();
}
const _sfc_main = {
__name: "order",
setup(__props) {
const {
proxy
} = common_vendor.getCurrentInstance();
const app = getApp();
const data = common_vendor.reactive({
form: {
total: 0,
orderName: "",
activeId: "",
larId: "",
orderName: "",
foodsList: []
},
rzRange: [],
popup: null,
food: {
num: 1
},
choseDays: [],
money: "",
address: "",
startTime: "",
endTime: ""
});
const {
form,
food,
money,
popup,
rzRange,
address,
startTime,
endTime,
choseDays
} = common_vendor.toRefs(data);
let usedays = 0;
common_vendor.onLoad((options) => {
if ("food" in options) {
food.value = JSON.parse(decodeURIComponent(options.food));
}
address.value = options.address;
form.value.activeId = options.activeId;
form.value.larId = options.menuId;
form.value.orderName = options.orderName;
const currUser = common_vendor.index.getStorageSync("currUser");
if (currUser.realTelno) {
form.value.phone = currUser.realTelno;
}
endTime.value = app.globalData.foodEnd;
const today = common_vendor.dayjs().format("YYYY-MM-DD");
const start = app.globalData.foodStart || today;
if (start < today) {
startTime.value = today;
} else {
startTime.value = start;
}
console.log(startTime.value);
});
function getDate(datestr) {
var temp = datestr.split("-");
if (temp[1] === "01") {
temp[0] = parseInt(temp[0], 10) - 1;
temp[1] = "12";
} else {
temp[1] = parseInt(temp[1], 10) - 1;
}
var date = new Date(temp[0], temp[1], temp[2]);
return date;
}
function getDaysBetween(e) {
var d1 = Date.parse(rzRange.value[0]);
var d2 = Date.parse(rzRange.value[1]);
if (d1 > d2) {
usedays = 1;
return;
}
if (d1 == d2) {
usedays = 1;
} else {
var days = (d2 - d1) / (1 * 24 * 60 * 60 * 1e3);
usedays = days + 1;
}
changeNum();
var startTime2 = getDate(rzRange.value[0]);
var endTime2 = getDate(rzRange.value[1]);
var dateArr = [];
while (endTime2.getTime() - startTime2.getTime() > 0) {
var year = startTime2.getFullYear();
var month = (startTime2.getMonth() + 1).toString().length === 1 ? "0" + (parseInt(startTime2.getMonth().toString(), 10) + 1) : startTime2.getMonth() + 1;
var day = startTime2.getDate().toString().length === 1 ? "0" + startTime2.getDate() : startTime2.getDate();
dateArr.push(year + "-" + month + "-" + day);
startTime2.setDate(startTime2.getDate() + 1);
}
dateArr.push(rzRange.value[1]);
choseDays.value = dateArr;
}
function changeNum() {
let moneyAll = 0;
moneyAll = food.value.foodPrice * food.value.num * usedays;
form.value.total = moneyAll.toFixed(2);
}
function submit() {
if (rzRange.value.length > 0) {
form.value.dcStart = rzRange.value[0];
form.value.dcEnd = rzRange.value[1];
}
if (rzRange.value.length == 0) {
common_vendor.index.showToast({
title: "请选择订餐周期",
icon: "none",
duration: 2e3
});
return;
}
if (!form.value.contacts) {
common_vendor.index.showToast({
title: "请填写联系人",
icon: "none",
duration: 2e3
});
return;
}
var pattern = /^1[345789]\d{9}$/;
if (!pattern.test(form.value.phone)) {
common_vendor.index.showToast({
title: "请输入正确的手机号",
duration: 2e3,
icon: "none"
});
return;
}
form.value.foodsList = [];
var obj = {
arfId: food.value.id,
name: food.value.name,
categoryName: food.value.categoryName,
category: food.value.category,
num: food.value.num,
price: food.value.foodPrice
};
form.value.foodsList.push(obj);
console.log(form.value);
common_vendor.index.showModal({
title: "提示",
content: "确定提交订单吗",
success: function(res) {
if (res.confirm) {
common_vendor.index.showLoading({
title: "提交中"
});
common_hotel.submitOrderFood(form.value).then((res2) => {
common_vendor.index.hideLoading();
if (res2.data) {
if (res2.data.total == -100) {
common_vendor.index.showToast({
title: "挤爆了,请稍后下单",
icon: "none",
duration: 2e3
});
} else {
let path = `/pages_hotel/hotel/pay?money=${res2.data.total}&orderId=${res2.data.orderId}`;
common_vendor.index.redirectTo({
url: path
});
}
} else {
common_vendor.index.showToast({
title: "挤爆了,请稍后下单",
icon: "none",
duration: 2e3
});
}
});
} else if (res.cancel) {
console.log("用户点击取消");
}
}
});
}
function popChoose() {
popup.value.open();
}
function initDate() {
if (proxy.$refs.rzRangeForm.$refs.mobile.aniMaskShow) {
return;
}
if (rzRange.value.length > 0) {
return;
}
proxy.$refs.rzRangeForm.$refs.mobile.init(startTime.value);
}
return (_ctx, _cache) => {
return {
a: common_vendor.t(common_vendor.unref(form).orderName),
b: common_vendor.t(`( ${common_vendor.unref(address)} )`),
c: common_vendor.t(common_vendor.unref(food).name),
d: common_vendor.t(common_vendor.unref(food).categoryName),
e: common_vendor.o(changeNum),
f: common_vendor.o(($event) => common_vendor.unref(food).num = $event),
g: common_vendor.p({
min: 1,
max: 9999,
modelValue: common_vendor.unref(food).num
}),
h: common_vendor.sr("rzRangeForm", "55187b2f-3,55187b2f-2"),
i: common_vendor.o(getDaysBetween),
j: common_vendor.o(($event) => common_vendor.isRef(rzRange) ? rzRange.value = $event : null),
k: common_vendor.p({
type: "daterange",
["return-type"]: "string",
placeholder: "选择时间",
start: common_vendor.unref(startTime),
end: common_vendor.unref(endTime),
modelValue: common_vendor.unref(rzRange)
}),
l: common_vendor.p({
label: "订餐周期",
required: true
}),
m: common_vendor.o(initDate),
n: common_vendor.o(($event) => common_vendor.unref(form).contacts = $event),
o: common_vendor.p({
type: "text",
modelValue: common_vendor.unref(form).contacts
}),
p: common_vendor.p({
label: "联系人",
required: true
}),
q: common_vendor.o(($event) => common_vendor.unref(form).phone = $event),
r: common_vendor.p({
type: "number",
placeholder: "请输入联系电话",
modelValue: common_vendor.unref(form).phone
}),
s: common_vendor.p({
label: "联系电话",
required: true
}),
t: common_vendor.t(common_vendor.unref(food).psStart),
v: common_vendor.t(common_vendor.unref(food).psEnd),
w: common_vendor.p({
label: "送餐时间"
}),
x: common_vendor.t(common_vendor.unref(food).address),
y: common_vendor.p({
label: "配送地址"
}),
z: common_vendor.o(($event) => common_vendor.unref(form).remarks = $event),
A: common_vendor.p({
type: "textarea",
modelValue: common_vendor.unref(form).remarks
}),
B: common_vendor.p({
label: "备注"
}),
C: common_vendor.p({
["label-width"]: "80"
}),
D: common_vendor.t(common_vendor.unref(form).total),
E: common_vendor.p({
type: "bottom",
size: "20"
}),
F: common_vendor.o(popChoose),
G: common_vendor.o(submit),
H: common_vendor.t(common_vendor.unref(food).name),
I: common_vendor.f(common_vendor.unref(choseDays), (c, index, i0) => {
return {
a: common_vendor.t(c),
b: index
};
}),
J: common_vendor.t(common_vendor.unref(food).num),
K: common_vendor.t(common_vendor.unref(food).foodPrice),
L: common_vendor.t(common_vendor.unref(form).total),
M: common_vendor.sr(popup, "55187b2f-14", {
"k": "popup"
}),
N: common_vendor.p({
["background-color"]: "#fff",
type: "bottom"
})
};
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-55187b2f"], ["__file", "/Users/yangyang/project/j-mini/Venue/pages_hotel/eat/order.vue"]]);
wx.createPage(MiniProgramPage);