/*******************************************************************************
 * Copyright(c) 2022 dongke All rights reserved. / Confidential
 * 类的信息：
 *		1.程序名称：
 * 编辑履历：
 *		作者				日期					版本				修改内容
 *		于继渤		 2024-1-23			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: {
    tagList: [{ title: mixins.$t('potentialCus'), code: mixins.$t('salePotentialCus') }, { title: mixins.$t('seasCus'), code: mixins.$t('saleSeasCus') }, { title: mixins.$t('dealCus'), code: mixins.$t('saleDealCus') }, { title: mixins.$t('allCus'), code: 'all' }],
    // 查询条件
    searchContent: [
      { code: 'createtime', title: mixins.$t('pastThirthtyDays'), defaultValue: 5, searchType: Constants.searchType.date },
      { code: 'staff', title: mixins.$t("staffId"), dropType: 'staff' },
      { code: 'org', title: mixins.$t("orgId"), dropType: 'org' },
      { code: 'choose', title: mixins.$t('choose'), searchType: Constants.searchType.pick }
    ],
    buttonSaveList: [{ code: 'add', title: mixins.$t('add'), width: '120rpx', color: '#1B365D' }],
    contentSaveList: [{ code: 'need', title: mixins.$t('together'), type: 'count', color: '#1B365D', tail: mixins.$t('customers'), bill: 1, fontSize: '15px' }],
    // 查询条件-筛选
    pullMenuList: [
      { code: 'cusFrom', pullType: 'mSelect', typeName: 'cusFrom' },
      { code: 'followCount', dataType: 'number' },
      { code: 'nextFollowTime', dataType: 'date' }
    ],
    // 列表区（脚部信息）
    footerInfo: [{
      prefix: mixins.$t('followedUp'),
      name: 'followCount',
      title: mixins.$t('next'),
      different: mixins.$t('notFollowedUp'),
      color: 'red'
    },],
    // 列表区（内容）
    contentList: [
      { name: 'cusPhone', title: mixins.$t('cusPhone'), phone: true },
      { name: 'addressFull', title: mixins.$t('addressFull') },
      {
        name: [{ name: 'orgName', title: '' },
        { name: 'staffName', title: '' }], title: mixins.$t('storeInformation')
      },
      { name: 'nextFollowTime', title: mixins.$t('nextFollowTime') }
    ],



    // 弹出按钮
    buttonList: [
      { name: 'followUp', title: mixins.$t('followUp') },
      { name: 'followUpTasks', title: mixins.$t('followUpTasks') },
      { name: 'collection', title: mixins.$t("cusCollection"), idKey: 'cusId' },//跳转客户收款
    ],

    totallength: 0, //视图下方提醒数量

    // 路由
    routeObjName: 'customer',
    active: 0,
    saleStatus: mixins.$t('salePotentialCus'),

  },
  /**
 * @desc : 切换
 * @date : 2024/2/1 15:49
 * @author : 于继渤
 */
  onChangeTabs(e) {
    let code = e.detail.detail.code
    this.setData({
      saleStatus: code,
    })
    this.searchData()
  },
  /**
* @desc : 详细页面
* @date : 2024/2/1 15:49
* @author : 于继渤
*/
  toDetail(e) {
    let cusId = e.detail.item.cusId
    this.setData({
      selectflag: true
    })
    wx.navigateTo({
      url: this.data.route.detail.url,
      success: function (res) {
        // 通过eventChannel向被打开页面传送数据 TODO 测试例子url是写死的，实际中，需要从route中读取
        res.eventChannel.emit('params', { id: cusId, formMode: Constants.formMode.edit })
      }
    })
  },


  /**
 * @desc : 设置查询参数
 * @date : 2024/2/1 15:49
 * @author : 于继渤
 */
  setSearchParams(params) {
    //销售状态
    params.saleStatus = this.data.saleStatus == 'all' ? '' : this.data.saleStatus
    return params
  },
  /**
     * @desc :   处理接口返回数据
     * @date : 2024/2/1 15:49
     * @author : 于继渤
     */
  handleSearchData(tableData) {
    let contentSaveList = this.data.contentSaveList
    contentSaveList[0].bill = tableData.length
    this.setData({
      contentSaveList: contentSaveList
    })
  },
  /**
   * @desc : 查询
   * @date : 2024/2/1 15:49
   * @author : 于继渤
   */
  getData(params) {
    return this.excute(this.data.service, this.data.service.selectByCond, params);
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {


  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (this.data.refreshDataFlag) {
      this.searchData()
    }
  },
})