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

524 lines
17 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. 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_shop_userAddress_index = require("../../api/shop/userAddress/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_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 { goodsList, totalPrice, carNum, merchantId, merchantName, merchantCode, type, dateTime } = common_vendor.storeToRefs(carStore);
const _sfc_main = {
data() {
return {
orderId: 0,
goodsId: 0,
userInfo: {},
address: {},
addressList: [],
week: 0,
goodsList,
// 订单总金额
totalPrice,
reducePrice: 0,
merchantId,
merchantName,
merchantCode,
getWeek: utils_common.getWeek,
payType: 1,
payment: [],
isLogin: false,
disabled: false,
// 支付密码是否正确
isPayPasswordCorrect: false,
disabledPayPayPassword: false,
payPassword: ""
};
},
onLoad(option) {
this.orderId = option.orderId;
this.reload();
},
onShow() {
if (common_vendor.index.getStorageSync("user_id") && common_vendor.index.getStorageSync("access_token")) {
this.isLogin = true;
}
this.openLogin();
},
methods: {
async reload() {
const app = this;
const userInfo = await userStore.fetchUserInfo();
app.userInfo = userInfo;
api_shop_userAddress_index.pageUserAddress({
userId: common_vendor.index.getStorageSync("user_id")
}).then((res) => {
app.addressList = res.list;
const arr = res.list.filter((d) => d.isDefault === true);
app.address = arr[0];
});
api_system_payment_index.select({ status: true }).then((list) => {
app.payment = list.filter((d) => d.type < 2).map((d) => {
if (d.code == "balancePay") {
d.name = `${d.name} (¥${userInfo.balance})`;
}
return d;
});
});
},
onDisabled() {
this.disabled = !this.disabled;
},
navTo(url) {
common_vendor.index.navigateTo({
url
});
},
openUrl(url) {
if (!this.isLogin) {
this.$refs.login.open("bottom");
return false;
} else {
common_vendor.index.navigateTo({
url
});
}
},
onAddress(item) {
this.address = item;
this.$refs.addForm.close();
},
// 切换支付方式
onPayType(index) {
this.payType = index;
},
openAddressList() {
this.$refs.addForm.open("center");
},
// 弹出登录提示框
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;
});
},
save() {
const app = this;
if (!this.disabled) {
common_vendor.index.showToast({
title: "请先阅读并同意服务协议",
icon: "none"
});
return false;
}
if (carStore.goodsList.length == 0) {
common_vendor.index.showToast({
title: "订单信息不存在",
icon: "none"
});
return false;
}
if (app.payType == 0 && !this.isPayPasswordCorrect) {
this.$refs.payPasswordForm.open("center");
return false;
}
common_vendor.index.showLoading({
title: "订单提交中."
});
api_shop_order_index.addOrder({
type: 0,
// 0商城订单
orderId: this.orderId,
merchantId: this.merchantId,
merchantCode: this.merchantCode,
merchantName: this.merchantName,
totalPrice: this.totalPrice,
payPrice: this.totalPrice - this.reducePrice,
goodsList: this.goodsList,
comments: this.goodsList[0].goodsName,
// 微信支付
payType: this.payType,
// 下单日期
dateTime: this.dateTime
}).then((data) => {
const orderInfo = data;
if (app.payType == 1) {
common_vendor.index.requestPayment({
provider: orderInfo.provider,
// 服务提供商
timeStamp: orderInfo.timeStamp,
// 时间戳
nonceStr: orderInfo.nonceStr,
// 随机字符串
package: orderInfo.package,
signType: orderInfo.signType,
// 签名算法
paySign: orderInfo.paySign,
// 签名
success: function(res) {
common_vendor.index.showToast({
title: "支付成功",
icon: "success"
});
setTimeout(function() {
app.disabled = false;
common_vendor.index.navigateTo({
url: "/package/goods/order"
});
}, 500);
},
fail: function(err) {
console.log("支付失败", err);
app.disabled = false;
common_vendor.index.navigateTo({
url: "/package/goods/order"
});
}
});
}
if (app.payType == 0) {
if (!orderInfo) {
return common_vendor.index.showToast({
title: "支付失败",
icon: "error"
});
}
if (orderInfo) {
common_vendor.index.showToast({
title: "支付成功",
icon: "success"
});
setTimeout(function() {
app.disabled = false;
app.$refs.payPasswordForm.close();
common_vendor.index.reLaunch({
url: "/package/goods/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_icon2 = common_vendor.resolveComponent("uv-icon");
const _easycom_uv_cell2 = common_vendor.resolveComponent("uv-cell");
const _easycom_uni_card2 = common_vendor.resolveComponent("uni-card");
const _easycom_uv_avatar2 = common_vendor.resolveComponent("uv-avatar");
const _easycom_uv_cell_group2 = common_vendor.resolveComponent("uv-cell-group");
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_uni_tag2 = common_vendor.resolveComponent("uni-tag");
const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
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_ws_login2 = common_vendor.resolveComponent("ws-login");
(_easycom_uv_icon2 + _easycom_uv_cell2 + _easycom_uni_card2 + _easycom_uv_avatar2 + _easycom_uv_cell_group2 + _easycom_uni_icons2 + _easycom_uv_gap2 + _easycom_uv_count_to2 + _easycom_uv_button2 + _easycom_uni_tag2 + _easycom_uni_popup2 + _easycom_uv_code_input2 + _easycom_uni_forms_item2 + _easycom_uni_forms2 + _easycom_ws_login2)();
}
const _easycom_uv_icon = () => "../../uni_modules/uv-icon/components/uv-icon/uv-icon.js";
const _easycom_uv_cell = () => "../../uni_modules/uv-cell/components/uv-cell/uv-cell.js";
const _easycom_uni_card = () => "../../uni_modules/uni-card/components/uni-card/uni-card.js";
const _easycom_uv_avatar = () => "../../uni_modules/uv-avatar/components/uv-avatar/uv-avatar.js";
const _easycom_uv_cell_group = () => "../../uni_modules/uv-cell/components/uv-cell-group/uv-cell-group.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_uni_tag = () => "../../uni_modules/uni-tag/components/uni-tag/uni-tag.js";
const _easycom_uni_popup = () => "../../uni_modules/uni-popup/components/uni-popup/uni-popup.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_ws_login = () => "../../uni_modules/ws-login/components/ws-login/ws-login.js";
if (!Math) {
(_easycom_uv_icon + _easycom_uv_cell + _easycom_uni_card + _easycom_uv_avatar + _easycom_uv_cell_group + _easycom_uni_icons + _easycom_uv_gap + _easycom_uv_count_to + _easycom_uv_button + _easycom_uni_tag + _easycom_uni_popup + _easycom_uv_code_input + _easycom_uni_forms_item + _easycom_uni_forms + _easycom_ws_login)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return common_vendor.e({
a: common_vendor.t($data.merchantId),
b: common_vendor.t($data.merchantCode),
c: common_vendor.t($data.merchantName),
d: common_vendor.t(_ctx.dateTime),
e: common_vendor.t($data.week),
f: common_vendor.t($data.totalPrice),
g: common_vendor.t(_ctx.type),
h: common_vendor.t($data.goodsList),
i: $data.address.name
}, $data.address.name ? {
j: common_vendor.p({
name: "arrow-right"
}),
k: common_vendor.o($options.openAddressList),
l: common_vendor.p({
title: `${$data.address.name}   ${$data.address.phone}`,
label: `${$data.address.address}`,
icon: "map",
cellStyle: {
padding: "5px 0"
},
border: false
})
} : {}, {
m: common_vendor.p({
border: false,
["is-shadow"]: false
}),
n: $data.goodsList.length == 0
}, $data.goodsList.length == 0 ? {} : {}, {
o: $data.goodsList
}, $data.goodsList ? {
p: common_vendor.f($data.goodsList, (item, index, i0) => {
return {
a: "d0ffe0d0-6-" + i0 + "," + ("d0ffe0d0-5-" + i0),
b: common_vendor.p({
src: item.image,
size: "60",
shape: "square"
}),
c: "d0ffe0d0-5-" + i0 + ",d0ffe0d0-4",
d: common_vendor.p({
title: `${item.goodsName}`,
label: `${item.comments}`,
cellStyle: {
padding: "10px 0"
},
border: false,
value: `¥${item.price}`
}),
e: index
};
})
} : {}, {
q: common_vendor.p({
customStyle: {
backgroundColor: "#ffffff"
},
border: false
}),
r: common_vendor.p({
title: "订单信息",
border: false,
["is-shadow"]: false
}),
s: common_vendor.f($data.payment, (item, index, i0) => {
return common_vendor.e({
a: item.type == $data.payType
}, item.type == $data.payType ? {
b: "d0ffe0d0-10-" + i0 + "," + ("d0ffe0d0-9-" + i0),
c: common_vendor.p({
size: "30rpx",
name: "checkbox-mark"
})
} : {}, {
d: common_vendor.o(($event) => $options.onPayType(item.type), index),
e: "d0ffe0d0-9-" + i0 + ",d0ffe0d0-8",
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
});
}),
t: common_vendor.p({
customStyle: {
backgroundColor: "#ffffff"
},
border: false
}),
v: common_vendor.t($data.totalPrice || 0),
w: common_vendor.o(($event) => _ctx.actionsClick("分享")),
x: common_vendor.p({
title: "选择支付方式",
border: false,
["is-shadow"]: false
}),
y: !$data.disabled
}, !$data.disabled ? {
z: common_vendor.o($options.onDisabled),
A: common_vendor.p({
type: "circle",
size: "20",
color: "#a4a5a7"
})
} : {
B: common_vendor.o($options.onDisabled),
C: common_vendor.p({
type: "checkbox",
size: "20",
color: "#11a954"
})
}, {
D: common_vendor.o(($event) => $options.navTo("/package/article/detail?articleId=501")),
E: common_vendor.o(($event) => $options.navTo("/package/article/detail?articleId=502")),
F: common_vendor.o((...args) => $options.onDisabled && $options.onDisabled(...args)),
G: common_vendor.p({
height: "50"
}),
H: common_vendor.p({
startVal: 0,
decimals: "2",
duration: "100",
color: "#ebcf00",
bold: true,
endVal: $data.totalPrice
}),
I: common_vendor.o($options.save),
J: common_vendor.p({
disabled: !$data.disabled || $data.goodsList.length == 0,
customStyle: {
background: "linear-gradient(to right, #70b915, #008e04)",
borderRadius: "0 30px 30px 0",
color: "#ffffff",
border: "none",
padding: "22px 30px"
},
text: "提交订单"
}),
K: common_vendor.f($data.addressList, (item, index, i0) => {
return common_vendor.e({
a: "d0ffe0d0-20-" + i0 + "," + ("d0ffe0d0-19-" + i0),
b: common_vendor.p({
text: item.type,
fontSize: "12",
size: "32",
randomBgColor: true
}),
c: common_vendor.t(item.name),
d: common_vendor.t(item.phone),
e: item.isDefault
}, item.isDefault ? {
f: "d0ffe0d0-21-" + i0 + "," + ("d0ffe0d0-19-" + i0),
g: common_vendor.p({
text: "默认",
size: "mini",
inverted: true,
type: "success"
})
} : {}, {
h: "d0ffe0d0-22-" + i0 + "," + ("d0ffe0d0-19-" + i0),
i: common_vendor.o(($event) => $options.onAddress(item), index),
j: "d0ffe0d0-19-" + i0 + ",d0ffe0d0-18",
k: common_vendor.p({
cellStyle: {
padding: "10px 0"
},
label: item.address
}),
l: index
});
}),
L: common_vendor.p({
type: "right"
}),
M: common_vendor.o(($event) => $options.navTo("/package/user/address")),
N: common_vendor.p({
customStyle: {
borderRadius: "30px"
},
text: "收货地址管理"
}),
O: common_vendor.p({
customStyle: {
backgroundColor: "#ffffff"
},
border: false
}),
P: common_vendor.p({
title: "选择收货地址",
border: false,
["is-shadow"]: false,
padding: 0
}),
Q: common_vendor.sr("addForm", "d0ffe0d0-16"),
R: common_vendor.p({
type: "center",
["border-radius"]: "10px 10px 0 0"
}),
S: common_vendor.o($options.onPayPassword),
T: common_vendor.o(($event) => $data.payPassword = $event),
U: common_vendor.p({
mode: "box",
dot: true,
space: 0,
maxlength: 6,
hairline: true,
modelValue: $data.payPassword
}),
V: common_vendor.p({
label: "支付密码",
name: "payPassword",
required: true
}),
W: common_vendor.sr("form", "d0ffe0d0-26,d0ffe0d0-25"),
X: common_vendor.p({
["label-width"]: 80
}),
Y: common_vendor.o(($event) => $options.navTo(`/package/user/pay-password`)),
Z: common_vendor.p({
title: "请输入支付密码",
border: false,
["is-shadow"]: false,
padding: 0
}),
aa: common_vendor.sr("payPasswordForm", "d0ffe0d0-24"),
ab: common_vendor.p({
type: "center",
["border-radius"]: "10px 10px 0 0"
}),
ac: common_vendor.sr("login", "d0ffe0d0-29"),
ad: common_vendor.o($options.reload),
ae: common_vendor.p({
logo: _ctx.logo
})
});
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-d0ffe0d0"], ["__file", "/Users/gxwebsoft/APP/gxtyzx-uniapp-cli/src/package/goods/checkout.vue"]]);
wx.createPage(MiniProgramPage);