Files
gxtyzx-uniapp/dist/dev/mp-weixin/package/booking/checkout.js
T

520 lines
17 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const api_layout_index = require("../../api/layout/index.js");
const api_shop_merchant_index = require("../../api/shop/merchant/index.js");
require("../../utils/request.js");
const api_booking_period_index = require("../../api/booking/period/index.js");
const store_modules_car = require("../../store/modules/car.js");
const utils_common = require("../../utils/common.js");
const carStore = store_modules_car.useCarStore();
const {
orderInfo,
totalPrice,
carNum,
merchant,
type,
dateTime,
childrenPrice
} = common_vendor.storeToRefs(carStore);
const _sfc_main = {
data() {
return {
// 场馆ID
merchantId: 0,
// 场馆信息
merchant,
// 未来7天
next7day: [],
// 预定信息
orderInfo,
// 订单总金额
totalPrice,
// 儿童票价
childrenPrice,
// 预定日期
dateTime: null,
// 0全场 1半场
type: 0,
// 星期几
week: 0,
// 是否可以预定半场
isHalf: 0,
// 服务器时间
serverTime: {},
items: ["全场", "半场"],
// 搜索条件
where: {},
// 时段
periodList: [],
// 场地
fieldList: [],
// 选中的场地
selection: [],
// 是否已登录
isLogin: false,
// 是否同意协议
disabled: false,
// 购物车信息
showCarInfo: false
};
},
onLoad(option) {
this.merchantId = option.id;
this.reload();
},
onShow() {
if (common_vendor.index.getStorageSync("user_id") && common_vendor.index.getStorageSync("access_token")) {
this.isLogin = true;
}
},
computed: {
totalPrice() {
const app = this;
let totalPrice2 = 0;
app.selection.map((d) => {
totalPrice2 = totalPrice2 + d.price;
});
carStore.totalPrice = totalPrice2;
console.log("totalPrice: ", totalPrice2);
return totalPrice2;
},
carNum() {
return this.selection.length;
}
},
methods: {
async reload() {
const app = this;
common_vendor.index.showLoading({
title: "数据读取中."
});
Promise.all([app.getServerTime(), app.getNext7day(), app.getMerchant()]).then((res) => {
const serverTime = res[0];
const next7day = res[1];
const merchant2 = res[2];
app.serverTime = serverTime;
app.next7day = next7day;
app.merchant = merchant2;
common_vendor.index.setNavigationBarTitle({
title: merchant2.merchantName
});
carStore.setMerchant(merchant2);
app.next7day = next7day.map((d, i) => {
if (!app.dateTime && i == 0) {
app.dateTime = d.dateTime;
app.week = d.week;
carStore.dateTime = d.dateTime;
}
d.name = utils_common.getWeek(d.week);
d.value = d.date;
return d;
});
app.getBookingPeriod();
}).catch(() => {
common_vendor.index.showToast({
title: "请检查您的网络.",
icon: "none"
});
common_vendor.index.hideLoading();
});
},
onDisabled() {
this.disabled = !this.disabled;
},
onDateTime(e) {
console.log("e: ", e);
this.week = e.week;
this.dateTime = e.dateTime;
carStore.dateTime = e.dateTime;
carStore.orderInfo = [];
this.selection = [];
this.reload();
},
onType(e) {
const index = e.currentIndex;
if (index == 0) {
this.type = 0;
this.isHalf = 0;
}
if (index == 1) {
this.type = 1;
this.isHalf = 1;
}
this.reload();
},
getMerchant() {
return new Promise((resolve, reject) => {
api_shop_merchant_index.getMerchant(this.merchantId).then((result) => {
resolve(result);
}).catch(reject);
});
},
getServerTime() {
return new Promise((resolve, reject) => {
api_layout_index.getServerTime().then((result) => {
resolve(result);
}).catch(reject);
});
},
getNext7day() {
return new Promise((resolve, reject) => {
api_layout_index.getNext7day().then((result) => {
resolve(result);
}).catch(reject);
});
},
// getBookingField() {
// FieldApi.listField({
// merchantId: this.merchantId,
// isStatus: 1,
// isHalf: this.isHalf,
// dateTime: `${this.dateTime}`
// }).then(list => {
// this.fieldList = list;
// })
// },
getBookingPeriod() {
const {
serverTime
} = this;
const now = /* @__PURE__ */ new Date();
const hours = now.getHours();
const minutes = now.getMinutes();
const startTime = serverTime.today == this.dateTime ? String(hours) + String(minutes) : void 0;
const week = this.week == 0 ? 7 : this.week;
api_booking_period_index.listPeriod({
merchantId: this.merchantId,
isStatus: 0,
week,
dateTime: `${this.dateTime}`,
startTime,
half: this.isHalf
}).then((list) => {
this.periodList = list;
common_vendor.index.hideLoading();
}).catch((err) => {
this.periodList = [];
common_vendor.index.showToast({
title: err.message,
icon: "none"
});
common_vendor.index.hideLoading();
if (err.message == "您还有未支付订单,请先支付") {
setTimeout(() => {
return common_vendor.index.switchTab({
url: "/pages/order/order"
});
}, 1e3);
}
});
},
callPhone(phone) {
common_vendor.index.makePhoneCall({
phoneNumber: phone
});
},
openCarInfo() {
this.$refs.popup.open("bottom");
},
closeCarInfo() {
this.$refs.popup.close();
},
onMap() {
common_vendor.index.getLocation({
type: "gcj02",
//返回可以用于uni.openLocation的经纬度
success: function(res) {
console.log("返回可以用于uni.openLocation的经纬度: ", res);
const latitude = this.merchant.latitude;
const longitude = this.merchant.longitude;
common_vendor.index.openLocation({
latitude,
longitude,
success: function() {
console.log("success");
}
});
}
});
},
onField(item, period) {
if (item.sold) {
return;
}
const app = this;
const { merchant: merchant2 } = this;
const key = utils_common.getKey(`${this.dateTime}${item.timePeriod}${this.merchantId}${item.fieldId}`);
const index = app.selection.findIndex((d) => d.key == key);
if (index >= 0) {
app.selection.splice(index, 1);
} else {
if (app.selection.length > 1) {
common_vendor.index.showToast({
title: "最多预定两个场地!",
icon: "none"
});
return false;
}
const split = item.timePeriod.split("-");
app.selection.push({
key,
merchantId: this.merchantId,
merchantCode: merchant2.merchantCode,
fieldId: item.fieldId,
fieldName: item.fieldName,
price: item.price,
childrenPrice: period.childrenPrice,
adultNum: 1,
childrenNum: 0,
merchantName: merchant2.merchantName,
isChildren: item.isChildren,
isHalf: this.type,
timePeriod: item.timePeriod,
periodId: item.periodId,
startTime: `${split[0].trim()}:00`,
endTime: `${split[1].trim()}:00`,
orderCode: key,
dateTime: `${this.dateTime}`,
comments: `${this.dateTime} (${utils_common.getWeek(this.week)}) ${item.timePeriod}`
});
console.log(app.selection);
console.log("period: ", period);
console.log("item.isChildren: ", item.isChildren);
if (item.isChildren == 1) {
console.log("item.isChildren2: ", item.isChildren);
carStore.childrenPrice = period.childrenPrice;
} else {
carStore.childrenPrice = 0;
}
carStore.orderInfo = app.selection;
carStore.carNum = app.selection.length;
carStore.totalPrice = totalPrice;
carStore.payPrice = totalPrice;
carStore.setPeriod(period);
}
},
getStratTime(value) {
const split = value.split("-");
const timeText = split[0].replace(" ", "");
const startTime = (/* @__PURE__ */ new Date(`${this.dateTime} ${timeText}:00`)).getTime();
return startTime / 1e3 || 0;
},
isActive(item) {
const index = this.selection.find((d) => d.key == utils_common.getKey(`${this.dateTime}${item.timePeriod}${this.merchantId}${item.fieldId}`));
if (item.sold) {
if (item.isHalf == 1) {
return "web-bg-warning";
}
return "web-bg-info";
}
if (index) {
return "active web-bg-success";
}
},
// isActive(text,item) {
// const index = this.selection.find(d => d.key == getKey(text))
// if(item.sold){
// if(item.isHalf == 1){
// return 'web-bg-warning'
// }
// return 'web-bg-info'
// }
// if (index) {
// return 'active web-bg-success'
// }
// },
remove(item) {
const index = this.selection.findIndex((d) => d.key == item.key);
this.selection.splice(index, 1);
carStore.orderInfo = this.selection;
},
save() {
common_vendor.index.$uv.route({
url: "/package/booking/confirm"
});
}
}
};
if (!Array) {
const _easycom_uv_tabs2 = common_vendor.resolveComponent("uv-tabs");
const _easycom_uni_segmented_control2 = common_vendor.resolveComponent("uni-segmented-control");
const _easycom_uv_badge2 = common_vendor.resolveComponent("uv-badge");
const _easycom_uv_gap2 = common_vendor.resolveComponent("uv-gap");
const _easycom_uv_icon2 = common_vendor.resolveComponent("uv-icon");
const _easycom_uv_count_to2 = common_vendor.resolveComponent("uv-count-to");
const _easycom_uv_button2 = common_vendor.resolveComponent("uv-button");
const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
const _easycom_uv_cell2 = common_vendor.resolveComponent("uv-cell");
const _easycom_uv_cell_group2 = common_vendor.resolveComponent("uv-cell-group");
const _easycom_uni_card2 = common_vendor.resolveComponent("uni-card");
const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
const _easycom_ws_login2 = common_vendor.resolveComponent("ws-login");
(_easycom_uv_tabs2 + _easycom_uni_segmented_control2 + _easycom_uv_badge2 + _easycom_uv_gap2 + _easycom_uv_icon2 + _easycom_uv_count_to2 + _easycom_uv_button2 + _easycom_uni_icons2 + _easycom_uv_cell2 + _easycom_uv_cell_group2 + _easycom_uni_card2 + _easycom_uni_popup2 + _easycom_ws_login2)();
}
const _easycom_uv_tabs = () => "../../uni_modules/uv-tabs/components/uv-tabs/uv-tabs.js";
const _easycom_uni_segmented_control = () => "../../uni_modules/uni-segmented-control/components/uni-segmented-control/uni-segmented-control.js";
const _easycom_uv_badge = () => "../../uni_modules/uv-badge/components/uv-badge/uv-badge.js";
const _easycom_uv_gap = () => "../../uni_modules/uv-gap/components/uv-gap/uv-gap.js";
const _easycom_uv_icon = () => "../../uni_modules/uv-icon/components/uv-icon/uv-icon.js";
const _easycom_uv_count_to = () => "../../uni_modules/uv-count-to/components/uv-count-to/uv-count-to.js";
const _easycom_uv_button = () => "../../uni_modules/uv-button/components/uv-button/uv-button.js";
const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
const _easycom_uv_cell = () => "../../uni_modules/uv-cell/components/uv-cell/uv-cell.js";
const _easycom_uv_cell_group = () => "../../uni_modules/uv-cell/components/uv-cell-group/uv-cell-group.js";
const _easycom_uni_card = () => "../../uni_modules/uni-card/components/uni-card/uni-card.js";
const _easycom_uni_popup = () => "../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
const _easycom_ws_login = () => "../../uni_modules/ws-login/components/ws-login/ws-login.js";
if (!Math) {
(_easycom_uv_tabs + _easycom_uni_segmented_control + _easycom_uv_badge + _easycom_uv_gap + _easycom_uv_icon + _easycom_uv_count_to + _easycom_uv_button + _easycom_uni_icons + _easycom_uv_cell + _easycom_uv_cell_group + _easycom_uni_card + _easycom_uni_popup + _easycom_ws_login)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return common_vendor.e({
a: $data.merchant
}, $data.merchant ? {
b: common_vendor.t($data.merchant.merchantId),
c: common_vendor.t($data.merchant.merchantCode),
d: common_vendor.t($data.merchant.merchantName),
e: common_vendor.t($data.dateTime),
f: common_vendor.t($data.week),
g: common_vendor.t($options.totalPrice),
h: common_vendor.t($data.type),
i: common_vendor.t($data.orderInfo)
} : {}, {
j: common_vendor.o($options.onDateTime),
k: common_vendor.p({
list: $data.next7day,
itemStyle: {
height: "58px"
},
activeStyle: {
color: "#2ba91c"
},
lineColor: "#2ba91c",
inactiveStyle: {
color: "#808080"
}
}),
l: common_vendor.o($options.onType),
m: common_vendor.p({
current: _ctx.current,
values: $data.items,
activeColor: "#2ba91c",
inActiveColor: "#ff0000"
}),
n: common_vendor.p({
isDot: true,
type: "blank"
}),
o: common_vendor.p({
isDot: true,
type: "info"
}),
p: common_vendor.p({
isDot: true,
type: "success"
}),
q: common_vendor.p({
isDot: true,
type: "warning"
}),
r: $data.periodList.length > 0
}, $data.periodList.length > 0 ? {
s: common_vendor.f($data.periodList, (item, index, i0) => {
return {
a: common_vendor.t(item.timePeriod),
b: common_vendor.f(item.fieldList, (field, index2, i1) => {
return {
a: common_vendor.t(field.fieldName),
b: common_vendor.n($options.isActive(field)),
c: common_vendor.o(($event) => $options.onField(field, item), index2),
d: index2
};
}),
c: common_vendor.t(item.price),
d: index
};
})
} : {}, {
t: common_vendor.p({
height: "50"
}),
v: common_vendor.p({
name: "shopping-cart",
size: "36",
color: "#ffffff"
}),
w: common_vendor.p({
type: "error",
max: "99",
value: $options.carNum
}),
x: common_vendor.o((...args) => $options.openCarInfo && $options.openCarInfo(...args)),
y: common_vendor.p({
startVal: 0,
decimals: "2",
duration: "100",
color: "#ebcf00",
bold: true,
endVal: $options.totalPrice
}),
z: common_vendor.o($options.save),
A: common_vendor.p({
disabled: $data.orderInfo.length == 0,
customStyle: {
background: "linear-gradient(to right, #70b915, #008e04)",
borderRadius: "0 30px 30px 0",
color: "#ffffff",
border: "none",
padding: "22px 30px"
},
text: "下一步"
}),
B: common_vendor.f($data.orderInfo, (item, index, i0) => {
return {
a: common_vendor.o(($event) => $options.remove(item), index),
b: "6e113c20-15-" + i0 + "," + ("6e113c20-14-" + i0),
c: common_vendor.o(($event) => $options.remove(item), index),
d: "6e113c20-14-" + i0 + ",6e113c20-13",
e: common_vendor.p({
title: `${item.fieldName} ¥${item.price}`,
label: `${item.dateTime}`,
cellStyle: {
padding: "10px 5px"
}
}),
f: index
};
}),
C: common_vendor.p({
type: "trash",
size: "20",
color: "#f76b4e"
}),
D: common_vendor.p({
customStyle: {
backgroundColor: "#ffffff"
},
border: false
}),
E: common_vendor.o($options.closeCarInfo),
F: common_vendor.p({
title: `购物车`,
extra: "关闭",
border: false,
["is-shadow"]: false,
padding: 0
}),
G: common_vendor.p({
height: "70"
}),
H: common_vendor.sr("popup", "6e113c20-11"),
I: common_vendor.sr("login", "6e113c20-17"),
J: common_vendor.o($options.reload),
K: common_vendor.p({
logo: _ctx.logo
})
});
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-6e113c20"], ["__file", "/Users/gxwebsoft/APP/gxtyzx-uniapp-cli/src/package/booking/checkout.vue"]]);
wx.createPage(MiniProgramPage);