<template>
  <div class="frenquency-container">
    <div class="frenquency-container-inner">
      <div class="header">
        <div class="header-title">频发问题</div>
        <div class="header-select">
          <div>
            <div class="text">类别 :</div>
            <NewSelect
              ref="auditTypeRef"
              :placeholder="'请选择类别'"
              class="select-input"
              v-model="typeSelectVal"
              :options="typeOptions"
              :value="typeSelectVal"
            />
          </div>
          <div>
            <div class="text">被审计街镇 :</div>
            <NewSelect
              ref="townTypeRef"
              :placeholder="'请选择街镇'"
              class="select-input"
              v-model="townSelectVal"
              :options="townOptions"
              :value="townSelectVal"
            />
          </div>
          <div>
            <div class="text">立项年度 :</div>
            <NewSelect
              ref="timeRef"
              :placeholder="'立项年度'"
              class="select-input"
              v-model="timeSelectVal"
              :options="timeOptions"
              :value="timeSelectVal"
            />
          </div>
        </div>
        <div class="query-btn" @click="getTableData(1)">查询</div>
        <div class="reset-btn" @click="resetEvent">重置</div>
      </div>
      <div class="center">
        <el-table :data="tableData" style="width: 100%" max-height="600">
          <el-table-column type="index" width="70" align="center">
          </el-table-column>
          <el-table-column
            prop="createYear"
            label="立项年度"
            width="150"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="auditTown"
            label="被审计镇"
            align="center"
            width="180"
          >
          </el-table-column>
          <el-table-column prop="type" label="类别" align="center">
          </el-table-column>
          <el-table-column prop="keyPoint" label="重点审计事项" align="center">
          </el-table-column>
          <el-table-column prop="problemType" label="问题分类" align="center">
          </el-table-column>
          <el-table-column prop="problemNature" label="问题定性" align="center">
          </el-table-column>
        </el-table>
      </div>
      <div class="footer">
        <Pagination class="pagination-style" :paginationData="paginationData" />
      </div>
    </div>
  </div>
</template>
<script>
import NewSelect from "@/components/common/NewSelect.vue";
import Pagination from "@/components/common/Pagination.vue";
/**
 * 频发问题 -- 智能辅助
 * @author: Gao Lu
 * @Date: 2022.11.24
 */
