index.js 3.38 KB
/*
 * @Description: huyue
 * @Author: huyue
 * @Date: 2022-12-15 17:13:19
 * @LastEditors: huyue
 * @LastEditTime: 2023-02-06 15:28:18
 */
Component({
  externalClasses: ['custom-class', 'novideo-img', 'sub-menu-active-custom', 'sidebar-active-custom'],
  /**
   * 组件的属性列表
   */
  properties: {
    // 顶部菜单
    hasMenu: {
      type: Boolean,
      value: false,
    },
    // 增值转化Data
    list: {
      type: Array,
      observer: function (n) {
        this.init(n)
      }
    },
    // banner下活动轮播数据
    activityList: {
      type: Array,
      value: [],
    },
    // currentScenIndex: {
    //   type: Number,
    //   observer(n) {
    //     this.setData({
    //       currentScen: n,
    //     });
    //   },
    // },
    // 选中活动tab下标,默认第一个
    discoverIndex: {
      type: Number,
      value: 0
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    currentScen: 0,
    scrollLeft: 0,
    bannerSrc: '',
    defaultBannerSrc: 'https://img02.glsx.com.cn/weapp/resource/saas/business-assistant/index/banner/banner_default.png',
    sceneCode: '',
    listData: []
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 初始化数据,新增数字化转型案例视频
    init(n) {
      if (n.length === 0) return
      let operationVideoList = []
      let videoList = []
      // 递归算出得到所有视频
      n.forEach(item => {
        operationVideoList = operationVideoList.concat(item.operationVideoList)
        videoList = videoList.concat(item.videoList)
        if (item.subList.length) {
          item.subList.forEach(itm => {
            operationVideoList = operationVideoList.concat(itm.operationVideoList)
            videoList = videoList.concat(itm.videoList)
          })
        }
      })
      n.push({
        name: '数字化转型案例',
        videoList: videoList,
        operationVideoList: operationVideoList
      })
      this.setData({
        listData: n
      })
    },
    // 点击特色产品
    proClick(e) {
      const sceneCode = this.data.sceneCode || this.data.listData[this.data.discoverIndex].sceneCode
      console.log(e.detail, sceneCode);
      this.triggerEvent('proClick', {info: e.detail, sceneCode});
    },
    // 点击案例视频
    videoClick(e) {
      const sceneCode = this.data.sceneCode || this.data.listData[this.data.discoverIndex].sceneCode
      console.log(sceneCode);
      this.triggerEvent('videoClick', {info: e.detail, sceneCode});
    },
    // 活动点击
    activityClick(e) {
      this.triggerEvent('activityClick', e.detail);
    },
    // 点击场景banner
    senceClick() {
      const info = this.data.listData.find(
        (item) => item.sceneCode === this.data.sceneCode
      );
      console.log(info);
      this.triggerEvent('senceClick', info);
    },
    // 点击切换菜单
    menuClick(e) {
      const menuInfo = this.data.listData.find(
        (item) => item.sceneCode === e.detail.info.sceneCode
      );
      const bannerSrc = menuInfo.banner;
      const sceneCode = menuInfo.sceneCode
      this.setData({
        discoverIndex: e.detail.id,
        bannerSrc,
        sceneCode
      });
    },
    // 初始化
    initMenu(e) {
      const menuInfo = e.detail
      const bannerSrc = menuInfo.banner;
      const sceneCode = menuInfo.sceneCode
      this.setData({
        bannerSrc,
        sceneCode
      })
    },
  },
});