<template>
  <el-container>
    <el-header>
      <div class="left-panel-group">
        <el-button
          type="primary"
          icon="el-icon-plus"
          @click="handleAdd"
        >新增</el-button>
      </div>
      <div class="right-panel">
        <el-input
            v-model="query.name"
            placeholder="专利名称"
            clearable
            @keyup.enter="handleQuery"
          ></el-input>
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="handleQuery"
          ></el-button>
      </div>
    </el-header>
    <el-main class="nopadding">
      <scTable ref="table" :apiObj="apiObj" row-key="id">
        <el-table-column label="#" type="index"></el-table-column>
        <el-table-column
          label="申请部门"
          prop="organization"
          min-width="60"
        ></el-table-column>
        <el-table-column
          label="拟申请专利名称"
          prop="name"
          min-width="60"
        ></el-table-column>
        <el-table-column
          label="发明人（设计人）"
          prop="author"
          min-width="60"
        ></el-table-column>
        <el-table-column
          label="拟申请专利类型"
          prop="type"
          min-width="60">
          <template #default="scope">
            {{patentType[scope.row.type]}}
          </template>
        </el-table-column>
        <el-table-column label="是否提前公开" prop="is_public" mim-width="60">
          <template #default="scope">
            <span :style="{color: scope.row.is_public ? '#67C23A' : '#F56C6C'}">
            {{ scope.row.is_public ? '是' : '否'}}
              </span>
          </template>
        </el-table-column>
        <el-table-column
          label="拟申请地域"
          prop="area"
          min-width="60"
        ><template #default="scope">
            {{areaOptions[scope.row.area]}}
        </template>
        </el-table-column>
        <el-table-column
          label="其他区域"
          prop="other_area"
          min-width="60"
        ></el-table-column>
        <el-table-column label="技术状态" prop="tech_status" min-width="160">
            <template #default="{row}">
                <div v-if="row.tech_status && row.tech_status.length">
                    <div v-for="(item, index) in row.tech_status" :key="index">
                        <strong>{{item.name}}</strong>：
                        <span>{{ item.status }}</span>
                        <br />
                        <el-link v-if="item.file"
                        type="primary"
                        :href="item.file"
                        target="_blank"
                        style="font-size: 12px;"
                        >文件下载</el-link> 
                </div>
            </div>
             <span v-else>—</span>
        </template>
        </el-table-column>
        <el-table-column label="技术文件" prop="tech_file" min-width="160">
            <template #default="{row}">
                <div v-if="row.tech_file && row.tech_file.length">
                    <div v-for="(item, index) in row.tech_file" :key="index">
                        <strong>{{item.name}}</strong>：
                        <span>{{ item.pages }}页</span>
                </div>
            </div>
             <span v-else>—</span>
        </template>
        </el-table-column>
        <el-table-column label="审批信息" width="200">
          <template #default="scope">
                                <el-tag :type="actStateEnum[scope.row.ticket_?.act_state]?.type">
                        {{ actStateEnum[scope.row.ticket_?.act_state]?.text }}
                    </el-tag>
            <el-tag type="info" effect="plain">{{ scope.row.ticket_?.state_.name }}</el-tag>

          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="center" width="120">
          <template #default="scope">
            <el-button
              link
              size="small"
              type="primary"
              @click="patentShow(scope.row)"
              >详情
            </el-button>
            <el-popconfirm
              title="确定删除吗？"
              @confirm="patentDel(scope.row)"
            >
              <template #reference>
                <el-button
                  link
                  size="small"
                  type="danger"
                  >删除</el-button
                >
              </template>
            </el-popconfirm>
          </template>
        </el-table-column>
      </scTable>
    </el-main>
  </el-container>
  <el-drawer
      title="专利审批"
      v-model="limitedVisible"
      :destroy-on-close="true"
      direction="rtl"
      size="70%"
      >
  <div style="display: flex; height: calc(100% - 60px);"> 
    <div style="flex: 1; padding-right: 20px; overflow-y: auto;">
      <PatentForm
        :mode="mode"
        :t_id="t_id"
        @success="()=>{handleQuery(); limitedVisible = false}"
        @closed="limitedVisible = false"
      />
    </div>
  </div>
</el-drawer>
</template>
<script>

import PatentForm from "./patent_form.vue";
import { actStateEnum, interveneTypeEnum } from "@/utils/enum.js";
export default {
  components: { PatentForm},
  name: "index",
  data() {
    return {
      actStateEnum, interveneTypeEnum,
      apiObj: this.$API.srm.patentinfo.list,
      fileList: [],
      query: {},
      t_id:null,
      limitedVisible: false,
      mode: "show",
      patentType: {
        "invention": "发明专利",
        "utility": "实用新型",
        "design": "外观设计",
      },
      areaOptions: {
        'Domestic':'国内申请',
        'Foreign':'国外申请',
        'PCT':'PCT申请',
      },
    };
  },
  methods: {
    handleAdd() {
      this.mode = "add";
      this.t_id = null;
      this.limitedVisible = true;
    },
    
    patentShow(row) {
      this.mode = "show";
      this.t_id = row.id;
      this.limitedVisible = true;
    },
    async patentDel(row) {
      var id = row.id;
      var res = await this.$API.srm.patentinfo.delete.req(id);
      this.$refs.table.refresh();
      this.$message.success("删除成功");
      
    },
  //搜索
    handleQuery() {
      this.$refs.table.queryData(this.query);
    },
  },
};
</script>

