<template>
  <div class="L-public-main" id="L-size-main">
    <div class="L-main">
      <header id="L-header">
        <el-form :inline="true" :model="formInline" size="small" class="demo-form-inline" ref="queryFrom">
          <el-col :span="22">
            <el-form-item label="政策文件名称：" prop="policyName">
              <el-input v-model.trim="formInline.policyName" placeholder="请输入内容"></el-input>
            </el-form-item>
            <el-form-item label="发文单位：" prop="dispatchUnit">
              <el-input v-model.trim="formInline.dispatchUnit" placeholder="请输入内容"></el-input>
            </el-form-item>
            <el-form-item label="政策等级：" prop="level">
              <el-select class="ignoreElement" v-model="formInline.level" placeholder="请选择">
                <!-- <el-option
                  v-for="dict in dict.type.jjh_project_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value">
                </el-option> -->
                <el-option
                  label="省级"
                  value="0">
                </el-option>
                <el-option
                  label="市级"
                  value="1">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="发文时间：" prop="projectYear">
              <el-date-picker
                class="ignoreElement"
                v-model="formInline.projectYear"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                type="daterange"
                placeholder="选择发文时间">
              </el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button size="mini" @click="resetQuery('queryFrom')">重置</el-button>
              <el-button size="mini" type="primary" @click="handleQuery('queryFrom')">查询</el-button>
            </el-form-item>
          </el-col>
          <el-col :span="2">
            <el-button type="primary" class="import-btn" icon="icon iconfont icon-jc-shangchuan" size="mini" @click="importBtn">新增发文</el-button>
          </el-col>
        </el-form>
      </header>
      <section>
        <el-table v-loading="loading" :data="tableData" :row-class-name="tableRowClassName" :height="tabHeader" :max-height="tabHeader">
          <el-table-column label="政策文件名称" width="450px" prop="projectClassify" />
          <el-table-column label="关联项目" prop="projectName" />
          <el-table-column label="发文单位" prop="declareUnit" />
          <el-table-column label="政策等级" prop="projectYear" />
          <el-table-column label="发文时间" prop="projectYear" />
          <el-table-column label="上传用户" prop="projectYear" />
          <el-table-column label="上传时间" prop="projectYear" />
          <el-table-column label="操作" prop="userId" class-name="table-operation">
            <template slot-scope="scope">
              <span class="look-info" @click="goInfo(scope.row)">查看详情</span>
              <span class="del-info" @click="delInfo(scope.row)">删除</span>
            </template>
          </el-table-column>
        </el-table>
        <my-pagination 
          id="L-pagination"
          :total="total"
          :page="pagination.current"
          :limit="pagination.size"
          @pagination="getPagination"
          :current-page.sync="pagination.current" 
        ></my-pagination>
      </section>
    </div>
    <my-dialog title="title" @close="importClose" ref="importProject">
      <el-row>
        <el-col :span="24">
          <el-form :model="addFrom" size="small" ref="importFrom" label-width="100px" :rules="rules">
            <el-form-item label="政策文件名称：" class="importFormItem" prop="projectClassify">
              <!-- <el-select class="ignoreElement" v-model="addFrom.projectClassify" placeholder="请选择">
                <el-option
                  v-for="dict in dict.type.jjh_project_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value">
                </el-option>
              </el-select> -->
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
    </my-dialog>
  </div>
</template>
<script>
import myPagination from "@/views/components/Pagination/index.vue"
import myDialog from "@/views/components/myDialog/index.vue"
export default {
  components:{myPagination, myDialog},
  data() {
    return {
      total:0,
      pagination: {
        current:1,
        size:10,
      },
      loading:false,
      formInline: {
        policyName: '',
        dispatchUnit:"",
        level:"",
        projectYear:"",
        status: ''
      },
      tableData:[],
      tabHeader: undefined,
      addFrom: {
        projectClassify:""
      }
    }
  },
  mounted() {
    this.cancalDebounce();
    window.addEventListener('resize', this.cancalDebounce);
    
    // this.getList();
  },
  destroyed() {
    window.removeEventListener('resize', this.cancalDebounce);
  },
  methods:{
    // 列表获取
    getList(){
      this.loading = true;
      jProject(this.pagination).then(res=>{
        this.loading = false;
        this.total = res.data.total;
        this.tableData = res.data.records;
      })
    },
    // 获取页码
    getPagination(pages) {
      this.pagination.current = pages.page;
      this.pagination.size = pages.limit;
      this.getList();
    },
    // 查询
    handleQuery() {
      this.pagination = {
        current: 1,
        size: 10
      }
      this.pagination = { ...this.pagination,...this.formInline };
      // console.log(this.pagination);
      // console.log(this.formInline);
      this.getList();
    },
    // 重置
    resetQuery(formName){
      this.$refs[formName].resetFields();
      this.pagination = {
        current: 1,
        size: 10
      }
      // this.getList();
    },
    // 修改table背景色
    tableRowClassName({row, rowIndex}){
      if (rowIndex % 2 !== 0) {
        return 'evenNumber-row';
      }
      return '';
    },
    // 导入按钮
    importBtn(){
      this.$refs.importProject.open();
    },
    // 关闭事件触发
    importClose(){
      this.$refs.importProject.close();
      this.$nextTick(()=>{
        this.$refs.importFrom.resetFields();
      })
    },
    // 查看详情
    goInfo(rwo){
      this.$router.push({
        path: '/project/projectInfo',
        query: { userId: rwo.id }
      })
    },
    // 删除
    delInfo(row){
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          jProjectDel({ id: row.id }).then((res) => {
            this.getList();
            this.$message({
              type: "success",
              message: "删除成功!",
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 屏幕尺寸变化
    cancalDebounce(){
      const element = document.getElementById('L-size-main'); // 通过元素的 ID 获取元素
      const header = document.getElementById('L-header'); // 通过元素的 ID 获取元素
      const pagination = document.getElementById('L-pagination'); // 通过元素的 ID 获取元素
      const elementHeight = element.offsetHeight;
      const headerHeight = header.offsetHeight;
      const paginationtHeight = pagination.offsetHeight;
      this.tabHeader = elementHeight - headerHeight - paginationtHeight - 140;
    }
  },
}
</script>
<style lang="scss" scoped>

</style>
