<template>
    <global-page
        :padding="24"
        title="防风害系留操作单"
        :showFooterBtn="getBasicVo.rxStatus == '0'"
        footerBtnText="接收"
        @handleFooterClick="handleFooterClick"
        showNavRight
        navRightType="button"
        navRightText="保存"
        :navRightDisabled="getDisabled"
        @handleRightClick="handleRightClick"
    >
        <template v-if="details">
            <view class="mocp-cell">
                <up-collapse :value="['1', '2', '3']" ref="collapseRef">
                    <up-collapse-item name="1">
                        <template #title>
                            <view class="mocp-title">
                                <text class="txt">基础信息</text>
                                <view>
                                    <global-tag :type="useGetDictByValue('wdm_rxStatusType', getBasicVo.rxStatus)">
                                        {{ useGetDictByValue('wdm_rxStatus', getBasicVo.rxStatus) }}
                                    </global-tag>
                                    <global-tag style="margin-left: 16rpx" v-if="getBasicVo.issueStatus">
                                        {{ useGetDictByValue('wdm_issueStatus', getBasicVo.issueStatus) }}
                                    </global-tag>
                                </view>
                            </view>
                        </template>
                        <template #value>
                            <view style="margin-right: 24rpx">
                                <global-button type="text" :disabled="getDisabled" @tap.stop="navigateTo('/panel/windDamageManagement/editBasic')">
                                    编辑
                                </global-button>
                            </view>
                        </template>
                        <view class="mocp-cell">
                            <up-cell-group>
                                <up-cell title="报文生成时间" :value="details.generateTime || '-'" />
                                <up-cell title="预报风速" :value="getBasicVo.windSpeed || '-'" />
                                <up-cell title="预计开始时间" :value="details.startTime || '-'" />
                                <up-cell title="基地值班" :value="getBasicVo.dutyName || '-'" />
                                <up-cell isLink>
                                    <template #title>
                                        <global-field label="航站"></global-field>
                                        <global-field :value="baseStore.getTerminalObject[details.terminal] || '-'"></global-field>
                                    </template>
                                    <template #value>
                                        <text @tap="goWeather">气象信息</text>
                                    </template>
                                </up-cell>
                                <up-cell title="机号" :value="getBasicVo.ac || '-'" />
                                <up-cell title="操作人" :value="getBasicVo.operateName || '-'" />
                                <up-cell title="发起人" :value="getBasicVo.proposedName || '-'" />
                                <up-cell title="发起时间" :value="timeStampFormat(getBasicVo.proposedTime) || '-'" />
                                <up-cell isLink>
                                    <template #title>
                                        <global-field label="填报人:" :value="getBasicVo.fillingName || '-'"></global-field>
                                        <global-field label="填报时间:" :value="timeStampFormat(getBasicVo.fillingTime) || '-'"></global-field>
                                    </template>
                                    <template #value>
                                        <text @tap="openReceiveHistory">接收历史</text>
                                    </template>
                                </up-cell>
                            </up-cell-group>
                        </view>
                    </up-collapse-item>
                    <up-collapse-item title="工作内容" name="2">
                        <view class="mocp-cell">
                            <up-cell-group>
                                <up-cell title="开始时间">
                                    <template #value>
                                        <global-date-picker v-model="formData.startTime" :disabled="getDisabled"></global-date-picker>
                                    </template>
                                </up-cell>
                                <up-cell title="系留情况">
                                    <template #label>
                                        <view style="margin-top: 12rpx">
                                            <global-radio
                                                v-model="formData.situation"
                                                clearable
                                                dictkey="wdm_situation"
                                                :disabled="getDisabled"
                                            ></global-radio>
                                        </view>
                                    </template>
                                </up-cell>
                            </up-cell-group>
                        </view>
                        <view class="mocp-cell" v-if="formData.situation == 0">
                            <up-cell-group>
                                <!-- 1 -->
                                <up-cell>
                                    <template #title>
                                        <view>1、参照各机型飞机系留工卡或AMM手册的要求执行系留</view>
                                    </template>
                                </up-cell>
                                <up-cell title="是否完成">
                                    <template #value>
                                        <view>
                                            <global-radio
                                                radioAlign="right"
                                                v-model="formData.executeComplete"
                                                clearable
                                                dictkey="wdm_complete"
                                                :disabled="getDisabled"
                                            ></global-radio>
                                        </view>
                                    </template>
                                </up-cell>
                                <up-cell title="发现问题及处理措施" :border="false">
                                    <template #label>
                                        <up-textarea
                                            placeholder="请输入"
                                            v-model="formData.executeMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.executeFiles"
                                            :file-list="getWorkVo.executeFiles"
                                            :show-upload="!getDisabled"
                                        ></global-upload>
                                    </template>
                                </up-cell>
                                <!-- 2 -->
                                <up-cell>
                                    <template #title>
                                        <view>2、同步执行防风害巡场检查单和防风害操作单</view>
                                    </template>
                                </up-cell>
                                <up-cell title="是否完成">
                                    <template #value>
                                        <view>
                                            <global-radio
                                                radioAlign="right"
                                                v-model="formData.syncComplete"
                                                clearable
                                                dictkey="wdm_complete"
                                                :disabled="getDisabled"
                                            ></global-radio>
                                        </view>
                                    </template>
                                </up-cell>
                                <up-cell title="发现问题及处理措施" :border="false">
                                    <template #label>
                                        <up-textarea
                                            placeholder="请输入"
                                            v-model="formData.syncMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.syncFiles"
                                            :file-list="getWorkVo.syncFiles"
                                            :show-upload="!getDisabled"
                                        ></global-upload>
                                    </template>
                                </up-cell>
                            </up-cell-group>
                        </view>
                        <view class="mocp-cell" v-if="formData.situation == 1">
                            <up-cell-group>
                                <!-- 1 -->
                                <up-cell>
                                    <template #title>
                                        <view>1、通报基地值班经理或基地负责人，公司值班经理；</view>
                                    </template>
                                </up-cell>
                                <up-cell title="是否完成">
                                    <template #value>
                                        <view>
                                            <global-radio
                                                radioAlign="right"
                                                v-model="formData.headComplete"
                                                clearable
                                                dictkey="wdm_complete"
                                                :disabled="getDisabled"
                                            ></global-radio>
                                        </view>
                                    </template>
                                </up-cell>
                                <up-cell title="发现问题及处理措施" :border="false">
                                    <template #label>
                                        <up-textarea
                                            placeholder="请输入"
                                            v-model="formData.headMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.headFiles"
                                            :file-list="getWorkVo.headFiles"
                                            :show-upload="!getDisabled"
                                        ></global-upload>
                                    </template>
                                </up-cell>
                                <!-- 2 -->
                                <up-cell>
                                    <template #title>
                                        <view>2、飞机所有机轮前后设置符合机型维修手册中防风停放相关技术要求的轮挡，并将轮挡成对缚牢；</view>
                                    </template>
                                </up-cell>
                                <up-cell title="是否完成">
                                    <template #value>
                                        <view>
                                            <global-radio
                                                radioAlign="right"
                                                v-model="formData.wheelComplete"
                                                clearable
                                                dictkey="wdm_complete"
                                                :disabled="getDisabled"
                                            ></global-radio>
                                        </view>
                                    </template>
                                </up-cell>
                                <up-cell title="发现问题及处理措施" :border="false">
                                    <template #label>
                                        <up-textarea
                                            placeholder="请输入"
                                            v-model="formData.wheelMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.wheelFiles"
                                            :file-list="getWorkVo.wheelFiles"
                                            :show-upload="!getDisabled"
                                        ></global-upload>
                                    </template>
                                </up-cell>
                                <!-- 3 -->
                                <up-cell>
                                    <template #title>
                                        <view>
                                            <view>3、参考各机型AMM 手册相关章节对飞机系留时停放的要求，停放姿态需满足以下一些基本条件：</view>
                                            <view>1）确保刹车压力充足后设置停留刹车；</view>
                                            <view>2）飞机尽量迎风停放;</view>
                                            <view>3）飞机各飞行操纵面处于中立位并按需按AMM手册要求进行锁定;</view>
                                            <view>4）水平安定面/升降舵配平至使机头向下位置;</view>
                                            <view>5）关闭并锁好所有舱门。</view>
                                        </view>
                                    </template>
                                </up-cell>
                                <up-cell title="是否完成">
                                    <template #value>
                                        <view>
                                            <global-radio
                                                radioAlign="right"
                                                v-model="formData.ammComplete"
                                                clearable
                                                dictkey="wdm_complete"
                                                :disabled="getDisabled"
                                            ></global-radio>
                                        </view>
                                    </template>
                                </up-cell>
                                <up-cell title="发现问题及处理措施" :border="false">
                                    <template #label>
                                        <up-textarea
                                            placeholder="请输入"
                                            v-model="formData.ammMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.ammFiles"
                                            :file-list="getWorkVo.ammFiles"
                                            :show-upload="!getDisabled"
                                        ></global-upload>
                                    </template>
                                </up-cell>
                                <!-- 4 -->
                                <up-cell>
                                    <template #title>
                                        <view>
                                            <view>
                                                4、将飞机加满油或在前货舱或客舱内增加足够数量的压舱物，以增加飞机的重量；增加压舱物时，可以首先考虑在飞机的前货舱或客舱的前部使用压舱物。压舱物应选用比重较大物体（推荐使用沙袋），使用压舱物后飞机的总重量不能超过飞机的最大滑行重量。
                                            </view>
                                            <view style="color: #86909c">注：压舱物的使用参考各机型AMM手册。</view>
                                        </view>
                                    </template>
                                </up-cell>
                                <up-cell title="是否完成">
                                    <template #value>
                                        <view>
                                            <global-radio
                                                radioAlign="right"
                                                v-model="formData.ballastComplete"
                                                clearable
                                                dictkey="wdm_complete"
                                                :disabled="getDisabled"
                                            ></global-radio>
                                        </view>
                                    </template>
                                </up-cell>
                                <up-cell title="发现问题及处理措施" :border="false">
                                    <template #label>
                                        <up-textarea
                                            placeholder="请输入"
                                            v-model="formData.ballastMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.ballastFiles"
                                            :file-list="getWorkVo.ballastFiles"
                                            :show-upload="!getDisabled"
                                        ></global-upload>
                                    </template>
                                </up-cell>
                                <!-- 5 -->
                                <up-cell>
                                    <template #title>
                                        <view>
                                            <view>5、确保飞机周围没有障碍物：</view>
                                            <view>·飞机在停放时要严格按照当地机场要求进行停放，避免飞机在发生滑动时撞上机坪上停放的其他飞机;</view>
                                            <view>· 尽量远离廊桥;</view>
                                            <view>· 撤除飞机周围没有梯架、设备等</view>
                                        </view>
                                    </template>
                                </up-cell>
                                <up-cell title="是否完成">
                                    <template #value>
                                        <view>
                                            <global-radio
                                                radioAlign="right"
                                                v-model="formData.obstacleComplete"
                                                clearable
                                                dictkey="wdm_complete"
                                                :disabled="getDisabled"
                                            ></global-radio>
                                        </view>
                                    </template>
                                </up-cell>
                                <up-cell title="发现问题及处理措施" :border="false">
                                    <template #label>
                                        <up-textarea
                                            placeholder="请输入"
                                            v-model="formData.obstacleMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.obstacleFiles"
                                            :file-list="getWorkVo.obstacleFiles"
                                            :show-upload="!getDisabled"
                                        ></global-upload>
                                    </template>
                                </up-cell>
                            </up-cell-group>
                        </view>
                        <view class="mocp-cell">
                            <up-cell-group>
                                <up-cell>
                                    <template #title>填报人:{{ getWorkVo.fillingName || '-' }}</template>
                                    <template #value>填报时间:{{ timeStampFormat(getWorkVo.fillingTime) || '-' }}</template>
                                </up-cell>
                                <up-cell title="结束时间">
                                    <template #value>
                                        <global-date-picker v-model="formData.endTime" :disabled="getDisabled"></global-date-picker>
                                    </template>
                                </up-cell>
                            </up-cell-group>
                        </view>
                        <view class="mocp-cell">
                            <up-cell-group>
                                <up-cell>
                                    <template #title>操作人:{{ getBasicVo.relieveName || '-' }}</template>
                                    <template #value>操作时间:{{ timeStampFormat(getBasicVo.relieveTime) || '-' }}</template>
                                </up-cell>
                            </up-cell-group>
                            <view style="padding: 12rpx">
                                <global-button
                                    size="medium"
                                    type="primary"
                                    @tap="saveRelieveInfo"
                                    :disabled="getBasicVo.isRelieve == '1' || getDisabled"
                                >
                                    解除系留
                                </global-button>
                            </view>
                        </view>
                    </up-collapse-item>
                    <up-collapse-item title="结论" name="3">
                        <template #value>
                            <view style="margin-right: 24rpx">
                                <global-button
                                    type="text"
                                    :disabled="getDisabled"
                                    @tap.stop="navigateTo('/panel/windDamageManagement/editConclusion')"
                                >
                                    编辑
                                </global-button>
                            </view>
                        </template>
                        <view class="mocp-cell">
                            <up-cell-group>
                                <up-cell title="是否有异常" :value="useGetDictByValue('wdm_isAbnormal', getConclusionVo.isAbnormal) || '-'" />
                                <up-cell>
                                    <template #label>
                                        {{ getConclusionVo.content || '无' }}
                                    </template>
                                </up-cell>
                                <up-cell title="附件">
                                    <template #label>
                                        <view style="margin-top: 16rpx">
                                            <global-upload :file-list="getConclusionVo.files" :show-upload="false"></global-upload>
                                        </view>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #title>填报人:{{ getConclusionVo.fillingName || '-' }}</template>
                                    <template #value>填报时间:{{ timeStampFormat(getConclusionVo.fillingTime) || '-' }}</template>
                                </up-cell>
                            </up-cell-group>
                        </view>
                    </up-collapse-item>
                </up-collapse>
            </view>
        </template>
    </global-page>
    <ReceiveHistoryList ref="receiveHistoryListRef"></ReceiveHistoryList>
    <up-modal
        :width="250"
        title="提示"
        content="填写完成后请及时保存!"
        confirmText="知道了"
        :show="show"
        closeOnClickOverlay
        @confirm="saveReceiveInfo"
        @cancel="show = false"
        @close="show = false"
    ></up-modal>
