<template>
  <div class="app-container">
    <div style="background-color: #fff;padding: 20px;border-radius: 10px;">
      <p style="margin: 0; font-weight: 800;font-size: 16px;color: #343434;display: flex;align-items: center;margin-bottom: 20px;">
        <img src="../../../assets/images/icon_htgl_btzs.png" alt="" style="width: 16px;height: 20px;">
       <span style="margin-left: 10px;">预约管理</span>
      </p>
      <div style="background: #F3F3F3;padding: 20px 15px; padding-bottom: 0;margin-bottom: 20px;">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-row>

        <el-col :span="8">
          <el-form-item label="访客姓名" prop="name">
            <el-input
              v-model="queryParams.name"
              placeholder="请输入访客姓名"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="手机号码" prop="mobileNumber">
            <el-input
              v-model="queryParams.mobileNumber"
              placeholder="请输入手机号码"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="是否驾车 " prop="isCar">
            <el-select v-model="queryParams.isCar" placeholder="请选择是否驾车" clearable>
                      <el-option
                        v-for="dict in dict.type.sys_yes_no"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                      />
                    </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="状态" prop="status">
            <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
              <el-option
                v-for="dict in dict.type.yuyetype"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item class="butt">
            <el-button type="primary"  size="mini" @click="handleQuery">搜索</el-button>
            <el-button  size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>

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

    <el-table :max-height="tableMaxHeight" v-loading="loading" :data="reservRecordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="详细门牌号" align="center" prop="houseAddress" width="100"/>
      <el-table-column label="分享人姓名" align="center" prop="shareName" width="100" />
      <el-table-column label="访客姓名" align="center" prop="name" />
      <el-table-column label="来访人数" align="center" prop="num" />
      <el-table-column label="来访事由" align="center" prop="reason" width="100" show-overflow-tooltip/>
      <el-table-column label="手机号码" align="center" prop="mobileNumber" width="120" />
      <el-table-column label="是否驾车" align="center" prop="isCar">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.isCar"/>
        </template>
      </el-table-column>
      <el-table-column label="车牌号码" align="center" prop="plateNumber" width="100"/>
      <el-table-column label="预约时间" align="center" prop="reserveTime" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.reserveTime}}</span>
        </template>
      </el-table-column>
      <el-table-column label="来访时间" align="center" prop="visitorTime" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.visitorTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" fixed="right">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yuyetype" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <!-- <el-table-column label="人脸信息" align="center" prop="photo" /> -->
      <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
      <el-table-column  fixed="right"  width="120" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
            style="color: #28C529;"
            v-hasPermi="['wuYe:reservRecord:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            style="color: red;"
            @click="handleDelete(scope.row)"
            v-hasPermi="['wuYe:reservRecord:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    </div>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
   </div>
    <!-- 添加或修改预约记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="门户id" prop="portalId">
          <el-input v-model="form.portalId" placeholder="请输入门户id" />
        </el-form-item>
        <el-form-item label="详细门牌号" prop="houseAddress">
          <el-input v-model="form.houseAddress" placeholder="请输入详细门牌号" />
        </el-form-item>
        <el-form-item label="详细地址" prop="detailAddress">
          <el-input v-model="form.detailAddress" placeholder="请输入详细地址" />
        </el-form-item>
        <el-form-item label="经度" prop="lgt">
          <el-input v-model="form.lgt" placeholder="请输入经度" />
        </el-form-item>
        <el-form-item label="纬度" prop="lat">
          <el-input v-model="form.lat" placeholder="请输入纬度" />
        </el-form-item>
        <el-form-item label="分享人姓名" prop="shareName">
          <el-input v-model="form.shareName" placeholder="请输入分享人姓名" />
        </el-form-item>
        <el-form-item label="访客姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入访客姓名" />
        </el-form-item>
        <el-form-item label="来访人数" prop="num">
          <el-input v-model="form.num" placeholder="请输入来访人数" />
        </el-form-item>
        <el-form-item label="来访事由" prop="reason">
          <el-input v-model="form.reason" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="手机号码" prop="mobileNumber">
          <el-input v-model="form.mobileNumber" placeholder="请输入手机号码" />
        </el-form-item>
        <el-form-item label="是否驾车 N:否 Y:是" prop="isCar">
          <el-input v-model="form.isCar" placeholder="请输入是否驾车 N:否 Y:是" />
        </el-form-item>
        <el-form-item label="车牌号码" prop="plateNumber">
          <el-input v-model="form.plateNumber" placeholder="请输入车牌号码" />
        </el-form-item>
        <el-form-item label="预约时间" prop="reserveTime">
          <el-date-picker clearable
            v-model="form.reserveTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择预约时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="来访时间" prop="visitorTime">
          <el-date-picker clearable
            v-model="form.visitorTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择来访时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="状态 1：待来访 2：已来访 3：已过期" prop="status">
          <el-select v-model="form.status" placeholder="请选择状态 1：待来访 2：已来访 3：已过期">
            <el-option
              v-for="dict in dict.type.yuyetype"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="人脸信息" prop="photo">
          <el-input v-model="form.photo" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </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 { listReservRecord, getReservRecord, delReservRecord, addReservRecord, updateReservRecord } from "@/api/wuguan/reservRecord";

