scene.js 7.52 KB
// components/scene/scene.js
import {
  componentsMixin
} from "../../mixins/index";
Component({
  behaviors: [componentsMixin],
  /**
   * 组件的属性列表
   */
  properties: {
    foldFlag: {
      type: Boolean,
      value: false
    },
    selectApply: {
      type: Number,
      value: 0
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    productTabList: [
      {
        id: "1",
        name: "scene2",
        title: "精品升级",
        url: "car1",
      },
      {
        id: "2",
        name: "scene3",
        title: "次新车转化",
        url: "car7",
      },
      {
        id: "3",
        name: "scene4",
        title: "售后众筹",
        url: "car3",
      },
      {
        id: "0",
        name: "scene1",
        title: "会员权益/升级",
        url: "car4",
      },
    ],
    productSubscribTabList: [{
        id: "0",
        name: "scene1",
        title: "客户线上化",
        url: "car5",
      },
      {
        id: "1",
        name: "scene2",
        title: "客户活跃",
        url: "car6",
      },
      {
        id: "2",
        name: "scene3",
        title: "膨胀金",
        url: "car2",
      },
    ],
    productList: {
      scene1: [{
          name: "equity",
          url: "digital_icon",
          nameZh: "数字无忧权益卡",
          isSelect: false,
          actNum: 0,
          activeNavIdx: 0,
        },
        {
          nameZh: "其他",
          isSelect: false,
        },
      ],
      scene2: [{
          name: "solarFilm",
          url: "solar_icon",
          nameZh: "汽车太阳膜",
          isSelect: false,
          actNum: 1,
          activeNavIdx: 0,
        },
        {
          nameZh: "其他",
          isSelect: false,
        },
      ],
      scene3: [{
          name: "paintProtect",
          url: "protect_icon",
          nameZh: "漆面保护膜",
          isSelect: false,
          actNum: 2,
          activeNavIdx: 0,
        },
        {
          name: "changingFilm",
          url: "change_icon",
          nameZh: "改色膜",
          isSelect: false,
          actNum: 2,
          activeNavIdx: 1,
        },
        {
          nameZh: "其他",
          isSelect: false,
        },
      ],
      scene4: [{
          name: "carBeauty",
          url: "beauty_icon",
          nameZh: "数字化美容",
          isSelect: false,
          actNum: 3,
          activeNavIdx: 0,
        },
        {
          name: "seatVentilate",
          url: "seat_icon",
          nameZh: "座椅通风",
          isSelect: false,
          actNum: 3,
          activeNavIdx: 1,
        },
        {
          name: "arNavigation",
          url: "ar_icon",
          nameZh: "AR导航",
          isSelect: false,
          actNum: 3,
          activeNavIdx: 2,
        },
        {
          name: "ambientLighting",
          url: "light_icon",
          nameZh: "氛围灯",
          isSelect: false,
          actNum: 3,
          activeNavIdx: 3,
        },
        {
          name: "navigationArround",
          url: "arround_icon",
          nameZh: "360全景导航",
          isSelect: false,
          actNum: 3,
          activeNavIdx: 4,
        },
        {
          name: "fragrance",
          url: "fragrance",
          nameZh: "智能香氛系统",
          isSelect: false,
          actNum: 3,
          activeNavIdx: 5,
        },
        {
          nameZh: "其他",
          isSelect: false,
        },
      ],
    },
    productSubscibList: {
      scene1: [{
          nameZh: "私域用户活跃代运营",
          isSelect: false,
          actNum: 0,
          activeNavIdx: 0,
        },
        {
          nameZh: "定保/续保数字化招揽",
          isSelect: false,
          actNum: 0,
          activeNavIdx: 1,
        },
        // {
        //   nameZh: "其他",
        //   isSelect: false,
        // },
      ],
      scene2: [{
          nameZh: "事故车救援服务",
          isSelect: false,
          actNum: 1,
          activeNavIdx: 0,
        },
        // {
        //   nameZh: "其他",
        //   isSelect: false,
        // },
      ],
      scene3: [{
        nameZh: "膨胀金",
        isSelect: false,
        actNum: 2,
        activeNavIdx: 0,
      },
      // {
      //   nameZh: "其他",
      //   isSelect: false,
      // },
    ],
    },
    sceneNum: "",
    sceneName: "",
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 选择业务场景
    selectScene(e) {
      // 遍历之前业务场景下产品是否已选择,选择了的话取消选中
      if (this.data.sceneName) {
        let newProductList;
        newProductList = this.data.productList[this.data.sceneName].map(
          (item) => {
            if (item.isSelect) item.isSelect = false;
            return item;
          }
        );
        let selectList = `productList.${this.data.sceneName}`;
        this.setData({
          [selectList]: newProductList,
        });
      }
      this.setData({
        sceneNum: e.currentTarget.dataset.item.id,
        sceneName: e.currentTarget.dataset.item.name,
      });
    },

    // 选择业务场景产品
    selectScenePro(e) {
      var index = e.currentTarget.dataset.index;
      var item = this.properties.selectApply == 0 ? this.data.productList[this.data.sceneName][index] : this.data.productSubscibList[this.data.sceneName][index];
      item.isSelect = !item.isSelect;
      if (this.properties.selectApply == 0) {
        this.setData({
          productList: this.data.productList,
        });
        return
      }
      this.setData({
        productSubscibList: this.data.productSubscibList,
      });

    },

    // 合作方式切换重置场景以及选择的产品
    resetScene() {
      if (!this.data.sceneName) return
      if (this.properties.selectApply == 1) {
        this.data.productList[this.data.sceneName].map((item) => {
          if (item.isSelect) item.isSelect = false
        })
        this.setData({
          productList: this.data.productList,
        })
      } else {
        this.data.productSubscibList[this.data.sceneName].map((item) => {
          if (item.isSelect) item.isSelect = false
        })
        this.setData({
          productSubscibList: this.data.productSubscibList,
        })
      }
      this.setData({
        sceneName: '',
        sceneNum: ''
      })
    },

    // 提交获取业务场景以及选择的产品
    getSceneItems() {
      // 如果选择了业务场景
      if (!this.data.sceneName) return
      let selectFlag = 0;
      let productItems = [];
      let businessItem
      if (this.properties.selectApply == 0) {
        this.data.productList[this.data.sceneName].forEach((item) => {
          if (item.isSelect) {
            selectFlag = selectFlag + 1;
            productItems.push(item.nameZh);
          }
        });
        businessItem = this.data.productTabList.find((item) => {
          return item.id == this.data.sceneNum;
        });
      } else {
        this.data.productSubscibList[this.data.sceneName].forEach((item) => {
          if (item.isSelect) {
            selectFlag = selectFlag + 1;
            productItems.push(item.nameZh);
          }
        });
        businessItem = this.data.productSubscribTabList.find((item) => {
          return item.id == this.data.sceneNum;
        });
      }
      // if (!selectFlag) {
      //   wx.hideLoading();
      //   wx.showToast({
      //     title: "请至少选择一个产品",
      //     icon: "none",
      //   });
      //   return false;
      // }
      return [businessItem, productItems, selectFlag]
    }
  }
})