<template>
  <!-- 合并申请人、权利人 -->
  <div class="">
    <el-drawer class="custom-drawer-form" title="合并申请人/权利人" size="1000px" :visible.sync="drawer" direction="rtl"
      :before-close="close" destroy-on-close>
      <el-container class="patent-applicant-merge">
        <el-header style="display:flex;align-items:center;justify-content: space-between;">
          <div>
            <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>
            <el-table-column prop="countryName" label="国家" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="addressStr" label="地址" align="center" show-overflow-tooltip></el-table-column>
            <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)"
                    v-if="$permission('/workspace/folder/merge/applicationMerge/modify')">
                    编辑</span>
                  <span v-else :disabled="true">编辑</span>
                  <el-dropdown-menu slot="dropdown" class="text-align_center">
                    <el-dropdown-item divided class="color-red" @click.native="handleDelete(scope.row)"
                      :disabled="!$permission('/workspace/folder/merge/applicationMerge/delete')">删除</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"></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,
      },
      addressIds: [],
      //检索字段
      searchFiled: [
        {
          label: '名称',
          value: 'name',
          type: 'String',
        }
      ],
      //检索条件
      searchOption: {},
    }
  },
  mounted() {
  },
  methods: {
    // 子组件传来的消息
    close2() {
      this.getList()
    },
    // 打开编辑合并申请人弹窗
    handleEdit(row) {
      row.mergeType = 2
      this.$refs.mergeDialog.open(row, '编辑合并')
    },
    // 打开新增弹窗
    handleAdd() {
      this.$refs.mergeDialog.open({
        mergeType: 2,
      }, '新增合并')
    },
    // 打开抽屉弹窗
    open(projectId) {
      this.projectId = projectId
      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: 0,//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
        this.$api.delMergePerson({ id: row.id }).then(response => {
          if (response.code == 200) {
            this.$message.success('删除成功')
            this.loading = false
            this.getList()
          }
        }).catch(error => {
          this.loading = false
        })
      })
    },

































    // 打开新增合并人弹窗
    // handleAdd() {
    //   this.$refs.mergeApplicantFormDialog.open({
    //     projectId: this.queryParams.projectId,
    //     applicantIds: [],
    //     name: '',
    //     remark: '',
    //     shortName: '',
    //     country: '',
    //     address: '',
    //     addressIds: []
    //   }, '新增合并申请人', this.commonData, this.areaTree)
    // },
    // // 打开添加申请人弹窗
    // // handleSelect(row) {
    // //   this.$refs.mergeApplicantSelectDialog.open(row)
    // // },
    // // 打开已合并申请人弹窗
    // handleExist(row) {
    //   this.$refs.mergeApplicantExistDialog.open(row)
    // },
    // 打开编辑合并申请人弹窗
    // handleEdit(row) {
    //   this.$refs.mergeDialog.open(2)
    //   // row.projectId = this.projectId
    //   // this.$refs.mergeApplicantFormDialog.open(row, '编辑合并申请人', this.commonData, this.areaTree)
    // },

  }
}
</script>

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