<template>
  <div class="patentData">
  <div class="patentData-collection">
    <div class="header-patentDataCollection">
      <el-button type="primary" @click="beginSync">同步应用到系统</el-button>
      <span>当前时间：{{ times }}</span>
      <span>上次同步时间：{{ lastTime }}</span>
    </div>
    <div class="derived-list">
      <div><i class="el-icon-search"></i><span>筛选查询</span></div>
      <el-button type="primary" size="mini">查询结果</el-button>
    </div>

    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" class="yourForm"
      label-position="left" label-width="100px">

      <el-form-item label="申请日" prop="appDate">
        <el-input v-model="queryParams.appDate" placeholder="请输入申请日" clearable size="small"
          @keyup.enter.native="handleQuery"/>
      </el-form-item>

      <el-form-item label="申请人类型" label-width="100px" prop="appliTypeSrc">
        <el-input v-model="queryParams.appliTypeSrc" placeholder="请输入申请人类型" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>


      <el-form-item label="原始州市" prop="appliCity">
        <el-input v-model="queryParams.appliCity" placeholder="请输入州市" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="原始区县" prop="appliCounty">
        <el-input v-model="queryParams.appliCounty" placeholder="请输入区县" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>


      <el-form-item label="高价值类型" label-width="100px" prop="highValue">
        <el-input v-model="queryParams.highValue" placeholder="请输入高价值类型" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="入库时间" prop="inboundDate">
        <el-input v-model="queryParams.inboundDate" placeholder="请输入入库时间" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <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-form-item>
    </el-form>
    <!--
    <div class="derived-list">
      <div><Popover :visible="visible" :showColumnArr="showColumnArr" /><span>数据表</span></div>
      <el-button type="primary" size="mini">导出列表</el-button>
    </div>-->
    <!--
    <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="['adjust:dPatentDataCollationInfo: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="['adjust:dPatentDataCollationInfo: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="['adjust:dPatentDataCollationInfo: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="['adjust:dPatentDataCollationInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    -->
    <el-table v-loading="loading" :data="dPatentDataCollationInfoList" style="width: 100%"
      :header-cell-style="{ background: '#2a8eed', color: '#fafcfe', }" border>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="数据类型" align="center" prop="dataType" />
      <el-table-column label="申请号" align="center" prop="appNumber" />
      <el-table-column label="申请日" align="center" prop="appDate" />
      <el-table-column label="第一申请人（原始专利权人）" align="center" prop="appli" />
      <el-table-column label="申请人类型（原始）" align="center" prop="appliTypeSrc" />
      <el-table-column label="申请人类型" align="center" prop="appliType" />
      <el-table-column label="申请人地址" align="center" prop="appliAddress" />
      <el-table-column label="省份（原始）" align="center" prop="appliProvince" />
      <el-table-column label="州市（原始）" align="center" prop="appliCity" />
      <el-table-column label="区县（原始）" align="center" prop="appliCounty" />
      <el-table-column label="省份" align="center" prop="modifyAppliProvince" />
      <el-table-column label="州市" align="center" prop="modifyAppliCity" />
      <el-table-column label="区县" align="center" prop="modifyAppliCounty" />
      <el-table-column label="高价值类型（出版社）" align="center" prop="highValue" />
      <el-table-column label="入库时间" align="center" prop="inboundDate" />
      <el-table-column label="地址调整时间" align="center" prop="addressAdjustmentTime" />
      <el-table-column label="申请人调整时间" align="center" prop="applyAdjustmentTime" />
      <!--
      <el-table-column label="专利名称" align="center" prop="title" />
      <el-table-column label="公开号" align="center" prop="pubNumber" />
      <el-table-column label="当前专利状态" align="center" prop="currPatentStatus" />
      <el-table-column label="当前专利人" align="center" prop="currPatentHolder" />
      <el-table-column label="专利类型" align="center" prop="patentType" />
      <el-table-column label="分类号（主IPC）" align="center" prop="ipcMain" />
      <el-table-column label="分类号（洛迦诺）" align="center" prop="locStr" />
      <el-table-column label="国民经济行业分类" align="center" prop="nationalEcoStr" />
      <el-table-column label="专利转移次数" align="center" prop="patTranCounts" />
      <el-table-column label="申请权转移次数" align="center" prop="appTranCounts" />
      <el-table-column label="许可发生次数" align="center" prop="licCounts" />
      <el-table-column label="质押发生次数" align="center" prop="pleCounts" />
      <el-table-column label="保全发生次数" align="center" prop="preCounts" />
      <el-table-column label="法院判决发生次数" align="center" prop="curtCounts" />
      <el-table-column label="代理机构" align="center" prop="agencyName" />
      <el-table-column label="状态" align="center" prop="status" />
      -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">

          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdateAdjaddress(scope.row)"
            v-hasPermi="['adjust:dPatentDataCollationInfo:edit']">地址调整</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdateAdjtype(scope.row)"
            v-hasPermi="['adjust:dPatentDataCollationInfo:edit']">申请人类型调整</el-button>
          <!--
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['adjust:dPatentDataCollationInfo:edit']"
          >修改</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['adjust:dPatentDataCollationInfo:remove']"
          >删除</el-button>
          -->
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <el-dialog :title="title" :visible.sync="adjaddress" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px"  class="yourForm">
        <el-form-item label="专利名称" prop="title">
          <el-input v-model="form.title" placeholder="请输入专利名称" disable="true" :disabled="true"/>
        </el-form-item>
        <el-form-item label="申请号" prop="appNumber">
          <el-input v-model="form.appNumber" placeholder="请输入申请号" disable="true" :disabled="true"/>
        </el-form-item>
        <el-form-item label="申请日" prop="appDate">
          <el-input v-model="form.appDate" placeholder="请输入申请日" disable="true" :disabled="true"/>
        </el-form-item>
        <el-form-item label="申请人地址" prop="appliAddress" v-if="title=='调整专利数据地址'">
          <el-input v-model="form.appliAddress" placeholder="请输入申请人地址" />
        </el-form-item>
        <el-form-item label="申请人类型" prop="appliTypeSrc" v-else>
          <el-select v-model="form.appliTypeSrc" placeholder="请选择申请人类型">
            <el-option label="大专院校" value="大专院校"></el-option>
            <el-option label="科研机构" value="科研机构"></el-option>
            <el-option label="企业" value="企业"></el-option>
            <el-option label="机关团体" value="机关团体"></el-option>
            <el-option label="个人" value="个人"></el-option>

          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormAdjaddress">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</div>
</template>

<script>
import { doSync,getLastTime,listDPatentDataCollationInfo, getDPatentDataCollationInfo, delDPatentDataCollationInfo, addDPatentDataCollationInfo, updateDPatentDataCollationInfo } from "@/api/adjust/dPatentDataCollationInfo"
import { getHashes } from "crypto"

export default {
  name: "DPatentDataCollationInfo",
  data () {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 专利数据整理表格数据
      dPatentDataCollationInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      adjaddress: false,
      adjtype: false,

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        appNumber: null,
        appDate: null,
        appli: null,
        appliTypeSrc: null,
        appliType: null,
        appliAddress: null,
        appliProvince: null,
        appliCity: null,
        appliCounty: null,
        modifyAppliProvince: null,
        modifyAppliCity: null,
        modifyAppliCounty: null,
        highValue: null,
        inboundDate: null,
        addressAdjustmentTime: null,
        applyAdjustmentTime: null,
        title: null,
        pubNumber: null,
        currPatentStatus: null,
        currPatentHolder: null,
        patentType: null,
        ipcMain: null,
        locStr: null,
        nationalEcoStr: null,
        patTranCounts: null,
        appTranCounts: null,
        licCounts: null,
        pleCounts: null,
        preCounts: null,
        curtCounts: null,
        agencyName: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      times: '',
      lastTime:''

    }
  },
  created () {
    this.getLastTime();
    this.getList()
    this.getTimes()
  },
  beforeDestroy() {
  if (this.times) {
    clearInterval(this.getDaytTime);
  }
},
  methods: {
    getTimes(){
      this.getDaytTime()
      setInterval(this.getDaytTime, 1000);
    },

    getLastTime(){
      this.loading = true
      getLastTime(this.queryParams).then(response => {
        this.lastTime = response.data
        this.loading = false
      })
    },

    beginSync(){
      this.loading = true
      doSync(this.queryParams).then(response => {
        this.lastTime = response.data
        this.loading = false
      })
    },
    /** 查询专利数据整理列表 */
    getDaytTime(){
      var _this = this
      let yy = new Date().getFullYear()
      let mm = new Date().getMonth() + 1
      let dd = new Date().getDate()
      let hh = new Date().getHours()
      let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes()
      let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds()
      _this.times = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss
    },
    getList () {
      this.loading = true
      listDPatentDataCollationInfo(this.queryParams).then(response => {
        this.dPatentDataCollationInfoList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel () {
      this.open = false
      this.adjaddress = false
      this.adjtype = false
      this.reset()
    },
    // 表单重置
    reset () {
      this.form = {
        id: null,
        dataType: null,
        appNumber: null,
        appDate: null,
        appli: null,
        appliTypeSrc: null,
        appliType: null,
        appliAddress: null,
        appliProvince: null,
        appliCity: null,
        appliCounty: null,
        modifyAppliProvince: null,
        modifyAppliCity: null,
        modifyAppliCounty: null,
        highValue: null,
        inboundDate: null,
        addressAdjustmentTime: null,
        applyAdjustmentTime: null,
        title: null,
        pubNumber: null,
        currPatentStatus: "0",
        currPatentHolder: null,
        patentType: null,
        ipcMain: null,
        locStr: null,
        nationalEcoStr: null,
        patTranCounts: null,
        appTranCounts: null,
        licCounts: null,
        pleCounts: null,
        preCounts: null,
        curtCounts: null,
        agencyName: null,
        remark: null,
        delFlag: null,
        status: 0,
        createTime: null,
        createBy: null,
        updateTime: null,
        adjtype: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery () {
      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
      getDPatentDataCollationInfo(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改专利数据整理"
      })
    },

    /** 修改按钮操作 */
    handleUpdateAdjaddress (row) {
      this.reset()
      const id = row.id || this.ids
      this.form.adjtype = 'addr'
      getDPatentDataCollationInfo(id).then(response => {
        this.form = response.data
        this.adjaddress = true
        this.title = "调整专利数据地址"
      })
    },
    handleUpdateAdjtype (row) {
      this.reset()
      const id = row.id || this.ids
      this.form.adjtype = 'type'
      getDPatentDataCollationInfo(id).then(response => {
        this.form = response.data
        this.adjaddress = true
        this.title = "调整专利申请人类型"
      })
    },

    /** 提交按钮 */
    submitForm () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDPatentDataCollationInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addDPatentDataCollationInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },

    submitFormAdjaddress () {

      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.adjtype = 'addr'
          if (this.form.id != null) {
            updateDPatentDataCollationInfo(this.form).then(response => {
              this.$modal.msgSuccess("调整地址成功")
              this.adjaddress = false
              this.adjtype = false
              this.getList()
            })
          } else {
            addDPatentDataCollationInfo(this.form).then(response => {
              this.$modal.msgSuccess("调整地址成功")
              this.adjaddress = false
              this.adjtype = false
              this.getList()
            })
          }
        }
      })
    },
    submitFormAdjtype () {

      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.adjtype = 'type'
          if (this.form.id != null) {
            updateDPatentDataCollationInfo(this.form).then(response => {
              this.$modal.msgSuccess("调整类型成功")
              this.adjaddress = false
              this.adjtype = false
              this.getList()
            })
          } else {
            addDPatentDataCollationInfo(this.form).then(response => {
              this.$modal.msgSuccess("调整类型成功")
              this.adjaddress = false
              this.adjtype = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete (row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除专利数据整理编号为"' + ids + '"的数据项？').then(function () {
        return delDPatentDataCollationInfo(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => { })
    },
    /** 导出按钮操作 */
    handleExport () {
      this.download('adjust/dPatentDataCollationInfo/export', {
        ...this.queryParams
      }, `dPatentDataCollationInfo_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>

<style lang="scss" scoped>
.route-view-container[data-v-02b43ddf] {
  padding: 0;
}

body .el-form .el-form-item,
body .app-container .el-form .el-form-item {
  margin-bottom: 10px !important;
}

::v-deep .el-input__inner {
  padding: 0 15px;
}

::v-deep .el-input__prefix {
  right: 5px;
  left: unset;
}

.patentData-collection {
  padding: 20px;
  min-width: 1300px;

  .header-patentDataCollection {
    padding-left: 20px;

    span {
      margin-left: 10px;
      color: #999999;
      font-size: 14px;
    }
  }

  .derived-list {
    height: 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #f8f8f8;
    padding: 0 10px 0 20px;
    margin: 20px 0;

    div {
      display: flex;

      span {
        color: #616161;
        font-size: 14px;
        margin-left: 5px;
      }
    }
  }
}

.yourForm {
  .el-input {
    width: 100%;
  }

  .el-textarea {
    width: 200px;
  }

  .el-select {
    width: 100%;
  }
}

.formItem {
  margin-right: 50px;
}

@media screen and (max-width:1600px) {
  .formItem {
    margin-right: 20px;
  }
}
::v-deep .el-dialog__body {
  padding: 30px 10px 30px 0;
}
</style>