</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 { reactive, ref, watch } from 'vue'
import { navigateTo } from 'mocp/utils/jump'
import useWindDamageManagementStore from 'mocp/store/windDamageManagement'
import ReceiveHistoryList from './components/ReceiveHistoryList.vue'
import useUserStore from 'mocp/store/user'
import { saveMooringWorkApi, saveReceiveInfoApi, saveRelieveInfoApi } from 'mocp/api/windDamageManagement'

const baseStore = useBaseStore()
const windDamageManagementStore = useWindDamageManagementStore()
const { details, getBasicVo, getConclusionVo, getWorkVo, basicId, tabIndex, getDisabled } = storeToRefs(windDamageManagementStore)
onLoad(() => {
    init()
})
const collapseRef = ref()
const init = async () => {
    await windDamageManagementStore.getAllTaskInfoByWeather()
    Object.assign(formData, getWorkVo.value)
    formData.basicId = basicId.value
    collapseRef.value?.init()
}
//接收历史
const receiveHistoryListRef = ref()
const openReceiveHistory = () => {
    receiveHistoryListRef.value?.open({ basicId: basicId.value, taskType: tabIndex.value + 1 })
}
//接收
const userStore = useUserStore()
const show = ref(false)
const handleFooterClick = () => {
    show.value = true
}
const saveReceiveInfo = async () => {
    const res = await saveReceiveInfoApi(
        { basicId: basicId.value, taskType: tabIndex.value + 1, receiveUid: userStore.userInfo?.id },
        { loading: true }
    )
    if (res.code == 200) {
        show.value = false
        uni.$mocpMessage.success(res.message)
        init()
        uni.$emit('windDamageManagementReload')
    } else {
        uni.$mocpMessage.error(res.message)
    }
}
//气象信息
const goWeather = () => {
    if (details.value?.mooringIsOpen == '0') {
        return uni.$mocpMessage.warning('气象信息已失效')
    }
    navigateTo('/panel/windDamageManagement/weather', { terminal: details.value?.terminal })
}
//保存
const formData = reactive({
    ammComplete: undefined,
    ammFiles: '',
    ammMeasure: '',
    ballastComplete: undefined,
    ballastFiles: '',
    ballastMeasure: '',
    basicId: '',
    endTime: undefined,
    executeComplete: undefined,
    executeFiles: '',
    executeMeasure: '',
    headComplete: undefined,
    headFiles: '',
    headMeasure: '',
    id: '',
    obstacleComplete: undefined,
    obstacleFiles: '',
    obstacleMeasure: '',
    situation: undefined,
    startTime: undefined,
    syncComplete: undefined,
    syncFiles: '',
    syncMeasure: '',
    wheelComplete: undefined,
    wheelFiles: '',
    wheelMeasure: ''
})
//适配折叠高度
watch(
    () => formData.situation,
    () => {
        collapseRef.value?.init()
    }
)
const handleRightClick = async () => {
    if (!formData.situation) {
        return uni.$mocpMessage.warning('请选择系统情况')
    }
    const res = await saveMooringWorkApi(formData, { loading: true })
    if (res.code == 200) {
        uni.$mocpMessage.success(res.message)
        init()
        uni.$emit('windDamageManagementReload')
    } else {
        uni.$mocpMessage.error(res.message)
    }
}
//解除系留
const saveRelieveInfo = async () => {
    const res = await saveRelieveInfoApi({ basicId: basicId.value, taskType: tabIndex.value + 1 }, { loading: true })
    if (res.code == 200) {
        uni.$mocpMessage.success(res.message)
        init()
        uni.$emit('windDamageManagementReload')
    } else {
        uni.$mocpMessage.error(res.message)
    }
}
</script>
<style lang="scss" scoped>
@import './constants/details.scss';
</style>
