<script setup>
import useCatchStore from "@/stores/modules/catch";
import {getPageConditionVo} from "@/api/report/index";
import {timeFormat} from "@/utils/util";
import {getFlowNodeValue} from "@/enums/flowEnums";
import feedback from "@/utils/feedback";
import {BASE_PATH} from "@/api/request";
import {useRouter} from "vue-router";
const router = useRouter();

const  total = ref(10)
const loading =ref(false)
const catchStore = useCatchStore();
const dict = catchStore.getDicts(["procurementMethod"]);
const dictNode = ref([
  {label:'项目进窗',value:'initial'},
  {label:'进窗报审',value:'review'},
  {label:'一审环节',value:'first'},
  {label:'二审环节',value:'second'},
  {label:'三审环节',value:'third'},
  {label:'领导审核',value:'Lead'},
  {label:'定案表审核',value:'original'},
  {label:'审计报告',value:'audit'},
  {label:'归档',value:'end'}
])

const tableData = ref([])
const query =ref({
  reportType:'all',
  code:"county",
  size:10,
  current:1
})
const getList = async ()=>{
  loading.value=true;
  console.log(query.value)
  const res = await getPageConditionVo(query.value)
  tableData.value=res.records
  total.value=res.total
  loading.value=false;
}
//重置数据
const reset =()=>{
  query.value={
    reportType:'all',
    size:10,
    current:1
  }
  getList();
}
//获取详情
const getDetail =(row)=>{
  let query ={
    id: row.id,
    isEnd:row.reportType == '结算项目',
    node:row.node,
    backPath:'/statement/condition'
  }
  router.push({
    path:"/warning/reportDetail",query:query
  })
  console.log('详情',row)
}

//点击tab切换
const handleClick =(val)=>{
  query.value.reportType=val.props.name;
  getList()
}
const handleExcel =async ()=>{
  // await feedback.confirm("确定要导出数据吗");
  window.open(`${BASE_PATH}/reportProject/excelConditionVo?` + new URLSearchParams(query.value).toString())
}
onMounted(()=>{
  getList()
})
</script>

