discovery.js 7.14 KB
// pages/tab/output/output.js
// const navStyle = "background-color: transparent;";
// import { subscriptionBannerUrl, subscriptionSystemData } from './constant/systemData'
// import {scenceList} from "./constant/data"
import ActivityApi from "~/api/activityApi/index";
import {
  getActivityRecord
} from '~/api/viewprod'
import {
  IMG_VERSION
} from "~/utils/constantData";
import {
  imgUrlMixin
} from "~/mixins/index";
const IMG_URL = wx.$imgUrl;
let leftMenuIndex = 0
Page({
  // behaviors: [imgUrlMixin],
  data: {
    // navList: ["增值服务", "客户数字化"],
    myTabIdx: 0,
    IMG_URL,
    // subscriptionBannerUrl: Object.freeze(subscriptionBannerUrl),
    // subscriptionSystemData: Object.freeze(subscriptionSystemData),
    activityList: [],
    resScenceList: [],
    curTabIdx: 0,
    curTabId: 0,
    img_version: IMG_VERSION(),
    headerHeight: 0,
    actNum: 0,
    // navStyle,
    sceneCodeList: [],
    showPage: false,
    systemData: [],
    productData: [],
  },
  // 产品点击事件
  proClick(e) {
    //登录的用户手机号
    let userInfo = wx.$storage.get("userInfo");
    const {
      info,
      sceneCode
    } = e.detail
    let obj = {
      phone: userInfo.phone,
      id: info.id,
      sceneCode
    }
    wx.$router.go('/packagesList/packageDiscovery/pages/productDetail/productDetail', obj)
  },

  sysMenuClick(e) {
    const {
      id
    } = e.detail;
    leftMenuIndex = id;
  },
  // 视频点击事件
  videoClick(e) {
    const {
      info,
      sceneCode
    } = e.detail
    // 一级菜单ID
    const typeId = this.data.myTabIdx == 0 ? this.data.productDataId : this.data.systemDataId
    const obj = {
      hasPhoneNumber: this.data.hasPhoneNumber,
      id: info.info.id,
      tabsActive: info.tabsActive,
      sceneCode,
      typeId
    }
    wx.$router.go('/packagesList/packageDiscovery/pages/videoDetail/videoDetail', obj)
  },
  leftClick(e) {
    const {
      sceneid
    } = e.detail
    const idx = this.data.resScenceList?.findIndex(item => item.sceneid == sceneid) || 0
    this.setData({
      curTabId: sceneid,
      curTabIdx: idx
    })
  },
  senceClick(e) {
    // const { scenIndex } = e.detail
    // wx.$router.go('/packageStoreAssistant/packageDiscovery/pages/scenarioDetail/scenarioDetail', {
    //   actNum: scenIndex
    // })
    // 如果没有sceneCode,或者没有配置banner跳转 isBannerLink 2-没有配置 1-有配置
    if (!e.detail.sceneCode || e.detail.isBannerLink != 1) return
    const {
      hasPhoneNumber
    } = this.data
    // 获取场景
    let systemItem = this.data.systemData.find(item => item.sceneCode == e.detail.sceneCode)
    let productItem = this.data.productData.find(item => item.sceneCode == e.detail.sceneCode)
    let id = ''
    if (systemItem) {
      id = systemItem.subList.length ? systemItem.subList[0].productList[0]?.id : systemItem.productList[0].id
    } else {
      id = productItem.subList.length ? productItem.subList[0].productList[0]?.id : productItem.productList[0].id
    }
    if (!id) return
    wx.$router.go('/packagesList/packageDiscovery/pages/productDetail/productDetail', {
      hasPhoneNumber,
      id,
      sceneCode: e.detail.sceneCode
    })
  },

  activityClick(e) {
    const id = e.detail
    wx.$router.go(
      "/packagesList/packageDiscovery/pages/activityDetail/activityDetail", {
        id
      }
    );
  },

  // 获取全部活动列表
  getActivityRecord() {
    getActivityRecord({}).then(({
      data,
      code,
      message
    }) => {
      if (code == -1) {
        wx.showToast({
          title: message,
          icon: 'none',
          duration: 2000
        })
      }
      this.setData({
        activityList: data
      })
    })
  },

  changeMyTab(e) {
    const {
      id
    } = e.currentTarget.dataset
    this.setData({
      myTabIdx: id
    });
  },
  onShow() {
    if (typeof this.getTabBar === 'function' ) {
      this.getTabBar((tabBar) => {
        tabBar.setData({
          active: 1
        })
      })
    }
  },
  onLoad(option) {
    // this.setData({
    //     tabIndex: option?.tabIndex || 0
    // })
    this.getActivityRecord()
    const app = getApp()
    app.getBaseData().then(res => {
      const productData = res[0].subList
      const systemData = res[1].subList
      // this.getSceneData(productData)
      this.setData({
        [`tabList[0].name`]: res[0].name,
        [`tabList[1]name`]: res[1].name,
        systemData,
        systemDataId: res[1].id,
        productData,
        productDataId: res[0].id,
      })
    })
  },
  emitUserInfo(options) {

  },
  getSceneData(list) {
    const {
      merchantId
    } = wx.$storage.get("userInfo");
    wx.showLoading({
      title: "加载中...",
    });
    ActivityApi.getOpenSceneList({
        merchantId,
      })
      .then((res) => {
        wx.hideLoading();
        let productData = []
        if (res.code == 21) {
          wx.$router.reLaunch('/packageStoreAssistant/packageAuth/pages/authentication/login/login')
          return;
        }
        if (res?.data?.length > 0) {
          // let res ={
          //     data:  [
          //         {
          //           sceneCode: "SC001",
          //           status: 1,
          //         },
          //         {
          //           sceneCode: "SC002",
          //           status: 1,
          //         },
          //         {
          //           sceneCode: "SC003",
          //           status: 1,
          //         },
          //         {
          //           sceneCode: "SC004",
          //           status: 1,
          //         },
          //         {
          //           sceneCode: "SC005",
          //           status: 1,
          //         },
          //       ]
          // }
          let openList = []
          res.data.forEach(item => {
            if (item.status == 1) {
              openList.push(item.sceneCode)
            }
          })
          productData = list.filter(item => openList.includes(item.sceneCode))
        }

      })
      .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.openCustomerServiceChat({
      extInfo: {
        url: "https://work.weixin.qq.com/kfid/kfcf7b721472201345e"
      },
      corpId: "ww047bdc0f1e76cc13",
      complete: (r) => {},
    });
  },

  applyActivity() {
    wx.$router.go(
      "/packagesList/packageActivity/pages/applyActivity/applyActivity"
    );
  },

  // 显示测算弹窗
  showCalculate() {
    wx.$router.go(
      "/packagesList/packageDiscovery/pages/measure/measure/measure"
    );
  },
  attached() {
    this.setData({
      isFullSucreen: wx.$api.isFullSucreen(),
    });
  },

});