<template>
    <global-page :padding="24" title="运行调查详情">
        <template v-if="details">
            <view class="mocp-cell">
                <up-cell-group>
                    <up-cell title="发起时间" :value="timeStampFormat(details.proposedTime, { format: 'YYYY/MM/DD HH:mm' }) || '-'" />
                    <up-cell title="机号" :value="details.ac || '-'" />
                    <up-cell title="机型" :value="details.acType || '-'" />
                    <up-cell title="航司" :value="details.acOwn || '-'" />
                    <up-cell title="航站" :value="baseStore.getTerminalObject[details.acTerminal] || '-'" />
                    <up-cell title="提出人" :value="details.proposer || '-'" />
                    <up-cell title="发起席位" :value="baseStore.getSeat(details.seat)" />
                    <up-cell title="调查等级" :value="useGetDictByValue('os_surveyLevel', details.surveyLevel) || '-'" />
                    <up-cell title="标题" :label="details.title || '无'" />
                </up-cell-group>
            </view>
            <view class="mocp-cell">
                <up-cell-group>
                    <up-cell title="客户延误定性" :value="delayNature[details.delayNature] || '-'" />
                    <up-cell title="是否争议" :value="useGetDictByValue('os_disputeMsg', details.disputeMsg) || '-'" />
                    <up-cell title="申诉定性" :value="delayNature[details.qualitativeAppeal] || '-'" />
                    <up-cell title="第一客观延误原因" :value="details.delayReason1 || '-'" />
                    <up-cell title="第二客观延误原因" :value="details.delayReason2 || '-'" />
                </up-cell-group>
            </view>
            <view class="mocp-cell">
                <up-collapse>
                    <up-collapse-item title="事件简述" name="1">
                        <view class="mocp-cell">
                            <up-cell-group>
                                <up-cell title="内容" :label="details.eventMsg || '-'" />
                                <up-cell title="相关附件">
                                    <template #label>
                                        <view style="margin-top: 16rpx">
                                            <global-upload :fileList="details.files" :showUpload="false"></global-upload>
                                        </view>
                                    </template>
                                </up-cell>
                                <up-cell title="事件分类" :value="getEventclass" />
                            </up-cell-group>
                        </view>
                    </up-collapse-item>
                    <view class="mocp-title">
                        故障历史
                        <global-button type="text" @tap="navigateTo('/panel/operationalSurvey/historicalFault')">点击查看</global-button>
                    </view>
                    <up-collapse-item title="手册标准" name="2" v-if="details.manualList?.length">
                        <view class="mocp-cell">
                            <up-cell-group>
                                <template v-for="(item, index) in details.manualList" :key="index">
                                    <up-cell title="内容" :label="item.content || '-'" />
                                    <up-cell title="相关附件">
                                        <template #label>
                                            <view style="margin-top: 16rpx">
                                                <global-upload :fileList="item.files" :showUpload="false"></global-upload>
                                            </view>
                                        </template>
                                    </up-cell>
                                </template>
                            </up-cell-group>
                        </view>
                    </up-collapse-item>
                    <up-collapse-item title="处置经过" name="3">
                        <view class="mocp-cell">
                            <up-cell-group>
                                <up-cell title="内容" :label="details.dispose?.content || '-'" />
                                <up-cell title="相关附件">
                                    <template #label>
                                        <view style="margin-top: 16rpx">
                                            <global-upload :fileList="details.dispose?.files" :showUpload="false"></global-upload>
                                        </view>
                                    </template>
                                </up-cell>
                            </up-cell-group>
                        </view>
                    </up-collapse-item>
                    <up-collapse-item title="经济损失分析" name="4">
                        <view class="mocp-cell">
                            <up-cell-group>
                                <up-cell title="不正常航班费用">
                                    <template #value>{{ details.economy?.abnormal || 0 }}元</template>
                                </up-cell>
                                <up-cell title="人员AOG差旅费用">
                                    <template #value>{{ details.economy?.travel || 0 }}元</template>
                                </up-cell>
                                <up-cell title="外委费用">
                                    <template #value>{{ details.economy?.outsourcing || 0 }}元</template>
                                </up-cell>
                                <up-cell title="航材保障费用">
                                    <template #value>{{ details.economy?.material || 0 }}元</template>
                                </up-cell>
                                <up-cell title="工具设备借用费用">
                                    <template #value>{{ details.economy?.equipment || 0 }}元</template>
                                </up-cell>
                                <up-cell title="其他">
                                    <template #value>{{ details.economy?.others || 0 }}元</template>
                                </up-cell>
                                <up-cell title="合计">
                                    <template #value>
                                        {{
                                            (details.economy?.abnormal || 0) * 1 +
                                            (details.economy?.travel || 0) * 1 +
                                            (details.economy?.outsourcing || 0) * 1 +
                                            (details.economy?.material || 0) * 1 +
                                            (details.economy?.equipment || 0) * 1 +
                                            (details.economy?.others || 0) * 1
                                        }}元
                                    </template>
                                </up-cell>
                            </up-cell-group>
                        </view>
                    </up-collapse-item>
                    <template v-for="(item, index) in details.elementList" :key="index">
                        <up-collapse-item :title="item.title || '-'" :name="item.id">
                            <view class="mocp-cell">
                                <up-cell-group>
                                    <up-cell title="内容" :label="item.content || '-'" />
                                    <up-cell title="相关附件">
                                        <template #label>
                                            <view style="margin-top: 16rpx">
                                                <global-upload :fileList="item.files" :showUpload="false"></global-upload>
                                            </view>
                                        </template>
                                    </up-cell>
                                    <up-cell title="填报人" :value="item.uname || '-'" />
                                    <up-cell title="填报时间" :value="timeStampFormat(item.time) || '-'" />
                                </up-cell-group>
                            </view>
                        </up-collapse-item>
                    </template>
                    <view class="mocp-title">
                        事件分析
                        <global-button type="text" @tap="navigateTo('/panel/operationalSurvey/analysisList')">点击查看</global-button>
                    </view>
                    <up-collapse-item title="事件结论" name="5">
                        <view class="mocp-cell">
                            <up-cell-group>
                                <up-cell title="内容" :label="details.conclusion?.eventConclusion || '-'" />
                                <up-cell title="相关附件">
                                    <template #label>
                                        <view style="margin-top: 16rpx">
                                            <global-upload :fileList="details.conclusion?.files" :showUpload="false"></global-upload>
                                        </view>
                                    </template>
                                </up-cell>
                                <template v-for="(item, index) in details.conclusion?.liabilities" :key="index">
                                    <up-cell title="责任单位" :value="getParamNameByValue('RcQaLiabilityBelong', item.liabilityBelong)" />
                                    <up-cell title="责任定性" :value="getParamNameByValue('RcQaNature', item.liabilityNature)" />
                                </template>
                                <up-cell title="填报人" :value="details.conclusion?.uname || '-'" />
                                <up-cell title="填报时间" :value="timeStampFormat(details.conclusion?.time) || '-'" />
                            </up-cell-group>
                        </view>
                    </up-collapse-item>
                    <up-collapse-item title="改进措施" name="6">
                        <view class="mocp-cell">
                            <up-cell-group>
                                <up-cell title="内容" :label="details.improve?.content || '-'" />
                                <up-cell title="填报人" :value="details.improve?.uname || '-'" />
                                <up-cell title="填报时间" :value="timeStampFormat(details.improve?.time) || '-'" />
                            </up-cell-group>
                        </view>
                    </up-collapse-item>
                    <up-collapse-item title="批准" name="7">
                        <view class="mocp-cell">
                            <up-cell-group>
                                <up-cell title="批示意见" :value="getAuditContent" />
                                <up-cell title="填报人" :value="details.audit?.auditName || '-'" />
                                <up-cell title="填报时间" :value="timeStampFormat(details.audit?.auditTime) || '-'" />
                            </up-cell-group>
                        </view>
                        <global-button type="primary" :radius="0" size="large" @tap="navigateTo('/panel/operationalSurvey/audit')">
                            批示
                        </global-button>
                    </up-collapse-item>
                    <up-collapse-item title="MOC点评" name="8">
                        <view class="mocp-cell">
                            <up-cell-group>
                                <up-cell title="内容" :label="details.reviews?.evaluation || '-'" />
                                <up-cell title="填报人" :value="details.reviews?.uname || '-'" />
                                <up-cell title="填报时间" :value="timeStampFormat(details.reviews?.time) || '-'" />
                            </up-cell-group>
                        </view>
                    </up-collapse-item>
                </up-collapse>
            </view>
            <view class="mocp-cell">
                <up-cell-group>
                    <up-cell title="填报人" :value="details.openUsernameL || '-'" />
                    <up-cell title="填报时间" :value="timeStampFormat(details.openTimeL) || '-'" />
                    <up-cell title="关闭人" :value="details.closeUsername || '-'" />
                    <up-cell title="关闭时间" :value="timeStampFormat(details.closeTime) || '-'" />
                </up-cell-group>
            </view>
        </template>
    </global-page>