<template>
  <div >
    <header class="mb-20 mt-20">
      <el-form label-width="120">
        <el-row>
          <el-col :span="6">
            <el-form-item label="项目名称">
              <el-input v-model="query.reportName" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="文号">
              <el-input v-model="query.referenceNumber" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="项目类别">
              <el-select v-model="query.projectType" clearable>
                <el-option value="服务类" label="服务类"></el-option>
                <el-option value="工程类" label="工程类"></el-option>
                <el-option value="货物类" label="货物类"></el-option>
                <el-option value="信息化类" label="信息化类"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="报审单位">
              <depart-tree-select :auth="false"  v-model="query.projectUnitId"
                                  :size="'default'" placeholder="请选择报审单位" clearable/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="审计单位">
              <depart-tree-select :auth="false"  v-model="query.auditUnitId"
                                  :size="'default'" placeholder="请选择报审单位" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="采购方式">
              <el-select v-model="query.purchaseMethod">
                <el-option v-for="(item,index) in dict.procurementMethod" :key="index"
                           :label="item.dictLabel"
                           :value="item.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="报审日期">
              <el-date-picker
                  value-format="YYYY-MM-DD HH:mm:ss"
                  v-model="query.applicantDateTime"
                  style="width: 100%"
                  type="datetimerange"
                  placeholder="选择报审日期"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="进度">
              <el-select v-model="query.node">
                <el-option v-for="(item,index) in dictNode" :value="item.value" :label="item.label"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="发文日期">
              <el-date-picker
                  value-format="YYYY-MM-DD HH:mm:ss"
                  v-model="query.publicationTime"
                  style="width: 100%"
                  type="datetimerange"
                  placeholder="选择发文日期"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="归档日期">
              <el-date-picker
                  value-format="YYYY-MM-DD HH:mm:ss"
                  v-model="query.archivingTime"
                  style="width: 100%"
                  type="datetimerange"
                  placeholder="选择归档日期"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <div class="flex end">
          <div>
            <el-button type="primary" @click="handleExcel">导出</el-button>
            <el-button type="primary" @click="getList">
              <template #icon>
                <icon name="el-icon-Search"/>
              </template>
              查询
            </el-button
            >
            <el-button @click="reset">重置</el-button>
          </div>
        </div>
      </el-form>
    </header>
    <el-main>
      <div  class="table-container">
        <el-tabs v-model="query.reportType" @tab-click="handleClick">
          <el-tab-pane label="全部" name="all"></el-tab-pane>
          <el-tab-pane label="项目控制价" name="项目控制价"></el-tab-pane>
          <el-tab-pane label="结算项目" name="结算项目"></el-tab-pane>
        </el-tabs>
        <el-table :data="tableData" v-loading="loading">
          <el-table-column label="项目名称" prop="reportName" width="110"/>
          <el-table-column label="报审单位" prop="projectUnit" width="110"/>
          <el-table-column label="审计单位" prop="auditUnit" width="110"/>
          <el-table-column label="项目类型" prop="projectType" width="110"/>
          <el-table-column label="主要内容" prop="content"  show-overflow-tooltip width="140"/>
          <el-table-column label="采购方式" prop="purchaseMethod" width="110"/>
          <el-table-column label="项目立项领导" prop="projectApprovalLead" width="130"/>
          <el-table-column label="报审日期" prop="applicantTime" min-width="130" >
            <template #default="{row}">
              {{timeFormat(row.applicantTime)}}
            </template>
          </el-table-column>
          <el-table-column label="报审金额(元)" prop="reportMoney" min-width="130"/>
          <el-table-column label="审定金额(元)" prop="archivingMoney" min-width="130"/>
          <el-table-column label="审减金额(元)" prop="archivingReduceMoney" min-width="130"/>
          <el-table-column label="审减率" prop="reportName">
            <template #default="{row}">
              {{  Number(row.reductionRate).toFixed(2) }}%
            </template>
          </el-table-column>
          <el-table-column label="立项日期" prop="projectApprovalTime" min-width="130">
            <template #default="{row}">
              {{timeFormat(row.projectApprovalTime)}}
            </template>
          </el-table-column>
          <el-table-column label="施工(服务、供货)单位" prop="serviceUnit" min-width="180"/>
          <el-table-column label="施工(服务)期限起" prop="serviceStartTime" min-width="150">
            <template #default="{row}">
              {{timeFormat(row.serviceStartTime)}}
            </template>
          </el-table-column>
          <el-table-column label="施工(服务)期限起" prop="serviceStartTime" min-width="180">
            <template #default="{row}">
              {{timeFormat(row.serviceEndTime)}}
            </template>
          </el-table-column>
          <el-table-column label="审计报告审批领导" prop="approvalSupervisor" min-width="180"/>
          <el-table-column label="审计报告文号" prop="referenceNumber" min-width="150"/>
          <el-table-column label="发文日期" prop="publicationDate" min-width="130">
            <template #default="{row}">
              {{timeFormat(row.publicationDate)}}
            </template>
          </el-table-column>
          <el-table-column label="归档日期" prop="archiving" min-width="130">
            <template #default="{row}">
              {{timeFormat(row.archiving)}}
            </template>
          </el-table-column>
          <el-table-column label="进度" prop="node" >
            <template #default="{row}">
              {{getFlowNodeValue(row.node)}}
            </template>
          </el-table-column>
          <el-table-column label="操作" fixed="right">
            <template #default="{row}">
              <el-button type="primary" link @click="getDetail(row)">详情</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="flex end mt-8">
        <el-pagination
            @size-change="getList"
            @current-change="getList"
            :page-sizes="[10, 20, 50]"
            v-model:page-size="query.size"
            v-model:current-page="query.current"
            layout="total, sizes, prev, pager, next"
            :total="total"
        >
        </el-pagination>
      </div>
    </el-main>
    <p>列表根据权限范围，展示报审金额超20万的项目</p>
  </div>
</template>

<style scoped lang="scss">

</style>
