customerManagement.js 5.37 KB
// pages/mineDetail/customerManagement/customerManagement.js
import mineApi from '~/api/mineApi/index'
// import USERAPI from '~/api/usersApi/index'
import { IMG_URL } from '~/utils/constantData'

const listObj = Object.freeze([
  {
    key: 'merchantId',
    label: '商户号:',
    editLabel: '商户号'
  },
  {
    key: 'actualAccountName',
    label: '商户账号:',
    editLabel: '商户账号'
  },
  {
    key: 'merchantName',
    label: '门店名称:',
    placeholder: '请输入您的客户门店简称',
    editLabel: '门店名称',
    maxLength: 20
  },
  {
    key: 'contactName',
    label: '联系人:',
    placeholder: '请输入客户门店联系人',
    editLabel: '联系人',
    maxLength: 10
  },
  {
    key: 'phone',
    label: '手机号:',
    placeholder: '请输入客户门店联系人手机号',
    editLabel: '手机号',
    maxLength: 11,
    reg: '/[^d]/g,',
    type: 'number'
  },
  {
    key: 'mainBrand',
    label: '主营品牌:',
    // 请输入客户门店主营品牌,
    placeholder: '多个品牌以分号区隔',
    editLabel: '主营品牌',
    maxLength: 20
  },
  {
    key: 'newCarSales',
    label: '新车销量:',
    placeholder: '请输入客户门店新车月平均销售数',
    editLabel: '新车销量',
    maxLength: 5,
    reg: '/[^d]/g',
    type: 'number'
  },
  {
    key: 'existUserNumber',
    label: '存量用户数:',
    placeholder: '请输入客户门店存量用户数',
    editLabel: '存量用户数',
    maxLength: 8,
    reg: '/[^d]/g',
    type: 'number'
  }
])
Component({
  options: {
    addGlobalClass: true
  },
  /**
   * 组件的属性列表
   */
  properties: {},

  /**
   * 组件的初始数据
   */
  data: {
    pageNum: 1,
    pageSize: 10,
    pages: 1,
    customerList: [{}],
    listObj,
    isSuper: false,
    testData: [
      {
        a: 1
      }
    ],
    bgUrl: `${IMG_URL}/output/empty.png`
  },
  attached() {
    // this.initTime()
    let { userInfo } = wx.$storage.get()
    this.setData({
      isSuper: userInfo.isSuper
    })
    this.getMerchantCustomInfoList()
  },
  /**
   * 组件的方法列表
   */
  methods: {
    restPageNum() {
      // console.log('restPageNum')
      this.setData({
        pageNum: 1
      })
      this.getMerchantCustomInfoList('reset')
    },
    scrollonReachBottom() {
      // console.log('scrollonReachBottom')
      let { pages, pageNum } = this.data
      // 判断当前页是否是末页
      if (pages == pageNum) return wx.$api.showToast('列表已到底')

      this.setData({
        pageNum: pageNum + 1
      })
      this.getMerchantCustomInfoList()
    },
    // 分页查询客户列表
    getMerchantCustomInfoList(type) {
      wx.$api.showLoading('加载中...')
      let { pageNum, pageSize, customerList } = this.data
      let params = {
        pageNum,
        pageSize
      }
      mineApi
        .merchantCustomInfo(params)
        .then(result => {
          console.log(result)
          let { pages, list, total } = result
          console.log(list)
          list = list.map(item => {
            item.merchantName = item.merchantName || item.actualMerchantName
            item.phone = item.phone || item.actualPhone
            // || item.actualContactName
            item.contactName = item.contactName || item.actualContactName
            return item
          })
          console.log(list)
          this.setData({
            customerList: pageNum == 1 ? list : [...customerList, ...list],
            triggered: false,
            pages
          })
        })
        .catch(err => {})
        .finally(() => {
          if (type == 'reset') {
            wx.$api.showToast({
              title: '刷新成功',
              icon: 'success'
            })
          } else {
            wx.$api.hideLoading()
          }
        })
    },
    submit(data) {
      let obj = ['merchantId', 'merchantName', 'contactName', 'phone', 'mainBrand', 'newCarSales', 'existUserNumber']
      let objList = {}
      obj.forEach(item => {
        if (data[item]) {
          objList[item] = data[item]
        }
      })
      mineApi
        .saveMerchantCustomInfo(objList)
        .then(result => {
          wx.$api.showToast('更新成功')
          // console.log(result)
          // this.setData({
          //   pageNum: 1
          // })
          // this.getMerchantCustomInfoList()
        })
        .catch(err => {})
    },
    changeStatus(e) {
      console.log(e)
      let { customerList, isSuper } = this.data
      let { index, item } = e.currentTarget.dataset
      // let
      let status = customerList[index].isEdit
      // console.log(isEdit)
      // customerList[index]['isEdit'] = !customerList[index]['isEdit']
      if (item.isEdit) {
        // 提交客户信息更新
        !isSuper && this.submit(customerList[index])
      }
      console.log(index)
      // let indexEdit = console.log(!status)
      this.setData({
        [`customerList[${index}].isEdit`]: !status
      })
    },
    input(e) {
      let { index, name } = e.currentTarget.dataset
      // console.log(index)
      // console.log(name)
      let { customerList, listObj } = this.data
      let { value } = e.detail
      // listObj

      customerList[index][name] = value
      this.setData({
        customerList
      })
      // let { name } = e.currentTarget.dataset

      // this.setData({
      //   [`orderObj.${name}`]: value
      // })
    }
  }
})