const { getShopDetail } = require('../../api/common') const { getProductDetail, postProductCollect } = require('./api/index') Page({ /** * 页面的初始数据 */ data: { searchForm: { product_id: '', type: -1 }, nav: [ { name: '描述', value: '1' }, { name: '供应商', value: '2' } ], active: '1', objProductDetail: { product_rotation_img_list: [], product_detail_img_list: [] }, objShopDetail: { shop_address: {} }, booLock: false }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { const { product_id } = options this.setData({ 'searchForm.product_id': product_id }, () => { this.fetchProductDetail() }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { }, async fetchProductDetail() { try { const { status, data, msg } = await getProductDetail(this.data.searchForm.product_id) if (status) { const { shop_id, product_img_url, product_rotation_img_list, product_detail_img_list } = data this.setData({ objProductDetail: { ...data, product_rotation_img_list: JSON.parse(product_rotation_img_list), product_detail_img_list: JSON.parse(product_detail_img_list) }, 'searchForm.shop_id': shop_id, 'searchForm.type': 1 // todo }, () => { this.fetchShopDetail() }) } else { wx.showToast({ title: msg, icon: 'none' }) } } catch (err) {} }, async fetchShopDetail() { try { const { status, data, msg } = await getShopDetail(this.data.searchForm.shop_id) if (status) { this.setData({ objShopDetail: { ...data, shop_address: JSON.parse(data.shop_address) } }) } else { wx.showToast({ title: msg, icon: 'none' }) } } catch (err) {} }, async productCollect() { const { type, product_id } = this.data.searchForm const _type = type === 1 ? 2 : 1 this.setData({ booLock: true }) try { const { status, msg } = await postProductCollect(product_id, _type) if (status) { this.setData({ 'searchForm.type': _type }) } else { wx.showToast({ title: msg, icon: 'none' }) } } catch (err) {} this.setData({ booLock: false }) }, handleNav(e) { const { value } = e.detail this.setData({ active: value }) } })