<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>
                                </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-group>
                        </view>
                        <view class="mocp-cell">
                            <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.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>
                                <!-- 2 -->
                                <up-cell>
                                    <template #title>
                                        <view>2、通报执行防风操作检查</view>
                                    </template>
                                </up-cell>
                                <up-cell title="是否完成">
                                    <template #value>
                                        <view>
                                            <global-radio
                                                radioAlign="right"
                                                v-model="formData.reportComplete"
                                                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.reportMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.reportFiles"
                                            :file-list="getWorkVo.reportFiles"
                                            :show-upload="!getDisabled"
                                        ></global-upload>
                                    </template>
                                </up-cell>
                                <!-- 3 -->
                                <up-cell>
                                    <template #title>
                                        <view>
                                            3、根据地面结冰条件，飞机状态，预报风速，核实场内飞机是否满足手册系留标准，如满足，组织安排系留；如不满足系留条件，安排替代方式防风
                                        </view>
                                    </template>
                                </up-cell>
                                <up-cell title="是否完成">
                                    <template #value>
                                        <view>
                                            <global-radio
                                                radioAlign="right"
                                                v-model="formData.stayComplete"
                                                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.stayMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.stayFiles"
                                            :file-list="getWorkVo.stayFiles"
                                            :show-upload="!getDisabled"
                                        ></global-upload>
                                    </template>
                                </up-cell>
                                <!-- 4 -->
                                <up-cell>
                                    <template #title>
                                        <view>4、轮档摆放按照HNAR369飞机停放与系留程序执行</view>
                                    </template>
                                </up-cell>
                                <up-cell title="是否完成">
                                    <template #value>
                                        <view>
                                            <global-radio
                                                radioAlign="right"
                                                v-model="formData.hnarComplete"
                                                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.hnarMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.hnarFiles"
                                            :file-list="getWorkVo.hnarFiles"
                                            :show-upload="!getDisabled"
                                        ></global-upload>
                                    </template>
                                </up-cell>
                                <!-- 5 -->
                                <up-cell>
                                    <template #title>
                                        <view>5、对可满足液压系统工作条件的飞机立即通电并重新打压</view>
                                    </template>
                                </up-cell>
                                <up-cell title="是否完成">
                                    <template #value>
                                        <view>
                                            <global-radio
                                                radioAlign="right"
                                                v-model="formData.pressureComplete"
                                                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.pressureMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.pressureFiles"
                                            :file-list="getWorkVo.pressureFiles"
                                            :show-upload="!getDisabled"
                                        ></global-upload>
                                    </template>
                                </up-cell>
                                <!-- 6 -->
                                <up-cell>
                                    <template #title>
                                        <view>6、检查刹车蓄压器满足各机型手册要求，设置停留刹车</view>
                                    </template>
                                </up-cell>
                                <up-cell title="是否完成">
                                    <template #value>
                                        <view>
                                            <global-radio
                                                radioAlign="right"
                                                v-model="formData.brakeComplete"
                                                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.brakeMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.brakeFiles"
                                            :file-list="getWorkVo.brakeFiles"
                                            :show-upload="!getDisabled"
                                        ></global-upload>
                                    </template>
                                </up-cell>
                                <!-- 7 -->
                                <up-cell>
                                    <template #title>
                                        <view>7、关闭飞机所有舱门及盖板</view>
                                    </template>
                                </up-cell>
                                <up-cell title="是否完成">
                                    <template #value>
                                        <view>
                                            <global-radio
                                                radioAlign="right"
                                                v-model="formData.shutComplete"
                                                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.shutMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.shutFiles"
                                            :file-list="getWorkVo.shutFiles"
                                            :show-upload="!getDisabled"
                                        ></global-upload>
                                    </template>
                                </up-cell>
                                <!-- 8 -->
                                <up-cell>
                                    <template #title>
                                        <view>8、撤登机梯/廊桥</view>
                                    </template>
                                </up-cell>
                                <up-cell title="是否完成">
                                    <template #value>
                                        <view>
                                            <global-radio
                                                radioAlign="right"
                                                v-model="formData.bridgeComplete"
                                                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.bridgeMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.bridgeFiles"
                                            :file-list="getWorkVo.bridgeFiles"
                                            :show-upload="!getDisabled"
                                        ></global-upload>
                                    </template>
                                </up-cell>
                                <!-- 9 -->
                                <up-cell>
                                    <template #title>
                                        <view>9、撤离接近飞机的一切勤务车辆</view>
                                    </template>
                                </up-cell>
                                <up-cell title="是否完成">
                                    <template #value>
                                        <view>
                                            <global-radio
                                                radioAlign="right"
                                                v-model="formData.serviceComplete"
                                                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.serviceMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.serviceFiles"
                                            :file-list="getWorkVo.serviceFiles"
                                            :show-upload="!getDisabled"
                                        ></global-upload>
                                    </template>
                                </up-cell>
                                <!-- 10 -->
                                <up-cell>
                                    <template #title>
                                        <view>10、将梯架和其他可移动的地面设备撤离到安全区域并固定</view>
                                    </template>
                                </up-cell>
                                <up-cell title="是否完成">
                                    <template #value>
                                        <view>
                                            <global-radio
                                                radioAlign="right"
                                                v-model="formData.fixComplete"
                                                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.fixMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.fixFiles"
                                            :file-list="getWorkVo.fixFiles"
                                            :show-upload="!getDisabled"
                                        ></global-upload>
                                    </template>
                                </up-cell>
                                <!-- 11 -->
                                <up-cell>
                                    <template #title>
                                        <view>
                                            11、对于处于过站状态飞机提醒地面维修人员通知机组设置停留刹车，对于后续过站飞机提醒机组保持停留刹车
                                        </view>
                                    </template>
                                </up-cell>
                                <up-cell title="是否完成">
                                    <template #value>
                                        <view>
                                            <global-radio
                                                radioAlign="right"
                                                v-model="formData.crossComplete"
                                                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.crossMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.crossFiles"
                                            :file-list="getWorkVo.crossFiles"
                                            :show-upload="!getDisabled"
                                        ></global-upload>
                                    </template>
                                </up-cell>
                                <!-- 12 -->
                                <up-cell>
                                    <template #title>
                                        <view>12、大风过境通知防风处置预案解除，并进行信息通报</view>
                                    </template>
                                </up-cell>
                                <up-cell title="是否完成">
                                    <template #value>
                                        <view>
                                            <global-radio
                                                radioAlign="right"
                                                v-model="formData.relieveComplete"
                                                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.relieveMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.relieveFiles"
                                            :file-list="getWorkVo.relieveFiles"
                                            :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>
                    </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 } 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 { saveOperateWorkApi, saveReceiveInfoApi } 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?.operateIsOpen == '0') {
        return uni.$mocpMessage.warning('气象信息已失效')
    }
    navigateTo('/panel/windDamageManagement/weather', { terminal: details.value?.terminal })
}
//保存
const formData = reactive({
    basicId: '',
    brakeComplete: undefined,
    brakeFiles: '',
    brakeMeasure: '',
    bridgeComplete: undefined,
    bridgeFiles: '',
    bridgeMeasure: '',
    crossComplete: undefined,
    crossFiles: '',
    crossMeasure: '',
    endTime: undefined,
    fixComplete: undefined,
    fixFiles: '',
    fixMeasure: '',
    hnarComplete: undefined,
    hnarFiles: '',
    hnarMeasure: '',
    id: '',
    pressureComplete: undefined,
    pressureFiles: '',
    pressureMeasure: '',
    relieveComplete: undefined,
    relieveFiles: '',
    relieveMeasure: '',
    reportComplete: undefined,
    reportFiles: '',
    reportMeasure: '',
    serviceComplete: undefined,
    serviceFiles: '',
    serviceMeasure: '',
    shutComplete: undefined,
    shutFiles: '',
    shutMeasure: '',
    startTime: undefined,
    stayComplete: undefined,
    stayFiles: '',
    stayMeasure: '',
    syncComplete: undefined,
    syncFiles: '',
    syncMeasure: ''
})
const handleRightClick = async () => {
    const res = await saveOperateWorkApi(formData, { 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>
