<!-- 成交登记 -->
<template>
  <div class="p20">
    <SearchForm v-show="showSearch" ref="SearchForm" @search="_getTableList" />
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" @click="handleAdd">新增</el-button>
        <el-button type="warning" icon="el-icon-download" @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :show-search.sync="showSearch" :columns="columns" @queryTable="_getTableList" />
    </el-row>
    <el-table v-loading="loading" :data="tableList">
      <el-table-column type="selection" width="50" align="center" />
      <template v-for="item in columns">
        <el-table-column v-if="item.visible" :key="item.prop" :label="item.label" align="center" min-width="100" :prop="item.prop" />
      </template>
      <el-table-column label="操作" fixed="right" align="center" width="160">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">修改</el-button>
          <el-button type="text" @click="handleCheck(scope.row)">审核</el-button>
          <el-button type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination :total="total" :page.sync="searchForm.pageNum" :limit.sync="searchForm.pageSize" @pagination="_getTableList" />
  </div>
</template>

<script>
import SearchForm from './components/SearchForm.vue';
import { defaultColumns } from './columns.js';
export default {
  components: {
    SearchForm
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      searchForm: {
        pageNum: 1,
        pageSize: 20
      },
      tableList: [],
      total: 0,
      columns: []
    };
  },
  created() {
    const str = localStorage.getItem(`${this.$route.name}-table-columns`);
    this.columns = str ? JSON.parse(str) : defaultColumns;
    // this._getTableList();
  },
  methods: {
    async _getTableList() {
      const tempForm = this.$refs.SearchForm?.searchForm || {};
      const params = { ...this.searchForm, ...tempForm };
      console.log(params);
      // api.list(params)
      this.tableList = [];
      for (let i = 0; i < 20; i++) {
        this.tableList.push({ name: `数据${i + 1}` });
      }
    },
    handleExport() {
      const tempForm = this.$refs.SearchForm?.searchForm || {};
      const params = { ...this.searchForm, ...tempForm };
      this.$confirm('是否确认导出所有成交记录项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then((resp) => {
          // return exportData(params)
        })
        .then((response) => {
          // this.download(response.msg);
        })
        .catch(function () {});
    },
    handleAdd() {}
  }
};
</script>

<style lang="scss" scoped>
</style>
