<template>
  <div class="frenquency-container">
    <el-dialog
      custom-class="myMission"
      title="详细信息"
      :append-to-body="true"
      :modal="true"
      :visible.sync="dialogVisible"
      width="70%"
      height="60%"
      :before-close="handleClose"
    >
      <div>
        <div class="dialog_title_info">
          <div>立项年度：{{ formData[activeRowIndex] && formData[activeRowIndex].c_lxndwt ? formData[activeRowIndex].c_lxndwt : '--' }}</div>
          <div>被审计镇：{{ formData[activeRowIndex] && formData[activeRowIndex].c_bsjzwt && unTownOptions && unTownOptions[formData[activeRowIndex].c_bsjzwt] ? unTownOptions[formData[activeRowIndex].c_bsjzwt] : '--' }}</div>
        </div>
        <div class="dialog_title_info">问题金额（万元）：{{ formData[activeRowIndex] && formData[activeRowIndex].c_wtjewt ? formData[activeRowIndex].c_wtjewt : '--'}}</div>
        <div class="dialog_title">审计报告中的问题反映情况</div>
        <div v-for="(item, index) in dialogData" :key="index" class="dialog_table">
          <div>{{ item.title }}</div>
          <div>{{ formData[activeRowIndex] && formData[activeRowIndex][item.columnName] ? formData[activeRowIndex][item.columnName] : '--'}}</div>
        </div>
        <!-- <div class="dialog_title3"><el-button size="mini" type="primary" class="infoBut">查看疑点图斑</el-button></div> -->
      </div>
    </el-dialog>
    <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" @row-click="rowClick">
          <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,
      // 整改中的查看详情弹窗状态
      dialogVisible: false,
      dialogData: [
        { title: "问题分类", columnName: "c_wtflwt", info: "--" },
        { title: "问题定性1", columnName: "c_wtdx1wt", info: "--" },
        { title: "问题定性2", columnName: "c_wtdx2wt", info: "--" },
        { title: "问题事项", columnName: "c_wtsxwt", info: "--" },
        { title: "使用法条", columnName: "c_syftwt", info: "--" },
        { title: "边审边改情况", columnName: "c_bsbgqkwt", info: "--" }
      ],
      // 暂存全部数据
      formData: [],
      // 选中的rowinxdex
      activeRowIndex: 0,
      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.unTownOptions = {};
    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.unTownOptions[i]=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);
    },
    rowClick(row, column, event) {
      this.activeRowIndex = row.rowIndex - 1;
      this.dialogVisible = true;
    },
    handleClose() {
      this.dialogVisible = false;
    },
    // 切换页
    getTableData(val) {
      this.tableData = [];
      let searchParam = [];
      // 类别
      if (this.typeSelectVal) {
        let paramType = {
          field: "c_sjlbwt",
          // 等值查询
          searchType: "1",
          content: {
            value: this.typeSelectVal
          }
        };
        searchParam.push(paramType);
      }
      // 被审计街镇
      if (this.townSelectVal && this.townSelectVal !== "全部") {
        let paramTown = {
          field: "c_bsjzwt",
          // 等值查询
          searchType: "1",
          content: {
            value: this.townSelectVal
          }
        };
        searchParam.push(paramTown);
      }
      // 立项年度
      if (this.timeSelectVal) {
        let paramTime = {
          field: "c_lxndwt",
          // 等值查询
          searchType: "1",
          content: {
            value: this.timeSelectVal
          }
        };
        searchParam.push(paramTime);
      }
      let params = new FormData();
      params = {
        columnId: 1127,
        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.formData = res.content.data;
          let rowIndex = 0;
          this.tableData = res.content.data.map(v => {
            rowIndex ++;            
            return {
              rowIndex: rowIndex,
              id: v.id || "--",
              createYear: v.c_lxndwt || "--",
              // createYear: this.$dayjs(v.c_year).format("YYYY")|| "--",
              auditTown: this.classDictMap["浦东新区行政区划"].get(v.c_bsjzwt) || "--",
              type: this.classDictMap["审计类别"].get(v.c_sjlbwt) || "--",
              keyPoint: v.c_zdsjsxwt || "--",
              problemType: v.c_ckwtdxwt || "--",
              problemNature: v.c_wtdx1wt || "--"
            };
          });
        }
      });
    },
    // 切换条数
    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;
      }
    }
  }
}

.dialog_title {
  font-size: 20px;
  font-weight: bold;
  color: #fff;
  padding-bottom: 1.5rem;
  &2 {
    font-weight: 100;
    font-size: 18px;
    color: #fff;
    padding-top: 1.5rem;
  }
  &3 {
    display: flex;
    justify-content: center;
    padding-top: 1.5rem;
  }
  &_info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 18px;
    font-weight: 400px;
    color: #dcdfe6;
    padding: 1rem 0;
  }
}
.dialog_table {
  display: flex;
  justify-content: space-between;
  div {
    width: 50%;
    text-align: center;
    background-color: #ffffff64 !important;
    margin: 1px;
    padding: 5px 10px;
    display: flex;
    justify-content: center;
    color: #dcdfe6;
    border: 1px solid #001d3c00;
  }
}
</style>
