/*******************************************************************************
 * 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,
    // 查询条件
    searchContent: [{
      code: 'createtime',
      title: '近30天',
      defaultValue: 5,
      searchType: Constants.searchType.date
    }, {
      code: 'staff',
      title: '业务员',
      dropType: 'staff'
    }, {
      code: 'orderStatus',
      title: '状态',
      searchType: Constants.searchType.switch,
      list: [
        {
          checked: true,
          text: "客户收款",
          value: "0"
        },
        {
          checked: false,
          text: "使用收款",
          value: "1"
        },
      ]

    },

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

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

    ],
    // 查询条件-筛选
    pullMenuList: [{
      code: 'outStatus',
      pullType: 'mSelect',
      typeName: 'outStatus'
    }, {
      code: 'receiveStatus',
      pullType: 'mSelect',
      typeName: 'receiveStatus'
    }, {
      code: 'designStatus',
      pullType: 'mSelect',
      typeName: 'designStatus'
    }, {
      code: 'customerFrom',
      pullType: 'mSelect',
      typeName: 'customerFrom'
    }, {
      code: 'keyType',
      pullType: 'mSelect',
      typeName: 'keyType'
    }, {
      code: 'delivery_Time',
      dataType: 'date'
    }],
    // 列表区（内容）
    contentList: [
      { name: 'rpNo', title: '收款单号' },
      { name: [{ name: 'orgName', title: '' }, { name: 'staffName', title: '业务员' }], title: '门店/业务员' },
      { name: 'accDate', title: '收款时间' },

    ],
    buttonSaveList: [{ code: 'add', title: mixins.$t("add") }],
    // 路由
    routeObjName: 'cusReceiptPayment',
    // 弹出按钮
    buttonList: [{
      name: 'cusReturnCollection',
      title: mixins.$t("cusReturnCollection")
    }, { name: 'invalid', title: mixins.$t("invaidOrder") },//作废 
    {
      name: 'saleReturn',
      title: mixins.$t("ticketPirnt")
    }
    ],
  },
  /**
   * @desc :   作废
   * @date : 2024年3月8日
   * @author : 于继渤
   */
  invalid(e) {
    // return this.excute(this.data.service, this.data.service.invalid + '/' + e.orderId, {}).then(res => {
    //   if (res.data.code == 200) {
    //     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
    if (customerEfundFlag || e.detail.item.rpType == '收付款类型-退收款') {
      url = this.data.route.editRefund.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/2/1 15:49
   * @author : 于继渤
   */
  loadInit() {
    //客户退款
    if (this.data.menuUuid == Constants.CUSTOMER_EFUND_FUNCTIONCODE) {
      wx.setNavigationBarTitle({
        title: '客户退款'
      })
      let searchContent = this.data.searchContent
      searchContent[3].list[1]['checked'] = true
      searchContent[3].list[0]['checked'] = false
      this.setData({
        searchContent:searchContent,
        buttonSaveList: [{ code: 'add', title: mixins.$t("add"), customUrl: this.data.route.refund.url }],
        customerEfundFlag: true //新建跳转类型标识
      })
    }
  },
})