<script setup>
import {nextTick, reactive, ref, watch} from "vue";
import Api from "../../../../../api/index.js";
import {Message} from "@arco-design/web-vue";

const {id, disabled} = defineProps({
    id: {
        type: Number,
        default: 0
    },
    disabled: {
        type: Boolean,
        default: 0
    }
});
const emits = defineEmits(['success']);
const visible = ref(false);
const form = reactive({
    id: null,
    real_price: null,
    security_level: null,
    time_level: null,
});

watch(
    () => visible.value,
    (val) => {
        if (val) {
            Api.admin.getTaskDetail(id).then(({data}) => {
                form.id = data.id;
                form.real_price = data.real_price;
                form.security_level = data.security_level;
                form.time_level = data.time_level;
            });
        }
    },
    {
        deep: true,
    }
)

const success = async () => {
    console.log(form);
    if (
        form.real_price === null ||
        form.security_level === null ||
        form.time_level === null ||
        form.real_price === '' ||
        form.security_level === '' ||
        form.time_level === '' ||
        form.real_price === undefined ||
        form.security_level === undefined ||
        form.time_level === undefined
    ) {
        Message.warning('填写信息不能为空');
        nextTick(() => {
            visible.value = true;
        })
        return;
    }
    const {msg, code} = await Api.admin.passTask(form);
    if (code === 1) Message.success(msg);
    emits('success');
    visible.value = false;
}
</script>

<template>
    <a-link :disabled="disabled" :hoverable="false" status="success" @click="visible=true">通过</a-link>

    <a-modal
        @ok="success"
        @cancel="visible=false"
        title-align="start"
        title="任务审核通过"
        :visible="visible">
        <a-form :model="form" layout="vertical">
            <a-form-item label="该任务对达人端的展示价格为：">
                <a-input-number :min="0" v-model:model-value="form.real_price" placeholder="请输入价格"
                                :precision="2"></a-input-number>
            </a-form-item>
            <a-form-item label="安全评分">
                <a-input-number :min="0" :max="100" :precision="0" v-model:model-value="form.security_level"
                                placeholder="请输入安全评分，满分100"></a-input-number>
            </a-form-item>
            <a-form-item label="耗时评分">
                <a-input-number :min="0" :max="100" :precision="0" v-model:model-value="form.time_level"
                                placeholder="请输入耗时评分，满分100"></a-input-number>
            </a-form-item>
        </a-form>
    </a-modal>
</template>

<style scoped>

</style>
