PopupSelect.js 1.85 KB
// components/CarBrands/CarBrands.js
// import api from '../../api/api.js'
import { optionsSelect } from '../constant/stepData'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      observer: function (n) {
        if (n) {
          // console.log(n)
          // n & this.initOptions()
        }
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    // orderInfo: {},
    optionsObj: {
      name: '支付方式',
      height: 'var(--fontSize450)'
      // optionsList: [
      //   {
      //     value: '微信支付'
      //   },
      //   {
      //     value: 'pos支付'
      //   },
      //   ]
    },
    optionsList: [
      {
        value: 1,
        label: '微信支付',
        active: true
      },
      {
        value: 3,
        label: 'pos支付'
      }
    ]
  },
  pageLifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行
      // console.log('attached', attached)
      // this.initOptions()
    },
    show: function () {},
    hide: function () {}
  },
  /**
   * 组件的方法列表
   */
  methods: {
    choose(e) {
      let { item, index } = e.currentTarget.dataset
      console.log(item, index)
      let { optionsList } = this.data
      optionsList = optionsList.map(item => {
        item.active = false
        return item
      })
      optionsList[index].active = true

      this.setData({
        optionsList
      })
    },
    confirm() {
      // let { attrname, attrtype } = this.data.popObj
      let { optionsList } = this.data
      let flag = optionsList.find(item => {
        return item.active
      })
      if (!flag) {
        return wx.$util.showToast('请选择')
      }
      if (flag.value == 3) {
        this.triggerEvent('confirm', flag)
      }
      this.setData({
        show: false
      })
    }
  }
})