<template>
  <div class="page">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="未处理" name="1">
        <LayoutTable :data="tableData" notAdd notDel :config="tableConfig">
        </LayoutTable>
      </el-tab-pane>
      <el-tab-pane label="已处理" name="2">
        <LayoutTable :data="tableData" notAdd notDel :config="tableConfig">
        </LayoutTable>
      </el-tab-pane>
      <el-tab-pane label="数据分析" name="3">
        <div class="content">
          <div class="search_box">
            <div class="search">
              <el-select
                v-model="dateValue"
                placeholder="请选择"
                style="margin: 0 10px;"
              >
                <el-option
                  v-for="item in optionsMonths"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
              <el-button type="primary" @click="getChartsData">搜索</el-button>
            </div>
          </div>
          <div class="data_box">
            <div class="top">
              <div class="box">
                <bar-charts
                  :title="'申诉次数部门排名TOP20'"
                  :id="'dept_20'"
                  :legendName="'申诉次数'"
                  :styleObj="{ width: '800px', height: '360px' }"
                  :chartsData="depChartsData"
                />
              </div>
              <div class="box">
                <bar-charts
                  :title="'申诉次数个人排名TOP20'"
                  :id="'person_20'"
                  :legendName="'申诉次数'"
                  :styleObj="{ width: '800px', height: '360px' }"
                  :chartsData="personChartsData"
                />
              </div>
            </div>
            <div class="down">
              <bar-charts
                :title="'申诉次数规则排名TOP20'"
                :id="'rule_20'"
                :legendName="'申诉次数'"
                :styleObj="{ width: '1800px', height: '300px' }"
                :chartsData="ruleChartsData"
              />
            </div>
          </div>
        </div>
      </el-tab-pane>
    </el-tabs>
    <!-- <bar-charts
      :title="'部门扣分排名TOP10'"
      :id="'koufen_10'"
      :legendName="'部门分值'"
      :styleObj="{ width: '100%', height: '300px' }"
    /> -->
    <drawer-show ref="drawerform" @ok="getData" />
  </div>
</template>

<script>
/** 表单弹出框模式需引入 */
import drawerShow from "./drawershow";
import table from "@/assets/mixins/table";
import BarCharts from "./components/BarCharts.vue";
import { downloadFile } from "@/assets/utils/index";

