applyActivity.js 2.83 KB
import activityApi from "~/api/activityApi/index"
import {
  reportData
} from '~/api/api.js'
Page({

  data: {
    list: [
      {
        name: '新车洽谈场景',
        tip: '1.0 新车权益销售',
      },
      {
        name: '新车交付场景',
        tip: '1.1 新车精品升级',
      },
      {
        name: '0-12个月',
        tip: '1.2 新车线上转化',
      },
      {
        name: '12个月以上',
        tip: '1.3 存量用户众筹',
      },
    ],
    currentIndex: 0,
    product: [
      {
        id: 1,
        name: '360全景导航',
        isSelect: false
      },
      {
        id: 2,
        name: '360全景导航',
        isSelect: false
      },
      {
        id: 3,
        name: '360全景导航',
        isSelect: false
      },
      {
        id: 4,
        name: '360全景导航',
        isSelect: false
      },
      {
        id: 5,
        name: '360全景导航',
        isSelect: false
      }
    ]
  },
  select(e) {
    const { index } = e.currentTarget.dataset
    this.setData({
      currentIndex: index
    })
  },
  selectProduct(e) {
    const { item, index } = e.currentTarget.dataset
    let name = `product[${index}].isSelect`
    this.setData({
      [name]: !item.isSelect
    })
  },
  // 申请开通
  applyOpened() {
    // 获取已选的产品code
    let { product, currentIndex } = this.data
    let arr = []
    product.forEach(val => {
      if (val.isSelect) arr.push(val.id)
    })
    console.log(reportData)
    const {
      USERINFO
    } = this.getCommonData()
    reportData({
      openId: USERINFO.weChatOpenId || '',
      unionId: USERINFO.uuid || '',
      nickName: USERINFO.weChatNickName || '',
      avatar: USERINFO.weChatAvatarUrl || '',
      phone: USERINFO.weChatPhone || '',
      shopId: USERINFO.merchantId || '',
      shopName: USERINFO.merchantName || '',
      shareOpenId: USERINFO.weChatOpenId || '',
      
    }, 2).then(res => {
      console.log(res)
    })
    if (!arr.length) return wx.showToast({
      title: '请选择产品/活动',
      icon: "none"
    })
    activityApi.applyActivity({
      serviceMerchantId: 1,
      merchantId: 2,
      sceneCode: currentIndex,
      productCodes: arr
    }).then(res => {
      if (res.code == 200) {
        const {
          USERINFO
        } = this.getCommonData()
        reportData({
          openId: USERINFO.weChatOpenId || '',
          unionId: USERINFO.uuid || '',
          nickName: USERINFO.weChatNickName || '',
          avatar: USERINFO.weChatAvatarUrl || '',
          phone: USERINFO.weChatPhone || '',
          merchantId: USERINFO.merchantId || ''
        }).then(res => {
          console.log(res)
        })
        wx.$router.go('packageActivity.applySuccess')
      }
    })
  },
  getCommonData() {
    const USERINFO = wx.$storage.get('userInfo')
    return {
      USERINFO
    }
  }

})