<template>
  <div class="law-container">
    <div class="law-container-inner">
      <LawDetailsPopup
        ref="lawRef"
        class="law-container-inner-details"
        @lawDetailsClose="lawDetailsClose"
        ><FilePreview ref="lawFilePreview" style="width: 100%; height: 100%"
      /></LawDetailsPopup>
      <div class="header">
        <div class="header-title">法律法规</div>
        <div class="header-select">
          <div>
            <div class="text">类型 :</div>
            <NewSelect
              ref="lawTypeRef"
              :placeholder="typePlaceholder"
              class="select-input"
              v-model="typeSelectVal"
              :options="typeOptions"
              :value="typeSelectVal"
              :isClear="true"
            />
          </div>
          <div>
            <div class="text">年份 :</div>
            <NewSelect
              ref="lawYearRef"
              :placeholder="timePlaceholder"
              class="select-input"
              v-model="timeSelectVal"
              :options="timeOptions"
              :value="timeSelectVal"
              :isClear="true"
            />
          </div>
          <div style="position: relative">
            <el-input class="search-input" v-model="searchInput" clearable>
              <i class="el-icon-search" slot="append"></i>
            </el-input>
          </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"
          :default-sort="{ prop: 'date', order: 'descending' }"
          @current-change="handleClick"
        >
          <el-table-column type="index" width="150" label="序号" align="center">
          </el-table-column>
          <!-- <el-table-column prop="type" label="类别" align="center">
          </el-table-column> -->
          <el-table-column
            prop="title"
            label="标题"
            align="center"
            width="250"
            sortable
          >
          </el-table-column>
          <el-table-column
            prop="code"
            label="文号"
            align="center"
            sortable
          ></el-table-column>
          <el-table-column
            prop="firstClass"
            label="一级分类"
            align="center"
            sortable
          >
          </el-table-column>
          <el-table-column
            prop="secondClass"
            label="二级分类"
            align="center"
            sortable
          >
          </el-table-column>
          <el-table-column
            prop="thirdClass"
            label="三级分类"
            align="center"
            sortable
          >
          </el-table-column>
          <el-table-column
            prop="fourthClass"
            label="四级分类"
            align="center"
            sortable
          >
          </el-table-column>
          <el-table-column prop="date" label="日期" align="center" sortable>
          </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";
// 法律法规细节文档弹窗
import LawDetailsPopup from "@/components/popup/LawDetailsPopup.vue";
import FilePreview from "@/components/common/FilePreView.vue";
/**
 * 法律法规 页面 -- 智能辅助，疑点相关的法律法规
 * @author: Gao Lu
 * @Date: 2022.11.24
 */
