discovery.js 7.66 KB
// pages/tab/output/output.js
const navStyle = "background-color: transparent;";
import {senceData} from "./constant/data";
import ActivityApi from '~/api/activityApi/index'
import {IMG_VERSION}  from '~/utils/constantData'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    senceData,
    img_version:IMG_VERSION(),
    headerHeight: 0,
    actNum: 0,
    navStyle,
     // 预估弹框
     visible: false,
     isReset: false,
     formData: {
       sales: 100,
       flow: 10000,
     },
     lastFormData: {
       sales: 100,
       flow: 10000,
     },
     isFirst: true,
     changeSale: 0,
     sceneCodeList:[],
     currentId: 0,
     showPage: false,
     showAuth: false
  },
    /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const { merchantId } = wx.$storage.get('userInfo')
    wx.showLoading({
      title: '加载中...',
    })
    ActivityApi.getOpenSceneList({
      merchantId
    }).then(res => {
      wx.hideLoading()
      if(res?.length>0){
        let sceneCodeList = []
        let senceData = [...this.data.senceData]
        // let  res = [
        //   {
        //     sceneCode: 'SC001',
        //     status: 0
        //   },
        //   {
        //     sceneCode: 'SC002',
        //     status: 1
        //   },
        //   {
        //     sceneCode: 'SC003',
        //     status: 1
        //   },
        //   {
        //     sceneCode: 'SC004',
        //     status: 1
        //   }
        // ]
        res.forEach((item,index) => {
          if(item.status==1) {
            let sceneTarget = senceData.find(sitem => sitem.sceneCode == item.sceneCode)
            sceneTarget.show = 1
            sceneCodeList.push(item.sceneCode)
          }
        })
        // senceData.forEach((item,index) => {
        //   if(item.show==1) {
        //     sceneCodeList.push(item.sceneCode)
        //   }
        // })
        let actNum = 0,currentId = 0;
        if(sceneCodeList?.length){
          actNum = senceData.findIndex(item => item.sceneCode== sceneCodeList[0])
        } 
        this.setData({
          sceneCodeList,
          senceData,
          actNum,
          currentId
        })
      }
      this.setData({
        showPage:true
      })
    }).catch(err =>{
      this.setData({
        showPage:true
      })
    })
  },
  navbarReady(e) {
    let {
      height
    } = e.detail;
    this.setData({
      headerHeight: height,
    });
  },
  onPageScroll({
    scrollTop
  }) {
    let opacity = scrollTop / 100
    let color = `rgba(255,255,255${opacity > 1 ? 1 : opacity})`
    this.setData({
      navStyle: scrollTop == 0 ? navStyle : `background-color:${color};`
    })
    wx.$eventbus.emit('evt_page_scroll',{scrollTop})
  },

  changeSwiper(e){
    this.setData({
      actNum:e.detail.currentItemId,
    });
  },

   // 跳转咨询页面
  goConsult() {
    wx.pro.openCustomerServiceChat({
      extInfo: { url: "https://work.weixin.qq.com/kfid/kfcf7b721472201345e" },
      corpId: "ww047bdc0f1e76cc13",
      complete: (r) => {
        console.log(r);
      },
    });
  },

  applyActivity(){
    wx.$router.go('/packageActivity/pages/applyActivity/applyActivity')
  },

   // 显示测算弹窗
   showCalculate() {
      this.setData({
        visible: !this.data.visible,
        isReset: false
      });
    },
    clickDialog(e) {
      if (e.changedTouches[0].clientY < 352) {
        this.setData({
          visible: false,
          isReset: false,
          formData: this.data.lastFormData
        });
      }
    },

    // 预估弹框
  showCalculate() {
    this.setData({
      visible: !this.data.visible,
      isReset: false
    });
  },
  clickDialog(e) {
    if (e.changedTouches[0].clientY < 352) {
      this.setData({
        visible: false,
        isReset: false,
        formData: this.data.lastFormData,
      });
    }
  },
  // 提交测算
  submit(e) {
    let sales = e ? +e.detail.value.sales : this.data.formData.sales;
    let flow = e ? +e.detail.value.flow : this.data.formData.flow;
    const reg = /^[1-9]\d*$/;
    console.log('flow', sales, flow)
    if (!reg.test(sales)) {
      wx.showToast({
        title: "门店月平均新车销量应为正整数",
        icon: "none",
        duration: 2000,
      });
      return;
    }
    if (!reg.test(flow)) {
      wx.showToast({
        title: "3年内售后存量用户应为正整数",
        icon: "none",
        duration: 2000,
      });
      return;
    }
    this.setData({
      "lastFormData.sales": sales,
      "lastFormData.flow": flow,
    });
    const _this = this;
    this.data.senceData.forEach((item, index) => {
      item.productList.forEach((i, lastIndex) => {
        if (i.profit) {
          // let name = `senceData[${index}].productList[${lastIndex}].profit`;
          let sale = `senceData[${index}].productList[${lastIndex}].sale`;
          let name = `senceData[${index}].productList[${lastIndex}].profit`;
          let flowKey = `senceData[${index}].productList[${lastIndex}].flow`
          // let changeSale = `senceData[${index}].productList[${lastIndex}].changeSale`;
          let profit = _this.formula(i.productType, sales, flow);
          this.setData({
            [name]: profit,
            [sale]:sales,
            [flowKey]: flow
            // [changeSale]: sales,
          });
        }
      });
    });

    this.setData({
      visible: false,
    });
    // this.showCase();
    // if (!this.data.isFirst) {
      wx.showToast({
        title: "测算结果已在页面内同步展示",
        icon: "none",
        duration: 2000,
      });
    // } else {
    //   this.setData({
    //     isFirst: false,
    //   });
    // }
  },
  formula(productType, sales, flow) {
    let profit = 0;
    switch (productType) {
      case "benefitCard":
        // 数字无忧权益卡
        profit = (sales * 0.5 * 2000 * 12).toFixed(0);
        break;
      case "sunMembrane":
        // 汽车太阳膜
        profit = (sales * 0.8 * 0.7 * 1500 * 12).toFixed(0);
        break;
      case "protectMembrane":
        // 漆面保护膜
        profit = (sales * 0.05 * 3000 * 12).toFixed(0);
        break;
      case "colorMembrane":
        // 改色膜
        profit = (sales * 0.05 * 5000 * 12).toFixed(0);
        break;
      case "digitBeauty":
        // 数字化美容
        profit = (sales * 0.2 * 300 * 12).toFixed(0);
        break;
      case "chair":
        // 座椅通风
        profit = (flow * 2580 * 0.9 * 0.01).toFixed(0);
        break;
      case "ar":
        // AR导航
        profit = (flow * 1680 * 0.9 * 0.015).toFixed(0);
        break;
      case "lamp":
        // 氛围灯
        profit = (flow * 2680 * 0.9 * 0.015).toFixed(0);
        break;
      case "navigation":
        // 360全景导航
        profit = (flow * 2880 * 0.9 * 0.015).toFixed(0);
        break;
    }
    if (profit.length > 9) {
      return (profit / 10000).toFixed(0) + "万";
    } else {
      return profit;
    }
  },
  reset() {
    this.setData({
      isReset: false,
      formData: {
        sales: 100,
        flow: 10000,
      },
    });
  },
  focus() {
    this.setData({
      isReset: true,
    });
    return false;
  },

  methods:{
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})