<script setup>
import {reactive} from "vue";
import Filter from "../../../../components/Filter/index.vue";
import useTableQuery from "../../../../hooks/useTableQuery.js";
import Api from "../../../../api/index.js";
import PreviewTaskModal from "../../../../components/PreviewTaskModal/PreviewTaskModal.vue";
import openTerminateTask from "../../../../components/TerminateTask/TerminateTask.js";
import {Message} from "@arco-design/web-vue";
import RejectTaskModal from "./components/RejectTaskModal.vue";

const columns = [
    {
        title: '任务编号',
        dataIndex: 'code',
    },
    {
        title: '子任务编号',
        dataIndex: 'uid',
    },
    {
        title: '子任务状态',
        dataIndex: 'status_text',
    },
    {
        title: '平台审核状态',
        dataIndex: 'check_status_text',
    },
    {
        title: '操作',
        dataIndex: 'action',
        slotName: 'action',
        width: 300,
    },
];
const FilterConfig = [
    {
        key: 'code',
        type: 'input',
        label: '任务编号',
        placeholder: '任务编号',
    },
    {
        key: 'uid',
        type: 'input',
        label: '子任务编号',
        placeholder: '子任务编号',
    },
    {
        key: 'check_status',
        type: 'select',
        label: '平台审核状态',
        placeholder: '请选择平台审核状态',
        api: async () => {
            return await Api.admin.getSubCheckStatusList();
        },
    },
    {
        key: 'status',
        type: 'select',
        label: '子任务状态',
        placeholder: '请选择子任务状态',
        api: async () => {
            return await Api.admin.getStatusList();
        },
    },
    {
        key: 'wd',
        type: 'input',
        label: '达人任务编号',
        placeholder: '请输入达人任务编号'
    },
];

const po = reactive({});
const vo = reactive({
    page: '',
    rows: [],
    total: 0,
});

const {loading, pagination, initFetchData, fetchData} = useTableQuery({
    parameter: po,
    api: Api.admin.getTaskChildrenList,
    callback: (data) => {
        Object.assign(vo, data);
        console.log(vo);
    }
});

const passTaskChildren = async (id) => {
    const {code, msg} = await Api.admin.passTaskChildren(id);
    if (code === 1) Message.success(msg);
    await fetchData();
}

const refuseTaskChildren = async (id) => {
    const {code, msg} = await Api.admin.refuseTaskChildren(id);
    if (code === 1) Message.success(msg);
    await fetchData();
}
</script>

<template>
    <!-- 子任务审核 -->
    <a-card>
        <Filter
            v-model:from="po"
            @search="initFetchData"
            :config="FilterConfig">
        </Filter>

        <a-table
            :data="vo.rows"
            @page-change="(e) => pagination.current = e"
            :pagination="pagination"
            :loading="loading"
            :columns="columns"
            class="flex-grow">
            <template v-slot:action="{record}">
                <div class="flex items-center gap-[20px] justify-between">
                    <PreviewTaskModal :id="record.id" @success="fetchData"></PreviewTaskModal>
                    <a-popconfirm content="确定通过?" @ok="passTaskChildren(record.id)">
                        <a-link :hoverable="false" status="success">通过</a-link>
                    </a-popconfirm>
                    <RejectTaskModal
                        :api="Api.admin.refuseTaskChildren"
                        :id="record.id"
                        @success="fetchData">
                    </RejectTaskModal>
                    <a-link :hoverable="false" status="danger" @click="openTerminateTask">终止子任务</a-link>
                </div>
            </template>
        </a-table>
    </a-card>
</template>

<style scoped>

</style>
