<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-inventor-merge">
        <el-header>
          <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="" size="small" @click="getList">查询</el-button>
              <el-button type="primary" size="small" @click="handleAdd()" :disabled="!$permission('/workspace/folder/merge/inventorMerge/add')">新增</el-button>
            </el-form-item>
          </el-form>
        </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="createTime" label="更新时间" align="center" show-overflow-tooltip>
              <template slot-scope="scope">
                <span>{{ $d(scope.row.updateTime) }}</span>
              </template>
            </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">
                  <p @click="handleEdit(scope.row)" v-if="$permission('/workspace/folder/merge/inventorMerge/modify')">编辑</p>
                  <p v-else :disabled="true">编辑</p>
                  <el-dropdown-menu slot="dropdown" class="text-align_center">
                    <el-dropdown-item class="color-red" @click.native="handleDelete(scope.row)" :disabled="!$permission('/workspace/folder/merge/inventorMerge/delete')">删除</el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </template>
            </el-table-column>
          </el-table>
          <div class="pagination">
            <el-pagination :current-page.sync="queryParams.current" :page-size="queryParams.size" :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>

    <patent-inventor-merge-manage-drawer ref="patentInventorMergeManageDrawer" @close="close2" />
  </div>
</template>

<script>
import PatentInventorMergeManageDrawer from "./MergeInventorManage";
export default {
  components: {
    PatentInventorMergeManageDrawer
  },
  data() {
    return {
      drawer: false,
      loading: false,
      total: 0,
      tableData: [],
      projectId: 0,
      queryParams: {
        name: '',
        merge: true,
        size: 10,
        current: 1,
        projectId: 0,
        order: 'desc'
      },
    }
  },
  mounted() {
  },
  methods: {
    open(id) {
      this.projectId = id
      this.queryParams.projectId = id
      this.drawer = true
      this.getList()
    },
    close() {
      this.drawer = false
      this.$emit('close')
    },
    getList() {
      this.loading = true
      this.$api.getPatentInventorList(this.queryParams).then(response => {
        this.tableData = response.data.records
        this.total = response.data.total
        this.loading = false
      }).catch(error => {
        this.loading = false
      })
    },
    handleCurrentChange(val) {
      this.queryParams.current = val;
      this.getList();
    },
    close2() {
      this.getList()
    },
    handleAdd() {
      this.$refs.patentInventorMergeManageDrawer.open({
        projectId: this.queryParams.projectId,
        inventorIds: [],
        name: '',
        remark: '',
      }, '新增合并')
    },
    handleEdit(row) {
      this.$refs.patentInventorMergeManageDrawer.open(row, '编辑合并')
    },
    handleDelete(row) {
      this.$confirm('确认删除本条数据吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true
        this.$api.deletePatentInventor({ id: row.id }).then(response => {
          this.$message.success('删除成功')
          this.loading = false
          this.getList()
        }).catch(error => {
          this.loading = false
        })
      })
    }
  }
}
</script>

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