Files
frontend-app/unpackage/dist/dev/mp-weixin/pages/productInfo/productInfo.js
T
2025-05-30 18:44:14 +08:00

475 lines
16 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 utils_index = require("../../utils/index.js");
const utils_config = require("../../utils/config.js");
const _sfc_main = {
computed: {
PRODUCT_DELIVERY_TIME() {
return utils_enumUtils.PRODUCT_DELIVERY_TIME;
},
CUSTOMER_SERVICE_PHONE_NUMBER() {
return utils_config.CUSTOMER_SERVICE_PHONE_NUMBER;
},
CLOUD_SERVICE_PHONE_NUMBER() {
return utils_config.CLOUD_SERVICE_PHONE_NUMBER;
}
},
data() {
return {
id: 0,
swiperList: [],
currentNum: 0,
specificationShow: false,
specificationShowType: "",
// 弹框类型
orderInfo: {},
specificationList: [],
//规格
selectSpecification: [],
// 选择的规格
specificationTempl: [],
// 规格模版数据
selectSpecificationTempl: {},
// 选择规格模版数据
serviceShow: false,
// 联系客服弹框
openShow: false,
source: null
// 来源:供应链,自营
};
},
onLoad(options) {
const id = options.id;
const source = options.source;
if (id && id !== 0) {
this.id = id ? parseInt(id, 10) : 0;
if (source && source === "supply_chain") {
this.source = source;
this.getSupplyChainById();
} else {
this.getById();
}
}
},
methods: {
getValue: utils_enumUtils.getValue,
copyMobile(mobile) {
utils_index.copyData(mobile);
this.serviceShow = false;
this.openShow = false;
},
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;
}
},
/**
* 来自商城的订单
*/
getSupplyChainById() {
const params = {
goods_id: this.id,
app_id: "2024111300164927",
sign_type: "MD5",
sign: "d04be0cedd49608e758458325faecf90"
};
common_vendor.index.request({
url: "https://cyysc.gscm.top/outside/1/atm/goods/detail",
method: "get",
data: params,
header: {},
success: (res) => {
const data = res.data;
if (data && data.result === 1) {
const objData = data.data;
const content = objData.content.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, "'").replace(/&#39;/g, '"').replace(/\n/g, "<br>");
const orderInfo = {
detailInfo: content,
minPrice: objData.min_price,
// maxPrice:objData.max_price,
adPrice: objData.price,
sales: objData.virtual_sales
};
const domain = "https://cyysc.gscm.top";
let currentThumb = objData.thumb;
if (objData.thumb.indexOf("https://") === -1 && objData.thumb.indexOf("http://") === -1) {
currentThumb = domain + "/static/upload/" + objData.thumb;
}
this.swiperList = [currentThumb];
this.orderInfo = orderInfo;
}
},
fail: (error) => {
common_vendor.index.__f__("log", "at pages/productInfo/productInfo.vue:379", "error", error);
}
});
},
async checkSpecification(val, type) {
const source = this.source;
if (source && source === "supply_chain") {
this.openShow = true;
return;
}
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");
const _easycom_up_modal2 = common_vendor.resolveComponent("up-modal");
const _easycom_up_overlay2 = common_vendor.resolveComponent("up-overlay");
(_easycom_up_swiper2 + _easycom_up_image2 + _easycom_up_popup2 + _easycom_up_modal2 + _easycom_up_overlay2)();
}
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";
const _easycom_up_modal = () => "../../uni_modules/uview-plus/components/u-modal/u-modal.js";
const _easycom_up_overlay = () => "../../uni_modules/uview-plus/components/u-overlay/u-overlay.js";
if (!Math) {
(_easycom_up_swiper + _easycom_up_image + _easycom_up_popup + _easycom_up_modal + _easycom_up_overlay)();
}
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) => {
$data.serviceShow = true;
}),
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"
}),
ae: common_vendor.p({
src: "/static/common/close.png",
width: "20",
height: "20",
bgColor: "#f1f6ff00"
}),
af: common_vendor.o(($event) => {
$data.serviceShow = false;
}),
ag: common_vendor.t($data.source === "supply_chain" ? "云仓客服" : "平台客服"),
ah: common_vendor.t($data.source === "supply_chain" ? $options.CLOUD_SERVICE_PHONE_NUMBER : $options.CUSTOMER_SERVICE_PHONE_NUMBER),
ai: common_vendor.o(($event) => $options.copyMobile($data.source === "supply_chain" ? $options.CLOUD_SERVICE_PHONE_NUMBER : $options.CUSTOMER_SERVICE_PHONE_NUMBER)),
aj: common_vendor.o(($event) => {
$data.serviceShow = false;
}),
ak: common_vendor.p({
show: $data.serviceShow,
showConfirmButton: false
}),
al: common_vendor.t($options.CLOUD_SERVICE_PHONE_NUMBER),
am: common_vendor.o(($event) => $options.copyMobile($options.CLOUD_SERVICE_PHONE_NUMBER)),
an: common_vendor.o(() => {
}),
ao: common_vendor.p({
show: $data.openShow
})
});
}
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