// 异常记录列表
<template>
  <div class="app-container">
    <el-form :inline="true" :model="page.data">
      <el-form-item class="margin-left input" v-if="checkRole([0])">
        <el-select
          v-model="page.data.accountId"
          filterable
          clearable
          placeholder="请选择所属账号"
        >
          <el-option
            v-for="item in option"
            :key="item.id"
            :label="item.username"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item class="margin-left input">
        <el-select
          filterable
          clearable
          v-model="page.data.positionId"
          placeholder="请选择巡逻点"
        >
          <el-option
            v-for="item in option1"
            :key="item.id"
            :label="item.positionName"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item class="margin-left">
        <el-time-picker
          value-format="HH:mm:ss"
          v-model="time"
          is-range
          range-separator="至"
          start-placeholder="选择巡逻开始时间"
          end-placeholder="选择巡逻结束时间"
          placeholder="选择时间范围"
        >
        </el-time-picker>
      </el-form-item>
      <el-form-item class="margin-left input">
        <el-input
          v-model="page.data.patrolIdName"
          placeholder="请输入姓名"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item class="margin-left input">
        <el-input
          v-model="page.data.patrolIdNumber"
          placeholder="请输入身份证号"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item class="margin-left input">
        <el-select
          v-model="page.data.appUserId"
          filterable
          clearable
          placeholder="请选择人员账号"
        >
          <el-option
            v-for="item in option2"
            :key="item.id"
            :label="item.username"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item class="margin-left">
        <el-date-picker
          v-model="page.data.startTime"
          type="datetime"
          placeholder="选择创建起始时间"
          value-format="yyyy-MM-dd HH:mm:ss"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item class="margin-left">
        <el-date-picker
          v-model="page.data.endTime"
          type="datetime"
          placeholder="选择创建结束时间"
          value-format="yyyy-MM-dd HH:mm:ss"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item class="margin-left">
        <el-button type="primary" @click="fetchData" icon="el-icon-search"
          >搜索</el-button
        >
      </el-form-item>
    </el-form>
    <!-- 主体表格 -->
    <el-table
      :data="tableData"
      v-loading="listLoading"
      border
      fit
      highlight-current-row
      class="table"
    >
      <el-table-column align="center" width="80" label="序号">
        <template slot-scope="scope">
          {{ indexMethod(scope.$index) }}
        </template>
      </el-table-column>
      <el-table-column align="center" prop="accountUsername" label="所属账号">
      </el-table-column>
      <el-table-column align="center" prop="positionName" label="巡逻点">
      </el-table-column>
      <el-table-column align="center" label="巡逻签到时间段">
        <template slot-scope="scope">
          {{ scope.row.patrolStartTime }}-{{ scope.row.patrolEndTime }}
        </template>
      </el-table-column>

      <el-table-column align="center" prop="patrolIdName" label="巡逻人姓名">
      </el-table-column>
      <el-table-column
        align="center"
        prop="patrolIdNumber"
        label="巡逻人身份证号"
      >
      </el-table-column>
      <el-table-column align="center" prop="patrolUsername" label="巡逻人账号">
      </el-table-column>
      <el-table-column align="center" prop="createTime" label="创建时间">
      </el-table-column>
      <!--分页栏-->
    </el-table>
    <pagination
      :total="total"
      :page.sync="page.pageNumber"
      :limit.sync="page.pageSize"
      @pagination="fetchData"
    />
  </div>
</template>

<script>
import Pagination from "@/components/Pagination";
import { getUserlist } from "@/api/user";
import { doGetPosition } from "@/api/orderRecord";
import { doGetSubuser } from "@/api/subuser";
import { doGetRecordCrashlist } from "@/api/patrolRecord";
import { checkRole } from "@/utils/checkRole";
export default {
  components: { Pagination },
  data() {
    return {
      //省市县列表
      province_list: [],
      city_list: [],
      area_list: [],
      dialogVisible: false, //新增编辑
      dialogTitle: "",
      listLoading: false,
      option: [], //所属账号
      option1: [], //巡逻列表
      option2: [], //人员账号
      submitLoading: false,
      submitSendLoading: false,
      isEdit: false, //判断是否是编辑
      tableData: [],
      total: 0,
      detailData: {},
      // 页面
      page: {
        // 搜索表单
        data: {
          accountId: "",
          positionId: "",
          patrolIdName: "",
          patrolIdNumber: "",
          appUserId: "", //人员账号
          startTime: null,
          endTime: null,
        },
        pageNumber: 1,
        pageSize: 10,
      },
      time: "",
    };
  },
  created() {
    this.fetchData();
    if (checkRole([0])) {
      this.getUserList();
    }
    this.getSelectPosition();
    this.getSubUser();
  },
  methods: {
    checkRole,
    fetchData() {
      this.listLoading = true;
      this.page.data.patrolStartTime = this.time ? this.time[0] : null;
      this.page.data.patrolEndTime = this.time ? this.time[1] : null;
      doGetRecordCrashlist(this.page).then((res) => {
        this.tableData = res.data.records;
        this.total = res.data.total;
        this.listLoading = false;
      });
    },
    getUserList() {
      getUserlist().then((res) => {
        this.option = res.data;
      });
    },
    // 查询巡逻点
    getSelectPosition() {
      doGetPosition().then((res) => {
        this.option1 = res.data;
      });
    },
    getSubUser() {
      doGetSubuser().then((res) => {
        this.option2 = res.data;
      });
    },
    // 返回列表序号
    indexMethod(index) {
      return (this.page.pageNumber - 1) * this.page.pageSize + index + 1;
    },
  },
};
</script>

<style lang="scss" scoped>
.margin-left {
  margin: 10px 0 0 10px;
}
.input {
  width: 150px;
}
.flex {
  width: 100%;
  display: flex;
  justify-content: flex-start;
  align-items: center;
}
</style>