export default {
  name: "LawView",
  components: { NewSelect, Pagination, LawDetailsPopup, FilePreview },
  data() {
    return {
      // 数据字典暂存对象
      classDictMap: {},
      searchInput: "",
      typePlaceholder: "请选择审计法律类别",
      typeSelectVal: "",
      typeOptions: [],
      timePlaceholder: "请选择年份",
      timeSelectVal: "不限",
      timeOptions: [],
      tableData: [],
      currentPageSize: 10,
      currentPage: 1,
      lawBaseUrl: "/dms",
      paginationData: {
        pageSize: 10,
        pagerCount: 5,
        currentPage: 1,
        pageSizes: [5, 10, 20, 30],
        total: 30,
        currentChange: (val) => {
          this.getTableData(val);
        },
        handleSizeChange: (val) => {
          this.handleSizeChange(val);
        },
      },
    };
  },
  created() {
    this.timeOptions = [];
    this.typeOptions = [];
    // 时间选择
    for (let i = 1980; i <= 2020; i++) {
      this.timeOptions.unshift({
        value: i,
        label: i,
      });
    }

    this.timeOptions.unshift({
      value: "不限",
      label: "不限",
    });

    // 审计等级
    this.classDictQuery("0", "sj_class", "审计等级");
    // 审计类别
    this.classDictQuery("0", "sh_law_type", "审计法律类别");
    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.typeOptions.unshift({
                  value: i,
                  label: v,
                });
              });
            }
          }
        },
        (error) => {
          this.$message.error();
          console.log(error);
        }
      );
    },
    resetEvent() {
      console.log("重置");
      this.typeSelectVal = "";
      this.timeSelectVal = "不限";
      this.searchInput = "";
      this.$refs.lawTypeRef.imgValue = "";
      this.$refs.lawYearRef.imgValue = "";
      this.getTableData(this.currentPage);
    },
    // 切换页 -- 新法律法规
    getTableData(val) {
      this.tableData = [];
      let searchParam = [];
      // 三级分类 -- 资源分类
      if (this.typeSelectVal) {
        console.log(this.classDictMap["审计法律类别"].get(this.typeSelectVal));
        let paramType = {
          field: "c_c_third_level",
          // 等值查询
          searchType: "2",
          content: {
            value:
              this.classDictMap["审计法律类别"].get(this.typeSelectVal) || "--",
          },
        };
        searchParam.push(paramType);
      }
      // 年份查询
      if (this.timeSelectVal && this.timeSelectVal != "不限") {
        let paramTime = {
          field: "c_c_execute_date",
          // 模糊查询
          searchType: "2",
          content: {
            value: this.timeSelectVal + "",
          },
        };
        searchParam.push(paramTime);
      }
      // 标题查询
      if (this.searchInput) {
        let paramSearch = {
          field: "c_c_name",
          // 模糊查询
          searchType: "2",
          content: {
            value: this.searchInput,
          },
        };
        searchParam.push(paramSearch);
      }
      let params = new FormData();
      params.append("columnId", 1396);
      params.append("states", "0,1,2,3");
      params.append("pageSize", this.currentPageSize);
      params.append("page", val - 1);
      params.append("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 || "--",
              title: v.c_c_name || "--",
              // 文件
              address: v.c_c_pdf || "--",
              // 实施日期
              date: v.c_c_execute_date || "--",
              // 文号
              code: v.c_c_code || "--",
              // 一级分类
              firstClass: v.c_c_first_level || "--",
              // 二级分类
              secondClass: v.c_c_second_level || "--",
              // 三级分类
              thirdClass: v.c_c_third_level || "--",
              // 四级分类
              fourthClass: v.c_c_fourth_level || "--",
              // 五级分类
              fifthClass: v.c_c_fifth_level,
            };
          });
        }
      });
    },
    // 切换条数
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.currentPageSize = val;
      this.getTableData(this.currentPage);
    },
    // 开启弹窗
    handleClick(row) {
      if (row.title) {
        this.$refs.lawRef.title = row.title;
      }
      if (row.date) {
        this.$refs.lawRef.time = row.date;
      }

      if (!row.address) {
        this.$$message.info("暂无文件");
      } else {
        this.$refs.lawRef.lawDetailsPopupShow = true;
        this.$nextTick(() => {
          if (this.$refs.lawFilePreview) {
            this.$refs.lawFilePreview.showView(this.lawBaseUrl + row.address);
          }
        });
      }
    },
    // 关闭弹窗
    lawDetailsClose() {
      if (this.$refs.lawFilePreview) {
        this.$refs.lawFilePreview.cancel();
      }
    },
  },
};
</script>
<style lang="less" scoped>
.law-container {
  display: flex;
  align-items: center;
  justify-content: center;
  &-inner {
    width: 98%;
    height: 97%;
    background: rgba(0, 39, 77, 0.5);
    position: relative;
    &-details {
      width: 100%;
      height: 100%;
      position: absolute;
      z-index: 9999;
    }
    .header {
      height: 120px;
      width: 100%;
      position: absolute;
      &-title {
        width: 84px;
        height: 20px;
        font-size: 20px;
        font-family: PingFang SC;
        font-weight: bold;
        color: #4dc3ff;
        line-height: 30px;
        position: absolute;
        top: 8px;
        left: 15px;
      }
      &-select {
        position: absolute;
        left: 10px;
        bottom: 5px;
        width: 950px;
        height: 40px;
        color: #e6e6e6;
        display: flex;
        justify-content: space-between;
        & > div {
          // position: absolute;
          display: flex;
          justify-content: flex-start;
          width: 280px;
          .text {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 80px;
            height: 28px;
          }
          .select-input {
            width: 190px;
          }
          .search-input {
            position: absolute;
            // right: -50px;
            bottom: 5px;
            width: 280px;
            /deep/.el-input-group__append,
            .el-input-group__prepend {
              background: transparent;
              // background-color: #00aaff54;
              color: #fff;
              border-left: none;
              // border: none;
              // border-radius: 1px;
            }
            /deep/.el-input-group--append .el-input__inner,
            .el-input-group__prepend {
              border-right: none;
            }
            /deep/ .el-input__inner {
              border-color: #fff !important;
              color: #fff;
              border-right: none;
            }
          }
        }
      }
      .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: 20px;
      }
      .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: calc(90% - 120px);
      width: 100%;
      position: absolute;
      overflow: auto;
      top: 130px;
      // background: red;
      /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 {
      position: absolute;
      right: 50px;
      bottom: 30px;
    }
  }
}
</style>
