<template>
    <global-page
        :padding="24"
        title="航站不正常事件详情"
        :showFooterBtn="details.state == 0 && checkPermi('/terminalQualityManagement/audit')"
        :footerBtnText="getFooterTxt"
        @handleFooterClick="handleFooterClick"
        :showNavRight="auditLabel != '审核通过' && checkPermi('/terminalQualityManagement/edit')"
        @handleRightClick="navigateTo('/panel/abnormalEventManage/edit')"
    >
        <view class="mocp-cell" v-if="details">
            <up-cell-group>
                <up-cell title="状态">
                    <template #value>
                        <global-text-status :value="details.state" dictkey="aem_state"></global-text-status>
                    </template>
                </up-cell>
                <up-cell title="事件来源" :value="getParamNameByValue('EventResource', details.source)" />
                <up-cell title="航站" :value="details.terminal || '-'" />
                <up-cell title="责任单位" :value="details.repairUnit || '-'" />
                <up-cell title="责任人" :value="details.personLiable || '-'" />
                <up-cell title="机号" :value="details.machineNumber || '-'" />
                <up-cell title="机型" :value="details.model || '-'" />
                <up-cell title="航司" :value="useGetDictByValue('', details.aviation, { data: getAirlineSelect() })" />
                <up-cell title="事件描述" :label="details.eventDescription || '-'" />
                <up-cell title="问题点" :value="details.problemPoints || '-'" />
                <up-cell title="类别" :value="getParamNameByValue('EventCategory', details.category)" />
                <up-cell title="扣分情况" :value="details.pointsDeduction || '-'" />
                <up-cell title="接报日期" :value="timeStampFormat(details.occurrenceTime, { format: 'YYYY/MM/DD' }) || '-'" />
                <up-cell title="调查单位" :value="details.surveyUnit || '-'" />
                <up-cell title="事件性质" :value="getParamNameByValue('EventProperty', details.eventProperty)" />
                <up-cell title="备注" :label="details.remake || '-'" />
                <up-cell title="调查已反馈" :value="useGetDictByValue('aem_surveyListSelect2', details.survey)" />
                <up-cell title="附件">
                    <template #label>
                        <view style="margin-top: 16rpx">
                            <global-upload :fileList="details.surveyAttaFileVoList" :showUpload="false"></global-upload>
                        </view>
                    </template>
                </up-cell>
                <up-cell
                    title="调查完成时限"
                    v-if="!(details.survey && details.survey == '2')"
                    :value="timeStampFormat(details.surveyTimeLimit, { format: 'YYYY/MM/DD' }) || '-'"
                />
                <up-cell title="调查结果简述" v-if="!(details.survey && details.survey == '2')" :label="details.surveyFeedback || '-'" />
                <up-cell title="完成整改" :value="useGetDictByValue('aem_surveyListSelect2', details.correctiveComplete)" />
                <up-cell title="附件">
                    <template #label>
                        <view style="margin-top: 16rpx">
                            <global-upload :fileList="details.correctiveAttaFileVoList" :showUpload="false"></global-upload>
                        </view>
                    </template>
                </up-cell>
                <up-cell
                    title="整改完成时限"
                    v-if="!(details.correctiveComplete && details.correctiveComplete == '2')"
                    :value="timeStampFormat(details.correctiveTimeLimit, { format: 'YYYY/MM/DD' }) || '-'"
                />
                <up-cell title="整改措施" :label="details.correctiveMeasures || '-'" />
                <up-cell title="是否延误" :value="useGetDictByValue('aem_yesOrNoRadio', details.delay)" />
            </up-cell-group>
        </view>
        <global-action-sheet
            v-model="showAction"
            title="审核"
            description="审核本条航站不正常事件"
            :options="[
                { label: '审核不通过', value: '4' },
                { label: '审核通过', value: '3' }
            ]"
            @select="handleSelect"
        ></global-action-sheet>
        <up-modal
            :width="250"
            content="确认提交审核吗？"
            :show="showConfirm"
            showCancelButton
            closeOnClickOverlay
            @confirm="handleSelect('2')"
            @cancel="showConfirm = false"
            @close="showConfirm = false"
        ></up-modal>
    </global-page>
</template>

<script setup>
import { storeToRefs } from 'pinia'
import { getParamNameByValue } from 'mocp/hooks/use-params/useParams'
import useAbnormalEventManageStore from 'mocp/store/abnormalEventManage'
import { timeStampFormat } from 'mocp/utils/tool'
import { useGetDictByValue } from 'mocp/hooks/use-dict/useDict'
import { computed, ref } from 'vue'
import { navigateTo } from 'mocp/utils/jump'
import { reviewedAdverseEventsApi } from 'mocp/api/abnormalEventManage'
import { checkPermi, getAirlineSelect } from 'mocp/utils/permission'

const abnormalEventManageStore = useAbnormalEventManageStore()
const { details } = storeToRefs(abnormalEventManageStore)
const auditLabel = computed(() => {
    return useGetDictByValue('aem_auditListSelect', details.value?.reviewedState)
})
//获取底部按钮
const getFooterTxt = computed(() => {
    if (details?.reviewedState == '' || auditLabel.value == '未提交审核' || auditLabel.value == '审核不通过') {
        return '提交审核'
    } else {
        return '审核'
    }
})
//审核
const showAction = ref(false)
const handleFooterClick = () => {
    if (getFooterTxt.value == '提交审核') {
        showConfirm.value = true
    } else {
        showAction.value = true
    }
}
const handleSelect = async (value) => {
    const params = {
        id: details.value?.id,
        reviewedState: value
    }
    const res = await reviewedAdverseEventsApi(params, { loading: true })
    if (res.code == 200) {
        uni.$mocpJump.navigateBack()
        uni.$emit('abnormalEventManageReload')
        uni.$mocpMessage.success(res.message)
    } else {
        uni.$mocpMessage.error(res.message)
    }
}
//提交审核
const showConfirm = ref(false)
</script>
<style lang="scss" scoped>
.mocp-cell {
    background: #fff;
}
.mocp-title {
    padding: 0 32rpx 24rpx 32rpx;
    background-color: $mocp-fill-1;
}
</style>
