<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      v-show="showSearch"
      :inline="true"
    >
      <el-form-item label="专利名称" prop="roleName">
        <el-input
          v-model="queryParams.roleName"
          placeholder="请输入专利名称"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请人" prop="roleName">
        <el-input
          v-model="queryParams.roleName"
          placeholder="请输入申请人"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发明人" prop="roleName">
        <el-input
          v-model="queryParams.roleName"
          placeholder="请输入发明人"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" size="mini" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <!-- 表格数据 -->
    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="数据编号" prop="id" />
      <el-table-column
        label="专利名称"
        prop="title"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="申请号"
        prop="apply_code"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="发明人" prop="inventor" />
      <el-table-column label="申请（专利权）人" prop="apply_name" />
      <el-table-column label="申请日期" align="center" prop="apply_at">
        <template #default="scope">
          <span>{{ parseTime(scope.row.apply_at) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center">
        <template #default="scope">
          <el-tag v-if="scope.row.is_bind">已认领</el-tag>
          <el-tag type="danger" v-else>未认领</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-button
            v-if="!scope.row.is_bind"
            size="mini"
            type="text"
            icon="el-icon-plus"
            @click="handleBind(scope.row.id)"
            >认领机构</el-button
          >
          <el-button
            v-else
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleUnbind(scope.row.id)"
            >取消认领</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script setup>
import {
  addRole,
  changeRoleStatus,
  dataScope,
  delRole,
  getRole,
  listRole,
  updateRole,
} from "@/api/system/role";
import {
  roleMenuTreeselect,
  treeselect as menuTreeselect,
} from "@/api/system/menu";
import {
  treeselect as deptTreeselect,
  roleDeptTreeselect,
} from "@/api/system/dept";

const router = useRouter();
const { proxy } = getCurrentInstance();

const dataList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    roleName: undefined,
  },
});

const { queryParams, rules } = toRefs(data);

/** 查询数据列表 */
function getList() {
  loading.value = true;
  dataList.value = [1];
  total.value = 15;
  loading.value = false;
  // listRole(queryParams.value).then(
  //   (response) => {
  //     dataList.value = response.rows;
  //     total.value = response.total;
  //     loading.value = false;
  //   }
  // );
}
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}
/** 删除按钮操作 */
function handleDelete(row) {
  proxy.$modal
    .confirm('是否确认删除数据编号为"' + row.id + '"的数据项?')
    .then(function () {
      return delRole(roleIds);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功");
    })
    .catch(() => {});
}
function handleBind(id) {
  // expertPatentBind({ id: this.queryParams.id, patent_ids: [id] }).then(
  //   (res) => {
  //     this.$modal.msgSuccess("修改成功");
  //     this.getList();
  //   }
  // );
}
function handleUnbind(id) {
  // expertPatentUnbind({ id: this.queryParams.id, patent_ids: [id] }).then(
  //   (res) => {
  //     this.$modal.msgSuccess("修改成功");
  //     this.getList();
  //   }
  // );
}

getList();
</script>
