<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="年份" prop="year">
        <el-select
          v-model="queryParams.year"
          placeholder="请选择年份"
          clearable
        >
          <el-option
            v-for="year in yearList"
            :key="year"
            :label="year"
            :value="year"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="月份" prop="month">
        <el-select
          v-model="queryParams.month"
          placeholder="请选择月份"
          clearable
        >
          <el-option label="01" value="01"></el-option>
          <el-option label="02" value="02"></el-option>
          <el-option label="03" value="03"></el-option>
          <el-option label="04" value="04"></el-option>
          <el-option label="05" value="05"></el-option>
          <el-option label="06" value="06"></el-option>
          <el-option label="07" value="07"></el-option>
          <el-option label="08" value="08"></el-option>
          <el-option label="09" value="09"></el-option>
          <el-option label="10" value="10"></el-option>
          <el-option label="11" value="11"></el-option>
          <el-option label="12" value="12"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item style="margin-left: 25px;">
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button type="primary"  size="mini" @click="handleExport"
          >导出列表</el-button
        >
      </el-form-item>
    </el-form>
    <!--
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['report:rzlNationalRankingInfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['report:rzlNationalRankingInfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['report:rzlNationalRankingInfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['report:rzlNationalRankingInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    -->

    <div id="scrollTable">
      <el-table
        v-loading="loading"
        :data="rzlNationalRankingInfoList"
        :max-height="maxHeight"
        :header-cell-style="{ background: '#2a8eed', color: '#fafcfe' }"
      >
        <el-table-column :label="zbctitle" align="center">
          <el-table-column label="排名" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.ranking }}</span>
            </template>
          </el-table-column>
          <el-table-column label="地区" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.area }}</span>
            </template>
          </el-table-column>
          <el-table-column label="发明专利有效量" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.inventionPatentsUmber }}</span>
            </template>
          </el-table-column>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import {
  listRzlNationalRankingInfo,
  getRzlNationalRankingInfo,
  delRzlNationalRankingInfo,
  addRzlNationalRankingInfo,
  updateRzlNationalRankingInfo,
  getYearList,
} from "@/api/report/rzlNationalRankingInfo";

export default {
  name: "RzlNationalRankingInfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      maxHeight: 0,
      yearList: [],
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 查询年份数据

      // 总条数
      total: 0,
      // 专利有效-全国排名表格数据
      rzlNationalRankingInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        year: "2022",
        month: "12",
        area: null,
        inventionPatentsUmber: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      zbctitle:''
    };
  },
  created() {
    this.getYear();
    this.getList();
    this.$nextTick(() => {
      this.maxHeight = window.innerHeight - 200; //300是页面中除了表格外其他组件的高度
    });
    this.zbctitle = `统计时期${this.queryParams.year}${this.queryParams.month}`
  },
  methods: {
    /** 获取查询年份列表 */
    getYear() {
      getYearList().then((response) => {
        this.yearList = response.data;
      });
    },
    handerMethod({ row, column, rowIndex, columnIndex }) {
      // if (rowIndex === 0) {
      //     if (column.label == '地区' || column.label == '专利类型') {
      //         this.$nextTick(() => {
      //             var _c = document.getElementsByClassName(column.id);
      //             document.getElementsByClassName(column.id)[0].setAttribute('rowSpan', 2);
      //         });
      //         return column;
      //     }
      // } else if (rowIndex === 1) {
      //     if (column.label == '地区' || column.label == '专利类型') {
      //         return { display: 'none' };
      //     }
      // }
      // if (column[0].level == 1) {
      //     column[0].rowSpan = 2
      //     column[1].rowSpan = 0
      //     if (rowIndex === 1) {
      //         return { display: 'none' }
      //     }
      // }
    },
    /** 查询专利有效-全国排名列表 */
    getList() {
      this.loading = true;
      this.zbctitle = `统计时期${this.queryParams.year}${this.queryParams.month}`
      listRzlNationalRankingInfo(this.queryParams).then((response) => {
        // this.rzlNationalRankingInfoList = response.rows;
        this.total = 0;
        this.rzlNationalRankingInfoList = response.data;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        year: null,
        month: null,
        area: null,
        inventionPatentsUmber: null,
        remark: null,
        delFlag: null,
        status: 0,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      if (this.queryParams.month) {
        if (this.queryParams.year) {
          this.queryParams.pageNum = 1;
          this.getList();
        } else {
          this.$message("请选择年份");
        }
      } else {
        this.queryParams.pageNum = 1;
        this.getList();
      }
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加专利有效-全国排名";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getRzlNationalRankingInfo(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改专利有效-全国排名";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateRzlNationalRankingInfo(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRzlNationalRankingInfo(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除专利有效-全国排名编号为"' + ids + '"的数据项？')
        .then(function () {
          return delRzlNationalRankingInfo(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "report/rzlNationalRankingInfo/export",
        {
          ...this.queryParams,
        },
        `rzlNationalRankingInfo_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
