<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.phone"
      placeholder="请输入手机号"
      class="margin-left input"
    ></el-input> -->
    <el-input
      v-model="page.data.idNumber"
      placeholder="请输入身份证号"
      class="margin-left input"
    ></el-input>
    <!-- <el-select
      v-if="!checkRole([99])"
      filterable
      clearable
      v-model="page.data.username"
      placeholder="请选择账号"
      class="margin-left input"
    >
      <el-option
        v-for="item in user_list"
        :key="item.id"
        :label="item.username"
        :value="item.username"
      >
      </el-option>
    </el-select> -->
    <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" v-if="checkRole([1, 2])">
        <template slot-scope="scope">
          <span>{{ scope.row.username | matchNull }}</span>
        </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">
          <el-image
            style="width: 100px; height: 100px"
            :src="scope.row.photo"
            :preview-src-list="[scope.row.photo]"
          >
          </el-image>
        </template>
      </el-table-column> -->
      <el-table-column label="身份证" align="center">
        <template slot-scope="scope">
          {{ scope.row.idNumber }}
        </template>
      </el-table-column>
      <el-table-column label="场所码Code" align="center">
        <template slot-scope="scope">
          {{ scope.row.addressCode }}
        </template>
      </el-table-column>
      <el-table-column label="场所码单位名称" align="center" width="150px">
        <template slot-scope="scope">
          {{ scope.row.unitName }}
        </template>
      </el-table-column>
      <el-table-column label="场所码单位地址" align="center" width="150px">
        <template slot-scope="scope">
          {{ scope.row.unitAddress }}
        </template>
      </el-table-column>
      <el-table-column label="详细地址" align="center">
        <template slot-scope="scope">
          {{ scope.row.provinceName }} -{{ scope.row.cityName }} -{{
            scope.row.areaName
          }}
          -{{ scope.row.streetName }} -{{ scope.row.address }}
        </template>
      </el-table-column>

      <el-table-column label="用户健康码信息" align="center">
        <template slot-scope="scope">
          {{ scope.row.healthCode }}
        </template>
      </el-table-column>
      <el-table-column label="健康码状态" align="center">
        <template slot-scope="scope">
          {{ scope.row.level }}
        </template>
      </el-table-column>
      <el-table-column label="核酸检测结果" align="center">
        <template slot-scope="scope">
          {{ scope.row.checkResult }}
        </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 detailsDialog from "@/components/DialogDetails/index.vue";

import Pagination from "@/components/Pagination";
import { checkRole } from "@/utils/checkRole";
import {
  getUserListSearch,
  placeRecordList,
} from "@/api/user_manage";
import { parseTime } from "@/utils"; // secondary package based on el-pagination

export default {
  components: { Pagination, detailsDialog },
  filters: {
    matchNull(str) {
      if (!str) {
        return "未记录";
      } else {
        return str;
      }
    },
    aAecimal(str) {
      return (str = str.slice(0, 4));
    },
  },
  data() {
    return {
      // 主表格&主表格加载状态
      list: [],
      listLoading: true,
      // 分页参数
      page: {
        data: {
          username: null,
          name: null,
          idNumber: null,
          phone: null,
          deviceSn: null,
          provinceId: null,
          cityId: null,
          areaId: null,
        },
        pageNum: 1,
        pageSize: 10,
      },
      total: 0,
      // 账号列表_搜索
      user_list: [],
    };
  },
  created() {
    this.page_copy = JSON.parse(JSON.stringify(this.page));
    this.fetchData();
  },
  computed: {},
  methods: {
    // 查询权限
    checkRole,
    // 获取列表数据
    fetchData() {
      this.listLoading = true;
      placeRecordList(this.page).then((res) => {
        this.list = res.data.list;
        this.total = res.data.total;
        this.listLoading = false;
      });
    },
    // 获取账号列表数据_搜索
    getUserListSearch() {
      getUserListSearch().then((res) => {
        this.user_list = 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: 150px;
}
</style>
