<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="applicationEvaluateDetail">
import { onMounted, reactive, ref } from 'vue'
import { projectList } from '@/http/apis/performanceEvaluation/applicationEvaluate'
import { useRoute } from 'vue-router'
const
  searchForm = reactive({
    name: undefined
  }),
  route = useRoute(),
  tableListRef = ref(),
  total = ref(5),
  column = reactive([
    {
      label: '序号',
      type: 'index',
      width: '80'
    },
    {
      label: '应用名称',
      key: 'applicationName',
      prop: 'applicationName',
      minWidth: '150',
      showOverflowTooltip: true
    },
    {
      label: '申报单位',
      key: 'buildOrgName',
      prop: 'buildOrgName',
      minWidth: '80',
      showOverflowTooltip: true
    },
    {
      label: '应用类型',
      key: 'applicationType',
      prop: 'applicationType',
      width: '100'
    },
    {
      label: '应用领域',
      key: 'bizDomain',
      prop: 'bizDomain',
      width: '80'
    },
    {
      label: '发布端',
      key: 'publishSide',
      prop: 'publishSide',
      width: '80'
    },
    {
      label: '操作',
      slot: 'action',
      width: 80,
      fixed: 'right'
    }
  ]),
  data = ref([]),
  getTableData = async (pageParams = tableListRef.value.pageParams) => {
    const res = await projectList(activeName.value, route.query.planId, {
      ...pageParams,
      ...searchForm
    })
    data.value = res.data.records
    total.value = res.data.total
  },
  search = () => {
    getTableData()
  },
  reset = () => {
    searchForm.name = undefined
    tableListRef.value.pageParams.pageNumber = 1
    tableListRef.value.pageParams.pageSize = 10
    getTableData()
  },
  activeName = ref('1'),
  changeTab = (val) => {
    activeName.value = val
    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.name"
              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 class="tab-card">
    <template #header>
      <el-tabs v-model="activeName" @tab-change="changeTab">
        <el-tab-pane label="待评价" name="1" />
        <el-tab-pane label="已评价" name="2" />
      </el-tabs>
    </template>
    <table-list
      ref="tableListRef"
      :column="column"
      :data="data"
      :total="total"
      @get-table-data="getTableData"
    >
      <template #action="{scope}">
        <a v-if="activeName==='1'" @click="$router.push({name:'applicationMark',query:{appId:scope.row.id,appraisalId:scope.row.appraisalId}})">评价</a>
        <a v-if="activeName==='2'" @click="$router.push({name:'applicationMarkDetail',query:{appId:scope.row.id,appraisalId:scope.row.appraisalId}})">详情</a>
      </template>
    </table-list>
  </el-card>
</template>
