clueDetail.js 6.73 KB
// packageEquity/pages/clueDetail/clueDetail.js
import carLifeApi from '../../carEquityApi'
import CONSTANTDATA from './data'
import itemMixin from '../clueList/components/itemMixins'
import NP from 'number-precision'

Page({
  behaviors: [itemMixin],
  /**
   * 页面的初始数据
   */
  data: {
    customerObj: [{
      label: '客户姓名',
      key: 'customerName'
    },
    {
      label: '手机号',
      key: 'customerPhone',
      // color: '#347BFF',
      // callBack: 'makePhoneCall',
      copy: true
    },
    {
      label: '性别',
      key: 'customerSex',
      enum: {
        1: '男',
        2: '女'
      }
    },
    {
      label: '年龄区间',
      key: 'customerAgeRange',
    },
    {
      label: '所在城市',
      key: 'customerCity',
    },
    {
      label: '兴趣爱好',
      key: 'customerHobby'
    },
    {
      label: '陪伴人员',
      key: 'customerCompanion'
    },
    {
      label: '销售顾问',
      key: 'employeeName'
    },
    {
      label: '客户画像',
      key: 'userPortrait',
      portrait: true
    }
    ],
    carInfoObk: [{
      label: '客户车型',
      key: 'carSeriesName'
    },
    {
      label: '车辆颜色',
      key: 'carColor'
    },
    {
      label: '座位数',
      key: 'carSeat'
    },
    {
      label: '车辆价格',
      key: 'carPrice'
    },
    {
      label: '车架号码',
      key: 'carVin'
    },
    ],
    recordObj: [{
      label: '跟进人',
      key: 'follower'
    },
    {
      label: ['事', '件'],
      key: 'eventDesc',
      // enum: {
      //   1: '车主领券',
      //   2: '车主预约',
      //   3: '预约时间',
      //   4: '修改时间',
      //   5: '取消预约'
      // }
    },
    {
      label: ['备', '注'],
      key: 'remark'
    }
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if (options.id) {
      this.getCustomerClueDetail(options.id)
    } else wx.$router.getData(({
      id
    }) => {
      this.getCustomerClueDetail(id)
    })
  },
  async getCustomerClueDetail(id) {
    wx.$util.showLoading()
    try {
      const {
        sceneType,
        shopMerchantId: merchantId
      } = wx.$util.getUserInfo(), {
        code,
        data,
        message
      } = await carLifeApi.getCustomerClueDetail({
        id,
        sceneType,
        merchantId: [merchantId]
      })
      if (code == 0) {
        wx.hideLoading()
        if (data.customerInfo && data.customerInfo.carPrice) data.customerInfo.carPrice = this.truncateDecimal(NP.times(data.customerInfo.carPrice, 0.01))
        if (data.records && data.records.length) {
          data.records.map(e => {
            let createdDate = new Date(e.createdDate)
            e.year = createdDate.format('yyyy-MM-dd')
            e.time = createdDate.format('hh:mm:ss')
          })
        }
        const TimeFormat = 'yyyy.MM.dd hh:mm:ss'
        data.boutiqueOrders?.map(e => {
          e.orderTime = new Date(e.orderTime).format(TimeFormat)
          e.totalPrice = this.truncateDecimal(e.totalPrice || 0)
          if (e.payOrder && e.payOrder.successDate) e.successDate = new Date(e.payOrder.successDate).format(TimeFormat)
          e.subOrderList?.map(x => {
            x.totalPrice = this.truncateDecimal(x.totalPrice || 0)
          })
        })
        data.vqOrders?.map(e => {
          if (e.payTime) e.payTime = new Date(e.payTime).format(TimeFormat)
          if (e.createdTime) e.createdTime = new Date(e.createdTime).format(TimeFormat)
          e.quotedPriceUpdate = this.truncateDecimal(NP.times(e.quotedPriceUpdate || 0, 0.01))
          e.vdQuotationGoodsList?.map(x => {
            if (x.goodsPrice) x.goodsPrice = this.truncateDecimal(NP.times(x.goodsPrice, 0.01))
          })
        })
        this.setData({
          detail: data,
          flag: true
        })
        this.dealPortrait()
      } else throw message

    } catch (error) {
      console.log(error)
      wx.hideLoading()
      if (error) wx.$util.showToast(error)
    }
  },
  async dealPortrait() {
    const {
      detail
    } = this.data
    if (!detail) return
    const {
      portraitCustomerId: id
    } = detail
    if (!id) return
    let _userPortrait = []
    let {
      code,
      data: info
    } = await carLifeApi.portraitQuery({
      id
    })
    if (code != 0) return

    CONSTANTDATA.formData.forEach(item => {
      if (info[item.name]) {
        if (item.type == 'textarea') {
          _userPortrait.push(info[item.name])
        } else {
          if (item.isMult) {
            // let _list = info[item.name].split(',')
            let _list = info[item.name]
            _list.forEach(n => {
              _userPortrait.push(item.optionList.find(k => k.confId == n).confName)
            })
          } else {
            // _userPortrait.push(item.optionList.find(k => k.confId == info[item.name])?.otherName || item.optionList.find(k => k.confId == info[item.name])?.confName)
            let labelName = item.optionList.find((k) => k.confId == info[item.name])
            if (labelName?.label) {
              _userPortrait.push(
                labelName?.otherName ||
                labelName?.confName + ' ' + labelName?.label
              );

            } else {
              _userPortrait.push(
                labelName?.otherName ||
                labelName?.confName
              );
            }
          }
        }
      }
    })
    this.setData({
      ['detail.customerInfo.userPortrait']: _userPortrait
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  setCopyData(e) {
    console.log(e)
    let {
      content
    } = e.currentTarget.dataset
    wx.$util.setCopyData(`${content}`)
  },
  editProtrait(e) {
    wx.$util.pointRecord(24)
    const {
      customerInfo,
      portraitCustomerId
    } = this.data.detail
    wx.$router.go('tabDate.userPortrait', {
      customer: customerInfo,
      customerId: portraitCustomerId
    })
  },
  truncateDecimal(number, decimalPlaces = 2) {
    let [integer, decimals] = String(number).split('.')
    if (!decimals) decimals = '00'
    if (decimals.length > 2) decimals = decimals.substring(0, decimalPlaces)
    if (decimals.length == 1) decimals += '0'
    return `${integer}.${decimals}`
  },
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // 用户画像
    this.dealPortrait()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})