<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <!-- <el-form-item label="开始时间" prop="beginDate">
      <el-input
        v-model="queryParams.beginDate"
        placeholder="请输入开始时间"
        clearable
        size="small"
        @keyup.enter.native="handleQuery"
      />
    </el-form-item>

      <el-form-item label="结束时间" prop="endDate">
        <el-input
          v-model="queryParams.endDate"
          placeholder="请输入结束时间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->

      <el-form-item label="时间" prop="appDate">
        <el-date-picker
          v-model="appDate"
          type="daterange"
          @input="appDateInput"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
        />
      </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-table
      v-loading="loading"
      :data="dAgentAuthInfoList"
      @selection-change="handleSelectionChange"
      :header-cell-style="{ background: '#2a8eed', color: '#fafcfe' }"
    >
      <el-table-column :label="zbc" align="center">
        <el-table-column label="排名" align="center" prop="ranking" />
        <el-table-column label="代理机构" align="center" prop="agencyName" />
        <el-table-column
          label="案件代理总量（公开总量）"
          align="center"
          prop="pubTotal"
        />
        <el-table-column label="授权量" align="center" prop="authTotal" />
        <el-table-column label="发明授权" align="center" prop="inventionCnt" />
        <el-table-column
          label="实用新型"
          align="center"
          prop="modelUtilityCnt"
        />
        <el-table-column label="外观设计" align="center" prop="appearanceCnt" />
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {
  listDAgentAuthInfo,
  getDAgentAuthInfo,
  delDAgentAuthInfo,
  addDAgentAuthInfo,
  updateDAgentAuthInfo,
} from "@/api/agentrep/dAgentAuthInfo";

export default {
  name: "DAgentAuthInfo",
  data() {
    return {
      zbc: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 代理机构报表格数据
      dAgentAuthInfoList: [],
      // 弹出层标题
      title: "",
      appDate: ['2022-01-01','2022-12-31'],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        beginDate: '2022-01-01',
        endDate: '2022-12-31',
        pageNum: 1,
        pageSize: 100,
        agencyName: null,
        pubTotal: null,
        authTotal: null,
        inventionCnt: null,
        modelUtilityCnt: null,
        appearanceCnt: null,
        status: null,
      },
      // 表单参数
      form: {},
      activityRegs2:['2022-01-01','2022-12-31'],
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
    this.gettable();
  },
  methods: {
    gettable() {
      console.log(this.activityRegs2,'this.activityRegs2');

      if (this.activityRegs2.length > 0) {
        this.zbc =
          "统计时期" + this.activityRegs2[0] + "到" + this.activityRegs2[1];
      } else {
        this.zbc = "统计时期";
      }
    },
    appDateInput(e) {
      console.log(e);
      this.$nextTick(() => {
        if (e == null) {
          this.queryParams.beginDate = null;
          this.queryParams.endDate = null;
        } else {
          console.log(this.activityRegs2);
          this.$set(this, "activityRegs2", [e[0], e[1]]);
          this.queryParams.beginDate = this.activityRegs2[0];
          this.queryParams.endDate = this.activityRegs2[1];
        }
      });
    },
    /** 查询代理机构报列表 */
    getList() {
      this.loading = true;
      listDAgentAuthInfo(this.queryParams).then((response) => {
        this.dAgentAuthInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        agencyName: null,
        pubTotal: null,
        authTotal: null,
        inventionCnt: null,
        modelUtilityCnt: null,
        appearanceCnt: null,
        status: "0",
        remark: null,
        delFlag: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
      this.gettable()

    },
    /** 重置按钮操作 */
    resetQuery() {
      this.appDate = null;
      this.queryParams.endDate = null;
      this.queryParams.beginDate = null;
      this.activityRegs2 = []
      this.resetForm("queryForm");
      this.handleQuery();
      this.gettable()
    },
    // 多选框选中数据
    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;
      getDAgentAuthInfo(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) {
            updateDAgentAuthInfo(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDAgentAuthInfo(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 delDAgentAuthInfo(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "agentrep/dAgentAuthInfo/export",
        {
          ...this.queryParams,
        },
        `dAgentAuthInfo_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
