// pages/coupons.js
const app = getApp()
const wxService = require('../../../../utils/wxService')
const utils = require('../../../../utils/util')
const envInfo = require('../../../../config/index').envInfo
import { Integer } from '../../../../utils/integerDigitalConvertion'

wxService.page({
  /**
   * 页面的初始数据
   */
  data: {
    // id: "5d6e2a2338c95504a8de84e8",
    id:'',
    proList: [],
    showCardModal: false,
    currentShareContent: null,
    pagePath: '',
    pageNo: 1,
    pageSize: 100,
    sharePicData: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options)
    console.log()
    if (options && options.id) {
      console.log('idididididi',options.id)
      this.setData({
        id: options.id
      })
    }

    let memberId = options.memberId;
    if (memberId) {
      let tentacleInfo = {
        content: '推广商品列表',
        title: '推广商品',
        tentacleId: memberId,
        contentType: app.globalData.contants.SHARE_TYPE.PRODUCTS_PROMOTION,
        type: 3// 1:门店,2:员工(暂时不做),3:会员,4:第三方外部渠道,5:智能营销
      };
      console.log('触点对象id-----------', options)

      this.generatePointObject(tentacleInfo);
    }
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    const { memberId, member } = wx.getStorageSync('_baseUserInfo')
    this.getExtendInfo()
    this.data.currentShareContent = null;
  },
 
  //获取推广商品获取商品id
  getExtendInfo() {
    console.log(this.data.id)
    wxService.post(`/merchant/spread/${this.data.id}`, {}).then(res => {
      if (!res) return false
      const { result, data } = res.data
      if (result == 0) {
        this.setData({
          proList: data
        })
        for (var i in data) {
          this.data.sharePicData.push(data[i].imgUrl)
          this.setData({
            sharePicData: this.data.sharePicData
          })
        }
      }
    }).finally(() => {
    })
  },

  /**
  * 用户点击右上角分享
  */
  onShareAppMessage: function (res) {
    this.data.proList.forEach((item)=>{
      item.url = item.indexUrl
      item.title = item.productName
      item.id = item.productId
    })
   
    //修改为参数memberId
    const { memberId, member } = wx.getStorageSync('_baseUserInfo')
    var path = `subPackage/page/pages/friendShareList/friendShareList`;
    if (memberId) {
      let m = Integer.digit(memberId, 10, 64);
      let id = Integer.digit(this.data.id, 10, 64);
      path = `subPackage/page/pages/friendShareList/friendShareList?m=${m}&i=${id}`;
    }
    return {
      title: '分享列表',
      path: path
    }
  }

})