323 lines
14 KiB
JavaScript
323 lines
14 KiB
JavaScript
"use strict";
|
||
var __async = (__this, __arguments, generator) => {
|
||
return new Promise((resolve, reject) => {
|
||
var fulfilled = (value) => {
|
||
try {
|
||
step(generator.next(value));
|
||
} catch (e) {
|
||
reject(e);
|
||
}
|
||
};
|
||
var rejected = (value) => {
|
||
try {
|
||
step(generator.throw(value));
|
||
} catch (e) {
|
||
reject(e);
|
||
}
|
||
};
|
||
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
||
step((generator = generator.apply(__this, __arguments)).next());
|
||
});
|
||
};
|
||
const common_vendor = require("../../../common/vendor.js");
|
||
const modules_mall_sheep_index = require("../sheep/index.js");
|
||
const modules_mall_sheep_api_trade_order = require("../sheep/api/trade/order.js");
|
||
const modules_mall_sheep_api_promotion_coupon = require("../sheep/api/promotion/coupon.js");
|
||
const modules_mall_sheep_hooks_useGoods = require("../sheep/hooks/useGoods.js");
|
||
if (!Array) {
|
||
const _easycom_s_goods_item2 = common_vendor.resolveComponent("s-goods-item");
|
||
const _easycom_uni_easyinput2 = common_vendor.resolveComponent("uni-easyinput");
|
||
const _easycom_s_coupon_select2 = common_vendor.resolveComponent("s-coupon-select");
|
||
const _easycom_s_discount_list2 = common_vendor.resolveComponent("s-discount-list");
|
||
const _easycom_su_fixed2 = common_vendor.resolveComponent("su-fixed");
|
||
const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
|
||
const _component_layout_default_uni = common_vendor.resolveComponent("layout-default-uni");
|
||
(_easycom_s_goods_item2 + _easycom_uni_easyinput2 + _easycom_s_coupon_select2 + _easycom_s_discount_list2 + _easycom_su_fixed2 + _easycom_s_layout2 + _component_layout_default_uni)();
|
||
}
|
||
const _easycom_s_goods_item = () => "../sheep/components/s-goods-item/s-goods-item.js";
|
||
const _easycom_uni_easyinput = () => "../../../uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.js";
|
||
const _easycom_s_coupon_select = () => "../sheep/components/s-coupon-select/s-coupon-select.js";
|
||
const _easycom_s_discount_list = () => "../sheep/components/s-discount-list/s-discount-list.js";
|
||
const _easycom_su_fixed = () => "../sheep/ui/su-fixed/su-fixed.js";
|
||
const _easycom_s_layout = () => "../sheep/components/s-layout/s-layout.js";
|
||
if (!Math) {
|
||
(AddressSelection + _easycom_s_goods_item + _easycom_uni_easyinput + _easycom_s_coupon_select + _easycom_s_discount_list + _easycom_su_fixed + _easycom_s_layout)();
|
||
}
|
||
const AddressSelection = () => "./addressSelection.js";
|
||
const _sfc_main = {
|
||
__name: "confirm",
|
||
setup(__props) {
|
||
const state = common_vendor.reactive({
|
||
orderPayload: {},
|
||
orderInfo: {
|
||
items: [],
|
||
// 商品项列表
|
||
price: {}
|
||
// 价格信息
|
||
},
|
||
showCoupon: false,
|
||
// 是否展示优惠劵
|
||
couponInfo: [],
|
||
// 优惠劵列表
|
||
showDiscount: false,
|
||
// 是否展示营销活动
|
||
// ========== 积分 ==========
|
||
pointStatus: false
|
||
// 是否使用积分
|
||
});
|
||
const addressState = common_vendor.ref({
|
||
addressInfo: {},
|
||
// 选择的收货地址
|
||
deliveryType: 1,
|
||
// 收货方式:1-快递配送,2-门店自提
|
||
isPickUp: true,
|
||
// 门店自提是否开启 TODO puhui999: 默认开启,看看后端有开关的话接入
|
||
pickUpInfo: {},
|
||
// 选择的自提门店信息
|
||
receiverName: "",
|
||
// 收件人名称
|
||
receiverMobile: ""
|
||
// 收件人手机
|
||
});
|
||
const changeIntegral = () => __async(this, null, function* () {
|
||
state.pointStatus = !state.pointStatus;
|
||
yield getOrderInfo();
|
||
});
|
||
function onSelectCoupon(couponId) {
|
||
return __async(this, null, function* () {
|
||
state.orderPayload.couponId = couponId;
|
||
yield getOrderInfo();
|
||
state.showCoupon = false;
|
||
});
|
||
}
|
||
function onConfirm() {
|
||
if (addressState.value.deliveryType === 1 && !addressState.value.addressInfo.id) {
|
||
modules_mall_sheep_index.sheep.$helper.toast("请选择收货地址");
|
||
return;
|
||
}
|
||
if (addressState.value.deliveryType === 2) {
|
||
if (!addressState.value.pickUpInfo.id) {
|
||
modules_mall_sheep_index.sheep.$helper.toast("请选择自提门店地址");
|
||
return;
|
||
}
|
||
if (addressState.value.receiverName === "" || addressState.value.receiverMobile === "") {
|
||
modules_mall_sheep_index.sheep.$helper.toast("请填写联系人或联系人电话");
|
||
return;
|
||
}
|
||
if (!/^[\u4e00-\u9fa5\w]{2,16}$/.test(addressState.value.receiverName)) {
|
||
modules_mall_sheep_index.sheep.$helper.toast("请填写您的真实姓名");
|
||
return;
|
||
}
|
||
if (!/^1(3|4|5|7|8|9|6)\d{9}$/.test(addressState.value.receiverMobile)) {
|
||
modules_mall_sheep_index.sheep.$helper.toast("请填写正确的手机号");
|
||
return;
|
||
}
|
||
}
|
||
submitOrder();
|
||
}
|
||
function submitOrder() {
|
||
return __async(this, null, function* () {
|
||
const { code, data } = yield modules_mall_sheep_api_trade_order.OrderApi.createOrder({
|
||
items: state.orderPayload.items,
|
||
couponId: state.orderPayload.couponId,
|
||
remark: state.orderPayload.remark,
|
||
deliveryType: addressState.value.deliveryType,
|
||
addressId: addressState.value.addressInfo.id,
|
||
// 收件地址编号
|
||
pickUpStoreId: addressState.value.pickUpInfo.id,
|
||
// 自提门店编号
|
||
receiverName: addressState.value.receiverName,
|
||
// 选择门店自提时,该字段为联系人名
|
||
receiverMobile: addressState.value.receiverMobile,
|
||
// 选择门店自提时,该字段为联系人手机
|
||
pointStatus: state.pointStatus,
|
||
combinationActivityId: state.orderPayload.combinationActivityId,
|
||
combinationHeadId: state.orderPayload.combinationHeadId,
|
||
seckillActivityId: state.orderPayload.seckillActivityId
|
||
});
|
||
if (code !== 0) {
|
||
return;
|
||
}
|
||
if (state.orderPayload.items[0].cartId > 0) {
|
||
modules_mall_sheep_index.sheep.$store("cart").getList();
|
||
}
|
||
modules_mall_sheep_index.sheep.$router.redirect("/modules/mall/pay/index", {
|
||
id: data.payOrderId
|
||
});
|
||
});
|
||
}
|
||
function getOrderInfo() {
|
||
return __async(this, null, function* () {
|
||
const { data, code } = yield modules_mall_sheep_api_trade_order.OrderApi.settlementOrder({
|
||
items: state.orderPayload.items,
|
||
couponId: state.orderPayload.couponId,
|
||
deliveryType: addressState.value.deliveryType,
|
||
addressId: addressState.value.addressInfo.id,
|
||
// 收件地址编号
|
||
pickUpStoreId: addressState.value.pickUpInfo.id,
|
||
// 自提门店编号
|
||
receiverName: addressState.value.receiverName,
|
||
// 选择门店自提时,该字段为联系人名
|
||
receiverMobile: addressState.value.receiverMobile,
|
||
// 选择门店自提时,该字段为联系人手机
|
||
pointStatus: state.pointStatus,
|
||
combinationActivityId: state.orderPayload.combinationActivityId,
|
||
combinationHeadId: state.orderPayload.combinationHeadId,
|
||
seckillActivityId: state.orderPayload.seckillActivityId
|
||
});
|
||
if (code !== 0) {
|
||
return;
|
||
}
|
||
state.orderInfo = data;
|
||
if (state.orderInfo.address) {
|
||
addressState.value.addressInfo = state.orderInfo.address;
|
||
}
|
||
});
|
||
}
|
||
function getCoupons() {
|
||
return __async(this, null, function* () {
|
||
const { code, data } = yield modules_mall_sheep_api_promotion_coupon.CouponApi.getMatchCouponList(
|
||
state.orderInfo.price.payPrice,
|
||
state.orderInfo.items.map((item) => item.spuId),
|
||
state.orderPayload.items.map((item) => item.skuId),
|
||
state.orderPayload.items.map((item) => item.categoryId)
|
||
);
|
||
if (code === 0) {
|
||
state.couponInfo = data;
|
||
}
|
||
});
|
||
}
|
||
common_vendor.onLoad((options) => __async(this, null, function* () {
|
||
if (!options.data) {
|
||
modules_mall_sheep_index.sheep.$helper.toast("参数不正确,请检查!");
|
||
return;
|
||
}
|
||
state.orderPayload = JSON.parse(options.data);
|
||
yield getOrderInfo();
|
||
yield getCoupons();
|
||
}));
|
||
common_vendor.watch(addressState, (newAddress, oldAddress) => __async(this, null, function* () {
|
||
if (newAddress.addressInfo.id !== oldAddress.addressInfo.id || newAddress.deliveryType !== oldAddress.deliveryType) {
|
||
yield getOrderInfo();
|
||
}
|
||
}));
|
||
return (_ctx, _cache) => {
|
||
return common_vendor.e({
|
||
a: common_vendor.o(($event) => addressState.value = $event),
|
||
b: common_vendor.p({
|
||
modelValue: addressState.value
|
||
}),
|
||
c: common_vendor.f(state.orderInfo.items, (item, k0, i0) => {
|
||
return {
|
||
a: item.skuId,
|
||
b: "f69e72ea-3-" + i0 + ",f69e72ea-1",
|
||
c: common_vendor.p({
|
||
img: item.picUrl,
|
||
title: item.spuName,
|
||
skuText: item.properties.map((property) => property.valueName).join(" "),
|
||
price: item.price,
|
||
num: item.count,
|
||
marginBottom: "10"
|
||
})
|
||
};
|
||
}),
|
||
d: common_vendor.o(($event) => state.orderPayload.remark = $event),
|
||
e: common_vendor.p({
|
||
maxlength: "20",
|
||
placeholder: "建议留言前先与商家沟通",
|
||
inputBorder: false,
|
||
clearable: false,
|
||
modelValue: state.orderPayload.remark
|
||
}),
|
||
f: common_vendor.t(common_vendor.unref(modules_mall_sheep_hooks_useGoods.fen2yuan)(state.orderInfo.price.totalPrice)),
|
||
g: state.orderInfo.type === 0
|
||
}, state.orderInfo.type === 0 ? {
|
||
h: common_vendor.t(state.pointStatus ? "剩余积分" : "当前积分"),
|
||
i: common_vendor.unref(modules_mall_sheep_index.sheep).$url.static("/static/img/shop/goods/score1.svg"),
|
||
j: common_vendor.t(state.pointStatus ? state.orderInfo.totalPoint - state.orderInfo.usePoint : state.orderInfo.totalPoint || 0),
|
||
k: state.pointStatus,
|
||
l: !state.orderInfo.totalPoint || state.orderInfo.totalPoint <= 0,
|
||
m: common_vendor.o(changeIntegral)
|
||
} : {}, {
|
||
n: addressState.value.deliveryType === 1
|
||
}, addressState.value.deliveryType === 1 ? common_vendor.e({
|
||
o: state.orderInfo.price.deliveryPrice > 0
|
||
}, state.orderInfo.price.deliveryPrice > 0 ? {
|
||
p: common_vendor.t(common_vendor.unref(modules_mall_sheep_hooks_useGoods.fen2yuan)(state.orderInfo.price.deliveryPrice))
|
||
} : {}) : {}, {
|
||
q: addressState.value.deliveryType === 2
|
||
}, addressState.value.deliveryType === 2 ? {
|
||
r: common_vendor.o(($event) => addressState.value.receiverName = $event),
|
||
s: common_vendor.p({
|
||
maxlength: "20",
|
||
placeholder: "请填写您的联系姓名",
|
||
inputBorder: false,
|
||
clearable: false,
|
||
modelValue: addressState.value.receiverName
|
||
})
|
||
} : {}, {
|
||
t: addressState.value.deliveryType === 2
|
||
}, addressState.value.deliveryType === 2 ? {
|
||
v: common_vendor.o(($event) => addressState.value.receiverMobile = $event),
|
||
w: common_vendor.p({
|
||
maxlength: "20",
|
||
placeholder: "请填写您的联系电话",
|
||
inputBorder: false,
|
||
clearable: false,
|
||
modelValue: addressState.value.receiverMobile
|
||
})
|
||
} : {}, {
|
||
x: state.orderInfo.type === 0
|
||
}, state.orderInfo.type === 0 ? common_vendor.e({
|
||
y: state.orderPayload.couponId > 0
|
||
}, state.orderPayload.couponId > 0 ? {
|
||
z: common_vendor.t(common_vendor.unref(modules_mall_sheep_hooks_useGoods.fen2yuan)(state.orderInfo.price.couponPrice))
|
||
} : {
|
||
A: common_vendor.t(state.couponInfo.length > 0 ? state.couponInfo.length + " 张可用" : "暂无可用优惠券"),
|
||
B: common_vendor.n(state.couponInfo.length > 0 ? "text-red" : "text-disabled")
|
||
}, {
|
||
C: common_vendor.o(($event) => state.showCoupon = true)
|
||
}) : {}, {
|
||
D: state.orderInfo.price.discountPrice > 0
|
||
}, state.orderInfo.price.discountPrice > 0 ? {
|
||
E: common_vendor.t(common_vendor.unref(modules_mall_sheep_hooks_useGoods.fen2yuan)(state.orderInfo.price.discountPrice))
|
||
} : {}, {
|
||
F: state.orderInfo.price.vipPrice > 0
|
||
}, state.orderInfo.price.vipPrice > 0 ? {
|
||
G: common_vendor.t(common_vendor.unref(modules_mall_sheep_hooks_useGoods.fen2yuan)(state.orderInfo.price.vipPrice))
|
||
} : {}, {
|
||
H: common_vendor.t(state.orderInfo.items.reduce((acc, item) => acc + item.count, 0)),
|
||
I: common_vendor.t(common_vendor.unref(modules_mall_sheep_hooks_useGoods.fen2yuan)(state.orderInfo.price.payPrice)),
|
||
J: common_vendor.o(onSelectCoupon),
|
||
K: common_vendor.o(($event) => state.showCoupon = false),
|
||
L: common_vendor.o(($event) => state.couponInfo = $event),
|
||
M: common_vendor.p({
|
||
show: state.showCoupon,
|
||
modelValue: state.couponInfo
|
||
}),
|
||
N: common_vendor.o(($event) => state.showDiscount = false),
|
||
O: common_vendor.o(($event) => state.orderInfo = $event),
|
||
P: common_vendor.p({
|
||
show: state.showDiscount,
|
||
modelValue: state.orderInfo
|
||
}),
|
||
Q: common_vendor.t(common_vendor.unref(modules_mall_sheep_hooks_useGoods.fen2yuan)(state.orderInfo.price.payPrice)),
|
||
R: common_vendor.o(onConfirm),
|
||
S: common_vendor.p({
|
||
bottom: true,
|
||
opacity: false,
|
||
bg: "bg-white",
|
||
placeholder: true,
|
||
noFixed: false,
|
||
index: 200
|
||
}),
|
||
T: common_vendor.p({
|
||
title: "确认订单"
|
||
})
|
||
});
|
||
};
|
||
}
|
||
};
|
||
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-f69e72ea"]]);
|
||
wx.createPage(MiniProgramPage);
|