openBusiness.js 4.03 KB
// packageOutput/pages/openBusiness/openBusiness.js
import outputApi from '~/api/outputApi/index'
import { IMG_URL } from '~/utils/constantData'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    IMGURL: IMG_URL,
    merchantInfo: {},
    sceneCodeList: [],
    // 场景业务
    formData: {
      scene1: true,
      scene2: true,
      scene3: true,
      scene4: true
    },
    sceneActive: 1,
    // 活动内容
    activityList: [],
    sceneActivityObj: {
      scene1: [],
      scene2: [],
      scene3: [],
      scene4: []
    }
  },

  getSceneProStatus(sceneCode) {
    var params = {
      serviceMerchantId: this.data.merchantInfo.pMerchantId,
      merchant4sId: this.data.merchantInfo.merchantId,
      sceneCode: sceneCode
    }
    outputApi.getSceneProStatus(params).then(res => {
      var proList = res.find(item => item.sceneCode == sceneCode)
      this.setData({
        ['sceneActivityObj.scene' + this.data.sceneActive]: proList.productList
      })
      this.setCurActivity()
    })
  },

  // 场景切换
  handleSceneChange(e) {
    var idx = e.detail.sceneIdx
    this.setData({
      sceneActive: idx
    })
    if (!this.data.sceneActivityObj['scene' + this.data.sceneActive].length) {
      this.getSceneProStatus(this.data.sceneCodeList[this.data.sceneActive - 1])
      return true
    }
    this.setCurActivity()
    // console.log('换内容---')
  },

  setCurActivity() {
    this.setData({
      activityList: JSON.parse(JSON.stringify(this.data.sceneActivityObj['scene' + this.data.sceneActive]))
    })
  },

  // 活动切换
  handleActClick(e) {
    var idx = e.currentTarget.dataset.idx
    this.setData({
      ['activityList[' + idx + '].checked']: !this.data.activityList[idx].checked
    })
  },

  handleJump() {
    // clearTimeout(this.data.time)
    // this.data.time = new setTimeout(() => {
    //   wx.$router.go('pages.output')
    // }, 3000)
    // wx.$api.showToast('申请成功')
    setTimeout(() => {
      wx.$router.back(page => {
        let node = page.selectComponent('#indexclue')
        // console.log(node)
        node.getClueInit && node.getClueInit()
        // page.getClueInit && page.getClueInit()
      })
    }, 1000)
  },

  handleConfirm() {
    var params = {
      serviceMerchantId: this.data.merchantInfo.pMerchantId,
      serviceMerchantName: this.data.merchantInfo.pMerchantName,
      merchantId: this.data.merchantInfo.merchantId,
      merchantName: this.data.merchantInfo.merchantName,
      sceneCode: this.data.sceneCodeList[this.data.sceneActive - 1],
      productCodes: this.data.activityList.filter(item => item.checked == true).map(item => item.productCode),
      clueId: this.data.clueId
    }
    if (!params.productCodes.length) {
      wx.$api.showToast('请选产品/活动')
      return true
    }
    outputApi.applyActivity(params).then(res => {
      wx.showToast({
        title: '提交成功',
        icon: 'success',
        duration: 2000,
        mask: true,
        success: () => {
          this.handleJump()
        }
      })
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.$router.getData(obj => {
      this.setData({
        merchantInfo: obj.merchantInfo,
        sceneActive: obj.sceneActive,
        sceneCodeList: obj.sceneCodeList || ['SC001', 'SC002', 'SC003', 'SC004'],
        clueId: obj.clueId
      })
      this.getSceneProStatus(this.data.sceneCodeList[this.data.sceneActive - 1])
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    wx.setNavigationBarTitle({
      title: '开通店面业务',
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {}
})