<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <el-card shadow="hover">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true">
            <el-form-item label="专家姓名" prop="evaluateUser">
              <el-input v-model="queryParams.evaluateUser" placeholder="请输入专家姓名"></el-input>
            </el-form-item>
            <el-form-item label="评审项目" prop="productName">
              <el-input v-model="queryParams.productName" placeholder="请输入评审项目"></el-input>
            </el-form-item>
            <el-form-item label="状态" prop="status">
              <el-select v-model="queryParams.status" placeholder="全部">
                <el-option v-for="(label, value) in statusOptions" :key="value" :label="label" :value="value"> </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="专家评语" prop="expertComment">
              <el-input v-model="queryParams.expertComment" placeholder="请输入专家评语"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
              <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </div>
    </transition>

    <el-card shadow="never">
      <el-table v-loading="loading" :data="sunnarizeList">
        <el-table-column
          :label="label"
          :align="align || 'center'"
          prop="evaluateUser"
          :min-width="minWidth || '100px'"
          v-for="{ label, prop, align, minWidth } in headers"
          :key="prop"
        >
          <template #default="{ row }">
            <span>{{ row[prop] || '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width" min-width="150px">
          <template #default="scope">
            <el-button v-if="scope.row.status == '未评价'" link type="primary" @click="handleEvaluate(scope.row)"> 评价 </el-button>
            <el-button v-else link type="primary" @click="handleShow(scope.row)">详情</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" />
      <evaluateDialog v-model="showEvaluateDialog" :row="activeRow" type="mutual" @updatelist="getList" />
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { listList } from '@/api/evaluate/list';
import { ListVO } from '@/api/evaluate/list/types';
import evaluateDialog from '../evaluateDialog/index.vue';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;

const sunnarizeList = ref<ListVO[]>([]);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);
const router = useRouter();

const queryFormRef = ref<ElFormInstance>();

const statusOptions = {
  0: '未评价',
  1: '已评价'
};

interface Header {
  label: string;
  prop: string;
  align?: 'center' | 'left' | 'right';
  minWidth?: string | number;
}
const headers = ref<Header[]>([
  {
    label: '专家姓名',
    prop: 'evaluateUser'
  },
  {
    label: '评审项目',
    prop: 'productName'
  },
  {
    label: '项目阶段',
    prop: 'itemStageName'
  },
  {
    label: '工作单位',
    prop: 'workUnit'
  },
  {
    label: '职务',
    prop: 'expertPost'
  },
  {
    label: '评价时间',
    prop: 'createTime'
  },
  {
    label: '专家评语',
    prop: 'expertComment'
  },
  {
    label: '状态',
    prop: 'status'
  }
]);

const queryParams = ref<any>({
  pageNum: 1,
  pageSize: 10,
  evaluateUser: '',
  productName: '',
  status: '',
  expertComment: ''
});

/** 查询expert列表 */
const getList = async () => {
  loading.value = true;
  const res = await listList(queryParams.value);
  sunnarizeList.value = res.rows;
  total.value = res.total;
  loading.value = false;
};

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  handleQuery();
};

/** 查看按钮操作 */
const handleShow = (row?: ListVO) => {
  const _id = row?.id;
  router.push({
    path: '/project/evaluate/detail',
    query: { id: _id, from: 'list' }
  });
};
const showEvaluateDialog = ref(false);
const activeRow = ref(null);
const handleEvaluate = (row?: ListVO) => {
  showEvaluateDialog.value = true;
  activeRow.value = row;
};
onActivated(() => {
  getList();
});
onMounted(() => {
  getList();
});
</script>
<style scoped>
.disUoloadSty :deep(.el-upload--picture-card) {
  display: none; /* 上传按钮隐藏 */
}
</style>
