<template>
  <div class="app-container">
    <el-input
      v-model="page.data.name"
      placeholder="请输入姓名"
      class="margin-left input"
    ></el-input>
    <el-input
      v-model="page.data.idNumber"
      placeholder="请输入身份证"
      class="margin-left input"
    ></el-input>

    <el-input
      v-model="page.data.phone"
      placeholder="请输入手机号"
      class="margin-left input"
    ></el-input>
    <el-select
      filterable
      clearable
      v-model="page.data.disinfectAreaId"
      placeholder="请选择巡查区域"
      class="margin-left input"
    >
      <el-option
        v-for="item in xiaosha_area"
        :key="item.disinfectAreaId"
        :label="item.disinfectAreaName"
        :value="item.disinfectAreaId"
      >
      </el-option>
    </el-select>
    <el-input
      v-model="page.data.disinfectAreaAddress"
      placeholder="请输入巡查区域详址"
      class="margin-left input"
    ></el-input>
    <el-select
      filterable
      clearable
      v-model="page.data.status"
      placeholder="请选择状态"
      class="margin-left input"
    >
      <el-option
        v-for="item in status_list"
        :key="item.id"
        :label="item.name"
        :value="item.id"
      >
      </el-option>
    </el-select>
    <el-date-picker
      v-model="page.data.startTime"
      type="datetime"
      placeholder="选择巡查开始时间"
      value-format="yyyy-MM-dd HH:mm:ss"
      class="margin-left"
    >
    </el-date-picker>
    <el-date-picker
      v-model="page.data.endTime"
      type="datetime"
      placeholder="选择巡查结束时间"
      value-format="yyyy-MM-dd HH:mm:ss"
      class="margin-left"
    >
    </el-date-picker>

    <el-button
      type="primary"
      icon="el-icon-search"
      class="margin-left"
      @click="fetchData"
      >搜索</el-button
    >

    <!--主表格-->
    <el-table
      class="table"
      ref="table_form"
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column label="序号" align="center" width="80px">
        <template slot-scope="scope">
          {{ indexMethod(scope.$index) }}
        </template>
      </el-table-column>
      <el-table-column label="巡查人员姓名" align="center">
        <template slot-scope="scope">
          {{ scope.row.name | matchNull }}
        </template>
      </el-table-column>
      <el-table-column label="巡查人员身份证" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.idNumber | matchNull }}</span>
        </template>
      </el-table-column>
      <el-table-column label="巡查人员手机号" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.phone | matchNull }}</span>
        </template>
      </el-table-column>
      <el-table-column label="巡查区域" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.disinfectAreaName | matchNull }}</span>
        </template>
      </el-table-column>
      <el-table-column label="巡查区域详址" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.disinfectAreaAddress | matchNull }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center">
        <template slot-scope="scope">
          <el-tag v-if=" scope.row.status===1" effect="plain">已完成 </el-tag>
          <el-tag v-else type="warning" effect="plain">未完成 </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="巡查时间" align="center">
        <template slot-scope="scope">
          {{ scope.row.disinfectTime }}
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center">
        <template slot-scope="scope">
          {{ scope.row.disinfectRemarks }}
        </template>
      </el-table-column>
      <el-table-column label="登记时间" align="center">
        <template slot-scope="scope">
          {{ scope.row.createTime }}
        </template>
      </el-table-column>
    </el-table>
    <!--分页栏-->
    <pagination
      :total="total"
      :page.sync="page.pageNum"
      :limit.sync="page.pageSize"
      @pagination="fetchData"
    />
  </div>
</template>
<script>
import {
  disinfectRecordList,disinfectAreaGetList
} from "@/api/xiaosha";
import Pagination from "@/components/Pagination";
import { checkRole } from "@/utils/checkRole";

export default {
  components: { Pagination },
  filters: {
    matchNull(str) {
      if (!str) {
        return "未填写";
      } else {
        return str;
      }
    },
  },
  data() {
    return {
      // 主表格&主表格加载状态
      list: [],
      listLoading: true,
      // 分页参数
      page: {
        data: {
          name: null,
          idNumber: null,
          phone: null,
          disinfectAreaId:null,
          earlyWarningIdNumber: null,
          disinfectAreaAddress: null,
          startTime: null,
          endTime: null,
        },
        pageNum: 1,
        pageSize: 10,
      },
      total: 0,
      xiaosha_area: [], //巡查区域
      // 状态
      status_list: [
        // { id: 104, name: "处理中" },
        // { id: 105, name: "待处理" },
        // { id: 301, name: "关闭" },
        { id: 1, name: "已完成" },
        { id: 2, name: "未完成" },
      ],
    };
  },
  created() {
    this.fetchData();
    this.disinfectAreaGetList()
  },
  methods: {
    // 查询权限
    checkRole,
    // 获取列表数据
    fetchData() {
      this.listLoading = true;
      disinfectRecordList(this.page).then((res) => {
        this.list = res.data.list;
        this.total = res.data.total;
        this.listLoading = false;
      });
    },
    // 巡查区域
    disinfectAreaGetList(){
      disinfectAreaGetList().then(res=>{
        this.xiaosha_area=res.data
      })
    },
    // 返回列表序号
    indexMethod(index) {
      return (this.page.pageNum - 1) * this.page.pageSize + index + 1;
    },
  },
};
</script>
<style scoped>
.table {
  margin-top: 15px;
}
.flex {
  display: flex;
  justify-content: flex-start;
  align-items: center;
}

.margin-left {
  margin: 10px 0 0 10px;
}

.input {
  width: 200px;
}
</style>
