<template>
  <div class="common-box">
    <el-form :model="formSearch" :inline="true">
      <el-form-item label="操作时间">
        <el-date-picker
          style="width: 250px"
          v-model="formSearch.oprtTime"
          type="daterange"
          range-separator="至"
          :editable="false"
          value-format="yyyy-MM-dd"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
      </el-form-item>
      <el-form-item label="操作人">
        <el-input
          v-model.trim="formSearch.opter"
          placeholder="请输入操作人"
          clearable
        />
      </el-form-item>
      <el-form-item label="操作类型">
        <el-select
          v-model.trim="formSearch.oprtType"
          placeholder="请选择操作类型"
          clearable
        >
          <el-option
            v-for="item in TypeData"
            :key="item.id"
            :label="item.oprtType"
            :value="item.oprtType"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="操作动作">
        <el-select
          v-model.trim="formSearch.oprtActi"
          placeholder="请选择操作动作"
          clearable
        >
          <el-option
            v-for="item in ActionData"
            :key="item.value"
            :label="item.label"
            :value="item.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="fetchData()">查询</el-button>
        <el-button @click="empty()">重置</el-button>
      </el-form-item>
    </el-form>

    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane
        :label="item.label"
        :name="item.id"
        v-for="item in tabs"
        :key="item.id"
      >
        <el-table
          v-loading="Loading"
          :data="getData"
          element-loading-text="加载中"
          fit
          stripe
          border
        >
          <template slot="empty">
            <img src="@/assets/nopage.png" alt />
            <p>暂无数据</p>
          </template>
          <el-table-column fixed type="index" label="序号" width="60" />
          <el-table-column prop="oprtType" label="操作类型" />
          <el-table-column prop="oprtActi" label="操作动作"> </el-table-column>
          <el-table-column label="操作人" width="200" prop="opter" />
          <!-- <el-table-column prop="oprtObj" label="操作对象" /> -->
          <el-table-column label="操作时间" width="200" prop="oprtTime" />
        </el-table>
        <!--分页-->
        <yl-pagination
          v-show="total > 0"
          :total="total"
          :page.sync="formSearch.current"
          :limit.sync="formSearch.size"
          @pagination="fetchData"
        />
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { getLogData, getLogType } from "@/api/system/log";
import ylPagination from "@/components/yl-pagination";
export default {
  components: {
    ylPagination
  },

  data() {
    return {
      //   tab栏
      tabs: [
        {
          id: "drugs",
          label: "药品"
        },
        {
          id: "consumables",
          label: "耗材"
        },
        {
          id: "equipment",
          label: "设备"
        }
      ],
      tab: "drugs",
      activeName: "drugs",
      getData: [], //数据
      total: 0, //分页
      Loading: false,
      formSearch: {
        tableType: "hosp",
        oprtTime: [],
        opter: "",
        oprtType: "",
        oprtActi: "",
        prodType: "",
        current: 1,
        size: 10
      },
      TypeData: [],
      ActionData: [
        { value: "0", label: "新增" },
        { value: "1", label: "编辑" },
        { value: "2", label: "删除" }
      ]
    };
  },
  methods: {
    oprtTypeData() {
      getLogType().then((res) => {
        if (res.success == true) {
          this.TypeData = res.data;
        }
      });
    },
    fetchData() {
      this.Loading = true;
      this.formSearch.prodType = this.tab;
      getLogData(
        this.formSearch
        // tableType: "hosp",
        // oprtTime: [],
        // opter: "",
        // oprtType: "",
        // oprtActi: "",
        // current: 1,
        // size: 10,
      ).then((res) => {
        if (res.success == true) {
          this.getData = res.data.records;
          this.total = res.data.total;
        }
        this.Loading = false;
      });
    },
    empty() {
      this.formSearch.oprtTime = [];
      this.formSearch.opter = "";
      this.formSearch.oprtType = "";
      this.formSearch.oprtActi = "";
      this.fetchData();
    },
    // 标签页
    handleClick(tab) {
      this.tab = tab.name;
      this.fetchData();
    }
  },
  mounted() {
    this.oprtTypeData();
    this.fetchData();
  }
};
</script>

<style scoped>
</style>
