CustomerInfo.js 2.81 KB
// components/CarBrands/CarBrands.js
import api from '../../api'
let isNum, num, y, time
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      observer: function (n) {
        let { isFirst } = this.data
        if (n && isFirst) {
          this.init()
          this.setData({
            isFirst: false
          })
        }
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    orderInfo: {},
    // storageData: null,
    customerList: [],
    isFirst: true
  },
  pageLifetimes: {
    show: function () {},
    hide: function () {}
  },
  /**
   * 组件的方法列表
   */
  methods: {
    init(keyword) {
      // console.log('getBrandList')
      // console.log(storageData)
      let params = {
        pageSize: 999999,
        pageNum: 1,
        // upgradeFinishFlag: 'R',
        inviteStatusList: [1, 3],
        // ...data
        keyword
      }
      let customerList = []
      api.getInviteList(params).then(res => {
        // console.log(res)
        // this.setCar(res.data, changeMerchantId)
        // console.log(res)
        let { data, code } = res
        if (code == 0 && data?.list.length) {
          // data.list = data.list.map(item => {
          //   if (item.customer && item.customer.carSeriesName) {
          //     item.carType = `${item.customer.carBrand || ''}-${item.customer.carChildsBrandName || ''}-${item.customer.carSeriesName || ''}`
          //   }
          //   return item
          // })
          customerList = data.list
        }
        this.setData({
          customerList
        })
      })
    },
    searchCar(e) {
      let { value } = e.detail
      this.init(value)
    },
    choose(e) {
      let { item, index } = e.currentTarget.dataset
      console.log(item, index)
      let { customerList } = this.data
      customerList = customerList.map(item => {
        item.active = false
        return item
      })
      customerList[index].active = true
      let orderInfo = item
      orderInfo.orderSource = 4
      // delete orderInfo.orderCode
      // 去除掉错误订单对应的关联码
      // delete orderInfo.associateOrderCode
      // 'orderCode',
      let deleteList = ['associateOrderCode', 'merchantDistributionList', 'expenseCategoryList', 'profitAllocatinList']
      for (var i = 0; i < deleteList.length; i++) {
        // console.log(arr[i])
        delete orderInfo[deleteList[i]]
      }
      this.setData({
        customerList,
        orderInfo
      })
    },
    confirm() {
      let { orderInfo, customerList } = this.data
      let flag = customerList.some(item => {
        return item.active
      })
      if (!flag) {
        return wx.$util.showToast('请选择客户')
      }
      this.triggerEvent('confirm', orderInfo)
      this.setData({
        show: false
      })
    }
  }
})