/*******************************************************************************
 * Copyright(c) 2022 dongke All rights reserved. / Confidential
 * 类的信息：
 *		1.程序名称：
 *		2.客户收款
 * 编辑履历：
 *		作者				日期					版本				修改内容
 *		于继渤		        2022-0-12	            1.00		   	    
 *******************************************************************************/
const Constants = require('@/utils/Constants.js');
const mixins = require('@/mixins/index.js')
Page({
  mixins: [mixins],
  /**
   * 页面的初始数据 
   */
  data: {
    customerEfundFlag: false,
    primaryKey: 'rpId',
    // 查询条件
    searchContent: [{
      code: 'createtime',
      title: '近30天',
      defaultValue: 5,
      searchType: Constants.searchType.date
    }, {
      code: 'staff',
      title: '业务员',
      dropType: 'staff'
    },

    {
      code: 'rpType', key: 'valueList', title: '类型', searchType: Constants.searchType.switch,

      list: [
        { code: 1, title: '收款', value: '收付款类型-收款', checked: true },
        { code: 2, title: '退款', value: '收付款类型-退收款' }]
    }

    ],

    // 列表区（内容）
    contentList: [
      { name: 'rpNo', title: '收款单号' },
      { name: [{ name: 'orgName', title: '' }, { name: 'staffName', title: '业务员' }], title: '门店/业务员' },
      { name: 'accDate', title: '收款时间' },

    ],
    // 列表区（脚部金额）
    footerAmount: {
      name: 'sumAmtRec',
      title: mixins.$t('totalAmount')
    },
    footerInfo: [{ name: 'sumAmtRec', }],
    buttonSaveList: [{ code: 'add', title: mixins.$t("add") }],
    // 路由
    routeObjName: 'cusReceiptPayment',
    // 弹出按钮
    buttonList: [],
  },
  /**
   * @desc :   作废
   * @date : 2024年3月8日
   * @author : 于继渤
   */
  invalid(e) {
    let that = this
    return this.excute(this.data.service, this.data.service.invalid + '/' + e.rpId, {}).then(res => {
      if (res.data.code == 200) {
        that.searchData()
        wx.showToast({
          title: mixins.$t('invalidSuccessfully'),
          image: '/static/image/success.png',
          duration: 1000
        })
      }
    })
  },
  /**
     * @desc : 设置查询参数
     * @date : 2024/2/1 15:49
     * @author : 于继渤
     */
  setSearchParams(params) {
    params.objectId = this.data.id ? this.data.id : null
    params.rpTypeList = params.rpTypeList ? params.rpTypeList : (this.data.menuUuid == Constants.CUSTOMER_EFUND_FUNCTIONCODE ? ['收付款类型-退收款'] : ['收付款类型-收款'])
    return params;
  },
  /**
   * @desc : 加载数据
   * @author : 于继渤
   * @date : 2024/1/23 9:16
   */
  getData(params) {
    return this.excute(this.data.service, this.data.service.selectByCond, params);
  },

  /**
   * @desc : 处理查询数据
   * @date : 2024/2/1 15:49
   * @author : 于继渤
   */
  handleSearchData(tableData) {
    if (tableData && tableData.length > 0) {
      tableData.forEach(res => {
        res.collectStatus = 'cusCollection'
        res.collectStatus = res.sumAmtRec
      })
    }
    this.setData({
      tableData: tableData
    })
  },


  /**
   * @desc : 跳转明细
   * @date : 2024/2/1 15:49
   * @author : 于继渤
   */
  toDetail(e) {
    let customerEfundFlag = this.data.customerEfundFlag //true 为退款
    console.log('跳转明细', e)
    // let url = this.data.route.edit.url
    let url = this.data.route.detail.url
    if (customerEfundFlag || e.detail.item.rpType == '收付款类型-退收款') {
      // url = this.data.route.editRefund.url
      url = this.data.route.editRefundDetail.url
    }
    let _this = this;
    wx.navigateTo({
      url: url,
      events: {
        // 保存成功后刷新页面
        refresh: function (data) {
          // 刷新一览界面
          _this.searchData();
        }
      },
      success: function (res) {
        let data = {
          id: e.detail.item.rpId,
          formMode: Constants.formMode.other
        }
        res.eventChannel.emit('params', data);
      }
    })
  },

  /**
  * @desc : 三个小点点击回调
  * @date : 2024年3月8日
  * @author : 姜永辉
  */
  toPoint(e) {
    let item = e.detail.item
    let buttonList = null
    if (!item.flgValid) { //作废
      buttonList = [{
        name: 'printedBill',
        title: mixins.$t("printedBill")
      }, ] //打印
    } else {  
    if (item.rpType == Constants.rpType.returnReceipt) {
      buttonList=
      [
        { name: 'invalid', title: mixins.$t("invaidOrder") },//作废 
        { name: 'printedBill', title: mixins.$t("printedBill") }, //打印
      ]
    } else {
      buttonList =
      [
        {
          name: 'cusReturnCollection',
          title: mixins.$t("cusReturnCollection")
        },
        { name: 'invalid', title: mixins.$t("invaidOrder") },//作废 
        { name: 'printedBill', title: mixins.$t("printedBill") }, //打印
      ]
    }}
    this.setData({
      // 弹出按钮
      buttonList: buttonList
    })
  },

  /**
   * @desc : 初始化
   * @date : 2024/2/1 15:49
   * @author : 于继渤
   */
  loadInit() {
    //客户退款
    if (this.data.menuUuid == Constants.CUSTOMER_EFUND_FUNCTIONCODE) {
      wx.setNavigationBarTitle({
        title: '客户退款'
      })
      let searchContent = this.data.searchContent
      searchContent[2].list[1]['checked'] = true
      searchContent[2].list[0]['checked'] = false
      this.setData({
        searchContent: searchContent,
        buttonSaveList: [{ code: 'add', title: mixins.$t("add"), customUrl: this.data.route.refund.url }],
        customerEfundFlag: true //新建跳转类型标识
      })
    }
  },
})