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: 'cusFollow',
    cardList: ['main'],
    buttonSaveList: [{ code: 'add', title: mixins.$t('save'), width: '120rpx' }],
    contentObj: {
      main: [
        { code: 'cusName', type: 'str', title: mixins.$t('customerName'), readonly: true, },
        { code: 'cusPhone', type: 'str', title: mixins.$t('cusPhone'), readonly: true },
        { code: 'addressFull', type: 'str', title: mixins.$t('addressFull'), readonly: true },
        { code: 'addressNo', type: 'str', title: mixins.$t('addressNo'), readonly: true },
        { code: 'intentionName', type: 'str', title: mixins.$t('intention'), readonly: true },
        { code: 'remarks', type: 'textarea', rows: '5', title: mixins.$t('followData'), readonly: true },
        { code: 'nextFollowTime', type: 'str', title: mixins.$t('nextFollowTime'), readonly: true },
        { code: 'stayTimeLenName', type: 'str', title: mixins.$t('stayTimeLen'), readonly: true },

        { code: 'file', type: 'uploader', title: mixins.$t("uploader"), readonly: true }
      ]
    },
  },
  /**
   * @desc : 设置保存参数
   * @date : 2024/2/1 15:49
   * @author : 于继渤
   */
  setParams(params) {
    // params.followStatus = this.data.followStatus

    return params
  },
  /**
   * @desc : 保存数据服务
   * @date : 2024/2/1 15:49
   * @author : 于继渤
   */
  saveData() {
    return this.excute(this.data.service, this.data.service.update, this.data.params);
  },

  /**
      * @desc :   编辑
      * @date : 2024/2/1 15:49
      * @author : 于继渤
      */
  toEdit() {
    let this_ = this
    wx.navigateTo({
      url: this_.data.route.add.url,
      events: {
        // 保存成功后刷新页面
        refresh: function (data) {
        }
      },
      success: function (res) {
        res.eventChannel.emit('params', {
          formMode: Constants.formMode.edit, id: this_.data.item.followId
        });
      }
    })
  },


  /**
     * 生命周期函数--监听页面加载
     */
  onLoad: function (options) {
    //接收父页面传递的参数
    let that = this
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.on('params', function (data) {
      let item = that.data.item
      let formData = that.setCus(JSON.parse(that.data.formData), item)
      that.setData({
        formData: formData
      })
      //陌生接待 控制字段
      if (that.data.item && that.data.item.followStatus == mixins.$t('followStatusReception')) {
        let contentObj = that.data.contentObj
        contentObj.main = [
          { code: 'intentionName', type: 'str', title: mixins.$t('intention'), readonly: true },
          { code: 'remarks', type: 'textarea', rows: '5', title: mixins.$t('followData'), readonly: true },
          { code: 'stayTimeLenName', type: 'str', title: mixins.$t('stayTimeLen'), readonly: true },
          { code: 'file', type: 'uploader', title: mixins.$t("uploader"), readonly: true }
        ]
        that.setData({
          contentObj: contentObj
        })
      }
    })

  },
  /**
  * @desc : 设置客户信息
  * @date : 2024/2/1 15:49
  * @author : 于继渤
  */
  setCus(formData, item) {
    formData = item
    formData.cusId = item.cusId
    formData.cusName = item.cusName
    formData.cusCode = item.cusCode
    formData.cusPhone = item.cusPhone
    //不这么设置 会不回显
    formData.address = {
      address: item.addressFull,
      addressFull: item.addressFull,
      addressArea: item.addressArea,
      addressGcj02: item.addressGcj02,
      addressName: item.addressName,
    }
    formData.addressArea = item.addressArea
    formData.addressFull = item.addressFull
    formData.addressGcj02 = item.addressGcj02
    formData.addressName = item.addressName
    formData.addressNo = item.addressNo
    formData.saleStatus = item.saleStatus
    return JSON.stringify(formData)
  },
})