"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: { id: 1, url: "/static/common/product_def.png", price: 87, oPrice: 199, couponPrice: 50, inventory: 100, // 库存 quantity: 1, addressObj: { name: "李个", address: "郑州市金水区东风路街道白庙小区五号楼" } }, 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,返回到上一级 }); }, jumpHome() { common_vendor.index.switchTab({ url: "/pages/home/home" }); }, // 分享 jumpShare() { common_vendor.index.navigateTo({ url: "/pages/invite_friends/invite_friends" }); }, /** * 查询详细内容 */ 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; this.getSpecification(data.specs); } }, checkSpecification(val, type) { if (val) { this.querySpecification(); } else { this.specificationList = []; this.selectSpecification = []; this.specificationTempl = []; } this.specificationShow = val; this.specificationShowType = type; }, // 拆解规格 getSpecification(specs) { common_vendor.index.__f__("log", "at pages/productInfo/productInfo.vue:296", "specs", specs); const optionArr = []; if (specs) { const arr = JSON.parse(specs); arr.map((item) => { common_vendor.index.__f__("log", "at pages/productInfo/productInfo.vue:301", "item", 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($options.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($options.jumpHome), x: common_vendor.p({ src: "/static/product/home.png", width: "20", height: "20", bgColor: "#f1f6ff00" }), y: common_vendor.o($options.jumpShare), z: common_vendor.p({ src: "/static/product/kefu.png", width: "20", height: "20", bgColor: "#f1f6ff00" }), A: common_vendor.o(($event) => $options.checkSpecification(true, "addCart")), B: common_vendor.o(($event) => $options.checkSpecification(true, "buy")), C: common_vendor.p({ src: $data.orderInfo.mainGraph, width: "100", height: "100", bgColor: "#f1f6ff00" }), D: $data.selectSpecificationTempl && Object.keys($data.selectSpecificationTempl).length !== 0 }, $data.selectSpecificationTempl && Object.keys($data.selectSpecificationTempl).length !== 0 ? { E: common_vendor.t($data.selectSpecificationTempl.price) } : { F: common_vendor.t($data.orderInfo.minPrice), G: common_vendor.t($data.orderInfo.maxPrice) }, { H: $data.orderInfo.couponPrice && $data.orderInfo.couponPrice !== 0 }, $data.orderInfo.couponPrice && $data.orderInfo.couponPrice !== 0 ? { I: common_vendor.t($data.orderInfo.couponPrice) } : {}, { J: common_vendor.t($data.orderInfo.adPrice), K: $data.orderInfo.couponPrice && $data.orderInfo.couponPrice !== 0 }, $data.orderInfo.couponPrice && $data.orderInfo.couponPrice !== 0 ? { L: common_vendor.t($data.orderInfo.couponPrice) } : {}, { M: common_vendor.t($data.orderInfo.inventory || 0), N: 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 }; }), O: common_vendor.o(($event) => $options.quantityFun("minus")), P: common_vendor.t($data.orderInfo.quantity), Q: common_vendor.o(($event) => $options.quantityFun("add")), R: $data.specificationShowType === "buy" }, $data.specificationShowType === "buy" ? { S: common_vendor.o((...args) => $options.byFun && $options.byFun(...args)) } : $data.specificationShowType === "addCart" ? { U: common_vendor.o((...args) => $options.addCart && $options.addCart(...args)) } : { V: common_vendor.o((...args) => $options.addCart && $options.addCart(...args)), W: common_vendor.o((...args) => $options.byFun && $options.byFun(...args)) }, { T: $data.specificationShowType === "addCart", X: common_vendor.o(($event) => $data.specificationShow = $event), Y: common_vendor.p({ round: 10, closeOnClickOverlay: false, closeable: true, mode: "bottom", show: $data.specificationShow }) }); } 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