export default {
  name: "PerformAttendAppealList",
  components: {
    drawerShow,
    BarCharts,
  },
  mixins: [table],
  created() {
    this.getData();
  },
  methods: {
    handleCellClick(row, column, event, cell) {
      if ((column.label == "图片凭证")) {
        const suffix = `(bmp|jpg|png|tif|gif|pcx|tga|exif|fpx|svg|psd|cdr|pcd|dxf|ufo|eps|ai|raw|WMF|webp|jpeg)`;
        const regular = new RegExp(`.*\.${suffix}`);
        regular.test(row.filePaths);
        if (!regular.test(row.filePaths)) {
          downloadFile(row.filePaths, row.fileName);
        }
      }
    },
    handleClick() {
      this.getData();
    },
    getData() {
      this.activeName == 1 || this.activeName == 2
        ? this.$post("/perform/attend/appeal/list", {
            processStatus: this.activeName,
          }).then((res) => {
            if (res.code == 1) {
              this.tableData = res.data;
              this.dict = res.dict;
            }
          })
        : this.getChartsData();
    },
    getChartsData() {
      this.$post("/perform/attend/appeal/stat", {
        appealTimeStart: this.dateValue,
        statType: 1,
      }).then((res) => {
        console.log(res);
        this.depChartsData = res.data;
      });
      this.$post("/perform/attend/appeal/stat", {
        appealTimeStart: this.dateValue,
        statType: 2,
      }).then((res) => {
        console.log(res);
        this.personChartsData = res.data;
      });
      this.$post("/perform/attend/appeal/stat", {
        appealTimeStart: this.dateValue,
        statType: 3,
      }).then((res) => {
        console.log(res);
        this.ruleChartsData = res.data;
      });
    },
    renderTable(tableData) {
      return (
        <el-table stripe data={tableData} class="total-table">
          {this.columnSet.map((item) => this.renderTableColumn(item))}
        </el-table>
      );
    },
    renderTableColumn(options) {
      return (
        <el-table-column
          prop={options.prop}
          label={options.label}
          width={options.width}
          formatter={options.formatter}
        ></el-table-column>
      );
    },
    /** 重写新增方法 */
    toAdd(row) {
      this.$refs.drawerform.add(row);
    },
    /** 重写编辑方法 */
    toEdit(row) {
      this.$refs.drawerform.edit(row);
    },
    /** 重写查看方法 */
    toView(row) {
      this.$refs.drawerform.view(row);
    },
  },
  data() {
    return {
      depChartsData: [],
      personChartsData: [],
      ruleChartsData: [],
      /** 子表列元素 */
      columnSet: [
        { label: "申诉Id", prop: "appealId", formatter: this.formatter },
        { label: "文件名称", prop: "fileName" },
        { label: "文件地址", prop: "filePath" },
      ],
      config: {
        isshowTabPane: false,
        search: [
          {
            name: "irregularOtherType",
            type: "select",
            label: "全部类型",
            fuzzy: false,
          },
          {
            name: "deptId",
            type: "select",
            label: "全部部门",
            fuzzy: false,
          },
          {
            name: "date",
            type: "date",
            label: "请选择日期",
            fuzzy: false,
          },
          {
            name: "staffName",
            type: "text",
            label: "员工姓名搜索",
            fuzzy: false,
          },
        ],
        columns: [
          { type: "selection", width: 60 },
          { type: "index", label: "序号", width: 50 },

          { label: "姓名", prop: "staffName" },

          { label: "所属部门", prop: "deptName" },

          {
            label: "违规类型",
            prop: "irregularType",
            formatter: this.formatter,
          },

          { label: "绩效规则", prop: "ruleId", formatter: this.formatter },

          {
            label: "加分/扣分方式",
            prop: "subAddType",
            formatter: this.formatter,
          },

          {
            label: "加分/扣分时间",
            prop: "deductTime",
            formatter: this.formatterDate,
          },

          { label: "分值", prop: "score", formatter: this.formatter },

          {
            label: "申诉时间",
            prop: "appealTime",
            formatter: this.formatterDate,
          },

          {
            label: "处理状态",
            prop: "processStatus",
            formatter: this.formatter,
          },

          /* {label: "绩效记录申诉附件信息",
                          width: 120,
                          prop: "subColumns",
                          formatter: (row) => {
                              let widthsize = this.columnSet.reduce((pre, cur) => {
                                  return pre + Number(cur.width);
                              }, 50);
                              return (
                                  <el-popover placement="right" width={widthsize} trigger="click">
                                      {this.renderTable(row.performAttendAppealFilesList)}
                                      <el-button type="text" slot="reference">详细</el-button>
                                  </el-popover>
                              );
                          },
                        },*/
          {
            label: "操作",
            formatter: (row) => {
              return row.processStatus == 2 ? (
                <table-buttons
                  noAdd
                  noDel
                  noEdit
                  row={row}
                  onEdit={this.toEdit}
                  onView={this.toView}
                  onDel={this.toDel}
                />
              ) : (
                <table-buttons
                  noAdd
                  noDel
                  noView
                  noEdit
                  chuli
                  row={row}
                  onEdit={this.toEdit}
                  onView={this.toView}
                  onDel={this.toDel}
                />
              );
            },
          },
        ],
      },
      activeName: "1",
      optionsMonths: [
        {
          value: "2023-01-01 00:00:00",
          label: "1月",
        },
        {
          value: "2023-02-01 00:00:00",
          label: "2月",
        },
        {
          value: "2023-03-01 00:00:00",
          label: "3月",
        },
        {
          value: "2023-04-01 00:00:00",
          label: "4月",
        },
        {
          value: "2023-05-01 00:00:00",
          label: "5月",
        },
        {
          value: "2023-06-01 00:00:00",
          label: "6月",
        },
        {
          value: "2023-07-01 00:00:00",
          label: "7月",
        },
        {
          value: "2023-08-01 00:00:00",
          label: "8月",
        },
        {
          value: "2023-09-01 00:00:00",
          label: "9月",
        },
        {
          value: "2023-10-01 00:00:00",
          label: "10月",
        },
        {
          value: "2023-11-01 00:00:00",
          label: "11月",
        },
        {
          value: "2023-12-01 00:00:00",
          label: "12月",
        },
      ],
      dateValue: "2023-07-01 00:00:00",
    };
  },
};
</script>
<style lang="less" scoped>
.page {
  width: 100%;
  height: 100%;
  overflow: hidden;

  /deep/.el-tabs__item {
    width: 120px;
    font-size: 14px;
    text-align: center;
  }

  .content {
    width: 100%;
    height: 730px;
    overflow: hidden;

    .search_box {
      width: 100%;
      height: auto;
      text-align: right;
      margin-bottom: 10px;
    }

    .data_box {
      width: 100%;
      height: 100%;

      .top {
        width: 100%;
        height: 380px;
        display: flex;
        justify-content: space-between;

        .box {
          width: 49%;
          height: 100%;
        }
      }
    }
  }
}
</style>
