<template>
    <hc-tab-card :tabs="tabsData" :tab-key="tabsKey" @change="tabsClick">
        <template v-if="tabsKey === '1'" #extra>
            <el-button :disabled="tableCheckedKeys.length <= 0" hc-btn type="primary" @click="batchApprovalTaskClick">批量审批</el-button>
        </template>
        <template #search>
            <div class="w-32">
                <el-select v-model="searchForm.typeValue" clearable block placeholder="任务类型">
                    <!-- el-option v-for="item in tasksType" :label="item.dictValue" :value="item.dictKey" / -->
                </el-select>
            </div>
            <div class="ml-2 w-32">
                <el-select v-model="searchForm.statusValue" clearable block placeholder="任务状态">
                    <!-- el-option v-for="item in tasksStatus" :label="item.dictValue" :value="item.dictKey" / -->
                </el-select>
            </div>
            <div class="ml-2 w-32">
                <el-select v-model="searchForm.batch" clearable block placeholder="上报批次">
                    <!-- el-option v-for="item in reportBatch" :label="item.batch" :value="item.batch" / -->
                </el-select>
            </div>
            <div class="ml-2 w-64">
                <hc-date-picker :dates="betweenTime" clearable @change="betweenTimeUpdate" />
            </div>
            <hc-search-input v-model="searchForm.queryValue" class="ml-2" placeholder="请输入名称关键词检索" @search="searchClick" />
        </template>
        <hc-table
            ref="tableListRef" :column="tableListColumn" :datas="tableListData" :loading="tableLoading"
            is-new is-check :check-style="{ width: 29 }" :index-style="{ width: 60 }"
            @selection-change="tableSelectionChange"
        >
            <template #taskName="{ row }">
                <span class="text-link" @click="rowTaskName(row)">{{ row?.taskName }}</span>
            </template>
            <template #taskStatusName="{ row }">
                <el-tag
                    v-if="row?.taskStatusName"
                    :type="`${row.taskStatusName === '已审批' ? 'success' : row.taskStatusName === '已废除' ? 'warning' : 'info'}`"
                    class="mx-1" effect="dark"
                >
                    {{ row.taskStatusName }}
                </el-tag>
            </template>
            <template #taskApproveUserNamesList="{ row }">
                <template v-for="(item, index) in row.taskApproveUserNamesList" :key="index">
                    <el-tag
                        v-if="item.taskUserName"
                        :type="`${item.evisaStatus === 2 ? 'success' : item.evisaStatus === 3 ? 'warning' : item.evisaStatus === 999 ? 'danger' : 'info'}`"
                        class="mx-1" effect="dark"
                    >
                        {{ item.taskUserName }}
                    </el-tag>
                </template>
            </template>
        </hc-table>
        <template #action>
            <div class="lr-dialog-footer">
                <div class="left">
                    <span class="text-success">审批人员中：</span>
                    <el-tag class="mx-1" effect="dark" type="info">未签字</el-tag>
                    <el-tag class="mx-1" effect="dark" type="success">已签字</el-tag>
                    <el-tag class="mx-1" effect="dark" type="warning">已废除</el-tag>
                    <el-tag class="mx-1" effect="dark" type="danger">签字异常</el-tag>
                </div>
                <div class="right">
                    <hc-pages :pages="searchForm" :sizes="[30, 40, 50, 200]" @change="pageChange" />
                </div>
            </div>
        </template>
        <!-- 任务审核 -->
        <taskReview v-model="isTaskReviewModalshow" :tabs="tabsKey" :row="taskReviewRow" />
    </hc-tab-card>
</template>

<script setup>
import { onMounted, ref } from 'vue'
import taskReview from './components/hc-data/task-review.vue'

//渲染完成
onMounted(() => {

})

//类型处理
const tabsKey = ref('1')
const tabsData = [
    { key: '1', name: '待办任务' },
    { key: '2', name: '已办任务' },
    { key: '3', name: '我发起的' },
]
const tabsClick = ({ key }) => {
    tabsKey.value = key
}

//搜索条件
const searchForm = ref({
    current: 1, size: 200, total: 0,
})

//日期范围选择
const betweenTime = ref(null)
const betweenTimeUpdate = ({ val, arr }) => {
    betweenTime.value = arr
    searchForm.value.startTimeValue = val['start']
    searchForm.value.endTimeValue = val['end']
}

//搜索
const searchClick = () => {
    searchForm.value.current = 1
}

//分页被点击
const pageChange = ({ current, size }) => {
    searchForm.value.current = current
    searchForm.value.size = size
}

//获取数据
const tableListRef = ref(null)
const tableLoading = ref(false)
const tableListColumn = ref([
    { key: 'taskName', name: '任务名称' },
    { key: 'taskTypeName', name: '任务类型', width: '120' },
    { key: 'taskStatusName', name: '任务状态', width: '120' },
    { key: 'startTime', name: '开始时间', width: '160' },
    { key: 'endTime', name: '限定时间', width: '160' },
    { key: 'taskDesc', name: '任务描述' },
    { key: 'taskReportUserName', name: '上报人', width: '120' },
    { key: 'taskApproveUserNamesList', name: '签字人员' },
    { key: 'evisaStatus', name: '电签状态', width: '120' },
])
const tableListData = ref([
    { taskName: '中间计量审批模板', type: 1 },
    { taskName: '开工预付款计量审批模板', type: 2 },
    { taskName: '变更令审批模板', type: 3 },
    { taskName: '材料预付款计量申请审批模板', type: 4 },
])

//多选
const tableCheckedKeys = ref([])
const tableSelectionChange = (rows) => {
    tableCheckedKeys.value = rows
}

//任务详情弹窗
const isTaskReviewModalshow = ref(false)

//任务名称被点击
const taskReviewRow = ref({})
const rowTaskName = (row) => {
    taskReviewRow.value = row
    isTaskReviewModalshow.value = true
}

//批量审批
const batchApprovalTaskClick = () => {

}
</script>
