"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: 1, 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; }, // 立即购买,确定订单页面 byFun() { this.addCart(); common_vendor.index.navigateTo({ url: "/pages/order_submit/order_submit" }); }, // 加入购入车 async addCart() { 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) { common_vendor.index.showToast({ title: "成功加入购物车", icon: "success", // 可选 success/loading/none duration: 2e3 // 持续时长,单位ms }); setTimeout(() => { this.checkSpecification(false, null); }, 2e3); } } } }; 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.p({ list: $data.swiperList, height: "280" }), d: common_vendor.o($options.jumpLeft), e: common_vendor.p({ src: "/static/common/left_b_st.png", width: "30", height: "30", bgColor: "#f1f6ff00" }), f: common_vendor.o(_ctx.jumpShare), g: common_vendor.p({ src: "/static/common/share_st.png", width: "30", height: "30", bgColor: "#f1f6ff00" }), h: $data.orderInfo.maxPrice && $data.orderInfo.maxPrice !== 0 }, $data.orderInfo.maxPrice && $data.orderInfo.maxPrice !== 0 ? { i: common_vendor.t($data.orderInfo.minPrice), j: common_vendor.t($data.orderInfo.maxPrice) } : { k: common_vendor.t($data.orderInfo.minPrice) }, { l: common_vendor.t($data.orderInfo.adPrice), m: common_vendor.t($data.orderInfo.name), n: common_vendor.t($data.selectSpecificationTempl.combTypes || "暂未选择规格"), o: common_vendor.p({ src: "/static/common/right.png", width: "20", height: "20", bgColor: "#f1f6ff00" }), p: common_vendor.o(($event) => $options.checkSpecification(true)), q: common_vendor.p({ src: "/static/common/address2.png", width: "10", height: "10", bgColor: "#f1f6ff00" }), r: common_vendor.t($options.getValue($options.PRODUCT_DELIVERY_TIME, $data.orderInfo.deliveryTime)), s: common_vendor.p({ src: "/static/product/product_b.png", width: "10", height: "12", bgColor: "#f1f6ff00" }), t: common_vendor.p({ src: "/static/product/product_js.png", width: "10", height: "10", bgColor: "#f1f6ff00" }), v: $data.orderInfo.detailInfo, w: common_vendor.o(($event) => $options.jumpOther("home")), x: common_vendor.p({ src: "/static/product/home.png", width: "20", height: "20", bgColor: "#f1f6ff00" }), y: common_vendor.o(($event) => $options.jumpOther("share")), z: common_vendor.p({ src: "/static/product/kefu.png", width: "20", height: "20", bgColor: "#f1f6ff00" }), A: common_vendor.o(($event) => $options.jumpOther("cart")), B: common_vendor.p({ src: "/static/product/cart.png", width: "24", height: "20", bgColor: "#f1f6ff00" }), C: common_vendor.o(($event) => $options.checkSpecification(true, "addCart")), D: common_vendor.o(($event) => $options.checkSpecification(true, "buy")), E: common_vendor.p({ src: $data.orderInfo.mainGraph, width: "100", height: "100", bgColor: "#f1f6ff00" }), F: $data.selectSpecificationTempl && Object.keys($data.selectSpecificationTempl).length !== 0 }, $data.selectSpecificationTempl && Object.keys($data.selectSpecificationTempl).length !== 0 ? { G: common_vendor.t($data.selectSpecificationTempl.price) } : { H: common_vendor.t($data.orderInfo.minPrice), I: common_vendor.t($data.orderInfo.maxPrice) }, { J: $data.orderInfo.couponPrice && $data.orderInfo.couponPrice !== 0 }, $data.orderInfo.couponPrice && $data.orderInfo.couponPrice !== 0 ? { K: common_vendor.t($data.orderInfo.couponPrice) } : {}, { L: common_vendor.t($data.orderInfo.adPrice), 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.inventory || 0), P: 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 }; }), Q: common_vendor.o(($event) => $options.quantityFun("minus")), R: common_vendor.t($data.orderInfo.quantity), S: common_vendor.o(($event) => $options.quantityFun("add")), T: $data.specificationShowType === "buy" }, $data.specificationShowType === "buy" ? { U: common_vendor.o((...args) => $options.byFun && $options.byFun(...args)) } : $data.specificationShowType === "addCart" ? { W: common_vendor.o((...args) => $options.addCart && $options.addCart(...args)) } : { X: common_vendor.o((...args) => $options.addCart && $options.addCart(...args)), Y: common_vendor.o((...args) => $options.byFun && $options.byFun(...args)) }, { V: $data.specificationShowType === "addCart", Z: 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