export default {
  name: "FrequencyDialog",
  components: { NewSelect, Pagination },
  data() {
    return {
      // 数据字典暂存对象
      classDictMap: {},
      typeSelectVal: "",
      typeOptions: [],
      townSelectVal: "",
      townOptions: [],
      timeSelectVal: "",
      timeOptions: [],
      tableData: [],
      currentPage: 1,
      currentPageSize: 10,
      paginationData: {
        pageSize: 10,
        pagerCount: 5,
        currentPage: 1,
        pageSizes: [5, 10, 20, 30],
        total: 50,
        currentChange: (val) => {
          this.getTableData(val);
        },
        handleSizeChange: (val) => {
          this.handleSizeChange(val);
        },
      },
    };
  },
  created() {
    this.townOptions = [];
    this.timeOptions = [];
    this.typeOptions = [];

    // 时间选择
    for (let i = 1980; i <= parseInt(this.$dayjs().format("YYYY")); i++) {
      this.timeOptions.unshift({
        value: i,
        label: i,
      });
    }
    // 获取数据字典中下拉框数据
    this.classDictQuery("0", "sj_select", "审计类别");
    this.classDictQuery("0", "浦东新区行政区划", "浦东新区行政区划");
    this.getTableData(1);
  },
  methods: {
    // 数据字典查询 -- 获取所需类别
    classDictQuery(type, cName, keyName) {
      let params = new FormData();
      params = {
        type: type,
        cName: cName,
      };

      this.$Post(this.urlsCollection.selectByCNameAType, params).then((res) => {
        if (res.code === 200 && res.content.length > 0) {
          this.classDictMap[keyName] = new Map();
          res.content.forEach((v) => {
            this.classDictMap[keyName].set(v.index + "", v.name);
          });

          if (keyName === "浦东新区行政区划") {
            this.classDictMap[keyName].forEach((v, i) => {
              this.townOptions.push({
                value: i,
                label: v,
              });
            });
            this.townOptions.unshift({
              value: "全部",
              label: "全部",
            });
          }

          if (keyName === "审计类别") {
            this.classDictMap[keyName].forEach((v, i) => {
              this.typeOptions.push({
                value: i,
                label: v,
              });
            });
          }
        }
      });
    },
    resetEvent() {
      this.typeSelectVal = "";
      this.townSelectVal = "";
      this.timeSelectVal = "";
      this.$refs.auditTypeRef.imgValue = "";
      this.$refs.townTypeRef.imgValue = "";
      this.$refs.timeRef.imgValue = "";
      this.getTableData(1);
      console.log("重置");
    },
    // 切换页
    getTableData(val) {
      this.tableData = [];
      console.log(`当前页: ${val}`);

      let searchParam = [];
      // 类别
      if (this.typeSelectVal) {
        let paramType = {
          field: "sj_select",
          // 等值查询
          searchType: "1",
          content: {
            value: this.typeSelectVal,
          },
        };
        searchParam.push(paramType);
      }
      // 被审计街镇
      if (this.townSelectVal && this.townSelectVal !== "全部") {
        let paramTown = {
          field: "bsjz",
          // 等值查询
          searchType: "1",
          content: {
            value: this.townSelectVal,
          },
        };
        searchParam.push(paramTown);
      }
      // 立项年度
      if (this.timeSelectVal) {
        let paramTime = {
          field: "c_new_date",
          // 等值查询
          searchType: "1",
          content: {
            value: this.timeSelectVal,
          },
        };
        searchParam.push(paramTime);
      }
      let params = new FormData();
      params = {
        columnId: 24,
        states: "0,1,2,3",
        pageSize: this.currentPageSize,
        page: val - 1,
        search: JSON.stringify(searchParam),
      };

      this.$Post(this.urlsCollection.selectContentList, params).then((res) => {
        if (res.code === 200 && res.content.data.length > 0) {
          this.paginationData.currentPage = val;
          this.paginationData.total = res.content.count;
          this.tableData = res.content.data.map((v) => {
            return {
              id: v.id || "--",
              createYear: v.c_new_date || "--",
              // createYear: this.$dayjs(v.c_year).format("YYYY")|| "--",
              auditTown:
                this.classDictMap["浦东新区行政区划"].get(v.bsjz) || "--",
              type: this.classDictMap["审计类别"].get(v.sj_select) || "--",
              keyPoint: v.c_zdsjsx || "--",
              problemType: v.c_wtfl || "--",
              problemNature: v.c_wtdx || "--",
            };
          });
        }
      });
    },
    // 切换条数
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.currentPageSize = val;
      this.getTableData(this.currentPage);
    },
  },
};
</script>
<style lang="less" scoped>
.frenquency-container {
  display: flex;
  align-items: center;
  justify-content: center;
  &-inner {
    width: 98%;
    height: 97%;
    background: rgba(0, 39, 77, 0.5);
    .header {
      height: 13%;
      width: 100%;
      position: relative;
      &-title {
        width: 84px;
        height: 20px;
        font-size: 20px;
        font-family: PingFang SC;
        font-weight: 400;
        color: #4dc3ff;
        line-height: 30px;
        position: absolute;
        top: 1px;
        left: 10px;
      }
      &-select {
        position: absolute;
        left: 10px;
        bottom: 5px;
        width: 900px;
        height: 40px;
        color: #e6e6e6;
        display: flex;
        justify-content: space-between;
        & > div {
          // position: absolute;
          display: flex;
          justify-content: space-around;
          width: 320px;
          .text {
            display: flex;
            align-items: center;
            justify-content: flex-end;
            width: 100px;
            height: 28px;
          }
          .select-input {
            width: 170px;
          }
        }
      }
      .reset-btn,
      .query-btn {
        width: 60px;
        height: 30px;
        border-radius: 3px;
        border: none;
        color: #fff;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        top: 15px;
      }
      .reset-btn {
        right: 30px;
        background: rgba(129, 140, 164, 1);
      }
      .query-btn {
        right: 110px;
        background-image: linear-gradient(
          to top,
          rgba(79, 172, 254, 1),
          rgba(0, 242, 254, 1)
        );
      }
    }
    .center {
      height: 77%;
      width: 100%;
      overflow: auto;
      /deep/.el-table {
        background: rgba(0, 39, 77, 0.6);
        // font-size: 0.95rem;
        font-family: PingFang SC;
        font-weight: 500;
        thead {
          color: #4dc3ff;
          font-size: 15px;
        }
      }
    }
    .footer {
      height: 10%;
      width: 100%;
      position: absolute;
      .pagination-style {
        position: absolute;
        right: 50px;
      }
    }
  }
}
</style>
