<template>
  <div>
    <Form ref="reimDetTableForm" :model="tableData" class="expand-table">
      <Table @on-select-all="onSelectAll" ref="reimDetTable" :columns="columns" :data="applyPayExpandList" @on-select="onSelect" @on-select-cancel="onSelectCannel"></Table>
    </Form>
  </div>
</template>

<script>
import { mapState } from "vuex";
import Server from "../server.js";
let server = new Server();

export default {
  data() {
    return {
      server: server,
      tableData: []
    };
  },
  components: {},
  props: {
    applyPayExpandList: {
      type: Array,
      default() {
        return [];
      }
    },
    row: {
      type: Object,
      default() {
        return {};
      }
    },
    columns: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  computed: {
    ...mapState("createPaymentPreparation", {
      selections: state => state.paymentSelects.selections
    })
  },
  mounted: function() {
    let self = this;
    self.server
      .queryPaymentInfo({
        payRequestLineId: self.row.payRequestLineId
      })
      .then(response => {
        if (response.stateCode == -1) {
          this.$Message.success(response.msg);
        } else {
          this.applyPayExpandList = response;
        }
      });
  },
  methods: {
    onSelectAll(selection) {
      let self = this;
      if (selection.length == 0) {
        for (let i = self.selections.length - 1; i >= 0; i--) {
          if (self.row.payWay == self.selections[i].payWay) {
            self.selections.splice(i, 1);
          }
        }
      } else {
        for (let j = 0; j < self.applyPayExpandList.length; j++) {
          let flag = true;
          for (let m = 0; m < self.selections.length; m++) {
            if (
              self.applyPayExpandList[j].payLineDetailId ==
              self.selections[m].payLineDetailId
            ) {
              flag = false;
              break;
            }
          }
          if (flag) {
            self.selections.push(self.applyPayExpandList[j]);
            flag = true;
          }
        }
      }
    },
    onSelect(selection, row) {
      row.checkStatus = true;
      this.selections.push(row);
    },
    onSelectCannel(selection, row) {
      for (let i = 0; i < this.selections.length; i++) {
        if (this.selections[i].payLineId == row.payLineId) {
          this.selections[i].checkStatus = false;
          this.selections.splice(i, 1);
          break;
        }
      }
    }
  }
};
</script>
<style>
/* .expand-table {
  margin-left: 20px;
} */
</style>