export default {
  name: "ReservRecord",
  dicts: ['yuyetype','sys_yes_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 预约记录表格数据
      reservRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        portalId: null,
        houseAddress: null,
        detailAddress: null,
        lgt: null,
        lat: null,
        shareName: null,
        name: null,
        num: null,
        reason: null,
        mobileNumber: null,
        isCar: null,
        plateNumber: null,
        reserveTime: null,
        visitorTime: null,
        status: null,
        photo: null,

      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        portalId: [
          { required: true, message: "门户id不能为空", trigger: "blur" }
        ],
        houseAddress: [
          { required: true, message: "详细门牌号不能为空", trigger: "blur" }
        ],
        detailAddress: [
          { required: true, message: "详细地址不能为空", trigger: "blur" }
        ],
        lgt: [
          { required: true, message: "经度不能为空", trigger: "blur" }
        ],
        lat: [
          { required: true, message: "纬度不能为空", trigger: "blur" }
        ],
        mobileNumber: [
          { required: true, message: "手机号码不能为空", trigger: "blur" }
        ],
        plateNumber: [
          { required: true, message: "车牌号码不能为空", trigger: "blur" }
        ],
      },
      tableMaxHeight:'200',
    };
  },
  created() {
    this.getList();
  window.onresize = () => {
  	      this.changeTableMaxHeight()
  	    }
  	    this.changeTableMaxHeight()
  },
  mounted() {
  	window.onresize = () => {
  	          this.changeTableMaxHeight()
  	        }
  	        this.changeTableMaxHeight()
  },
  methods: {
    /** 查询预约记录列表 */
    getList() {
      this.loading = true;
      listReservRecord(this.queryParams).then(response => {
        this.reservRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        reservRecordId: null,
        portalId: null,
        houseAddress: null,
        detailAddress: null,
        lgt: null,
        lat: null,
        shareName: null,
        name: null,
        num: null,
        reason: null,
        mobileNumber: null,
        isCar: null,
        plateNumber: null,
        reserveTime: null,
        visitorTime: null,
        status: null,
        photo: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.reservRecordId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加预约记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const reservRecordId = row.reservRecordId || this.ids
      getReservRecord(reservRecordId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改预约记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.reservRecordId != null) {
            updateReservRecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addReservRecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const reservRecordIds = row.reservRecordId || this.ids;
      this.$modal.confirm('是否确认删除预约记录编号为"' + reservRecordIds + '"的数据项？').then(function() {
        return delReservRecord(reservRecordIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('wuYe/reservRecord/export', {
        ...this.queryParams
      }, `reservRecord_${new Date().getTime()}.xlsx`)
    },
    // 获取屏幕高度
    showFilterForm () {
          this.filterActive = !this.filterActive
          this.changeTableMaxHeight()
        },

        changeTableMaxHeight () {
          let height = document.body.offsetHeight // 网页可视区域高度
          // if (this.filterActive) {
          //   this.tableMaxHeight = height - 320
          // } else {
            this.tableMaxHeight = height - 150
          // }
          console.log(height)
        }
  }
};
</script>
<style  lang="scss">
 .el-table .el-table__header-wra#f5f6f8per th{
    background-color:#F5F6F8;
    color:#343434;
  }
  .el-table{
    color:#343434;
  }
  </style>
