<script>
import { defineComponent } from 'vue'

export default defineComponent({
  beforeRouteEnter (to, from, next) {
    if (to.query.title) {
      to.meta.title = to.query.title
    }
    next()
  }
})
</script>
<script setup name="reviewProjectList">
import { h, onMounted, reactive, ref } from 'vue'
import { groupProjectList } from '@/http/apis/performanceEvaluation/projectReview'
import { useRoute } from 'vue-router'
const
  route = useRoute(),
  searchForm = reactive({
    projectName: undefined
  }),
  tableListRef = ref(),
  total = ref(5),
  column = reactive([
    {
      label: '序号',
      type: 'index',
      width: '80'
    },
    {
      label: '项目名称',
      key: 'projectName',
      prop: 'projectName',
      minWidth: '150',
      showOverflowTooltip: true
    },
    {
      label: '申报单位',
      key: 'buildOrgName',
      prop: 'buildOrgName',
      minWidth: '80',
      showOverflowTooltip: true
    },
    {
      label: '项目类型',
      key: 'projectTypeName',
      prop: 'projectTypeName',
      width: '100'
    },
    {
      label: '预算年度',
      key: 'projectYear',
      prop: 'projectYear',
      width: '80'
    },
    {
      label: '自评得分',
      key: 'selfAppraisalTotalScore',
      prop: 'selfAppraisalTotalScore',
      width: '80',
      render: row => h('span', row.selfAppraisalTotalScore || row.selfAppraisalTotalScore === 0 ? row.selfAppraisalTotalScore : '-')
    },
    {
      label: '操作',
      slot: 'action',
      width: '110',
      fixed: 'right'
    }
  ]),
  data = ref([]),
  getTableData = async (pageParams = tableListRef.value.pageParams) => {
    const res = await groupProjectList(route.query.reAppraisalGroupId, {
      ...searchForm,
      ...pageParams
    })
    data.value = res.data.records
    total.value = res.data.total
  },
  search = () => {
    getTableData()
  },
  reset = () => {
    searchForm.projectName = undefined
    tableListRef.value.pageParams.pageNumber = 1
    tableListRef.value.pageParams.pageSize = 10
    getTableData()
  }
onMounted(() => {
  getTableData()
})
</script>

<template>
  <el-card class="search mb-16">
    <el-form label-suffix=":" :model="searchForm" size="small">
      <el-row :gutter="16">
        <el-col :span="8">
          <el-form-item label="项目名称">
            <el-input
              v-model="searchForm.projectName"
              placeholder="请输入"
            />
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item class="btn">
            <el-button type="primary" @click="search">查询</el-button>
            <el-button @click="reset">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </el-card>
  <el-card>
    <template #header>
      <div class="flex justify-between items-center">
        <span>项目列表</span>
      </div>
    </template>
    <table-list
      ref="tableListRef"
      :column="column"
      :data="data"
      :total="total"
      @get-table-data="getTableData"
    >
      <template #action="{scope}">
        <a v-if="scope.row.canReAppraisal" @click="$router.push({name:'reviewGiveScore',query:{projectCode:scope.row.projectCode,projectId:scope.row.projectId,appraisalId:scope.row.appraisalId,groupId:scope.row.groupId,canReAppraisal:true}})">{{ scope.row.draftId?'继续打分':'打分' }}</a>
        <a v-else @click="$router.push({name:'reviewScoreDetail',query:{projectCode:scope.row.projectCode,projectId:scope.row.projectId,appraisalId:scope.row.appraisalId,groupId:scope.row.groupId}})">详情</a>
      </template>
    </table-list>
  </el-card>
</template>
