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

748 lines
25 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use strict";
const common_vendor = require("../../common/vendor.js");
const api_shop_order_index = require("../../api/shop/order/index.js");
const api_booking_users_index = require("../../api/booking/users/index.js");
const api_booking_userCard_index = require("../../api/booking/userCard/index.js");
const api_system_payment_index = require("../../api/system/payment/index.js");
const api_passport_login_index = require("../../api/passport/login/index.js");
const utils_decimal = require("../../utils/decimal.js");
const utils_common = require("../../utils/common.js");
const store_modules_car = require("../../store/modules/car.js");
const store_modules_user = require("../../store/modules/user.js");
const userStore = store_modules_user.useUserStore();
const carStore = store_modules_car.useCarStore();
const { merchantId, orderInfo, period, totalPrice, reducePrice, payPrice, childrenPrice, carNum, carNum2, merchant, type, dateTime } = common_vendor.storeToRefs(carStore);
const _sfc_main = {
data() {
return {
orderId: 0,
userInfo: {},
// 表单信息
form: {
cardId: 0,
payType: 1
},
// 支付方式
payment: [],
// 场馆信息
merchant,
merchantId,
orderInfo,
carNum,
carNum2: 0,
week: 0,
totalPrice,
reducePrice: 0,
payPrice,
childrenPrice,
period,
cardId: 0,
getWeek: utils_common.getWeek,
payType: 1,
isLogin: false,
disabled: false,
cardList: [],
userCard: {},
// isRefresh: true,
// 支付密码是否正确
isPayPasswordCorrect: false,
disabledPayPayPassword: false,
payPassword: "",
// 折扣率
discount: 1,
// 票类型
radiolist: [
{
name: "成人票",
price: 50,
totalPrice: 50,
disabled: false
},
{
name: "儿童票",
price: 35,
totalPrice: 35,
disabled: false
}
],
radiovalue: "成人票"
};
},
onLoad(option) {
if (option.id) {
this.orderId = option.id;
this.form.orderId = option.id;
}
this.reload();
},
onShow() {
if (common_vendor.index.getStorageSync("user_id") && common_vendor.index.getStorageSync("access_token")) {
this.isLogin = true;
}
this.openLogin();
},
// computed: {
// payPrice(){
// console.log('this.payPrice: ',this.payPrice);
// },
// carNum(){
// console.log('orderInfo[0].adultNum: ',this.adultNum);
// return this.adultNum;
// // return carStore.payPrice;
// }
// },
methods: {
async reload() {
const app = this;
const { form, orderId, merchant: merchant2, totalPrice: totalPrice2, orderInfo: orderInfo2 } = this;
app.userInfo = await userStore.fetchUserInfo();
api_booking_users_index.getByPhone({
phone: app.userInfo.phone
}).then((data) => {
if (data) {
app.hideUser = false;
app.userInfo.ouid = data.userId;
app.userInfo = Object.assign({}, app.userInfo, data);
}
});
form.type = 1;
form.payPrice = totalPrice2;
form.orderInfo = orderInfo2;
app.payPrice = totalPrice2;
if (merchant2) {
app.merchantId = merchant2.merchantId;
form.merchantId = merchant2.merchantId;
form.merchantName = merchant2.merchantName;
form.merchantCode = merchant2.merchantCode;
form.comments = merchant2.merchantName + " " + orderInfo2[0].fieldName + " " + orderInfo2[0].dateTime;
}
console.log("重新赋值订单信息: ", orderId);
if (orderId > 0) {
api_shop_order_index.getOrder(orderId).then((data) => {
app.form = data;
app.orderInfo = data.orderInfo;
app.totalPrice = data.totalPrice;
app.reducePrice = data.reducePrice;
app.payPrice = data.payPrice;
app.merchantId = data.merchantId;
app.childrenPrice = data.orderInfo[0].childrenPrice;
if (data.orderInfo[0].adultNum > 0) {
app.radiovalue = "成人票";
app.carNum = data.orderInfo[0].adultNum;
}
if (data.orderInfo[0].childrenNum > 0) {
app.radiovalue = "儿童票";
app.carNum = data.orderInfo[0].childrenNum;
}
carStore.setOrderInfo(data.orderInfo);
});
}
Promise.all([app.getUserCard(), app.getPayment()]).then((res) => {
const userCard = res[0];
const payment = res[1];
app.userCard = userCard;
app.payment = payment.map((d) => {
if (d.type == 0) {
d.name = `${d.name} (余额¥${app.userInfo.balance})`;
}
if (d.type == 2 && userCard) {
d.name = `${userCard.name}(¥${userCard.remainingMoney})`;
}
return d;
});
if (userCard) {
form.cardId = userCard.id;
form.payType = 2;
app.payType = 2;
if (userCard.type == 1) ;
if (userCard.type == 2) ;
if (userCard.type == 3) ;
if (userCard.type == 2) ;
if (userCard.type == 5) {
app.discount = utils_decimal.cal.cheng(userCard.discount, 0.1);
const orderPrice = totalPrice2 || form.totalPrice;
if (orderPrice) {
console.log("orderPrice: ", orderPrice);
const lastTotalPrice = utils_decimal.cal.cheng(orderPrice, app.discount);
console.log("折后金额: ", lastTotalPrice);
app.reducePrice = utils_decimal.cal.jian(orderPrice, lastTotalPrice);
console.log("减少的金额: ", app.reducePrice);
app.payPrice = orderPrice * app.discount;
console.log("实付额: ", app.payPrice);
}
}
}
});
},
// 读取可用的会员卡
async getUserCard() {
return new Promise((resolve, reject) => {
const { merchantId: merchantId2 } = this;
api_booking_userCard_index.findUseCard({
sid: merchantId2
}).then((result) => {
resolve(result);
}).catch(reject);
});
},
// 读取支付方式列表
getPayment() {
return new Promise((resolve, reject) => {
api_system_payment_index.select({ status: true }).then((result) => {
resolve(result);
}).catch(reject);
});
},
onDisabled() {
this.disabled = !this.disabled;
},
navTo(url) {
common_vendor.index.navigateTo({
url
});
},
// 切换支付方式
async onPayType(index) {
const app = this;
const { form, totalPrice: totalPrice2, carNum: carNum3, childrenPrice: childrenPrice2, radiovalue } = this;
app.payType = index;
app.form.payType = index;
app.form.cardId = 0;
console.log("childrenPrice: ", childrenPrice2);
app.payPrice = 0;
app.reducePrice = 0;
await app.countTotalPrice();
if (index === 2) {
await app.reload();
}
},
openUrl(url) {
if (!this.isLogin) {
this.$refs.login.open("bottom");
return false;
} else {
common_vendor.index.navigateTo({
url
});
}
},
// 弹出登录提示框
openLogin() {
if (!this.isLogin) {
this.$refs.login.open("bottom");
return false;
}
},
// 验证支付密码
onPayPassword() {
if (this.payPassword == "" || !this.payPassword) {
common_vendor.index.showToast({
title: "请输入支付密码",
icon: "none"
});
return false;
}
this.disabledPayPayPassword = true;
const { payPassword } = this;
api_passport_login_index.checkPayPassword({ payPassword }).then((res) => {
this.disabledPayPayPassword = false;
this.isPayPasswordCorrect = true;
this.save();
}).catch((err) => {
common_vendor.index.showToast({
title: err.message,
icon: "none"
});
this.disabledPayPayPassword = false;
});
},
onAdultNum(e) {
const app = this;
const index = e.value;
app.carNum = index;
app.orderInfo[0].adultNum = index;
app.countTotalPrice();
},
onAdultNum2(e) {
const app = this;
const index = e.value;
app.carNum2 = index;
app.orderInfo[0].childrenNum = index;
app.countTotalPrice();
},
// 重新计算金额
countTotalPrice() {
const app = this;
const prices = [];
app.orderInfo.map((d) => {
prices.push(d.price * d.adultNum + d.childrenPrice * d.childrenNum);
});
const sum = prices.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
console.log(sum);
app.totalPrice = sum;
app.payPrice = sum;
},
save() {
const app = this;
console.log("payPrice000: ", app.payPrice);
console.log(carStore.payPrice);
const { form, merchant: merchant2, orderInfo: orderInfo2, totalPrice: totalPrice2, payPrice: payPrice2 } = this;
if (!this.disabled) {
common_vendor.index.showToast({
title: "请先阅读并同意服务协议",
icon: "none"
});
return false;
}
if (orderInfo2.length == 0) {
common_vendor.index.showToast({
title: "订单信息不存在",
icon: "none"
});
return false;
}
if (form.payType == 2 && !app.userCard) {
common_vendor.index.showToast({
title: "没有找到可用的会员卡",
icon: "none"
});
return false;
}
if (form.payType == 0 && !this.isPayPasswordCorrect) {
app.$refs.payPasswordForm.open("center");
return false;
}
common_vendor.index.showLoading({
title: "订单提交中."
});
form.payPrice = app.payPrice;
form.totalPrice = app.payPrice;
form.reducePrice = app.reducePrice;
api_shop_order_index.addOrder({
type: 1,
orderId: form.orderId,
merchantId: form.merchantId,
merchantName: form.merchantName,
merchantCode: form.merchantCode,
// 订单金额
totalPrice: app.payPrice,
// 实付金额
payPrice: app.payPrice,
// 预定场地信息
orderInfo: form.orderInfo,
comments: form.comments,
// 微信支付
payType: form.payType,
// 下单日期
dateTime: form.dateTime,
// 会员卡ID
cardId: form.cardId
}).then((data) => {
const orderInfo3 = data;
if (form.payType == 1) {
common_vendor.index.requestPayment({
provider: orderInfo3.provider,
// 服务提供商
timeStamp: orderInfo3.timeStamp,
// 时间戳
nonceStr: orderInfo3.nonceStr,
// 随机字符串
package: orderInfo3.package,
signType: orderInfo3.signType,
// 签名算法
paySign: orderInfo3.paySign,
// 签名
success: function(res) {
common_vendor.index.showToast({
title: "支付成功",
icon: "success"
});
setTimeout(function() {
app.disabled = false;
common_vendor.index.reLaunch({
url: "/pages/order/order",
success: function(e) {
var page = getCurrentPages()[0];
if (page == void 0 || page == null) return;
page.onLoad();
}
});
}, 1500);
},
fail: function(err) {
console.log("支付失败", err);
app.disabled = false;
common_vendor.index.reLaunch({
url: "/pages/order/order",
success: function(e) {
var page = getCurrentPages()[0];
if (page == void 0 || page == null) return;
page.onLoad();
}
});
}
});
}
if (form.payType == 0) {
if (!orderInfo3) {
return common_vendor.index.showToast({
title: "支付失败",
icon: "error"
});
}
if (orderInfo3) {
common_vendor.index.showToast({
title: "支付成功",
icon: "success"
});
setTimeout(function() {
app.disabled = false;
app.$refs.payPasswordForm.close();
common_vendor.index.reLaunch({
url: "/pages/order/order",
success: function(e) {
var page = getCurrentPages()[0];
if (page == void 0 || page == null) return;
page.onLoad();
}
});
}, 1500);
}
}
if (form.payType == 2) {
if (!orderInfo3) {
return common_vendor.index.showToast({
title: "支付失败",
icon: "error"
});
}
if (orderInfo3) {
common_vendor.index.showToast({
title: "支付成功",
icon: "success"
});
setTimeout(function() {
app.disabled = false;
common_vendor.index.reLaunch({
url: "/pages/order/order",
success: function(e) {
var page = getCurrentPages()[0];
if (page == void 0 || page == null) return;
page.onLoad();
}
});
}, 1500);
}
}
common_vendor.index.hideLoading();
}).catch((res) => {
common_vendor.index.showToast({
title: res.message || "请检查您的网络.",
icon: "none"
});
common_vendor.index.hideLoading();
});
}
}
};
if (!Array) {
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_uv_number_box2 = common_vendor.resolveComponent("uv-number-box");
const _easycom_uv_icon2 = common_vendor.resolveComponent("uv-icon");
const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
const _easycom_uv_gap2 = common_vendor.resolveComponent("uv-gap");
const _easycom_uv_count_to2 = common_vendor.resolveComponent("uv-count-to");
const _easycom_uv_button2 = common_vendor.resolveComponent("uv-button");
const _easycom_ws_login2 = common_vendor.resolveComponent("ws-login");
const _easycom_uv_code_input2 = common_vendor.resolveComponent("uv-code-input");
const _easycom_uni_forms_item2 = common_vendor.resolveComponent("uni-forms-item");
const _easycom_uni_forms2 = common_vendor.resolveComponent("uni-forms");
const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
(_easycom_uv_cell2 + _easycom_uv_cell_group2 + _easycom_uni_card2 + _easycom_uv_number_box2 + _easycom_uv_icon2 + _easycom_uni_icons2 + _easycom_uv_gap2 + _easycom_uv_count_to2 + _easycom_uv_button2 + _easycom_ws_login2 + _easycom_uv_code_input2 + _easycom_uni_forms_item2 + _easycom_uni_forms2 + _easycom_uni_popup2)();
}
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_uv_number_box = () => "../../uni_modules/uv-number-box/components/uv-number-box/uv-number-box.js";
const _easycom_uv_icon = () => "../../uni_modules/uv-icon/components/uv-icon/uv-icon.js";
const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
const _easycom_uv_gap = () => "../../uni_modules/uv-gap/components/uv-gap/uv-gap.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_ws_login = () => "../../uni_modules/ws-login/components/ws-login/ws-login.js";
const _easycom_uv_code_input = () => "../../uni_modules/uv-code-input/components/uv-code-input/uv-code-input.js";
const _easycom_uni_forms_item = () => "../../uni_modules/uni-forms/components/uni-forms-item/uni-forms-item.js";
const _easycom_uni_forms = () => "../../uni_modules/uni-forms/components/uni-forms/uni-forms.js";
const _easycom_uni_popup = () => "../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
if (!Math) {
(_easycom_uv_cell + _easycom_uv_cell_group + _easycom_uni_card + _easycom_uv_number_box + _easycom_uv_icon + _easycom_uni_icons + _easycom_uv_gap + _easycom_uv_count_to + _easycom_uv_button + _easycom_ws_login + _easycom_uv_code_input + _easycom_uni_forms_item + _easycom_uni_forms + _easycom_uni_popup)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return common_vendor.e({
a: common_vendor.t($data.radiolist),
b: common_vendor.t($data.carNum),
c: common_vendor.t($data.childrenPrice),
d: common_vendor.t($data.orderInfo),
e: $data.merchant
}, $data.merchant ? {
f: common_vendor.t($data.merchant.merchantId),
g: common_vendor.t($data.merchant.merchantCode),
h: common_vendor.t($data.merchant.merchantName),
i: common_vendor.t(_ctx.dateTime),
j: common_vendor.t($data.week),
k: common_vendor.t($data.totalPrice),
l: common_vendor.t(_ctx.type),
m: common_vendor.t($data.payPrice),
n: common_vendor.t($data.period),
o: common_vendor.t($data.orderInfo)
} : {}, {
p: $data.userInfo.realName
}, $data.userInfo.realName ? {
q: common_vendor.t($data.userInfo.realName)
} : {
r: common_vendor.o(($event) => $options.navTo(`/package/user/personal`))
}, {
s: common_vendor.p({
title: "真实姓名",
cellStyle: {
padding: "10px 5px"
},
border: false
}),
t: common_vendor.p({
title: "手机号码",
cellStyle: {
padding: "10px 5px"
},
value: $data.userInfo.phone,
border: false
}),
v: common_vendor.p({
customStyle: {
backgroundColor: "#ffffff"
},
border: false
}),
w: common_vendor.p({
title: "预约人信息",
border: false,
["is-shadow"]: false
}),
x: $data.orderInfo.length == 0
}, $data.orderInfo.length == 0 ? {} : {}, {
y: $data.orderInfo
}, $data.orderInfo ? {
z: common_vendor.p({
title: `场馆`,
label: $data.form.merchantName,
cellStyle: {
padding: "10px 5px"
}
}),
A: common_vendor.f($data.orderInfo, (item, index, i0) => {
return common_vendor.e($data.childrenPrice > 0 ? {
a: "246b5229-7-" + i0 + ",246b5229-5",
b: common_vendor.p({
title: `${item.fieldName}`,
label: `${item.dateTime} ${$data.getWeek(this.week)} ${item.timePeriod}`,
cellStyle: {
padding: "10px 5px"
}
})
} : {
c: "246b5229-8-" + i0 + ",246b5229-5",
d: common_vendor.p({
title: `${item.fieldName}`,
label: `${item.dateTime} ${$data.getWeek(this.week)} ${item.timePeriod}`,
value: `¥${item.price}`,
cellStyle: {
padding: "10px 5px"
}
})
}, {
e: common_vendor.f($data.radiolist, (item2, index2, i1) => {
return common_vendor.e($data.childrenPrice > 0 ? common_vendor.e({
a: common_vendor.t(item2.name),
b: item2.name == "成人票"
}, item2.name == "成人票" ? {
c: common_vendor.t(item2.price)
} : {}, {
d: item2.name == "儿童票"
}, item2.name == "儿童票" ? {
e: common_vendor.t(item2.price)
} : {}, {
f: item2.name === "成人票"
}, item2.name === "成人票" ? {
g: common_vendor.o($options.onAdultNum, index2),
h: "246b5229-10-" + i0 + "-" + i1 + "," + ("246b5229-9-" + i0 + "-" + i1),
i: common_vendor.o(($event) => $data.carNum = $event, index2),
j: common_vendor.p({
min: 0,
max: 1e3,
disabled: $data.orderId > 0,
modelValue: $data.carNum
})
} : {}, {
k: item2.name === "儿童票"
}, item2.name === "儿童票" ? {
l: common_vendor.o($options.onAdultNum2, index2),
m: "246b5229-11-" + i0 + "-" + i1 + "," + ("246b5229-9-" + i0 + "-" + i1),
n: common_vendor.o(($event) => $data.carNum2 = $event, index2),
o: common_vendor.p({
min: 0,
max: 1e3,
disabled: $data.orderId > 0,
modelValue: $data.carNum2
})
} : {}, {
p: "246b5229-9-" + i0 + "-" + i1 + ",246b5229-5",
q: common_vendor.p({
iconStyle: "checkbox-mark",
cellStyle: {
padding: "10px 5px"
},
border: false
})
}) : {}, {
r: index2
});
}),
f: index
});
}),
B: $data.childrenPrice > 0,
C: $data.childrenPrice > 0
} : {}, {
D: common_vendor.p({
customStyle: {
backgroundColor: "#ffffff"
},
border: false
}),
E: common_vendor.p({
title: "订单信息",
border: false,
["is-shadow"]: false
}),
F: common_vendor.f($data.payment, (item, index, i0) => {
return common_vendor.e({
a: item.type == $data.payType
}, item.type == $data.payType ? {
b: "246b5229-15-" + i0 + "," + ("246b5229-14-" + i0),
c: common_vendor.p({
size: "30rpx",
name: "checkbox-mark"
})
} : {}, {
d: common_vendor.o(($event) => $options.onPayType(item.type), index),
e: "246b5229-14-" + i0 + ",246b5229-13",
f: common_vendor.p({
title: `${item.name}`,
icon: `${item.image}`,
cellStyle: {
padding: "20rpx 10rpx",
borderRadius: "8rpx",
backgroundColor: item.type == $data.payType ? "#f6fff1" : ""
},
border: false
}),
g: index
});
}),
G: common_vendor.p({
customStyle: {
backgroundColor: "#ffffff"
},
border: false
}),
H: common_vendor.t($data.reducePrice),
I: common_vendor.t($data.payPrice || 0),
J: common_vendor.p({
title: `选择支付方式`,
border: false,
["is-shadow"]: false
}),
K: !$data.disabled
}, !$data.disabled ? {
L: common_vendor.o($options.onDisabled),
M: common_vendor.p({
type: "circle",
size: "20",
color: "#a4a5a7"
})
} : {
N: common_vendor.o($options.onDisabled),
O: common_vendor.p({
type: "checkbox",
size: "20",
color: "#11a954"
})
}, {
P: common_vendor.o(($event) => $options.navTo("/package/article/detail?articleId=501")),
Q: common_vendor.o(($event) => $options.navTo("/package/article/detail?articleId=502")),
R: common_vendor.o((...args) => $options.onDisabled && $options.onDisabled(...args)),
S: common_vendor.p({
height: "50"
}),
T: common_vendor.p({
decimals: "2",
duration: "50",
color: "#ebcf00",
bold: true,
endVal: $data.payPrice
}),
U: common_vendor.o($options.save),
V: common_vendor.p({
disabled: !$data.disabled,
customStyle: {
background: "linear-gradient(to right, #70b915, #008e04)",
borderRadius: "0 30px 30px 0",
color: "#ffffff",
border: "none",
padding: "22px 30px"
},
text: "提交订单"
}),
W: common_vendor.sr("login", "246b5229-21"),
X: common_vendor.o($options.reload),
Y: common_vendor.p({
logo: _ctx.logo
}),
Z: common_vendor.o($options.onPayPassword),
aa: common_vendor.o(($event) => $data.payPassword = $event),
ab: common_vendor.p({
mode: "box",
dot: true,
space: 0,
maxlength: 6,
hairline: true,
modelValue: $data.payPassword
}),
ac: common_vendor.p({
label: "支付密码",
name: "payPassword",
required: true
}),
ad: common_vendor.sr("form", "246b5229-24,246b5229-23"),
ae: common_vendor.p({
["label-width"]: 80
}),
af: common_vendor.o(($event) => $options.navTo(`/package/user/pay-password`)),
ag: common_vendor.p({
title: "请输入支付密码",
border: false,
["is-shadow"]: false,
padding: 0
}),
ah: common_vendor.sr("payPasswordForm", "246b5229-22"),
ai: common_vendor.p({
type: "center",
["border-radius"]: "10px 10px 0 0"
})
});
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-246b5229"], ["__file", "/Users/gxwebsoft/APP/gxtyzx-uniapp-cli/src/package/booking/confirm.vue"]]);
wx.createPage(MiniProgramPage);