/*******************************************************************************
 * Copyright(c) 2022 dongke All rights reserved. / Confidential
 * 类的信息：
 *		1.程序名称：
 *		2.客户资料明细
 * 编辑履历：
 *		作者				日期					版本				修改内容
 *		于继渤		        2022-0-12	            1.00		   	    
 *******************************************************************************/
const Constants = require('@/utils/Constants.js');
const util = require('@/utils/util.js')
const mixins = require('@/mixins/index.js')
const app = getApp()

Page({
  mixins: [mixins],
  /**
   * 页面的初始数据
   */
  data: {
    // 路由
    routeObjName: 'customer',
    cusFollowService: app.globalData['cusFollowService'],
    item: {},
    customerFollowList: [],
    active: 0,
    // 主键Id
    primaryKey: 'cusId',
  },

  getCusFollowList(cusId) {
    return this.excute(this.data.cusFollowService, this.data.cusFollowService.selectByList, { cusId: cusId }).then(res => {
      if (res.data.code == 200) {
        console.log('getCusFollowList', res.data.data)
        let list = res.data.data
        let followList = []
        for (let i = 0; i < list.length; i++) {
          if (list[i].followId) {
            followList.push(list[i])
          }
        }
        this.setData({
          customerFollowList: followList.length > 0 ? this.classify(followList) : []
        })
        if (followList.length > 0) {
          let that = this
          setTimeout(() => {
            wx.createSelectorQuery().select('#time0').boundingClientRect(function (rect) {
              that.setData({
                timeWidth: rect.width
              })
            }).exec()
            wx.createSelectorQuery().select('#xian0').boundingClientRect(function (rect) {
              that.setData({
                xianWidth: rect.width
              })
            }).exec()
            wx.createSelectorQuery().select('#kuang0').boundingClientRect(function (rect) {
              that.setData({
                kuangHeight: rect.height
              })
            }).exec()
          }, 200)
        }
      }
    });
  },

  /**
  * 把创建时间相同的跟进记录放入到一个item 然后扔到list
  * @param {*} arr 
  */
  classify(arr) {
    let map = {};
    let myArr = [];
    for (let i = 0; i < arr.length; i++) {
      if (!map[arr[i].createTime]) {
        myArr.push({
          createTime: arr[i].createTime,
          weekTime: arr[i].weekTime,
          data: [arr[i]]
        });
        map[arr[i].createTime] = arr[i]
      } else {
        for (let j = 0; j < myArr.length; j++) {
          if (arr[i].createTime === myArr[j].createTime) {
            myArr[j].data.push(arr[i]);
            break
          }
        }
      }
    }
    return myArr
  },
  /**
   * @desc : 给表单赋值
   * @date : 2024/2/1 15:49
   * @author : 于继渤
   */
  setValuesByEdit(data) {
    data.name = 'edit'
    this.setData({
      item: data
    })
    this.getCusFollowList(data.cusId)
  }
})