<template>
    <a-modal v-model:visible="modelValue" width="800px" :title="$t('order.examine')" @cancel="cancel" @ok="submitStatus"
    :okText="$t('form.Confirm')" :cancelText="$t('form.Cancel')">
        <a-form :model="formStatus" :style="{ width: '600px' }">
            <a-form-item :label="$t('lotCard.userName')">
                {{ FormDataList.userName }}
            </a-form-item>
            <a-form-item :label="$t('order.OrderNum')">
                {{ FormDataList.id }}
            </a-form-item>
            <a-form-item :label="$t('order.TariffName')">
                {{ FormDataList.trafficName }}
            </a-form-item>
            <a-form-item :label="$t('order.AuditOpinion')">
                <a-radio-group v-model="formStatus.moderationStatus" :options="optionsStatus">
                    <template #label="{ data }">
                        <a-tag>{{ data.label }}</a-tag>
                    </template>
                </a-radio-group>
            </a-form-item>
            <a-form-item :label="$t('lotCard.remark')">
                <a-textarea :placeholder="$t('form.datapoolForm.pleaseSelect')+$t('lotCard.remark')" v-model:model-value="formStatus.moderationNotes" allow-clear />
            </a-form-item>
        </a-form>
    </a-modal>
</template>

<script setup>
import { ref, onMounted, toRefs, defineProps, toRef, defineEmits } from 'vue';
import { OrderCardStatus } from '@/api/path/order'
import { Message } from '@arco-design/web-vue';
import {useI18n} from 'vue-i18n'
const {t} = useI18n();
const props = defineProps({
    modelValue: {
        type: Boolean,
        default: false
    },
    FormDataList: {
        type: Object,
        default: () => ({})
    }
})
const modelValue = toRef(props, 'modelValue')
const FormDataList = toRef(props, 'FormDataList')
const emit = defineEmits(['update:modelValue', 'submit'])

const state = ref({
    formStatus: {
        id: null,
        moderationStatus: '', // 审核状态
        moderationNotes: '', // 审核备注
    },
    optionsStatus: [
        { label: t('order.PassTheExamination'), value: '2' },
        { label: t('order.TurnDown'), value: '3' },
    ],
})

const { formStatus ,optionsStatus} = toRefs(state.value)

// 订单审核
const submitStatus = async () => {
    new Promise((resolve, reject) => {
        formStatus.value.id = FormDataList.value.id
        OrderCardStatus(formStatus.value).then(res => {
            Message.success(res.message)
            emit('update:modelValue', false)
            emit('submit', true)
        }).catch(error => [
            reject(error)
        ])
    })
}

const cancel = ()=>{
    emit('update:modelValue', false)
    Object.keys(formStatus.value).forEach(key => {
        formStatus.value[key] = ''
    })
}
</script>
<style scoped></style>