<template>
  <div class="law-related" v-if="lawPopupShow" v-drag>
    <LawDetailsPopup
      ref="lawDetailsRef"
      class="law-details-popup"
      @lawDetailsClose="lawDetailsClose"
    >
      <FilePreView style="width: 100%; height: 100%" ref="lawFileRef" />
    </LawDetailsPopup>
    <div class="title">
      <div class="title-text">XXXX疑点相关的法律法规</div>
      <div class="title-close-btn" @click="closeEvent"></div>
    </div>
    <div class="option">
      <div class="option-left">
        <el-input
          class="search-input"
          placeholder="请输入关键字"
          v-model="searchInput"
          clearable
        >
          <div class="search-icon" @click="getTableData(1)" slot="append">
            <i class="el-icon-search"></i>
          </div>
        </el-input>
      </div>
      <div class="option-right">
        <NewSelect class="option-right-item" :placeholder="'排序方式'" />
        <NewSelect class="option-right-item" :placeholder="'搜索范围'" />
        <NewSelect class="option-right-item" :placeholder="'时间范围'" />
      </div>
    </div>
    <div class="table">
      <el-table
        ref="singleTable"
        highlight-current-row
        style="width: 100%"
        max-height="300"
        :data="tableData"
        @current-change="handleRowChange"
      >
        <el-table-column prop="title" label="名称" align="center">
        </el-table-column>
        <el-table-column prop="date" label="日期" align="center">
        </el-table-column>
      </el-table>
    </div>
    <div class="footer">
      <Pagination :paginationData="paginationData" />
    </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";
/**
 * XXXX 疑点相关的法律法规
 * @author: Gao Lu
 * @Date: 2022.11.25
 */
export default {
  name: "LawPopup",
  components: { NewSelect, Pagination, LawDetailsPopup, FilePreView },
  data() {
    return {
      lawBaseUrl: "/dms",
      searchInput: "",
      // lawDetailsPopupShow: false,
      sortSelectVal: "土地资源",
      sortOptions: [
        {
          value: "土地资源",
          label: "土地资源",
        },
      ],
      scopeSelectVal: "浦东新区",
      scopeOptions: [
        {
          value: "浦东新区",
          label: "浦东新区",
        },
      ],
      timeSelectVal: "",
      timeOptions: [],
      tableData: [],
      paginationData: {
        pageSize: 10,
        pagerCount: 5,
        currentPage: 1,
        pageSizes: [5, 10, 20, 50],
        total: 200,
        currentChange: (val) => {
          this.getTableData(val);
        },
        handleSizeChange: (val) => {
          this.handleSizeChange(val);
        },
      },
      currentRow: null,
    };
  },
  computed: {
    lawPopupShow() {
      return this.$store.state.lawPopupShow;
    },
  },
  created() {
    this.timeOptions = [];
    // 时间选择
    for (let i = 1980; i < 2023; i++) {
      this.timeOptions.unshift({
        value: i,
        label: i,
      });
    }
    this.getTableData(1);
  },
  methods: {
    queryEvent() {
      console.log("查询");
    },
    resetEvent() {
      console.log("重置");
    },
    // 切换页
    getTableData(val) {
      // console.log(`当前页: ${val}`);
      this.tableData = [];

      let searchParam = [];

      if (this.searchInput) {
        let paramSearch = {
          field: "c_name",
          // 模糊查询
          searchType: "2",
          content: {
            value: this.searchInput,
          },
        };
        searchParam.push(paramSearch);
      }

      let params = new FormData();
      params = {
        columnId: 23,
        states: 3,
        pageSize: this.currentPageSize,
        page: val - 1,
        search: JSON.stringify(searchParam),
      };

      this.$Post(this.urlsCollection.selectContentList, params).then(
        (res) => {
          // console.log(res, "当前的法律法规");
          if (res.code === 200 && res.content.data.length > 0) {
            // console.log(res.content, "查询到的法律法规相关的数据");
            this.paginationData.currentPage = val;
            this.paginationData.total = res.content.count;
            this.tableData = res.content.data.map((v) => {
              return {
                id: v.id || "",
                title: v.c_name || "--",
                date: v.c_new_date || "--",
                // date: v.c_date || "--",
                address: v.c_pdf || "",
              };
            });
          }
        },
        (error) => {
          console.log(error);
        }
      );
    },
    // 切换条数
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    closeEvent() {
      this.$store.state.lawPopupShow = false;
    },
    lawDetailsClose() {
      if (this.$refs.lawFileRef) {
        this.$refs.lawFileRef.cancel();
      }
    },
    // 选中当前行
    handleRowChange(val) {
      console.log(val, "currentRow");
      this.currentRow = val;
      this.$refs.lawDetailsRef.title = val.title;
      this.$refs.lawDetailsRef.time = val.date;
      this.$refs.lawDetailsRef.lawDetailsPopupShow = true;
      this.$nextTick(() => {
        if (this.$refs.lawFileRef) {
          this.$refs.lawFileRef.showView(this.lawBaseUrl + val.address);
        }
      });
    },
  },
};
</script>
<style lang="less" scoped>
.law-related {
  width: 700px;
  height: 500px;
  background: rgba(0, 39, 77, 0.95);
  border: 1px solid #2fb8ff;
  pointer-events: auto;
  // 单击每一行后弹出法律相关的详细内容
  .law-details-popup {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 99;
  }
  .title {
    margin: 0 auto;
    width: 99%;
    height: 8%;
    position: relative;
    border-bottom: 1px solid;
    border-image: -webkit-linear-gradient(
        -90deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(47, 184, 255, 1) 50%,
        rgba(255, 255, 255, 0) 99%
      )
      2 2 2 2;
    border-image: -moz-linear-gradient(
        90deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(47, 184, 255, 1) 50%,
        rgba(255, 255, 255, 0) 99%
      )
      2 2 2 2;
    border-image: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(47, 184, 255, 1) 50%,
        rgba(255, 255, 255, 0) 99%
      )
      2 2 2 2;

    &-text {
      position: absolute;
      left: 10px;
      top: 7px;
      color: #fff;
      word-spacing: 2px;
      letter-spacing: 2px;
      font-size: 18px;
      font-family: PingFang SC;
      font-weight: 300;
    }
    &-close-btn {
      width: 30px;
      height: 30px;
      position: absolute;
      top: 1px;
      right: 1px;
      background: url("../../assets/image/close.png") no-repeat center;
      cursor: pointer;
    }
  }
  .option {
    width: 100%;
    height: 11%;
    position: relative;
    &-left {
      position: absolute;
      left: 0;
      width: 35%;
      .search-input {
        position: absolute;
        top: 7px;
        left: 5px;
        width: 225px;
      }
      /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 {
        height: 35px;
        border-right: none;
      }

      /deep/ .el-input__inner {
        border-color: #fff !important;
        color: #fff;
      }
      .search-icon {
        position: absolute;
        top: 10px;
        right: 16px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }
    &-right {
      display: flex;
      align-items: center;
      justify-content: space-around;
      position: absolute;
      right: 0;
      width: 65%;
      &-item {
        width: 120px;
        height: 40px;
        line-height: 50px;
      }
    }
  }
  .table {
    width: 100%;
    height: 70%;
    /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;
      }
      td {
        cursor: pointer;
      }
    }
  }
  .footer {
    margin: 0 auto;
    width: 100%;
    height: 10%;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
</style>
