// mall/index/shopInfo/shopInfo.js const app = getApp(); const regeneratorRuntime = app.loadAsync() const model = app.loadModel("index") const http = app.loadHttp() const util = app.loadUtils("util") Page({ /** * 页面的初始数据 */ data: { system: app.globalData.system, //设备相关信息 pageTitle: "详情", //头部标题 isBack: true,//显示返回 imgUrls: [ 'https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1564218168&di=f9df8e6bc2e9d02f6f1b7fc73247d927&src=http://ac-r.static.booking.cn/images/hotel/max1024x768/987/98767654.jpg', 'https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1564218168&di=f9df8e6bc2e9d02f6f1b7fc73247d927&src=http://ac-r.static.booking.cn/images/hotel/max1024x768/987/98767654.jpg', 'https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1564218168&di=f9df8e6bc2e9d02f6f1b7fc73247d927&src=http://ac-r.static.booking.cn/images/hotel/max1024x768/987/98767654.jpg' ], indicatorDots: false, autoplay: true, interval: 3000, duration: 1000, current: 0, visible: false, cartNum: 0,//角标 id: "",//商品id shopInfo: {},//商品的详情信息 shopAttr: [],//商品的属性 attr: [],//勾选了的属性 type: null,//0购物车 1购买 num: 1,//商品的数量 }, // 轮播图下表 currentChange(e) { this.setData({ current: e.detail.current }) }, //弹出层开启关闭 onClose(e) { let type = e.currentTarget.dataset.type this.setData({ visible: !this.data.visible, type: type }) }, // 打开弹出层 onOpen() { this.setData({ visible: true }) }, // 选择数量 numChang(e) { this.setData({ num: e.detail.value }) }, // 选择完确定 async sure() { let shopInfo = this.data.shopInfo let data = { id: shopInfo.id, name: shopInfo.name, image: shopInfo.top_img, original_price: shopInfo.original_price, price: shopInfo.price, num: this.data.num, attr: this.data.attr } this.setData({ visible: false }) if (this.data.type == 0) { model.shopCart.setCart(data) return } let isLogin = await util.isLoginJump() if (isLogin == 1) return; app.globalData.temCart = { total: (data.num * data.price).toFixed(2), allCart: [data] } wx.navigateTo({ url: "/mall/placeOrder/placeOrder" }) }, // 获取商品的详情 async getShopInfo() { let res = await http.http.request1({ url: `${http.api.storeProductDetails}/${this.data.id}`, method: "GET" }) this.setData({ shopInfo: res.data.data }) this.getAttr() }, // 获取商品属性 async getAttr() { let res = await http.http.request1({ url: `${http.api.storeProductAttr}/${this.data.id}`, method: "GET" }) res.data.data.map((v, i) => { res.data.data[i].index = i }) this.setData({ shopAttr: res.data.data }) }, // 实时更新购物车角标 async realUpdateCarker() { var that = this app.setWatching('cartNum', (v) => { that.setData({ cartNum: v }); }); }, // 去往购物车 goCart() { wx.navigateTo({ url: "/mall/shopcart/shopcart" }) }, // 选择商品属性 selectAttr(e) { let { i1, i2 } = e.currentTarget.dataset let shopAttr = this.data.shopAttr let attr = this.data.attr //选中的商品属性 let isShow = [] //当前选中或者移除的所有isShow字段 shopAttr[i1].attr_vals.map((v, i) => { if (i2 == i) { shopAttr[i1].attr_vals[i].isShow = !shopAttr[i1].attr_vals[i].isShow } else { shopAttr[i1].attr_vals[i].isShow = false } isShow.push(v.isShow) }) // 获取当前商品属性选中的下表,然后插入对应下表的method_value到attr let is = isShow.indexOf(true) if (is != -1) { attr[i1] = shopAttr[i1].attr_vals[is].method_value } else { attr[i1] = "" } this.setData({ shopAttr: shopAttr, attr: attr }) }, // 商品详情查看大图 bigShopImg(e) { let imgI = e.currentTarget.dataset.url, imgsArr = this.data.shopInfo.imgs, news = []; imgsArr.map((v, i) => { news.push(v.detail_img) }) wx.previewImage({ current: imgI, // 当前显示图片的http链接 urls: news // 需要预览的图片http链接列表 }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.realUpdateCarker() // 接收商品id this.setData({ id: options.id }) this.getShopInfo() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })