<template>
  <div>
    <div class="pay-table">
      <Form :model="tableData">
        <Table
          :data="tableData"
          :columns="columns"
          border
          stripe
          @on-selection-change="onSelectChange"
        ></Table>
      </Form>

      <div
        v-if="showMoneyInfo"
        class="money-info-box"
      >
        <div class="money-info-item">
          总申请金额：
          <span>{{ moneyInfo.total }}</span>
        </div>
        <div class="money-info-item">
          已拆分金额：
          <span>{{ moneyInfo.wasSplit }}</span>
        </div>
        <div class="money-info-item">
          待拆分金额：
          <span>{{ moneyInfo.rest }}</span>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import SelectRealPaymentCompany from '../selectRealPaymentCompany/SelectRealPaymentCompany.vue';
// import SelectVendorBankInfo from '../selectVendorBankInfo/SelectVendorBankInfo.vue';
// import DataSelect from '../dataSelect/DataSelect.vue';
import accounting from 'accounting';
import Server from './server.js';

const server = new Server();
let vm;
export default {
  name: 'PayInfoForm',
  components: {
    // SelectRealPaymentCompany: SelectRealPaymentCompany,
    // SelectVendorBankInfo,
    // DataSelect
  },
  props: {
    title: {
      type: String,
      default() {
        return '付款信息';
      }
    },
    payRequestLineId: {
      type: [String, Number],
      default() {
        return '';
      }
    },
    payLineId: {
      type: String,
      default() {
        return '';
      }
    },
    showAmount: {
      type: Boolean,
      default() {
        return false;
      }
    },
    checkFlag: {
      type: Boolean,
      default() {
        return false;
      }
    },
    applyAmount: {
      type: Number,
      default() {
        return 0;
      }
    },
    compName: {
      type: String,
      default() {
        return '';
      }
    },
    companyCode: {
      type: String,
      default() {
        return '';
      }
    },
    initFun: {
      type: Function,
      default() {
        return function() {};
      }
    },
    refreshFun: {
      type: Function,
      default() {
        return function() {};
      }
    },
    categoryCode: {
      type: String,
      default: ''
    },
    isPaymentCreate: {
      type: Boolean,
      default: false
    },
    paymentEdit: {
      type: Boolean,
      default: false
    },
    isNowDraft: {
      type: String,
      default: '0'
    }
  },
  props: {
    title: {
      type: String,
      default() {
        return '付款信息';
      }
    },
    payRequestLineId: {
      type: String,
      default() {
        return '';
      }
    },
    payLineId: {
      type: String,
      default() {
        return '';
      }
    },
    showAmount: {
      type: Boolean,
      default() {
        return false;
      }
    },
    checkFlag: {
      type: Boolean,
      default() {
        return false;
      }
    },
    applyAmount: {
      type: Number,
      default() {
        return 0;
      }
    },
    compName: {
      type: String,
      default() {
        return '';
      }
    },
    companyCode: {
      type: String,
      default() {
        return '';
      }
    },
    initFun: {
      type: Function,
      default() {
        return function() {};
      }
    },
    refreshFun: {
      type: Function,
      default() {
        return function() {};
      }
    },
    categoryCode: {
      type: String,
      default: ''
    },
    isPaymentCreate: {
      type: Boolean,
      default: false
    },
    paymentEdit: {
      type: Boolean,
      default: false
    },
    isNowDraft: {
      type: String,
      default: '0'
    }
  },
  data() {
    return {
      paymentModeList: [],
      saveFlag: false,
      disabledFlag: false,
      payWayFlag: false,
      buttons: [],
      text: '',
      selections: [],
      showAdd: false,
      server: server,
      tableData: [],
      configFileCodeList: [],
      payTpList: [],
      transfersTypeList: [],
      paymentModePayWayList: [],
      moneyInfo: {
        total: 0,
        wasSplit: 0,
        rest: 0
      },
      showMoneyInfo: false,
      columns: [
        {
          type: 'selection',
          width: 60,
          align: 'center',
          fixed: 'left'
        },
        {
          type: 'index',
          title: '序号',
          width: 70,
          align: 'left'
        },
        {
          align: 'left',
          width: 200,
          key: 'paymentMethod',
          renderHeader: (h, params) => {
            return h('div', [
              h('Icon', {
                props: {
                  type: 'asterisk',
                  color: 'red',
                  size: '5px'
                },
                style: {
                  marginRight: '5px'
                }
              }),
              h('strong', '付款方式')
            ]);
          },
          render: (h, params) => {
            if (vm.checkFlag) {
              vm.payWayFlag = true;
            }
            if (vm.payWayFlag || params.row.prepareStatus == '1') {
              return h('DataSelect', {
                props: {
                  value: params.row.paymentMethod,
                  code: 'PAYMENT_MODE'
                },
                attrs: {
                  transfer: true,
                  disabled: true
                },
                style: {
                  width: '160px'
                }
              });
            } else {
              const paymentModeOptions = [];
              let checkOptionFlag = false;
              let paymentModeFlag = true;
              // 循环遍历是为了将查出来的值选中
              for (let i = 0; i < vm.paymentModePayWayList.length; i++) {
                checkOptionFlag = false;
                if (vm.paymentModePayWayList[i].value == params.row.paymentMethod) {
                  checkOptionFlag = true;
                }
                paymentModeOptions.push(
                  h(
                    'Option',
                    {
                      props: {
                        value: vm.paymentModePayWayList[i].value,
                        checked: checkOptionFlag,
                        label: vm.paymentModePayWayList[i].label
                      }
                    },
                    vm.paymentModePayWayList[i].label
                  )
                );
              }
              if (vm.paymentModePayWayList.length > 0) {
                // 如果查出来的值不在下拉框内就将其替换成空
                for (let j = 0; j < vm.paymentModePayWayList.length; j++) {
                  if (vm.paymentModePayWayList[j].value == params.row.paymentMethod) {
                    paymentModeFlag = false;
                    break;
                  }
                }
                if (paymentModeFlag) {
                  this.tableData[params.index].paymentMethod = '';
                }
              }

              return h(
                'Select',
                {
                  props: {
                    transfer: true,
                    value: params.row.paymentMethod
                  },
                  on: {
                    'on-change': data => {
                      this.tableData[params.index].paymentMethod = data;
                      this.tableData[params.index].ouName = '';
                      this.tableData[params.index].bankAccountName = '';
                      this.tableData[params.index].bankAccountNum = '';
                      // if (vm.isNowDraft == '1') {
                      vm.paymentChanges(params.row, data);
                      // }
                    }
                  }
                },
                paymentModeOptions
              );
            }
          }
        },
        {
          title: '实际付款公司',
          align: 'left',
          minWidth: 200,
          renderHeader: (h, params) => {
            return h('div', [
              h('Icon', {
                props: {
                  type: 'asterisk',
                  color: 'red',
                  size: '5px'
                },
                style: {
                  marginRight: '5px'
                }
              }),
              h('strong', '实际付款公司')
            ]);
          },
          render: (h, params) => {
            const ouDom = h(SelectRealPaymentCompany, {
              props: {
                title: '付款银行账号列表',
                value: vm.tableData[params.index].ouName,
                columns: [
                  {
                    type: 'selection',
                    width: 55,
                    // fixed: 'left',
                    align: 'left'
                  },
                  {
                    title: '实际付款公司名称',
                    key: 'compName',
                    width: 160,
                    align: 'left',
                    // sortable: "custom",
                    render: (h, params) => {
                      return h(
                        'div',
                        {
                          attrs: {
                            class: 'ivu-table-cell-ellipsis',
                            title: params.row.compName
                          }
                        },
                        params.row.compName
                      );
                    }
                  },
                  {
                    title: '银行名称',
                    key: 'bankName',
                    align: 'left',
                    // sortable: "custom",
                    width: 140,
                    render: (h, params) => {
                      return h(
                        'div',
                        {
                          attrs: {
                            class: 'ivu-table-cell-ellipsis',
                            title: params.row.bankName
                          }
                        },
                        params.row.bankName
                      );
                    }
                  },
                  {
                    title: '银行账户名',
                    align: 'left',
                    key: 'bankAccountName',
                    width: 170,
                    render: (h, params) => {
                      return h(
                        'div',
                        {
                          attrs: {
                            class: 'ivu-table-cell-ellipsis',
                            title: params.row.bankAccountName
                          }
                        },
                        params.row.bankAccountName
                      );
                    }
                  },
                  {
                    title: '银行账号',
                    align: 'left',
                    key: 'bankAccountNum',
                    minWidth: 140,
                    render: (h, params) => {
                      return h(
                        'div',
                        {
                          attrs: {
                            class: 'ivu-table-cell-ellipsis',
                            title: params.row.bankAccountNum
                          }
                        },
                        params.row.bankAccountNum
                      );
                    }
                  }
                ],
                compName: vm.compName,
                compCode: vm.companyCode,
                paymentmode: vm.tableData[params.index].paymentMethod
              },
              on: {
                handleSelect: d => {
                  vm.tableData[params.index].ouName = d.compName;
                  vm.tableData[params.index].accountName = d.bankAccountName;
                  vm.tableData[params.index].accountNo = d.bankAccountNum;
                  vm.tableData[params.index].ouCode = d.compCode;
                  // vm.tableData[params.index].payWay = d.payMode
                }
              }
            });
            if (
              params.row.paymentMethod == '' ||
              params.row.paymentMethod == null ||
              params.row.paymentMethod == undefined
            ) {
              return h('strong', '实际付款公司');
            } else if (params.row.prepareStatus == '1') {
              return h('strong', vm.tableData[params.index].ouName);
            } else if (vm.checkFlag) {
              if (vm.isPaymentCreate) {
                return ouDom;
              } else {
                return h('strong', vm.tableData[params.index].ouName);
              }
            } else {
              return ouDom;
            }
          }
        },
        {
          title: '银行账户名称',
          align: 'left',
          minWidth: 200,
          key: 'accountName',
          renderHeader: (h, params) => {
            return h('div', [
              h('Icon', {
                props: {
                  type: 'asterisk',
                  color: 'red',
                  size: '5px'
                },
                style: {
                  marginRight: '5px'
                }
              }),
              h('strong', '银行账户名称')
            ]);
          }
        },
        {
          title: '银行账号',
          align: 'left',
          minWidth: 200,
          key: 'accountNo',
          renderHeader: (h, params) => {
            return h('div', [
              h('Icon', {
                props: {
                  type: 'asterisk',
                  color: 'red',
                  size: '5px'
                },
                style: {
                  marginRight: '5px'
                }
              }),
              h('strong', '银行账号')
            ]);
          }
        },
        {
          title: '金额',
          align: 'right',
          width: 140,
          key: 'payAmount',
          renderHeader: (h, params) => {
            return h('div', [
              h('Icon', {
                props: {
                  type: 'asterisk',
                  color: 'red',
                  size: '5px'
                },
                style: {
                  marginRight: '5px'
                }
              }),
              h('strong', '金额')
            ]);
          },
          render: (h, params) => {
            let flag = false;
            if (vm.payLineId != '' || vm.checkFlag) {
              flag = true;
            } else {
              flag = false;
            }
            return h(
              'Input',
              {
                props: {
                  value: vm.tableData[params.index].payAmount ? vm.tableData[params.index].payAmount.toFixed(2) : 0.00,
                  disabled: flag
                },
                on: {
                  'on-blur': event => {
                    vm.tableData[params.index].payAmount = Number(event.target.value);
                    if (event.target.value === '') {
                      vm.$Message.info('不能为空');
                      vm.tableData[params.index].payAmount = params.row.payAmount;
                      return;
                    }
                    if (!/^\-?(\d+|\d+\.\d{1,2})$/.test(event.target.value)) {
                      vm.$Message.info('必须为数字');
                      vm.tableData[params.index].payAmount = params.row.payAmount;
                      return;
                    }
                    if (event.target.value < 0) {
                      vm.$Message.info('金额必须大于等于0');
                      vm.tableData[params.index].payAmount = params.row.payAmount;
                      return;
                    }
                    if (vm.applyAmount - vm.money < 0) {
                      vm.$Message.info('已拆分金额必须小于等于申请金额');
                      // vm.tableData[params.index].payAmount = params.row.payAmount;
                      // return;
                    }
                    vm.buttons = [];
                    // vm.text =
                    //   '申请总金额：' +
                    //   `${accounting.formatNumber(vm.applyAmount, 2)}` +
                    //   // vm.applyAmount +
                    //   ';已拆分金额：' +
                    //   `${accounting.formatNumber(vm.money, 2)}` +
                    //   // vm.money +
                    //   ';待拆分金额：' +
                    //   `${accounting.formatNumber(
                    //     vm.applyAmount - vm.money,
                    //     2
                    //   )}`;
                    vm.moneyInfo.total = accounting.formatNumber(vm.applyAmount, 2);
                    vm.moneyInfo.wasSplit = accounting.formatNumber(vm.money, 2);
                    vm.moneyInfo.rest = accounting.formatNumber(vm.applyAmount - vm.money, 2);
                    vm.changeButtons(vm.text);
                  }
                }
              },
              '是'
            );
          }
        },
        {
          title: '资金计划',
          align: 'left',
          width: 200,
          key: 'fundPlan',
          renderHeader: (h, params) => {
            return h('div', [
              h('Icon', {
                props: {
                  type: 'asterisk',
                  color: 'red',
                  size: '5px'
                },
                style: {
                  marginRight: '5px'
                }
              }),
              h('strong', '资金计划')
            ]);
          },
          render: (h, params) => {
            if (vm.checkFlag || vm.paymentEdit) {
              vm.disabledFlag = true;
            }
            return h('DataSelect', {
              props: {
                value: params.row.fundPlan,
                code: 'capitalPlan'
              },
              attrs: {
                transfer: true,
                disabled: vm.disabledFlag
              },
              style: {
                width: '170px'
              },
              on: {
                input: data => {
                  vm.tableData[params.index].fundPlan = data;
                }
              }
            });
          }
        },
        {
          title: '摘要',
          align: 'left',
          minWidth: 170,
          key: 'summary',
          renderHeader: (h, params) => {
            return h('div', [
              h('Icon', {
                props: {
                  type: 'asterisk',
                  color: 'red',
                  size: '5px'
                },
                style: {
                  marginRight: '5px'
                }
              }),
              h('strong', '摘要')
            ]);
          },
          render: (h, params) => {
            if (vm.checkFlag || vm.paymentEdit) {
              vm.disabledFlag = true;
            }
            return h('Input', {
              props: {
                value: vm.tableData[params.index].summary,
                disabled: vm.disabledFlag,
                // maxlength: 7,
                placeholder: ''
              },
              on: {
                'on-blur': event => {
                  vm.tableData[params.index].summary = event.target.value;
                  // if (
                  //   vm.tableData[params.index].purpose == "" ||
                  //   vm.tableData[params.index].purpose == null
                  // ) {
                  vm.tableData[params.index].purpose =
                      vm.tableData[params.index].summary;
                  // }
                }
              },
              attrs: {
                placeholder: '摘要',
                title: vm.tableData[params.index].summary
              }
            });
          }
        }
      ]
    };
  },
  computed: {
    money: function() {
      const self = this;
      let useMoney = 0;
      if (self.tableData.length > 0) {
        for (let i = 0; i < self.tableData.length; i++) {
          useMoney += Number(self.tableData[i].payAmount);
        }
        return useMoney.toFixed(2);
      } else {
        return useMoney == 0.00;
      }
    }
  },
  watch: {
    tableData(newVal, oldVal) {
      const self = this;
      self.money = 0;
      for (let i = 0; i < newVal.length; i++) {
        self.money += parseFloat(newVal[i].payAmount);
      }
      vm.buttons = [];
      // vm.text =
      //   '申请总金额：' +
      //   `${accounting.formatNumber(vm.applyAmount, 2)}` +
      //   // vm.applyAmount +
      //   ';已拆分金额：' +
      //   `${accounting.formatNumber(vm.money, 2)}` +
      //   // vm.money +
      //   ';待拆分金额：' +
      //   `${accounting.formatNumber(vm.applyAmount - vm.money, 2)}`;
      vm.moneyInfo.total = accounting.formatNumber(vm.applyAmount, 2);
      vm.moneyInfo.wasSplit = accounting.formatNumber(vm.money, 2);
      vm.moneyInfo.rest = accounting.formatNumber(vm.applyAmount - vm.money, 2);
      // (vm.applyAmount - vm.money);
      vm.changeButtons(vm.text);
    }
  },
  created: function() {
    vm = this;
    this.$emit('SetTitle', this.title);
  },
  mounted: function() {
    // 判断是否是批页面

    /* 以this.categoryCode != ""来进行server.getPaymentModes的方法是多余的 */
    if (this.categoryCode != '') {
      // 查询付款 方式值集数据
      this.server.getPaymentModes({ categoryCode: this.categoryCode })
        .then(res => {
          if (res.statusCode == '-1') {
            this.$Message.error(res.msg);
          } else {
            this.paymentModeList = res;
          }
        });
    }
    /* 以this.categoryCode != ""来进行server.getPaymentModes的方法是多余的 */

    this.server.QueryValueSetByCode({ code: 'PAYMENT_MODE' }).then(response => {
      if (response.statusCode == '-1') {
        this.$Message.error(response.msg);
      } else {
        this.paymentModePayWayList = response;
      }
    });
    this.$emit('SetPageSize', window.innerWidth * 0.9);
    if (this.payLineId != '') {
      this.showAdd = false;
      this.server
        .queryCreatePaymentInfo({ payLineId: parseInt(this.payLineId) })
        .then(response => {
          if (response.statusCode == '-1') {
            this.$Message.error(response.msg);
          } else {
            for (let i = 0; i < response.length; i++) {
              if (response[i].prepareStatus == '1') {
                response[i]._disabled = true;
              }
            }
            this.tableData = response;
            for (let i = 0; i < this.tableData.length; i++) {
              if (
                this.tableData[i].purpose == '' ||
                this.tableData[i].purpose == null
              ) {
                this.tableData[i].purpose = this.tableData[i].summary;
              }
            }
            vm.buttons = [];
            // vm.text =
            //   '申请行总金额：' +
            //   this.applyAmount +
            //   ';已拆分金额：' +
            //   this.money +
            //   ';待拆分金额：' +
            //   (this.applyAmount - this.money);
            this.moneyInfo.total = this.applyAmount;
            this.moneyInfo.wasSplit = this.money;
            this.moneyInfo.total = this.applyAmount - this.money;
            this.changeButtons(vm.text);
          }
        });
    } else {
      this.showAdd = true;
      this.server
        .queryPaymentInfo({ payRequestLineId: this.payRequestLineId })
        .then(response => {
          if (response.statusCode == '-1') {
            this.$Message.error(response.msg);
          } else {
            this.tableData = response;
            for (let i = 0; i < this.tableData.length; i++) {
              if (
                this.tableData[i].purpose == '' ||
                this.tableData[i].purpose == null
              ) {
                this.tableData[i].purpose = this.tableData[i].summary;
              }
            }
            vm.buttons = [];
            this.moneyInfo.total = this.applyAmount;
            this.moneyInfo.wasSplit = this.money;
            this.moneyInfo.total = this.applyAmount - this.money;
            // vm.text =
            //   '申请行总金额：' +
            //   this.applyAmount +
            //   ';已拆分金额：' +
            //   this.money +
            //   ';待拆分金额：' +
            //   (this.applyAmount - this.money);
            this.changeButtons(vm.text);
          }
        });
    }
  },
  methods: {
    paymentChanges(row, sels) {
      const getParams = {
        index: row._index,
        // paymentMode: sels,
        paymentMethod: sels,
        categoryCode: this.categoryCode,
        ouCode: this.companyCode,
        ouName: this.compName,
        payAmount: this.tableData[row._index].payAmount
      };
      let newParams = {};
      this.server.changePaymentType(getParams).then((res) => {
        if (JSON.stringify(res) == '{}') {
          this.tableData[row._index].accountName = null;
          this.tableData[row._index].accountNo = null;
          this.$Message.info({
            content: '没有相关数据',
            duration: 3
          });
        } else {
          // 取accountName(账户名称) accountNo(账号) fundPlan(资金计划)
          const getPars = {
            accountName: res.accountName || '',
            accountNo: res.accountNo || '',
            // fundPlan: res.fundPlan || '',
            paymentMethod: getParams.paymentMethod,
            ouName: res.compName
          };
          if (this.isNowDraft === '1') {
            getPars.fundPlan = res.fundPlan || '';
          }
          newParams = Object.assign({}, row, getPars);
          this.tableData.splice(getParams.index, 1, newParams);
        }
      });
    },
    onSelectChange(d) {
      this.selections = d;
      if (d.length == 0) {
        this.money = '';
      }
    },
    deletePaymentInfo() {
      if (this.selections.length == 0) {
        this.$Message.info('至少勾选一条付款信息');
      } else {
        new $confirm('删除不可恢复，请谨慎操作', this).then(() => {
          let ids = '';
          const deleteData = this.tableData;
          for (let m = this.selections.length - 1; m >= 0; m--) {
            if (this.selections[m].payRequestLinePayInfoId != undefined) {
              if (ids.length == 0) {
                ids = this.selections[m].payRequestLinePayInfoId;
              } else {
                ids += ',' + this.selections[m].payRequestLinePayInfoId;
              }
            } else {
              for (let i = this.selections.length - 1; i >= 0; i--) {
                for (let j = 0; j < deleteData.length; j++) {
                  if (this.selections[i].payRequestLinePayInfoId != undefined) {
                  } else {
                    if (this.selections[i].random == deleteData[j].random) {
                      this.$nextTick(() => {
                        deleteData.splice(j, 1);
                        this.tableData = deleteData;
                        this.selections.splice(i, 1);
                      });
                    }
                  }
                }
              }
            }
          }
          if (ids != '') {
            const self = this;
            const param = {
              payRequestLineId: self.payRequestLineId,
              payRequestLinePayInfoIds: ids
            };
            self.server.deletePaymentInfo(param).then(response => {
              if (response.code == '0') {
                self.$Message.error(response.msg);
              } else {
                for (let n = self.selections.length - 1; n >= 0; n--) {
                  for (let k = 0; k < self.tableData.length; k++) {
                    if (
                      self.selections[n].payRequestLinePayInfoId ==
                      self.tableData[k].payRequestLinePayInfoId
                    ) {
                      this.$nextTick(() => {
                        deleteData.splice(k, 1);
                        this.tableData = deleteData;
                        this.selections.splice(n, 1);
                      });
                      // self.tableData.splice(k, 1);
                      // vm.tableData=self.tableData;
                      // self.selections.splice(n, 1);
                    }
                  }
                }
                self.$Message.success('删除成功');
                this.$emit('delete');
              }
            });
          }
        });
      }
    },
    savePaymentInfo() {
      // 首先校验金额是否拆分完成
      if (Number(this.applyAmount) - Number(this.money) != 0) {
        this.$Message.info('金额未拆分完成不能保存');
      } else {
        // 先校验金额
        for (let i = 0; i < this.tableData.length; i++) {
          this.tableData[i].documentConfigFile = '0';
          this.tableData[i].payDocument = '1';
          this.tableData[i].bankTransferType = '0';
          this.tableData[i].ouCode = vm.companyCode;
          if (
            this.tableData[i].payAmount === '' ||
            this.tableData[i].payAmount == null
          ) {
            this.$Message.info('保存金额不能为空');
            return;
          }
          if (
            this.tableData[i].paymentMethod == '' ||
            this.tableData[i].paymentMethod == null
          ) {
            this.$Message.info('付款方式不能为空');
            return;
          }
          if (
            this.tableData[i].ouName == '' ||
            this.tableData[i].ouName == null
          ) {
            this.$Message.info('实际付款公司不能为空');
            return;
          }
          if (
            this.tableData[i].accountName == '' ||
            this.tableData[i].accountName == null
          ) {
            this.$Message.info('银行账户名称不能为空');
            return;
          }
          if (
            this.tableData[i].accountNo == '' ||
            this.tableData[i].accountNo == null
          ) {
            this.$Message.info('银行账号不能为空');
            return;
          }
          if (
            this.tableData[i].fundPlan == '' ||
            this.tableData[i].fundPlan == null
          ) {
            this.$Message.info('资金计划不能为空');
            return;
          }
          if (
            this.tableData[i].summary == '' ||
            this.tableData[i].summary == null
          ) {
            this.$Message.info('摘要不能为空');
            return;
          }
          // if (
          //   this.tableData[i].purpose == "" ||
          //   this.tableData[i].purpose == null
          // ) {
          //   this.$Message.info("用途不能为空");
          //   return;
          // }
          // if (
          //   this.tableData[i].documentConfigFile == "" ||
          //   this.tableData[i].documentConfigFile == null
          // ) {
          //   this.$Message.info("数据处理配置文件不能为空");
          //   return;
          // }
        }
        // 保存之前先给按钮参数saveFlag设置true，防止用户多次连着点击
        if (!this.saveFlag) {
          this.saveFlag = true;
        } else {
          return;
        }
        if (this.payLineId != '') {
          vm.buttons = [];
          vm.buttons.push({
            text: '保存',
            theme: 'warning',
            icon: 'ios-checkmark-outline',
            action: 'saveBtn',
            handle: () => {
              vm.savePaymentInfo();
            }
          });
          vm.buttons.push({
            text: vm.text,
            theme: 'text',
            handle: () => {}
          });
          vm.$emit('SetPageActions', vm.buttons);
          // if (this.selections.length == 0) {
          //   this.$Message.info("请至少勾选一条付款信息");
          // } else {
          this.$emit('SetActionsState', {
            btn: 'saveBtn',
            state: true
          });
          const pramsArr = [];
          for (let i = 0; i < this.tableData.length; i++) {
            if (this.tableData[i].prepareStatus != '1') {
              pramsArr.push({
                payLinePayInfoId: this.tableData[i].payLinePayInfoId,
                accountName: this.tableData[i].accountName,
                accountNo: this.tableData[i].accountNo,
                ouCode: this.tableData[i].ouCode,
                ouName: this.tableData[i].ouName,
                paymentMethod: this.tableData[i].paymentMethod
              });
            }
          }
          this.server
            // .saveCreatePaymentInfo({payLineId: parseInt(this.payLineId),payLinePayInfoList: this.selections})
            .saveCreatePaymentInfo(pramsArr)
            .then(response => {
              // 保存接口返回后再讲按钮参数设置false
              vm.saveFlag = false;
              vm.buttons = [];
              vm.buttons.push({
                text: '保存',
                theme: 'warning',
                icon: 'ios-checkmark-outline',
                action: 'saveBtn',
                handle: () => {
                  vm.savePaymentInfo();
                }
              });
              // vm.buttons.push({
              //   text: vm.text,
              //   theme: 'text',
              //   handle: () => {}
              // });
              vm.$emit('SetPageActions', vm.buttons);
              this.$emit('SetActionsState', {
                btn: 'saveBtn',
                state: false
              });
              if (response.sucess) {
                this.$Message.success('保存成功');
                this.$emit('save');
                this.$emit('Close');
              } else {
                this.$Message.error(response.msg);
              }
            });
          // }
        } else {
          vm.buttons = [];
          vm.buttons.push({
            text: '保存',
            theme: 'warning',
            icon: 'ios-checkmark-outline',
            action: 'saveBtn',
            handle: () => {
              vm.savePaymentInfo();
            }
          });
          vm.buttons.push({
            text: '新增',
            theme: 'warning',
            icon: 'ios-plus-outline',
            handle: () => {
              vm.addPaymentInfo();
            }
          });
          vm.buttons.push({
            text: '删除',
            theme: 'warning',
            icon: 'ios-minus-outline',
            loading: true,
            handle: () => {
              vm.deletePaymentInfo();
            }
          });
          // vm.buttons.push({
          //   text: vm.text,
          //   theme: 'text',
          //   handle: () => {}
          // });
          vm.$emit('SetPageActions', vm.buttons);
          this.$emit('SetActionsState', {
            btn: 'saveBtn',
            state: true
          });
          this.server.savePaymentInfo(this.tableData).then(response => {
            // 保存接口返回后再讲按钮参数设置false
            vm.saveFlag = false;
            vm.buttons = [];
            vm.buttons.push({
              text: '保存',
              theme: 'warning',
              icon: 'ios-checkmark-outline',
              action: 'saveBtn',
              handle: () => {
                vm.savePaymentInfo();
              }
            });
            vm.buttons.push({
              text: '新增',
              theme: 'warning',
              icon: 'ios-plus-outline',
              handle: () => {
                vm.addPaymentInfo();
              }
            });
            vm.buttons.push({
              text: '删除',
              theme: 'warning',
              loading: false,
              icon: 'ios-minus-outline',
              handle: () => {
                vm.deletePaymentInfo();
              }
            });
            // vm.buttons.push({
            //   text: vm.text,
            //   theme: 'text',
            //   handle: () => {}
            // });
            vm.$emit('SetPageActions', vm.buttons);
            this.$emit('SetActionsState', {
              btn: 'saveBtn',
              state: false
            });
            if (response.sucess) {
              this.$Message.success('保存成功');
              this.initFun();
              this.refreshFun();
              this.$emit('save');
              this.$emit('Close');
            } else {
              this.$Message.error(response.msg);
            }
          });
        }
      }
    },
    changeButtons(text) {
      if (vm.checkFlag) {
        if (vm.isPaymentCreate) {
          vm.buttons.push({
            text: '保存',
            theme: 'warning',
            icon: 'ios-checkmark-outline',
            action: 'saveBtn',
            handle: () => {
              vm.savePaymentInfo();
            }
          });
          this.showMoneyInfo = true;
          // vm.buttons.push({
          //   text: text,
          //   theme: 'text',
          //   handle: () => {}
          // });
        } else {
          this.showMoneyInfo = true;
          // vm.buttons.push({
          //   text: text,
          //   theme: 'text',
          //   handle: () => {}
          // });
        }
      } else {
        if (vm.payLineId != '') {
          vm.buttons.push({
            text: '保存',
            theme: 'warning',
            icon: 'ios-checkmark-outline',
            action: 'saveBtn',
            handle: () => {
              vm.savePaymentInfo();
            }
          });
          this.showMoneyInfo = true;
          // vm.buttons.push({
          //   text: text,
          //   theme: 'text',
          //   handle: () => {}
          // });
        } else {
          this.showMoneyInfo = false;
          vm.buttons.push({
            text: '保存',
            theme: 'warning',
            icon: 'ios-checkmark-outline',
            action: 'saveBtn',
            handle: () => {
              vm.savePaymentInfo();
            }
          });
          vm.buttons.push({
            text: '新增',
            theme: 'warning',
            icon: 'ios-plus-outline',
            handle: () => {
              vm.addPaymentInfo();
            }
          });
          vm.buttons.push({
            text: '删除',
            theme: 'warning',
            icon: 'ios-minus-outline',
            handle: () => {
              vm.deletePaymentInfo();
            }
          });
          this.showMoneyInfo = true;
          // vm.buttons.push({
          //   text: text,
          //   theme: 'text',
          //   handle: () => {}
          // });
        }
      }

      vm.$emit('SetPageActions', vm.buttons);
    },
    addPaymentInfo() {
      let configFileCode = '';
      let payTp = '';
      let transfersType = '';
      if (this.configFileCodeList.length > 0) {
        configFileCode = this.configFileCodeList[0].value;
      }
      if (this.payTpList.length > 0) {
        payTp = this.payTpList[0].value;
      }
      if (this.transfersTypeList.length > 0) {
        transfersType = this.transfersTypeList[0].value;
      }
      this.tableData.push({
        random: Math.random(),
        payRequestLineId: this.payRequestLineId,
        addFlag: true,
        paymentMethod: '',
        ouName: '',
        accountName: '',
        accountNo: '',
        payAmount: 0,
        fundPlan: '',
        // remittanceSpeed: "",
        summary: '',
        purpose: '',
        documentConfigFile: configFileCode,
        payDocument: payTp,
        // tpCode: tpCode,
        // settleType: settleType,
        bankTransferType: transfersType
      });
    }
  }
};
</script>
<style lang="less" scoped>
.money-info-box {
  display: flex;
  float: right;
  padding-top: 20px;

  .money-info-item {
    font-size: 12px;
    color: #424656;
    height: 20px;
    span {
      font-size: 16px;
      color: #F99C34;
      font-weight: 600;
    }
  }
  .money-info-item:not(:last-child){
    padding: 0 16px;
    border-right: 1px solid #E0E1E3;
  }
  .money-info-item:last-child{
    padding-left: 16px;
  }
}
</style>
