<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="reformCheckProjectList">
import { onMounted, reactive, ref } from 'vue'
import { projectList } from '@/http/apis/performanceEvaluation/reformCheck'
import { useRoute } from 'vue-router'
const route = useRoute(),
  searchForm = reactive({
    projectName: undefined
  }),
  tableListRef = ref(),
  total = ref(0),
  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: '操作',
      slot: 'action',
      width: '110',
      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.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 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:'reformCheckHandle',query:{projectCode:scope.row.projectCode,projectId:scope.row.projectId,appraisalId:scope.row.appraisalId}})">处理</a>
        <a v-else @click="$router.push({name:'reformCheckScoreDetail',query:{projectCode:scope.row.projectCode,projectId:scope.row.projectId,appraisalId:scope.row.appraisalId,groupId:scope.row.groupId}})">详情</a>
      </template>
    </table-list>
  </el-card>
</template>
