const mixins = require('@/mixins/index.js')
const Constants = require('@/utils/Constants.js');
const app = getApp();
Page({
  mixins: [mixins],
  /**
 * 页面的初始数据
 */
  data: {
    cardList: [
      { name: 'main' },
      { name: 'bill', title: mixins.$t('receivable'), chooseFlag: true, chooseTitle: mixins.$t('receivableSelect'), urlKey: 'selectBill' },
      { name: 'file' }],
    contentObj: {
      main: [
        {
          code: 'accDate',
          name: 'accDate',
          type: 'date',
          required: true,
        },
        {
          code: 'staffId',
          name: 'staffName',
          required: true,
          title: mixins.$t('payee'),
          type: 'choose',
          urlKey: 'chooseStaff'
        },
        {
          code: 'orgId',
          name: 'orgName',
          required: true,
          type: 'choose',
          urlKey: 'chooseOrg'
        },
        {
          code: 'sumAmtRec',
          type: 'number',
          title: mixins.$t('thisPayment'),
          required: true
        },

      ],
      bill: [
        { code: 'cancelAmount', type: 'cancel', title: mixins.$t('sumAmtReceivableHandle'), bill: 0, amount: 0 },
        { code: 'receivableResidue', type: 'number', title: mixins.$t('tobeverifiedAmount'), readonly: true, },
        { code: 'currentReceivableResidue', type: 'number', title: mixins.$t('curentVerifiedAmount'), required: true, readonly: true, },
        { code: 'sumWaiveAmt', type: 'number', title: mixins.$t('sumWaiveAmt'), readonly: true, },
        { code: 'receiptResidue', type: 'number', title: mixins.$t('paymentDeduction'), readonly: true, },
      ],
      file: [{
        code: 'remarks', type: 'textarea', title: mixins.$t('remarks')
      },
      { code: 'file', type: 'uploader', title: mixins.$t('uploader') }]
    },
    // 预存金额 预收金额
    amountArr: [
      { title: mixins.$t('receivableAmount'), code: 'receivableResidue' },
      { title: mixins.$t('advancePaymentAmount'), code: 'receiptResidue' }],
    // 三个汇总金额
    totalObj: {
      bill: [{ title: mixins.$t('collectAmount'), code: 'collectAmount' },
      { title: mixins.$t('totalWriteOffAmount'), code: 'totalWriteOffAmount' },
      { title: mixins.$t('toAdvancePaymentAmount'), code: 'toAdvancePaymentAmount' }]
    },
    // 弹出按钮
    buttonList: [{
      name: 'merge',
      title: mixins.$t('collection')
    }],
    contentList: [{
      code: 'need',
      title: mixins.$t('totalAmount'),
      type: 'str'
    }, {
      code: 'amount',
      content: 0,
      type: 'number'
    }],
    btnFormData: null,
    routeObjName: 'receiptPayment',
    accountService: app.globalData['accountService'],
    receivableResidue: 0,
    receiptResidue: 0,
    bill: 0,
    objInfo: {},
    table: Constants.tables.recPay,
  },


  /**
  * @desc : 给表单赋值
  * @date : 2024/2/1 15:49
  * @author : 姜永辉
  */
  setValuesByEdit(data) {
    console.log("setValuesByEdit", data,this.data.item); 
    let formData = {...this.data.item} 
    formData.objInfo = this.data.item
    formData.receivableList = data.recPayHandleItem
    formData.objInfo.cusId = this.data.item.objectId
     // 收款总额
     formData.collectAmount = formData.sumAmtRec
     formData.currentReceivableResidue = formData.sumAmtReceivableHandle  // 本次核销金额
    formData.totalWriteOffAmount = formData.receivableResidue  // 核销总额
    console.log("setValuesByEdit", formData); 
    this.setData({
      itemData: data,
      formData: JSON.stringify(formData),
    })
  },

})