PointsSource.js 1.73 KB
// pages/Login/components/PointsSource/PointsSource.js
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean
    },
    pointsSource: {
      type: Array,
      observer: function(val) {
        let { sourceArr } = this.data
        const filteredArr = sourceArr.filter(item => val?.includes(Number(item.id)))
        this.setData({
          channelSourceArr: filteredArr
        })
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    sourceArr: [ {
      id: 1,
      label: '阳光激励用户',
      color: '#C7462B',
      background: 'linear-gradient(90deg, #FCF3F2 0%, #FFE0DB 100%)',
      icon: 'source-2'
    }, {
      id: 2,
      label: '续保用户',
      color: '#AF531F',
      background: 'linear-gradient(90deg, #FCF5E5 0%, #FFE9BD 100%)',
      icon: 'source-1'
    }, {
      id: 3,
      label: '管理层',
      color: '#244BCA',
      background: 'linear-gradient(90deg, #E7F5FD 0%, #C3E7FF 100%)',
      icon: 'source-3'
    }],
    channelSourceArr: []
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 切换选择来源
    checkSource(e) {
      let { target } = e.currentTarget.dataset
      let { channelSourceArr } = this.data
      channelSourceArr?.forEach(val => {
        val.isChecked = false
        if (val.id == target.id) {
          val.isChecked = true
        }
      })
      this.setData({channelSourceArr})
    },
    // 下一步
    nextStep(e) {
      let { target } = e.currentTarget.dataset
      if (target) return // 未选择来源不可点击
      let { channelSourceArr } = this.data
      let channelSource = channelSourceArr?.find(val => val.isChecked == true)?.id
      this.triggerEvent('confirm', channelSource)
    }
  }
})