<template>
  <el-dialog
    title="选择对账单"
    custom-class="ele-dialog-form long-dialog-form"
    :visible.sync="accountstatementDialogFlag"
    :before-close="handleClose"
    :close-on-click-modal="false"
    top="5vh"
    :close-on-press-escape="false"
    append-to-body
    width="70%"
  >
    <el-card shadow="never">
      <search @search="reload"></search>
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        row-key="id"
        height="calc(100vh - 500px)"
        class="dict-table"
      >
        <!-- 表头工具栏 -->
        <template v-slot:action="{ row }">
          <el-button size="mini" type="text" @click="handleSelect(row)">对账明细</el-button>
        </template>
      </ele-pro-table>
    </el-card>

    <div slot="footer">
      <el-button size="small" @click="handleClose">关闭</el-button>
    </div>
    <!-- 对账明细   -->
    <accountInfoDialog ref="accountInfoDialogRef"
                       v-if="accountInfoDialogFlag"
                       :account-info-dialog-flag.sync="accountInfoDialogFlag"
    @getAccountInfo="getAccountInfo"></accountInfoDialog>
  </el-dialog>
</template>

<script>
import search from './accountstatementSearch.vue';
import {getAccountstatementList} from "@/api/saleManage/accountstatement";
import accountInfoDialog from "./accountInfoDialog.vue";

export default {
  components: {
    search,
    accountInfoDialog
  },
  props: {
    form: {
      type: Object,
      default: () => {
        return {}
      }
    },
    accountstatementDialogFlag: {
      default: false,
      type: Boolean
    },
  },
  data() {
    return {
      currentIndex: null,
      accountInfoDialogFlag: false,
      columns: [
        {
          columnKey: 'index',
          label: '序号',
          type: 'index',
          width: 55,
          align: 'center',
          showOverflowTooltip: true,
          fixed: 'left'
        },
        {
          action: 'action',
          slot: 'action',
          align: 'center',
          label: '选择',
          fixed: 'left'
        },
        {
          prop: 'statementNo',
          label: '对账单编码',
          align: 'center',
          slot: 'statementNo',
          showOverflowTooltip: true,
          minWidth: 200
        },
        {
          prop: 'contactName',
          label: '客户名称',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 180
        },
        {
          prop: 'startDate',
          label: '对账开始日期',
          align: 'center',
          slot: 'startDate',
          showOverflowTooltip: true,
          minWidth: 200
        },
        {
          prop: 'endDate',
          label: '对账结束日期',
          align: 'center',
          slot: 'endDate',
          showOverflowTooltip: true,
          minWidth: 200
        },
        {
          prop: 'amountTotalPrice',
          label: '总金额',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 130
        },
        {
          prop: 'amountReceivablePrice',
          label: '应收金额',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 130
        },
        {
          prop: 'amountPayablePrice',
          label: '应付金额',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 130
        },
        {
          prop: 'createTime',
          label: '创建时间',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 170
        },
      ],
      currentRow:{},
      radio: null
    };
  },

  methods: {
    init(item = {}, currentIndex = '') {
      this.currentIndex = currentIndex;
      // if (item.id) {
      //   this.radio = item.id;
      // }
    },
    getAccountInfo(item) {
      this.currentRow.children = item;
      this.$emit('getAccountData', this.currentRow);
      this.handleClose()
    },
    /* 表格数据源 */
    datasource({page, limit, where, order}) {
      return getAccountstatementList({
        pageNum: page,
        size: limit,
        ...where,
        reviewStatus: 2,

      });
    },

    /* 刷新表格 */
    reload(where) {
      this.$refs.table.reload({pageNum: 1, where: where});
    },
    handleSelect(row, index) {
      this.currentRow = row
      this.accountInfoDialogFlag = true;
      this.$nextTick(() => {
        this.$refs.accountInfoDialogRef.init(row, index);
      })
    },
    handleClose() {
      this.$emit('update:accountstatementDialogFlag', false)
    },
  }
};
</script>

<style lang="scss" scoped>
.tree_col {
  border: 1px solid #eee;
  padding: 10px 0;
  box-sizing: border-box;
  height: 500px;
  overflow: auto;
}

.table_col {
  padding-left: 10px;

  ::v-deep .el-table th.el-table__cell {
    background: #f2f2f2;
  }
}

.pagination {
  text-align: right;
  padding: 10px 0;
}

.btns {
  text-align: center;
  padding: 10px 0;
}

.topsearch {
  margin-bottom: 15px;
}
</style>
