<template>
  <div class="inspection-action-logs">
    <div class="part-box-head">
      <div class="part-box-head-right">
        <Button type="primary" icon="md-download" @click="exportLogs"
          >导出操作日志</Button
        >
      </div>
    </div>
    <div class="part-box">
      <Form ref="FilterForm" label-position="left" inline>
        <FormItem label="工作文件夹：">
          <Select
            v-model="filter.workId"
            placeholder="请选择工作文件夹"
            style="width: 150px"
          >
            <Option
              v-for="(work, windex) in works"
              :key="windex"
              :value="work.id"
              :label="work.name"
            ></Option>
          </Select>
        </FormItem>
        <FormItem label="科目：">
          <Select v-model="filter.subject" placeholder="请选择科目">
            <Option value=""></Option>
          </Select>
        </FormItem>
        <FormItem label="考号：">
          <Input
            v-model.trim="filter.examNumber"
            placeholder="请输入考号"
            clearable
          ></Input>
        </FormItem>
        <FormItem label="姓名：">
          <Input
            v-model.trim="filter.name"
            placeholder="请输入姓名"
            clearable
          ></Input>
        </FormItem>
        <FormItem label="操作：">
          <Select
            v-model="filter.operType"
            placeholder="请选择操作"
            clearable
            style="width: 130px"
          >
            <Option
              v-for="(val, key) in ACTION_TYPE"
              :key="key"
              :value="key * 1"
              :label="val"
            ></Option>
          </Select>
        </FormItem>
        <FormItem label="查询时间：">
          <DatePicker
            v-model="searchTime"
            type="datetimerange"
            placeholder="请选择查询时间段"
            style="width: 400px"
            transfer
          ></DatePicker>
        </FormItem>
        <FormItem>
          <Button type="primary" icon="ios-search" @click="toPage(1)"
            >查询</Button
          >
        </FormItem>
      </Form>

      <Table
        ref="TableList"
        :columns="columns"
        :data="dataList"
        disabled-hover
        border
      ></Table>

      <div class="part-page">
        <Page
          :current="current"
          :total="total"
          :page-size="size"
          show-total
          show-elevator
          @on-change="toPage"
        ></Page>
      </div>
    </div>
  </div>
</template>

<script>
import { inspectionActionLogPageList, workList } from "@/api";
import { ACTION_TYPE } from "@/constants/enumerate";

export default {
  name: "inspection-action-logs",
  data() {
    return {
      filter: {
        workId: 33,
        subject: "SC",
        examNumber: "",
        name: "",
        operType: null,
        startTime: null,
        endTime: null
      },
      ACTION_TYPE,
      current: 1,
      size: this.GLOBAL.pageSize,
      total: 0,
      works: [],
      searchTime: [],
      dataList: [],
      columns: [
        {
          title: "工作",
          key: "workName"
        },
        {
          title: "操作人",
          key: "createUserName"
        },
        {
          title: "角色",
          key: "createRole"
        },
        {
          title: "科目",
          key: "subject"
        },
        {
          title: "准考证号",
          key: "examNumber",
          width: 130
        },
        {
          title: "学生姓名",
          key: "studentName"
        },
        {
          title: "操作类型",
          key: "operType"
        },
        {
          title: "操作前数据",
          key: "operDataBefore"
        },
        {
          title: "操作后数据",
          key: "operDataAfter"
        },
        {
          title: "操作时间",
          key: "createTime"
        }
      ]
    };
  },
  mounted() {
    this.getWorkList();
    this.getList();
  },
  methods: {
    async getWorkList() {
      const data = await workList();
      this.works = data.map(item => {
        return {
          id: item.id,
          name: item.name
        };
      });
    },
    async getList() {
      // const [startTime, endTime] = this.searchTime;
      const datas = {
        // ...this.filter,
        // startTime,
        // endTime,
        curPage: this.current - 1,
        pageSize: this.size
      };
      const data = await inspectionActionLogPageList(datas);
      this.dataList = data.data;
      this.total = data.totalCount;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    exportLogs() {}
  }
};
</script>