</template>

<script setup>
import { storeToRefs } from 'pinia'
import useBaseStore from 'mocp/store/base'
import { timeStampFormat } from 'mocp/utils/tool'
import { useGetDictByValue } from 'mocp/hooks/use-dict/useDict'
import { onLoad } from '@dcloudio/uni-app'
import useOperationalSurveyStore from 'mocp/store/operationalSurvey'
import { computed } from 'vue'
import { getParamNameByValue } from 'mocp/hooks/use-params/useParams'
import { navigateTo } from 'mocp/utils/jump'

const query = defineProps(['workbenchId'])
const baseStore = useBaseStore()
const {
    rcOptions: { delayNature }
} = useBaseStore()
const operationalSurveyStore = useOperationalSurveyStore()
onLoad(() => {
    operationalSurveyStore.setState('workbenchId', query.workbenchId)
    operationalSurveyStore.getRsData2()
})
const { details } = storeToRefs(operationalSurveyStore)
//获取事件分类
const getEventclass = computed(() => {
    return (
        details.value?.eventclassList
            .map((item) => {
                return item.eventclass2 || item.eventclass1
            })
            .join(',') || '-'
    )
})
//获取批准意见
const getAuditContent = computed(() => {
    if (details.value?.audit) {
        return (
            useGetDictByValue('os_opinion', details.value.audit.opinion) +
            (details.value.audit.content ? ',' + details.value.audit.content : details.value.audit.content)
        )
    } else {
        return '-'
    }
})
//获取默认展开项
const getCollapseValue = computed(() => {
    const value = ['1', '2', '3', '4', '5', '6', '7', '8']
    details.value?.elementList.forEach((element) => {
        value.push(element.id)
    })
    return value
})
</script>
<style lang="scss" scoped>
.mocp-cell {
    background: #fff;
    margin-bottom: 16rpx;
}
.mocp-title {
    padding: 12rpx 32rpx 12rpx 32rpx;
    background-color: $mocp-fill-1;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.mocp-subTitle {
    padding: 24rpx 32rpx 0 32rpx;
    font-weight: bold;
}
:deep(.u-collapse-item) {
    .u-cell {
        background: $mocp-fill-1;
    }
    .u-collapse-item__content {
        .u-cell {
            background: #fff;
        }
    }
    .u-collapse-item__content__text {
        padding: 0;
    }
    .u-cell__title {
        color: $mocp-text-5;
    }
}
</style>
