<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="68px">
      <el-form-item label="申请人" prop="applicant">
        <el-input
            v-model="queryParams.applicant"
            placeholder="请输入申请人"
            clearable
            style="width: 240px"
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务类型" prop="businessType">
        <el-select
            v-model="queryParams.businessType"
            placeholder="业务类型"
            clearable
            style="width: 240px"
        >
          <el-option
              key="t_metadata_supp_info"
              label="元数据信息补录"
              value="t_metadata_supp_info"
          />
        </el-select>
      </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-table :data="flowList">
      <el-table-column label="业务类型" align="center" prop="businessType">
        <template #default="scope">
          <span v-if="scope.row.businessType === 't_metadata_supp_info'">元数据信息补录</span>
        </template>
      </el-table-column>
      <el-table-column label="业务编号" align="center" prop="businessId" :show-overflow-tooltip="true" width="280">
        <template #default="scope">
          <el-link type="primary" @click="showBusinessDataDialog(scope.row)" :underline="false">{{ scope.row.businessId }}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="申请人" align="center" prop="applicant" :show-overflow-tooltip="true" />
      <el-table-column label="申请时间" align="center" prop="applyTime" :show-overflow-tooltip="true" />
      <el-table-column label="当前状态" align="center" prop="configType">
        <template #default="scope">
          <span v-if="scope.row.status === 'waiting'">未审批</span>
          <span v-if="scope.row.status === 'pending'">未审批</span>
          <span v-if="scope.row.status === 'succeed'">已审批</span>
          <span v-if="scope.row.status === 'rejected'">已驳回</span>
        </template>
      </el-table-column>
      <el-table-column label="下一步审批人" align="center" prop="approver" :show-overflow-tooltip="true" >
        <template #default="scope">
          <el-link type="primary" @click="showFlowConfig(scope.row)" :underline="false">{{ scope.row.approver }}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="150" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="success" icon="Select" @click="agree(scope.row)">同意</el-button>
          <el-button link type="danger" icon="CloseBold" @click="reject(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"
    />
  </div>
</template>

<script setup>
import {getApprovalList, operateProcess } from "@/api/flow/flow.js"
const { proxy } = getCurrentInstance();
import { ref, nextTick, computed, watch, reactive, onMounted } from 'vue'
import {getWaitingFlowCount} from "../../../api/flow/flow.js";
import cache from "../../../plugins/cache.js";
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    applicant: undefined,
    businessType: undefined,
  },
});
const total = ref(0);
const { queryParams } = toRefs(data);
const flowList = ref([]);
/** 查询参数列表 */
function getList() {
  getApprovalList(queryParams.value).then(res=>{
    flowList.value = res.data.rows
    total.value = res.data.total
  })
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}
function resetQuery(){
  queryParams.value = {
    pageNum: 1,
    pageSize: 10,
    applicant: undefined,
    businessType: undefined,
  }
  getList()
}
function showBusinessDataDialog(row){

}
function showFlowConfig(row){

}
function agree(row){
  let data = {
    flowId: row.id,
    operateType: 'success',
    operateComment: ''
}
  operateProcess(data).then(res=>{
    proxy.$modal.msgSuccess("操作成功");
    getWaitingFlowCount().then(res=>{
      cache.local.set("waitingTotal",res.data)
    })
  })
}
function reject(row){

}
onMounted(()=>{
  handleQuery()
})
</script>
