<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="访客电子卡号/学工号" prop="visitorCardNumber">
              <el-input
                v-model="queryParams.visitorCardNumber"
                placeholder="请输入访客电子卡号/学工号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="访客姓名" prop="visitorName">
              <el-input
                v-model="queryParams.visitorName"
                placeholder="请输入访客姓名"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="访客手机号" prop="visitorPhone">
              <el-input
                v-model="queryParams.visitorPhone"
                placeholder="请输入访客手机号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="受访人电子卡号/学工号" prop="cardNumber">
              <el-input
                v-model="queryParams.cardNumber"
                placeholder="请输入受访人电子卡号/学工号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="受访人姓名" prop="memberName">
              <el-input
                v-model="queryParams.memberName"
                placeholder="请输入受访人姓名"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="受访人手机号" prop="memberPhone">
              <el-input
                v-model="queryParams.memberPhone"
                placeholder="请输入受访人手机号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="受访人所在部门" prop="memberOrg">
              <el-input
                v-model="queryParams.memberOrg"
                placeholder="请输入受访人所在部门"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="到访事由" prop="reason">
              <el-input
                v-model="queryParams.reason"
                placeholder="请输入到访事由"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="状态" prop="statusWithTime">
              <el-input
                v-model="queryParams.statusWithTime"
                placeholder="请输入状态"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="补充证件图片路径" prop="idCardImg">
              <el-input
                v-model="queryParams.idCardImg"
                placeholder="请输入补充证件图片路径"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="预约起始时间" prop="visitStartTime">
              <el-input
                v-model="queryParams.visitStartTime"
                placeholder="请输入预约起始时间"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="预约结束时间" prop="visitEndTime">
              <el-input
                v-model="queryParams.visitEndTime"
                placeholder="请输入预约结束时间"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="预约申请时间" prop="createdTime">
              <el-input
                v-model="queryParams.createdTime"
                placeholder="请输入预约申请时间"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="实际到访时间" prop="visitedAt">
              <el-input
                v-model="queryParams.visitedAt"
                placeholder="请输入实际到访时间"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="扩展-到访事由" prop="visitReason">
              <el-input
                v-model="queryParams.visitReason"
                placeholder="请输入扩展-到访事由"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="扩展-到访部门" prop="visitingDepartments">
              <el-input
                v-model="queryParams.visitingDepartments"
                placeholder="请输入扩展-到访部门"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="扩展-被访问人" prop="interviewee">
              <el-input
                v-model="queryParams.interviewee"
                placeholder="请输入扩展-被访问人"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="扩展-进厂日期" prop="dateOfArrival">
              <el-input
                v-model="queryParams.dateOfArrival"
                placeholder="请输入扩展-进厂日期"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="扩展-访客单位" prop="visitorUnit">
              <el-input
                v-model="queryParams.visitorUnit"
                placeholder="请输入扩展-访客单位"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="扩展-证件号码" prop="idNumber">
              <el-input
                v-model="queryParams.idNumber"
                placeholder="请输入扩展-证件号码"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="扩展-车牌号码" prop="licensePlateNumber">
              <el-input
                v-model="queryParams.licensePlateNumber"
                placeholder="请输入扩展-车牌号码"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="扩展-访问地点" prop="visitPlace">
              <el-input
                v-model="queryParams.visitPlace"
                placeholder="请输入扩展-访问地点"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['visit:book:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['visit:book:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['visit:book:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['visit:book:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="bookList"  @sort-change="handleSortChange"  @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
              <el-table-column label="主键ID" align="center" prop="id" sortable='custom' />
              <el-table-column label="访客电子卡号/学工号" align="center" prop="visitorCardNumber" sortable='custom' />
              <el-table-column label="访客姓名" align="center" prop="visitorName" sortable='custom' />
              <el-table-column label="访客手机号" align="center" prop="visitorPhone" sortable='custom' />
              <el-table-column label="受访人电子卡号/学工号" align="center" prop="cardNumber" sortable='custom' />
              <el-table-column label="受访人姓名" align="center" prop="memberName" sortable='custom' />
              <el-table-column label="受访人手机号" align="center" prop="memberPhone" sortable='custom' />
              <el-table-column label="受访人所在部门" align="center" prop="memberOrg" sortable='custom' />
              <el-table-column label="到访事由" align="center" prop="reason" sortable='custom' />
              <el-table-column label="状态" align="center" prop="statusWithTime" sortable='custom' />
              <el-table-column label="补充证件图片路径" align="center" prop="idCardImg" sortable='custom' />
              <el-table-column label="预约起始时间" align="center" prop="visitStartTime" sortable='custom' />
              <el-table-column label="预约结束时间" align="center" prop="visitEndTime" sortable='custom' />
              <el-table-column label="预约申请时间" align="center" prop="createdTime" sortable='custom' />
              <el-table-column label="实际到访时间" align="center" prop="visitedAt" sortable='custom' />
              <el-table-column label="扩展-到访事由" align="center" prop="visitReason" sortable='custom' />
              <el-table-column label="扩展-到访部门" align="center" prop="visitingDepartments" sortable='custom' />
              <el-table-column label="扩展-被访问人" align="center" prop="interviewee" sortable='custom' />
              <el-table-column label="扩展-进厂日期" align="center" prop="dateOfArrival" sortable='custom' />
              <el-table-column label="扩展-访客单位" align="center" prop="visitorUnit" sortable='custom' />
              <el-table-column label="扩展-证件号码" align="center" prop="idNumber" sortable='custom' />
              <el-table-column label="扩展-车牌号码" align="center" prop="licensePlateNumber" sortable='custom' />
              <el-table-column label="备注" align="center" prop="remark" sortable='custom' />
              <el-table-column label="扩展-访问地点" align="center" prop="visitPlace" sortable='custom' />
      <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="handleUpdate(scope.row)"
            v-hasPermi="['visit:book:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['visit:book:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      hide-on-single-page
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改访客预约信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="70%" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
                <el-col :span="12">
                  <el-form-item label="访客电子卡号/学工号" prop="visitorCardNumber">
                    <el-input v-model="form.visitorCardNumber" placeholder="请输入访客电子卡号/学工号" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="访客姓名" prop="visitorName">
                    <el-input v-model="form.visitorName" placeholder="请输入访客姓名" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="访客手机号" prop="visitorPhone">
                    <el-input v-model="form.visitorPhone" placeholder="请输入访客手机号" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="受访人电子卡号/学工号" prop="cardNumber">
                    <el-input v-model="form.cardNumber" placeholder="请输入受访人电子卡号/学工号" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="受访人姓名" prop="memberName">
                    <el-input v-model="form.memberName" placeholder="请输入受访人姓名" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="受访人手机号" prop="memberPhone">
                    <el-input v-model="form.memberPhone" placeholder="请输入受访人手机号" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="受访人所在部门" prop="memberOrg">
                    <el-input v-model="form.memberOrg" placeholder="请输入受访人所在部门" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="到访事由" prop="reason">
                    <el-input v-model="form.reason" placeholder="请输入到访事由" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="状态" prop="statusWithTime">
                    <el-input v-model="form.statusWithTime" placeholder="请输入状态" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="补充证件图片路径" prop="idCardImg">
                    <el-input v-model="form.idCardImg" placeholder="请输入补充证件图片路径" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="预约起始时间" prop="visitStartTime">
                    <el-input v-model="form.visitStartTime" placeholder="请输入预约起始时间" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="预约结束时间" prop="visitEndTime">
                    <el-input v-model="form.visitEndTime" placeholder="请输入预约结束时间" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="预约申请时间" prop="createdTime">
                    <el-input v-model="form.createdTime" placeholder="请输入预约申请时间" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="实际到访时间" prop="visitedAt">
                    <el-input v-model="form.visitedAt" placeholder="请输入实际到访时间" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="扩展-到访事由" prop="visitReason">
                    <el-input v-model="form.visitReason" placeholder="请输入扩展-到访事由" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="扩展-到访部门" prop="visitingDepartments">
                    <el-input v-model="form.visitingDepartments" placeholder="请输入扩展-到访部门" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="扩展-被访问人" prop="interviewee">
                    <el-input v-model="form.interviewee" placeholder="请输入扩展-被访问人" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="扩展-进厂日期" prop="dateOfArrival">
                    <el-input v-model="form.dateOfArrival" placeholder="请输入扩展-进厂日期" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="扩展-访客单位" prop="visitorUnit">
                    <el-input v-model="form.visitorUnit" placeholder="请输入扩展-访客单位" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="扩展-证件号码" prop="idNumber">
                    <el-input v-model="form.idNumber" placeholder="请输入扩展-证件号码" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="扩展-车牌号码" prop="licensePlateNumber">
                    <el-input v-model="form.licensePlateNumber" placeholder="请输入扩展-车牌号码" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="备注" prop="remark">
                    <el-input v-model="form.remark" placeholder="请输入备注" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="扩展-访问地点" prop="visitPlace">
                    <el-input v-model="form.visitPlace" placeholder="请输入扩展-访问地点" />
                  </el-form-item>
                </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { pageListBook, getBook, delBook, addBook, updateBook } from "@/api/visit/book";

  export default {
    name: "Book",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 选中名字
        names: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 访客预约信息表格数据
              bookList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
                    visitorCardNumber: null,
                    visitorName: null,
                    visitorPhone: null,
                    cardNumber: null,
                    memberName: null,
                    memberPhone: null,
                    memberOrg: null,
                    reason: null,
                    statusWithTime: null,
                    idCardImg: null,
                    visitStartTime: null,
                    visitEndTime: null,
                    createdTime: null,
                    visitedAt: null,
                    visitReason: null,
                    visitingDepartments: null,
                    interviewee: null,
                    dateOfArrival: null,
                    visitorUnit: null,
                    idNumber: null,
                    licensePlateNumber: null,
                    visitPlace: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询访客预约信息列表 */
      getList() {
        this.loading = true;
        pageListBook(this.queryParams).then(response => {
          this.bookList = response.rows;
          this.total = response.total;
          this.loading = false;
        }).catch(e => {
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
                    id: null,
                    visitorCardNumber: null,
                    visitorName: null,
                    visitorPhone: null,
                    cardNumber: null,
                    memberName: null,
                    memberPhone: null,
                    memberOrg: null,
                    reason: null,
                    statusWithTime: null,
                    idCardImg: null,
                    visitStartTime: null,
                    visitEndTime: null,
                    createdTime: null,
                    visitedAt: null,
                    visitReason: null,
                    visitingDepartments: null,
                    interviewee: null,
                    dateOfArrival: null,
                    visitorUnit: null,
                    idNumber: null,
                    licensePlateNumber: null,
                    remark: null,
                    visitPlace: null,
        };
        this.resetForm("form");
      },
      //排序
      handleSortChange(col) {
        this.$sortBy(col, this.queryParams);
        this.getList();
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id);
        this.names = selection.map(item => item.id);
        this.single = selection.length!==1;
        this.multiple = !selection.length;
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加访客预约信息";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids;
        getBook(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改访客预约信息";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateBook(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addBook(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        const names = row.id || this.names;
        this.$modal.confirm('是否确认删除访客预约信息为"' + names + '"的数据项？').then(function() {
          return delBook(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
  /** 导出按钮操作 */
  handleExport() {
    this.download('visit/book/export', {
      ...this.queryParams
    }, `book_${new Date().getTime()}.xlsx`)
  }
  }
  };
</script>
