/*******************************************************************************
 * Copyright(c) 2022 dongke All rights reserved. / Confidential
 * 类的信息：
 *		1.程序名称：
 *		2.新增接待
 * 编辑履历：
 *		作者				日期					版本				修改内容
 *		yjb		        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: {
    tagList: [{ title: mixins.$t('allReceptions'), code: 'all' }, { title: mixins.$t('followUpTasks'), code: mixins.$t('followStatusFollowUp') }, { title: mixins.$t('followStatusInvitationName'), code: mixins.$t('followStatusInvitation') }, { title: mixins.$t('followStatusFootName'), code: mixins.$t('followStatusFoot') }],
    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('receptionInformation'), bill: 1, fontSize: '15px' }],
    // 查询条件
    searchContent: [
      { code: 'createtime', title: mixins.$t('pastThirthtyDays'), defaultValue: 5, searchType: Constants.searchType.date },
      { code: 'staff', title: mixins.$t('staffId'), dropType: 'staff' },
      { code: 'choose', title: mixins.$t('choose'), searchType: Constants.searchType.pick }
    ],
    // 查询条件-筛选
    pullMenuList: [
      { code: 'followStatus', pullType: 'mSelect', typeName: 'followStatus' },
      { code: 'followCount', dataType: 'number' },
      { code: 'nextFollowTime', dataType: 'date' }
    ],


    // 列表区（内容）
    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: 'followTime', title: mixins.$t('followTime') }
    ],

    contentObj: {
      '跟进状态-跟进': [{ name: 'cusPhone', title: mixins.$t('cusPhone'), phone: true },
      { name: 'addressFull', title: mixins.$t('addressFull') },
      { name: [{ name: 'orgName', title: '' }, { name: 'staffName', title: mixins.$t('staffId') }], title: mixins.$t('storeInformation') },
      { name: 'followTime', title: mixins.$t('followTime') }],
      '跟进状态-报备': [{ name: 'cusPhone', title: mixins.$t('cusPhone'), phone: true },
      { name: 'addressFull', title: mixins.$t('addressFull') },
      { name: [{ name: 'orgName', title: '' }, { name: 'staffName', title: mixins.$t('staffId') }], title: mixins.$t('storeInformation') },
      { name: 'followTime', title: mixins.$t('followTime') }],
      '跟进状态-邀约': [{ name: 'cusPhone', title: mixins.$t('cusPhone'), phone: true },
      { name: 'addressFull', title: mixins.$t('addressFull') },
      { name: [{ name: 'orgName', title: '' }, { name: 'staffName', title: mixins.$t('staffId') }], title: mixins.$t('storeInformation') },
      { name: 'followTime', title: mixins.$t('followTime') }],
      '跟进状态-约尺': [{ name: 'cusPhone', title: mixins.$t('cusPhone'), phone: true },
      { name: 'addressFull', title: mixins.$t('addressFull') },
      { name: [{ name: 'orgName', title: '' }, { name: 'staffName', title: mixins.$t('staffId') }], title: mixins.$t('storeInformation') },
      { name: 'followTime', title: mixins.$t('followTime') }],
      '跟进状态-接待': [
        { name: [{ name: 'orgName', title: '' }, { name: 'staffName', title: mixins.$t('staffId') }], title: mixins.$t('storeInformation') },
        { name: 'followTime', title: mixins.$t('followTime') }],

      '跟进状态-成交': [{ name: 'cusPhone', title: mixins.$t('cusPhone'), phone: true },
      { name: 'addressFull', title: mixins.$t('addressFull') },
      { name: [{ name: 'orgName', title: '' }, { name: 'staffName', title: mixins.$t('staffId') }], title: mixins.$t('storeInformation') },
      { name: 'followTime', title: mixins.$t('followTime') }],
      '跟进状态-报价': [{ name: 'cusPhone', title: mixins.$t('cusPhone'), phone: true },
      { name: 'addressFull', title: mixins.$t('addressFull') },
      { name: [{ name: 'orgName', title: '' }, { name: 'staffName', title: mixins.$t('staffId') }], title: mixins.$t('storeInformation') },
      { name: 'followTime', title: mixins.$t('followTime') }],

    },

    // 列表区（脚部信息）
    footerInfo: [{
      prefix: mixins.$t('followedUp'),
      name: 'followCount',
      title: mixins.$t('next')
    },],

    // 弹出按钮
    buttonList: [
      { name: 'followUp', title: mixins.$t('follow') },
      { name: 'followUpTasks', title: mixins.$t('followUpTasks') },
      { name: 'customerRefundList', title: mixins.$t('saleOrder') },
      { name: 'customerRefundList', title: mixins.$t('cusCollection') },

    ],

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

    // 路由
    routeObjName: 'cusFollow',
    followStatus: 'all',
    active: 0
  },
  /**
  * @desc : 点击三个点事件
  * @date : 2024/2/1 15:49
  * @author : 于继渤
  */
  toPoint(e) {
    let item = e.detail.item
    let buttonList = this.data.buttonList
    if (item.followStatus == mixins.$t('followStatusFoot') && item.measureStatus == mixins.$t('scaleStatusMeasured')) {
      buttonList = [
        { name: 'followUp', title: mixins.$t('follow') },
        { name: 'followUpTasks', title: mixins.$t('followUpTasks') },
        { name: 'customerRefundList', title: mixins.$t('saleOrder') },
        { name: 'customerRefundList', title: mixins.$t('cusCollection') },
        { name: 'measureTo', title: mixins.$t('measuringScaleReceipt') }
      ]
    } else {
      buttonList = [
        { name: 'followUp', title: mixins.$t('follow') },
        { name: 'followUpTasks', title: mixins.$t('followUpTasks') },
        { name: 'customerRefundList', title: mixins.$t('saleOrder') },
        { name: 'customerRefundList', title: mixins.$t('cusCollection') },
      ]
    }
    this.setData({
      buttonList: buttonList
    })

  },
  /**
  * @desc : 跳转
  * @date : 2024/2/1 15:49
  * @author : 于继渤
  */
  toDetail(e) {
    let item = e.detail.item
    let url = null
    if (item.followStatus == '跟进状态-报备' || item.followStatus == '跟进状态-接待') {
      url = this.data.route.toFollowStatus1.url
    } else if (item.followStatus == '跟进状态-跟进' || item.followStatus == '跟进状态-邀约') {
      url = this.data.route.toFollowStatus2.url
    } else if (item.followStatus == '跟进状态-约尺') {
      url = this.data.route.toFollowStatus3.url
    }
    let _this = this;
    wx.navigateTo({
      url: url,
      events: {
        // 保存成功后刷新页面
        refresh: function (data) {
          // 刷新一览界面
          _this.searchData();
        }
      },
      success: function (res) {
        let data = {}
        data.id = item.followId
        data.formMode = Constants.formMode.edit
        data.formType = Constants.formMode.detail
        res.eventChannel.emit('params', data);
      }
    })
  },

  /**
 * @desc : 切换
 * @date : 2024/2/1 15:49
 * @author : 于继渤
 */
  onChangeTabs(e) {
    let code = e.detail.detail.code
    this.setData({
      followStatus: code,
    })
    this.searchData()
  },

  /**
* @desc : 设置查询参数
* @date : 2024/2/1 15:49
* @author : 于继渤
*/
  setSearchParams(params) {
    //销售状态
    params.followStatus = this.data.followStatus == 'all' ? '' : this.data.followStatus
    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);
  },
})