<template>
  <div class="app-container">
    <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="equipId">
             <el-input
               v-model="queryParams.equipId"
               placeholder="请输入设备编号"
               clearable
               style="width: 100%;"
               @keyup.enter.native="handleQuery"
             />
           </el-form-item>
        </el-col>
        <el-col :span="8">
           <el-form-item label="设备名称" prop="equipName">
             <el-input
               v-model="queryParams.equipName"
               placeholder="请输入设备名称"
               clearable
               style="width: 100%;"
               @keyup.enter.native="handleQuery"
             />
           </el-form-item>
        </el-col>
        <el-col :span="8">
           <el-form-item label="姓名" prop="name">
             <el-input
               v-model="queryParams.name"
               placeholder="请输入姓名"
               clearable
               style="width: 100%;"
               @keyup.enter.native="handleQuery"
             />
           </el-form-item>
        </el-col>
        <el-col :span="8">
           <el-form-item label="身份证号" prop="idCard">
             <el-input
               v-model="queryParams.idCard"
               placeholder="请输入身份证号码"
               clearable
               style="width: 100%;"
               @keyup.enter.native="handleQuery"
             />
           </el-form-item>
        </el-col>
        <el-col :span="8">
           <el-form-item label="联系号码" prop="phoneNum">
             <el-input
               v-model="queryParams.phoneNum"
               placeholder="请输入联系号码"
               clearable
               style="width: 100%;"
               @keyup.enter.native="handleQuery"
             />
           </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="体温" prop="temperature">
            <el-input
              v-model="queryParams.temperature"
              placeholder="请输入体温"
              clearable
              style="width: 100%;"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
           
        </el-col>
        <el-col :span="8">
           <el-form-item label="小区名称" prop="community">
             <el-input
               v-model="queryParams.community"
               placeholder="请输入小区名称"
               clearable
               style="width: 100%;"
               @keyup.enter.native="handleQuery"
             />
           </el-form-item>
        </el-col>

        <el-col :span="8">
           <el-form-item label="单位名称" prop="unitName">
             <el-input
               v-model="queryParams.unitName"
               placeholder="请输入单位名称"
               clearable
               style="width: 100%;"
               @keyup.enter.native="handleQuery"
             />
           </el-form-item>
        </el-col>
        <el-col :span="8">
           <el-form-item label="所属用户" prop="belongsUser">
             <el-input
               v-model="queryParams.belongsUser"
               placeholder="请输入所属用户"
               clearable
               style="width: 100%;"
               @keyup.enter.native="handleQuery"
             />
           </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="开始时间" prop="startTime">
           <el-date-picker clearable
             v-model="queryParams.startTime"
             type="datetime"
             value-format="yyyy-MM-dd HH:mm:ss"
             format="yyyy-MM-dd HH:mm:ss"
             @keyup.enter.native="handleQuery"
             style="width: 93%;"
             placeholder="请选择开始时间">
           </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
        <el-form-item label="结束时间" prop="endTime">
          <el-date-picker clearable
            v-model="queryParams.endTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd HH:mm:ss"
            style="width: 93%;"
            @keyup.enter.native="handleQuery"
            placeholder="请选择结束时间">
          </el-date-picker>
        </el-form-item>
        </el-col>
        <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-row>
    </el-form>
    <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
     <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="设备编号" align="center" prop="equipId" />
      <el-table-column label="设备名称" align="center" prop="equipName" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="身份证号码" align="center" prop="idCard" width="180"/>
      <el-table-column label="联系号码" align="center" prop="phoneNum" width="110"/>
      <el-table-column label="扫码时间(采集时间）" align="center" prop="collectTime" width="157"/>
      <el-table-column label="单位名称" align="center" prop="unitName" />
      <el-table-column label="小区名称" align="center" prop="community" />
      <el-table-column label="体温" align="center" prop="temperature" />
      <el-table-column label="所属用户" align="center" prop="belongsUser" />
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改安康码扫码地点对话框 -->
    <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>
      <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 { listData, getData, delData, addData, updateData } from "@/api/system/data";

export default {
  name: "Data",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 安康码扫码地点表格数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        equipId: null,
        equipName: null,
        name: null,
        idCard: null,
        phoneNum: null,
        unitName: null,
        community: null,
        temperature: null,
        belongsUser: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询安康码扫码地点列表 */
    getList() {
      this.loading = true;
      listData(this.queryParams).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        equipId: null,
        equipName: null,
        name: null,
        idCard: null,
        phoneNum: null,
        collectTime: null,
        collectSite: null,
        unitName: null,
        community: null,
        type: null,
        state: null,
        temperature: null,
        belongsUser: 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.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
      getData(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) {
            updateData(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addData(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除安康码扫码地点编号为"' + ids + '"的数据项？').then(function() {
        return delData(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/data/export', {
        ...this.queryParams
      }, `data_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
