123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- 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: []
- },
- shopDetail: { 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() {
- },
- bindCallBack() {
- this.fetchProductDetail()
- },
- async fetchProductDetail() {
- try {
- const { status, data, msg } = await getProductDetail(this.data.searchForm.product_id)
- if (status) {
- const { shop_id, product_rotation_img_list, product_detail_img_list, collect_status } = data
- this.setData({
- objProductDetail: {
- ...data,
- product_rotation_img_list: product_rotation_img_list ? JSON.parse(product_rotation_img_list) : [],
- product_detail_img_list: product_detail_img_list ? JSON.parse(product_detail_img_list) : []
- },
- 'searchForm.shop_id': shop_id,
- 'searchForm.type': collect_status === 0 ? 1 : 2 // 是否收藏(0否1是)
- }, () => {
- 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({
- shopDetail: {
- ...data,
- shop_address: 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
- this.setData({
- booLock: true
- })
- try {
- const { status, msg } = await postProductCollect(product_id, type)
- if (status) {
- this.setData({
- 'searchForm.type': type === 1 ? 2 : 1
- })
- } else {
- wx.showToast({
- title: msg,
- icon: 'none'
- })
- }
- } catch (err) {}
- this.setData({
- booLock: false
- })
- },
- handleNav(e) {
- const { value } = e.detail
- this.setData({
- active: value
- })
- },
- handlePreviewImage(e) {
- const { imgs, index } = e.currentTarget.dataset
- if (Array.isArray(imgs)) {
- wx.previewImage({
- urls: imgs,
- current: imgs[index]
- })
- }
- }
- })
|