<template>
  <div class="app-container">
    <!-- 搜索插件 -->
    <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" size="mini" @click="handleAddAndUpdate(undefined)" v-hasPermi="['zs:officeSign:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['zs:officeSign:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" :columns="columns" @queryTable="_getTableList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="signList">
      <el-table-column type="index" width="55" align="center" />
      <template v-for="item in columns">
        <el-table-column v-if="item.visible" :key="item.key" :label="item.label" align="center" :width="item.width" :prop="item.prop" :show-overflow-tooltip="item.overflow" />
      </template>
      <el-table-column align="center" width="100" fixed="right" label="审核状态">
        <template slot-scope="{row}">
          <el-button type="danger" size="mini" v-if="row.checkState == 1">待审核</el-button>
          <el-button type="success" size="mini" v-else-if="row.checkState == 2">已审核</el-button>
          <el-button type="warning" size="mini" v-else-if="row.checkState == 3">驳回</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleAddAndUpdate(scope.row)" v-hasPermi="['zs:officeSign:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleCheck(scope.row)" v-hasPermi="['zs:officeSign:check']">审核</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['zs:officeSign:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="searchForm.pageNum" :limit.sync="searchForm.pageSize" @pagination="_getTableList" />

    <!-- 添加或修改报名点成交登记对话框 -->
    <PlaceSignDialogForm v-if="dialogVisible" ref="dialogForm" :dialog-visible="dialogVisible" @refreshDataList="_getTableList" :signPlaceOptions="signPlaceOptions" />

  </div>
</template>

<script>
import { listSign, getSign, delSign } from "@/api/zs/placeSign";
import SearchForm from "./components/SearchForm.vue";
import PlaceSignDialogForm from "./components/PlaceSignDialogForm.vue";
import { defaultColumns } from './columns.js';


export default {
  name: "PlaceSign",
  components: {
    SearchForm, PlaceSignDialogForm
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 报名点成交登记表格数据
      signList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      searchForm: {
        pageNum: 1,
        pageSize: 10
      },
      columns: [],
      dialogVisible: false,
      signPlaceOptions: []
    };
  },
  created() {
    const str = localStorage.getItem(`${this.$route.name}-table-columns`);
    this.columns = str ? JSON.parse(str) : defaultColumns;
    this._getTableList();

    // 报名点
    this.getDicts('sign_place').then((response) => {
      this.signPlaceOptions = response.data;
    });

  },
  methods: {
    /** 查询报名点成交登记列表 */
    _getTableList() {
      this.loading = true;
      const tempForm = this.$refs.SearchForm?.searchForm || {};
      const params = { ...this.searchForm, ...tempForm };
      listSign(params).then(response => {
        this.signList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.officeSignId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAddAndUpdate(item) {
      this.dialogVisible = true;
      this.$nextTick(() => {
        this.$refs.dialogForm.init(item, 1);
      });
    },
    /** 审核 */
    handleCheck(item) {
      this.dialogVisible = true;
      this.$nextTick(() => {
        this.$refs.dialogForm.init(item, 2);
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const officeSignIds = row.officeSignId || this.ids;
      this.$modal.confirm('是否确认删除报名点成交登记编号为"' + officeSignIds + '"的数据项？').then(function () {
        return delSign(row.officeSignId);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      const tempForm = this.$refs.SearchForm?.searchForm || {};
      const params = { ...this.searchForm, ...tempForm };
      this.download('zs/officeSign/export', params, `报名点登记_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
