switchPopup.js 3.51 KB
// components/switchPopup/switchPopup.js
const app = getApp()
import api from '~/api/api'
import { getYQorderInfo } from '~/store/index'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      value: true
      // observer: function (n) {
      //   if (n) {
      //     this.checkCoupon()
      //   }
      // }
    },
    title: String,
    tips: String,
    height: {
      type: String,
      value: '85%'
    },
    isYqdSuper: Boolean
    // merchantSettingInfo: {
    //   type: Object,
    //   observer: function (n) {
    //     if (n) {
    //       this.setOrderSettingList(n)
    //     }
    //   }
    // }
  },

  /**
   * 组件的初始数据
   */
  data: {
    merchantSettingInfo: '',
    // switchStatus: 1,
    orderSettingList: [
      {
        label: '选择车型',
        valueName: 'carTypeRequiredFlag',
        value: false
      },
      {
        label: '车架号(VIN码)',
        valueName: 'standNoRequiredFlag',
        value: false
      },
      {
        label: '车牌号',
        valueName: 'plateNumRequiredFlag',
        value: false
      },
      {
        label: '战败下单是否体验',
        valueName: 'foEfRequiredFlag',
        value: true
      },
      {
        label: '战败下单拒升理由提交',
        valueName: 'foRrRequiredFlag',
        value: true
      }
    ]
  },
  /** 组件生命周期 */
  lifetimes: {
    attached: function () {
      // console.log(app.globalData.isYqdSuper)
      console.log(this.data.isYqdSuper)
      // app .
      getYQorderInfo()
        .then(merchantSettingInfo => {
          console.log(merchantSettingInfo)
          this.setData({ merchantSettingInfo })
          this.setOrderSettingList(merchantSettingInfo)
        })
        .catch(err => {
          console.log(err)
        })
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    async confirm() {
      // 判断是不是园区店管理员 不是都不处理
      let { isYqdSuper, merchantSettingInfo, orderSettingList } = this.data
      // 是管理员请求数据 并存全局读取
      if (isYqdSuper) {
        let { merchantId, merchantName } = merchantSettingInfo
        wx.$util.showLoading('设置中...')
        let params = orderSettingList.reduce((obj, item) => {
          obj[item.valueName] = item.value == true ? 'Y' : 'N'
          // item
          return obj
        }, {})

        let result = await api.setMerchantRecordingSettings({
          merchantId,
          merchantName,
          ...params
        })
        let { code, data } = result
        if (code == 0) {
          app.globalData.YQorderSetting = Object.assign(app.globalData.YQorderSetting, params)
        }
        wx.$util.hideLoading()
      }
      this.setData({
        show: false
      })
    },
    onSwitchChange(e) {
      // console.log(e)
      let { index } = e.currentTarget.dataset
      let { orderSettingList } = this.data
      // console.log(index)
      orderSettingList[index]['value'] = !orderSettingList[index]['value']
      // console.log(orderSettingList[index]['value'])
      this.setData({
        orderSettingList
      })
    },
    setOrderSettingList(n) {
      // 做转换
      let { orderSettingList } = this.data
      orderSettingList.forEach(element => {
        // if (element.valueName == n) {
        let value = n[element.valueName]
        element.value = value == 'Y' ? true : false
        // }
      })
      console.log(orderSettingList)
      this.setData({
        orderSettingList
      })
    }
  }
})