<template>
  <!-- 合并发明人，合并权利人/申请人 -->
  <div class="">
    <el-drawer class="custom-drawer-form" :title="mergeType == 2?'合并发明人':'合并申请人/权利人'" size="1000px" :visible.sync="drawer" direction="rtl"
      :before-close="close" destroy-on-close>
      <el-container class="patent-inventor-merge">
        <el-header style="display:flex;align-items:center;justify-content: space-between;">
          <div>
            <el-form :inline="true" class="margin-left_20">
              <el-form-item label="名称">
                <el-input v-model="queryParams.name" size="small" placeholder="请输入名称"></el-input>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" size="small" @click="getList">查询</el-button>
              </el-form-item>
            </el-form>
            <!-- 后端没有根据检索式检索 -->
            <!-- <mySearch style="width: 500px" :SearchFields="searchFiled" @search="search" :searchValue="searchOption">
            </mySearch> -->
          </div>
          <div>
            <el-button type="primary" size="small" @click="handleAdd()">新增</el-button>
          </div>
        </el-header>
        <el-main class="container-common-main">
          <el-table v-loading="loading" :data="tableData" border header-row-class-name="custom-table-header">
            <el-table-column type="index" label="#" width="55" align="center"></el-table-column>
            <el-table-column prop="name" label="名称" align="center" show-overflow-tooltip></el-table-column>
            <template v-if="mergeType == 0">
              <el-table-column prop="country" label="国家" align="center" show-overflow-tooltip></el-table-column>
              <el-table-column prop="address" label="地址" align="center" show-overflow-tooltip></el-table-column>
            </template>
            <el-table-column prop="createTime" label="更新时间" align="center" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="remark" label="备注" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="操作" align="center" width="150">
              <template slot-scope="scope">
                <el-dropdown split-button type="primary" size="small">
                  <span @click="handleEdit(scope.row)">编辑</span>
                  <el-dropdown-menu slot="dropdown" class="text-align_center">
                    <el-dropdown-item class="color-red" @click.native="handleDelete(scope.row)">删除</el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </template>
            </el-table-column>
          </el-table>
          <div class="pagination">
            <el-pagination :current-page.sync="queryParams.pageNum" :page-size="queryParams.pageSize" :total="total"
              @current-change="handleCurrentChange" layout="total, prev, pager, next, jumper" background></el-pagination>
          </div>
        </el-main>
        <el-footer class="footer-common">
          <el-button @click="close">关 闭</el-button>
        </el-footer>
      </el-container>
    </el-drawer>

    <mergeDialog ref="mergeDialog" :projectId="projectId" @close="close2"></mergeDialog>
  </div>
</template>

<script>
import mergeDialog from './merge.vue'
export default {
  components: {
    mergeDialog,
  },
  data() {
    return {
      drawer: false,
      loading: false,
      total: 0,
      tableData: [],
      projectId: 0,
      queryParams: {
        pageSize: 10,
        pageNum: 1,
      },
      //检索字段
      searchFiled: [
        {
          label: '名称',
          value: 'name',
          type: 'String',
        }
      ],
      //检索条件
      searchOption: {},
      // 判断是2发明人还是0权利人/申请人
      mergeType: '',
    }
  },
  mounted() {
  },
  methods: {
    // 子组件传来的消息
    close2() {
      this.getList()
    },
    // 编辑合并弹窗
    handleEdit(row) {
      row.mergeType = this.mergeType
      this.$refs.mergeDialog.open(row, '编辑合并')
    },
    // 打开新增弹窗
    handleAdd() {
      this.$refs.mergeDialog.open({
        mergeType: this.mergeType,
      }, '新增合并')
    },
    // 打开合并发明人抽屉弹窗
    open(obj) {
      this.projectId = obj.projectId
      this.mergeType = obj.type
      this.drawer = true
      this.getList()
    },
    //获取检索条件检索
    search(val) {
      let params = {}
      val.forEach(item => {
        if (item.type == 3) {
          params[item.value] = item.searchValue.map(itemValue => {
            return itemValue.value
          })
        } else {
          params[item.value] = item.searchValue.label
        }
      })
      // 返回条件对象
      this.searchOption = this.$commonJS.ArrayToArray(val)
      // 调用查询接口
      this.queryParams.current = 1
      this.getList()
    },
    // 获取表格数据
    getList() {
      this.loading = true
      let params = {
        projectId: this.projectId,
        ...this.queryParams,
        searchQuery: this.$commonJS.objectToString(this.searchOption || {}),//检索条件
        type: this.mergeType,//2是发明人0是申请人/权利人
      }
      this.$api.selectMergePerson(params).then(response => {
        if (response.code == 200) {
          this.tableData = response.data.data
          this.total = response.data.total
          this.loading = false
        }
      }).catch(error => {
        this.loading = false
      })
    },
    // 分页信息
    handleCurrentChange(val) {
      this.queryParams.pageNum = val;
      this.getList();
    },
    // 关闭抽屉弹窗
    close() {
      this.drawer = false
      this.$emit('mergeClose')
    },
    // 删除表格数据
    handleDelete(row) {
      this.$confirm('确认删除本条数据吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true
        let params = {
          id: row.id,
          type: 2,
        }
        this.$api.delMergePerson(params).then(response => {
          if (response.code == 200) {
            this.$message.success('删除成功')
            this.loading = false
            this.getList()
          }
        }).catch(error => {
          this.loading = false
        })
      })
    },

















    // 打开新增弹窗
    // handleAdd() {
    //   this.$refs.mergeDialog.open({
    //     // mergedName: [],
    //     mergeType: 1,
    //   }, '新增合并')
    //   // this.$refs.patentInventorMergeManageDrawer.open({
    //   //   projectId: this.queryParams.projectId,
    //   //   // mergedName: [],
    //   //   name: '',
    //   //   remark: '',
    //   // }, '新增合并')
    // },
    // // 编辑合并弹窗
    // handleEdit(row) {
    //   row.mergeType = 1
    //   this.$refs.mergeDialog.open(row, '编辑合并')
    //   // row.projectId = this.projectId
    //   // this.$refs.patentInventorMergeManageDrawer.open(row, '编辑合并')
    // },

  }
}
</script>

<style lang="scss">
.patent-inventor-merge {
  .pagination {
    text-align: center;
    margin: 20px 0;
  }
}
</style>
