<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" label-width="150px">
        <el-select
          v-model="queryParams.year"
          placeholder="请选择截止年份"
          clearable
        >
          <el-option
            v-for="year in yearList"
            :key="year"
            :label="year"
            :value="year"
          />
        </el-select>
        <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
          label="时间"
          prop="appDate"
          label-width="150px"
        >
          <el-date-picker
            v-model="appDate"
            type="daterange"
            @input="appDateInput2"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            clearable
          />
        </el-form-item> -->


        <el-form-item label="原始州市" prop="appliCity">
          <el-select
            v-model="queryParams.appliCity"
            placeholder="请选择州市"
            clearable
          >
            <el-option label="全部" :value="null"></el-option>
            <el-option
              v-for="region in regionOptions"
              :key="region.cityShortName"
              :label="region.cityShortName"
              :disabled="region.cityShortName == '云南省'"
              :value="region.code"
            />
            <el-option label="空值" :value="'null'"></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="原始区县" prop="appliCounty">
          <el-select
            v-model="queryParams.appliCounty"
            placeholder="请选择区县"
            clearable
            :disabled="opensb"
          >
            <el-option label="全部" :value="null"></el-option>
            <el-option
              v-for="item in ysDistrictCounty"
              :key="item.cityShortName"
              :label="item.cityShortName"
              :value="item.name"
            />
            <el-option label="空值" :value="'null'"></el-option>
            <el-option label="非本区化" :value="'notnull'"></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>

    <div id="scrollTable">
      <el-table
        v-loading="loading"
        :data="Population"
        :max-height="maxHeight"
        :header-cell-style="{ background: '#2a8eed', color: '#fafcfe' }"
      >
        <el-table-column label="地区" align="center" width="100" fixed="left">
          <template slot-scope="scope">
            <span>{{ scope.row["areaName"] }}</span>
          </template>
        </el-table-column>

        <el-table-column :label="zbtitle" align="center">

          <el-table-column
            :label="String(y)"
            align="center"
            v-for="(y) in popuYearList"
            :key="y"
          >
          <template slot-scope="scope">
                <span>{{ scope.row.totals[String(y)] }}</span>
              </template>
        </el-table-column>


        </el-table-column>
      </el-table>
      <!-- <div style="margin-top: 30px;">
        <el-table
        v-loading="loading"
        :data="Population2"
        :max-height="maxHeight"
        :header-cell-style="{ background: '#2a8eed', color: '#fafcfe' }"
      >


        <el-table-column :label="zbctitel" align="center">
          <el-table-column label="地区" align="center" >
          <template slot-scope="scope">
            <span>{{ scope.row["areaName"] }}</span>
          </template>
        </el-table-column>
          <el-table-column
            :label="String(y)"
            align="center"
            v-for="(y, i) in popuYearList2"
            :key="i"
          >
          <template slot-scope="scope">
            <span>{{ scope.row.totalCnt }}</span>
          </template>

        </el-table-column>


        </el-table-column>
      </el-table>
      </div> -->
    </div>
  </div>
</template>

<script>
import {listReportAct,listReportAct2} from '@/api/trademark/chineseTrademarkApplication'
import{getyearList} from '@/api/staticdata'
import {getRegionList} from "@/api/system/urPatentValid";
export default {
  name: "TrademarkRegistration",
  data() {
    return {
      maxHeight: 0,
      yearList: [],
      headerList: [],
      hearderTitle: "统计时期:2022",
      yearColumn1: "年",
      yearColumn2: "年发明专利有效量（件）",
      yearColumn3: "年人口（万人）",
      popuYearList2: ['申请量'],
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      appDate:['2017-12','2022-12'],
      regionOptions: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 专利有效-万人发明拥有量统计表格数据
      popuYearList: [],
      Population: [],
      Population2: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        patentType: null,
        cityCode: null,
        cityName: null,
        year: '2023',
        month: '',
        higherSchool: null,
        researchInstitute: null,
        status: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      zbctitel:'统计时期',
      zbtitle:'统计时期',
      activityRegs3:['2017-12','2022-12']
    };
  },
  created() {
    let monthint=new Date().getMonth()+1;
    if(monthint>=10){
      this.queryParams.month=monthint+'';
    }else{
      this.queryParams.month='0'+monthint;
    }
    this.getHeader();
    this.getList();
    this.$nextTick(() => {
      this.maxHeight = window.innerHeight - 200; //300是页面中除了表格外其他组件的高度
    });
    this.yearList = getyearList()
    this.getRegion()
    this.zbtitle = `统计时期${this.queryParams.year}${this.queryParams.month}（范围近6年含本年，每年范围截止到当年12月15日）`
    this.zbctitel = `统计时期（截止时间${this.queryParams.year}-${this.queryParams.month}）`
  },
  methods: {
    /** 获取省市列表 */
    getRegion() {
      let params = {};
      getRegionList(params).then((response) => {
        this.regionOptions = response.data;
      });
    },
    appDateInput2(e){
      this.$nextTick(() => {
        if (e == null) {
          this.queryParams.applyAdjustmentTimeBegin = null;
          this.queryParams.applyAdjustmentTimeEnd = null;
        } else {
          this.$set(this, "activityRegs3", [e[0], e[1]]);
          this.queryParams.applyAdjustmentTimeBegin =
            this.activityRegs3[0];
          this.queryParams.applyAdjustmentTimeEnd =
            this.activityRegs3[1];
        }
      });
    },
    /** 获取动态表头 */
    getHeader() {
      let head = "统计时期";
      this.hearderTitle = head;
    },


    /** 查询专利有效-万人发明拥有量统计列表 */
    getList() {
      this.loading = true;
      let flag1=false;
      let flag2=false;
      listReportAct(this.queryParams).then(res=>{
        flag1=true;
        this.popuYearList =  res.data.years
        this.Population = res.data.list
        if(flag1&&flag2){
          this.loading = false;
        }

      });
      listReportAct2(this.queryParams).then(res=>{
        flag2=true;
        this.Population2 = res.data.list
        if(flag1&&flag2){
          this.loading = false;
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        patentType: null,
        cityCode: null,
        cityName: null,
        year: null,
        month: null,
        higherSchool: null,
        researchInstitute: null,
        remark: null,
        delFlag: null,
        status: 0,
        createTime: null,
        createBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.zbctitel = `统计时期（截止时间${this.queryParams.year}-${this.queryParams.month}）`
      this.zbtitle = `统计时期${this.queryParams.year}-${this.queryParams.month}（范围近6年含本年，每年范围截止到当年12月15日）`
      if (this.queryParams.month) {
        if (this.queryParams.year) {
          this.getHeader();
          // this.popuYearList = []
          // this.Population = []
          this.queryParams.pageNum = 1;
          this.getList();
        } else {
          this.$message("请选择年份");
        }
      } else {
        this.getHeader();
        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;
      getRzlInventStatisticsInfo(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) {
            updateRzlInventStatisticsInfo(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRzlInventStatisticsInfo(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 delRzlInventStatisticsInfo(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "trade/cTrademark/exportReportAct",
        {
          ...this.queryParams,
        },
        `rzlInventStatisticsInfo_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
