<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:office:add']">新增</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="_getTableList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="officeList">
      <el-table-column type="index" width="55" align="center" />
      <el-table-column label="报名点名称" align="center" prop="officeName" />
      <el-table-column label="负责人" align="center" prop="leader" />
      <el-table-column label="联系方式" align="center" prop="phone" />
      <el-table-column label="推送驾校" align="center" prop="schoolNames" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" 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:office:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['zs:office: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" />

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

  </div>
</template>

<script>
import { listOffice, getOffice, delOffice, } from "@/api/zs/office";
import SearchForm from "./components/SearchForm.vue";
import OfiiceDialogForm from "./components/OfiiceDialogForm.vue";

export default {
  name: "Office",
  components: {
    SearchForm, OfiiceDialogForm
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 报名点表格数据
      officeList: [],
      // 查询参数
      searchForm: {
        pageNum: 1,
        pageSize: 10,
      },
      dialogVisible: false
    };
  },
  created() {
    this._getTableList();
  },
  methods: {
    /** 查询报名点列表 */
    _getTableList() {
      this.loading = true;
      const tempForm = this.$refs.SearchForm?.searchForm || {};
      const params = { ...this.searchForm, ...tempForm };
      listOffice(params).then(response => {
        this.officeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this._getTableList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAddAndUpdate(item) {
      this.dialogVisible = true;
      this.$nextTick(() => {
        this.$refs.dialogForm.init(item);
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const officeIds = row.officeId || this.ids;
      this.$modal.confirm('是否确认删除报名点编号为"' + officeIds + '"的数据项？').then(function () {
        return delOffice(officeIds);
      }).then(() => {
        this._getTableList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/office/export', {
        ...this.queryParams
      }, `office_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
