<template>
  <div>
    <div class="tableDistance">
      <el-table
        :data="tableData"
        :border="true"
        style="width: 100%"
        v-loading="loading"
      >
        <el-table-column prop="punishmenType" label="奖惩类型">
          <template slot-scope="scope">
            {{ filterDict(scope.row.punishmenType, "punishmenType") }}
          </template>
        </el-table-column>
        <el-table-column prop="punishmentTime" label="时间">
          <template slot-scope="scope">
            <span>{{
              parseTime(scope.row.punishmentTime, "{y}-{m}-{d}")
            }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="punishmentName" label="奖惩名称">
        </el-table-column>
        <el-table-column prop="backgroundReasons" label="背景原因">
        </el-table-column>
        <el-table-column prop="remark" label="备注"> </el-table-column>
      </el-table>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.current"
      :limit.sync="queryParams.size"
      @pagination="getList"
    />
  </div>
</template>
<script>
import { dictList, exportExcel } from "@/api/jcy";
export default {
  data() {
    return {
      dict: {},
      total: 0,
      loading: false,
      tableData: [],
      queryParams: {
        inspectorId: undefined,
        current: 1,
        size: 10,
      },
    };
  },
  props: {
    //检查员id
    inspectorId: {
      type: Number,
    },
  },
  created() {
    this.queryParams.inspectorId = this.inspectorId;
    this.getDict("punishmenType");
  },
  methods: {
    //导出
    async exportTrain() {
      let params = {
        value: 3,
        ids: this.inspectorId,
      };
      exportExcel(params, this.form).then((res) => {
        if (res.data.code == 200) {
          this.uploadFile(
            res.data.data.result.url,
            res.data.data.result.originalFilename
          );
        }
      });
    },
    /**获取字典列表 */
    getDict(typeList) {
      let query = {
        list: typeList,
      };
      dictList(query).then((res) => {
        if (res.status == 200) {
          for (let key in res.result) {
            this.dict[key] = res.result[key];
          }

          this.getList();
        }
      });
    },
    /**过滤字典 */
    filterDict(value, type) {
      if (this.dict[type] == undefined) {
        return value;
      }

      let dictLable = this.dict[type].filter((item) => item.dictValue == value);
      return dictLable.length > 0 ? dictLable[0].dictLabel : "未知";
    },
    //获取列表
    async getList() {
      this.loading = true;
      let msg1 = await this.$api.jiangcheng.list(this.queryParams);
      if (msg1.status == 200) this.loading = false;
      this.tableData = msg1.result.records;
      this.total = msg1.result.total;
    },
  },
};
</script>
<style lang="scss" scoped></style>
