Files
frontend-app/unpackage/dist/dev/mp-weixin/pages/productInfo/productInfo.js
T
2025-05-23 18:03:45 +08:00

373 lines
12 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const api_product = require("../../api/product.js");
const utils_enumUtils = require("../../utils/enumUtils.js");
const _sfc_main = {
computed: {
PRODUCT_DELIVERY_TIME() {
return utils_enumUtils.PRODUCT_DELIVERY_TIME;
}
},
data() {
return {
id: 0,
swiperList: [],
currentNum: 0,
specificationShow: false,
specificationShowType: "",
// 弹框类型
orderInfo: {},
specificationList: [],
//规格
selectSpecification: [],
// 选择的规格
specificationTempl: [],
// 规格模版数据
selectSpecificationTempl: {}
// 选择规格模版数据
};
},
onLoad(options) {
const id = options.id;
if (id && id !== 0) {
this.id = id ? parseInt(id, 10) : 0;
this.getById();
}
},
methods: {
getValue: utils_enumUtils.getValue,
jumpLeft() {
common_vendor.index.navigateBack({
delta: 1
// 返回的页面数,默认为1,返回到上一级
});
},
jumpOther(type) {
if (type === "home") {
common_vendor.index.switchTab({
// 首页
url: "/pages/home/home"
});
} else if (type === "share") {
common_vendor.index.navigateTo({
url: "/pages/invite_friends/invite_friends"
});
} else if (type === "cart") {
common_vendor.index.switchTab({
url: "/pages/shopping_cart/shopping_cart"
});
}
},
/**
* 查询详细内容
*/
async getById() {
const params = {
id: this.id
};
const resp = await api_product.getGoodsDetail(params);
if (resp && resp.bizcode === 100) {
const data = resp.data;
if (data.goodsGraph) {
this.swiperList = data.goodsGraph.split(",");
}
data.addressObj = {};
data.quantity = 1;
data.inventory = 0;
this.orderInfo = data;
}
},
async checkSpecification(val, type) {
if (val) {
await this.querySpecification();
const data = this.orderInfo;
this.getSpecification(data.specs);
} else {
this.specificationList = [];
this.selectSpecification = [];
this.specificationTempl = [];
}
this.specificationShow = val;
this.specificationShowType = type;
},
// 拆解规格
getSpecification(specs) {
const optionArr = [];
if (specs) {
const arr = JSON.parse(specs);
arr.map((item) => {
optionArr.push({
type: item.type,
items: item.items,
selectVal: null
});
});
}
this.specificationList = optionArr;
},
// 获取规格模版数据
async querySpecification() {
const params = {
id: this.id
};
const resp = await api_product.getGoodsSpecs(params);
if (resp && resp.bizcode === 100) {
const data = resp.data;
let stock = 0;
data.map((item) => {
stock = stock + item.stock;
});
this.specificationTempl = data;
this.orderInfo.inventory = stock;
}
},
//改变规格的样式
clickSpecification(pIndex, oItem) {
this.specificationList[pIndex].selectVal = oItem.n;
this.selectSpecificationFun(pIndex, oItem);
},
// 选择规格
selectSpecificationFun(index, item) {
const currentSelectSpecification = this.selectSpecification;
currentSelectSpecification[index] = item.n;
this.selectSpecification = currentSelectSpecification;
const oldLength = this.specificationList.length;
const newLength = this.selectSpecification.length;
if (oldLength === newLength) {
const newLengthStr = this.selectSpecification.join("♧");
const specificationTempl = this.specificationTempl;
let selectTempl = {};
specificationTempl.map((item2) => {
if (item2.combNames === newLengthStr) {
selectTempl = item2;
return;
}
});
this.selectSpecificationTempl = selectTempl;
this.orderInfo.inventory = selectTempl.stock;
}
},
// 改变数量
quantityFun(type) {
let currentQuantity = this.orderInfo.quantity;
if (type === "minus") {
if (currentQuantity === 1) {
this.$refs.uToastRef.show({
type: "error",
message: "不能低于最低购买数量"
});
} else {
currentQuantity = currentQuantity - 1;
}
} else if (type === "add") {
currentQuantity = currentQuantity + 1;
}
this.orderInfo.quantity = currentQuantity;
},
// 加入购入车
async addCart(isBy = false) {
const selectTempl = this.selectSpecificationTempl;
if (!selectTempl || Object.keys(selectTempl).length === 0) {
common_vendor.index.showToast({
title: "请先选择规格",
icon: "none",
// 可选 success/loading/none
duration: 2e3
// 持续时长,单位ms
});
return;
}
const params = {
id: this.id,
specsId: selectTempl.id,
// 规格ID
goodsNum: this.orderInfo.quantity
// 商品数量
};
const resp = await api_product.addGoods(params);
if (resp && resp.bizcode === 100) {
if (isBy) {
common_vendor.index.navigateTo({
url: "/pages/order_submit/order_submit?ids=" + resp.data
});
} else {
common_vendor.index.showToast({
title: "成功加入购物车",
icon: "success",
// 可选 success/loading/none
duration: 2e3
// 持续时长,单位ms
});
}
setTimeout(() => {
this.checkSpecification(false, null);
}, 2e3);
}
},
// 跳转到分享页面
jumpShare() {
}
}
};
if (!Array) {
const _easycom_up_swiper2 = common_vendor.resolveComponent("up-swiper");
const _easycom_up_image2 = common_vendor.resolveComponent("up-image");
const _easycom_up_popup2 = common_vendor.resolveComponent("up-popup");
(_easycom_up_swiper2 + _easycom_up_image2 + _easycom_up_popup2)();
}
const _easycom_up_swiper = () => "../../uni_modules/uview-plus/components/u-swiper/u-swiper.js";
const _easycom_up_image = () => "../../uni_modules/uview-plus/components/u-image/u-image.js";
const _easycom_up_popup = () => "../../uni_modules/uview-plus/components/u-popup/u-popup.js";
if (!Math) {
(_easycom_up_swiper + _easycom_up_image + _easycom_up_popup)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return common_vendor.e({
a: common_vendor.t($data.currentNum + 1),
b: common_vendor.t($data.swiperList.length),
c: common_vendor.o((e) => $data.currentNum = e.current),
d: common_vendor.p({
list: $data.swiperList,
height: "280"
}),
e: common_vendor.o($options.jumpLeft),
f: common_vendor.p({
src: "/static/common/left_b_st.png",
width: "30",
height: "30",
bgColor: "#f1f6ff00"
}),
g: common_vendor.o($options.jumpShare),
h: common_vendor.p({
src: "/static/common/share_st.png",
width: "30",
height: "30",
bgColor: "#f1f6ff00"
}),
i: $data.orderInfo.minPrice && $data.orderInfo.maxPrice
}, $data.orderInfo.minPrice && $data.orderInfo.maxPrice ? {
j: common_vendor.t($data.orderInfo.minPrice),
k: common_vendor.t($data.orderInfo.maxPrice)
} : {
l: common_vendor.t($data.orderInfo.minPrice)
}, {
m: common_vendor.t($data.orderInfo.adPrice),
n: common_vendor.t($data.orderInfo.name),
o: common_vendor.t($data.orderInfo.sales),
p: common_vendor.t($data.selectSpecificationTempl.combTypes || "暂未选择规格"),
q: common_vendor.p({
src: "/static/common/right.png",
width: "20",
height: "20",
bgColor: "#f1f6ff00"
}),
r: common_vendor.o(($event) => $options.checkSpecification(true)),
s: common_vendor.p({
src: "/static/common/address2.png",
width: "10",
height: "10",
bgColor: "#f1f6ff00"
}),
t: common_vendor.t($options.getValue($options.PRODUCT_DELIVERY_TIME, $data.orderInfo.deliveryTime)),
v: common_vendor.p({
src: "/static/product/product_b.png",
width: "10",
height: "12",
bgColor: "#f1f6ff00"
}),
w: common_vendor.p({
src: "/static/product/product_js.png",
width: "10",
height: "10",
bgColor: "#f1f6ff00"
}),
x: $data.orderInfo.detailInfo,
y: common_vendor.o(($event) => $options.jumpOther("home")),
z: common_vendor.p({
src: "/static/product/home.png",
width: "20",
height: "20",
bgColor: "#f1f6ff00"
}),
A: common_vendor.o(($event) => $options.jumpOther("share")),
B: common_vendor.p({
src: "/static/product/kefu.png",
width: "20",
height: "20",
bgColor: "#f1f6ff00"
}),
C: common_vendor.o(($event) => $options.jumpOther("cart")),
D: common_vendor.p({
src: "/static/product/cart.png",
width: "24",
height: "20",
bgColor: "#f1f6ff00"
}),
E: common_vendor.o(($event) => $options.checkSpecification(true, "addCart")),
F: common_vendor.o(($event) => $options.checkSpecification(true, "buy")),
G: common_vendor.p({
src: $data.orderInfo.mainGraph,
width: "100",
height: "100",
bgColor: "#f1f6ff00"
}),
H: $data.selectSpecificationTempl && Object.keys($data.selectSpecificationTempl).length !== 0
}, $data.selectSpecificationTempl && Object.keys($data.selectSpecificationTempl).length !== 0 ? {
I: common_vendor.t($data.selectSpecificationTempl.price)
} : common_vendor.e({
J: common_vendor.t($data.orderInfo.minPrice),
K: $data.orderInfo.maxPrice
}, $data.orderInfo.maxPrice ? {
L: common_vendor.t($data.orderInfo.maxPrice)
} : {}), {
M: $data.orderInfo.couponPrice && $data.orderInfo.couponPrice !== 0
}, $data.orderInfo.couponPrice && $data.orderInfo.couponPrice !== 0 ? {
N: common_vendor.t($data.orderInfo.couponPrice)
} : {}, {
O: common_vendor.t($data.orderInfo.adPrice),
P: $data.orderInfo.couponPrice && $data.orderInfo.couponPrice !== 0
}, $data.orderInfo.couponPrice && $data.orderInfo.couponPrice !== 0 ? {
Q: common_vendor.t($data.orderInfo.couponPrice)
} : {}, {
R: common_vendor.t($data.orderInfo.inventory || 0),
S: common_vendor.f($data.specificationList, (item, index, i0) => {
return {
a: common_vendor.t(item.type),
b: common_vendor.f(item.items, (oItem, oIndex, i1) => {
return {
a: common_vendor.t(oItem.n),
b: common_vendor.n(oItem.inventory === 0 ? "item_Warp item_Warp_no_warp" : item.selectVal === oItem.n ? "item_Warp item_Warp_yes_warp" : "item_Warp"),
c: oItem.n,
d: common_vendor.o(($event) => $options.clickSpecification(index, oItem), oItem.n)
};
}),
c: item.id
};
}),
T: common_vendor.o(($event) => $options.quantityFun("minus")),
U: common_vendor.t($data.orderInfo.quantity),
V: common_vendor.o(($event) => $options.quantityFun("add")),
W: $data.specificationShowType === "buy"
}, $data.specificationShowType === "buy" ? {
X: common_vendor.o(($event) => $options.addCart(true))
} : $data.specificationShowType === "addCart" ? {
Z: common_vendor.o(($event) => $options.addCart(false))
} : {
aa: common_vendor.o(($event) => $options.addCart(false)),
ab: common_vendor.o(($event) => $options.addCart(true))
}, {
Y: $data.specificationShowType === "addCart",
ac: common_vendor.o(($event) => $data.specificationShow = false),
ad: common_vendor.p({
show: $data.specificationShow,
round: 10,
closeOnClickOverlay: false,
closeable: true,
mode: "bottom"
})
});
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-ceb0d096"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/productInfo/productInfo.js.map