<template>
  <div class="noticepage">
    <!-- 头部导航面包屑 -->
    <div class="noticetm-nav">
      <span>商标公告查询</span>
    </div>
    <!-- 查询选择表单 -->
    <div class="choice-form">
      <el-form :inline="true" :model="choiceForm">
        <el-row class="first-row">
          <el-form-item label="公告类型：" class="left-span">
            <el-select
              v-model="choiceForm.type"
              placeholder="商标初步审定公告"
              class="info-box"
              @change="changeOption"
            >
              <el-option label="商标初步审定公告" value="TMZCSQ"></el-option>
              <el-option label="商标注册公告（一）" value="TMZCZC"></el-option>
              <el-option label="商标注册公告（二）" value="TMQTZC"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="公告期号：" class="left-span" prop="num">
            <el-input
              v-model="choiceForm.num"
              placeholder="请输入公告期号"
              class="info-box"
            ></el-input>
          </el-form-item>
          <el-button type="primary" @click="onSubmit" class="btn-size left-span"
            >查询</el-button
          >
        </el-row>
      </el-form>
    </div>

    <!-- 初审公告 -->
    <div class="record">
      <span>最新12期初审公告</span>
    </div>

    <!-- 公告表格 -->
    <div class="brand-form-wrap">
      <el-table :data="brandData" class="brand-form" v-loading="loading">
        <el-table-column prop="notice_issue" label="公告期" align="center">
        </el-table-column>
        <el-table-column
          prop="date"
          label="初审公告日期"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="enddate"
          label="异议申请截止日期"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="lastday"
          label="异议申请剩余时间"
          align="center"
        ></el-table-column>

        <el-table-column prop="operation" label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="passNoticeNumber(scope.$index, scope.row)"
              >公告详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
// 近12期初审公告 公告查询接口
import { noticequeryTMZCSQ } from "@/api/tmQuery.js";
export default {
  data() {
    return {
      // 查询选择表单数据
      choiceForm: {
        type: "TMZCSQ", // 公告类型
        num: null // 公告期号
      },

      // 商标表格数据
      brandData: [],

      // loading动画
      loading: false,

      // 最大工期号
      maxNum: null
    };
  },
  methods: {
    // 点击 查询 按钮，提交表单数据进行查询
    onSubmit() {
      // 关于输入的工期号的验证判断
      if (this.choiceForm.num == null) {
        // 非空
        this.$message({
          message: "请输入目标",
          type: "warning"
        });
      } else if (/\D/.test(this.choiceForm.num)) {
        // 数字
        this.$message({
          message: "工期号只能是正整数数字",
          type: "warning"
        });
      } else if (this.choiceForm.num <= 0) {
        // 大于0
        this.$message({
          message: "工期号是大于0的数字",
          type: "warning"
        });
      } else if (this.choiceForm.num > this.maxNum) {
        // 小于最大工期号
        this.$message({
          message: `工期号是小于或等于最大工期号${this.maxNum}的数字`,
          type: "warning"
        });
      } else {
        // 验证通过，提交表单的数据，在详情页面显示查询结果
        this.$router.push({
          path: "/bycnoticeindex",
          query: {
            type: this.choiceForm.type,
            noticenum: this.choiceForm.num
          }
        });
      }
    },
    // 选择不同的 初审公告 注册公告一 注册公告二 三种类型对应不同的类型接口参数
    changeOption(value) {
      this.choiceForm.type = value;
    },
    // 点击公告详情 按钮，提交工期号和公告类型进行查询，在详情页面显示查询结果
    passNoticeNumber(index, row) {
      this.choiceForm.num = row.notice_issue;
      // 提交请求
      this.$router.push({
        path: "/bycnoticeindex",
        query: {
          type: this.choiceForm.type,
          noticenum: this.choiceForm.num
        }
      });
    }
  },
  created() {
    // 刷新页面取消查询的query参数
    this.$router.push("/bycnoticetm");

    this.loading = true; // 查询数据之前显示 loading
    noticequeryTMZCSQ().then(res => {
      if (res.status == 0) {
        this.brandData = res.data.rows;
        this.loading = false; //数据查询成功之后隐藏 loading
        if (res.data.rows.length != 0) {
          this.maxNum = res.data.rows[0].notice_issue; // 保留数据中的最大工期号
        }
      } else {
        this.$notify.error({
          title: "错误", // 服务器端请求失败
          message: res.msg
        });
      }
    });
  }
};
</script>

<style lang="scss">
.noticepage {
  // 企链 70px的footer ; 启服通的footer是377px
  min-height: calc(100% - 70px);

  .choice-form {
    .el-input__inner {
      border-radius: 0px;
      height: 34px;
      width: 300px;
    }
  }
  .has-gutter tr th {
    background: #d6daeb;
  }
  /* 头部导航面包屑 */
  .noticetm-nav {
    width: 1200px;
    margin: 0 auto;
    padding-top: 21px;
    padding-bottom: 19px;
    span {
      width: 96px;
      height: 21px;
      font-size: 16px;
      color: rgba(3, 0, 76, 1);
      line-height: 21px;
    }
  }

  /* 查询选择表单 */
  .choice-form {
    width: 1200px;
    height: 76px;
    background: rgba(247, 248, 252, 1);
    border: 1px solid rgba(239, 241, 249, 1);
    margin: 0 auto;

    .first-row {
      margin-top: 18px;
      button.el-button {
        background: #0989c5;
        width: 80px;
        height: 34px;
        padding: 0;
        box-sizing: border-box;
        border-radius: 0;
        line-height: 0;
        margin-top: 2px;
      }
    }

    .left-span {
      margin-left: 20px;
      height: 34px;
    }

    .info-box {
      width: 300px;
      border-radius: 0px;
    }

    .btn-size {
      width: 60px;
      height: 34px;
      font-family: PingFangSC-Regular;
      font-size: 14px;
    }
  }

  /* 最新12期初审公告 */
  .record {
    width: 1200px;
    margin: 0 auto;
    height: 40px;
    span {
      padding-left: 20px;
      width: 113px;
      height: 20px;
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: rgba(102, 102, 102, 1);
      line-height: 40px;
    }
  }

  /* 商标表格 */
  .brand-form-wrap {
    width: 1200px;
    margin: 0 auto;
    border: 1px solid #d6daeb;
    margin-bottom: 100px;
    .brand-form {
      font-size: 12px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: rgba(102, 102, 102, 1);
      th.is-center {
        padding: 8px 0px;
      }
      td.is-center {
        padding: 4px 0px;
      }
    }
    .el-table__row {
      td:nth-child(4) {
        .cell {
          color: #de2828;
        }
      }
    }
  }
}
</style>
