<template>
  <div>
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="80%"
      @close="close"
    >
      <span>
        <el-table
          :data="tableData"
          style="width: 100%"
          @selection-change="selectionChange"
        >
          <el-table-column
            type="selection"
            width="50"
            :selectable="selectable"
          />
          <el-table-column label="序号" type="index" width="50" />
          <el-table-column
            v-for="(item, index) in tableOption"
            :key="index"
            :label="item.name"
            :width="item.width"
            :prop="item.label"
            align="center"
            :fixed="item.fixed"
            :show-overflow-tooltip="true"
          >
          </el-table-column>
        </el-table>
        <pagination
          v-show="page.total > 0"
          :total="page.total"
          :page.sync="page.pageNum"
          :limit.sync="page.pageSize"
          @pagination="getList"
        />
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="importDate">导 入</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { tableOption2 } from "./js/index";
import { contrastList } from "@/api/finance/kaihe/contrast";
export default {
  data() {
    return {
      form: {},
      dialogVisible: false,
      tableOption: tableOption2,
      page: {
        pageNum: 1,
        pageSize: 10,
        total: 0,
      },
      selectionList: [],
      tableData: [],
      checkList: [],
    };
  },
  components: {},
  created() {},
  methods: {
    selectable(row) {
      if (this.checkList.some((e) => e.fSrcid == row.fSrcid)) {
        return false;
      } else {
        return true;
      }
    },
    init(data, list) {
      this.checkList = list;
      this.dialogVisible = true;
      this.form = data;
      this.getList();
    },
    getList() {
      const data = {
        ...this.form,
        pageNum: this.page.pageNum,
        pageSize: this.page.pageSize,
      };
      contrastList(data).then((res) => {
        this.tableData = res.rows;
        this.page.total = res.total;
      });
    },
    selectionChange(rows) {
      this.selectionList = rows;
    },
    importDate() {
      if (this.selectionList.length == 0) {
        return this.$message.error("请选择数据");
      }
      (this.dialogVisible = false), this.$emit("imporData", this.selectionList);
    },
    close() {
      this.form = this.$options.data().form;
      this.tableData = this.$options.data().tableData;
      this.page = this.$options.data().page;
    },
  },
};
</script>
<style lang="scss" scoped></style>
