<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.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.startComplete"
                                                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.startMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.startFiles"
                                            :file-list="getWorkVo.startFiles"
                                            :show-upload="!getDisabled"
                                        ></global-upload>
                                    </template>
                                </up-cell>
                                <!-- 2 -->
                                <up-cell>
                                    <template #title>
                                        <view>
                                            2、飞机是否按需档好轮挡
                                            <text style="color: #86909c">
                                                （对于A320/330/350机型，当风速达到6级，所有前轮和主轮的前后摆放轮档。 共放置 12 个轮档。）
                                            </text>
                                        </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>
                                            3、停场飞机相关布罩和堵盖在位，周围无可吹移动危险物体
                                            <text style="color: #86909c">
                                                （注：如发现发动机布罩脱落后，应通知维修控制员安排人员对发动机进行目视检查）
                                            </text>
                                        </view>
                                    </template>
                                </up-cell>
                                <up-cell title="是否完成">
                                    <template #value>
                                        <view>
                                            <global-radio
                                                radioAlign="right"
                                                v-model="formData.parkingComplete"
                                                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.parkingMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.parkingFiles"
                                            :file-list="getWorkVo.parkingFiles"
                                            :show-upload="!getDisabled"
                                        ></global-upload>
                                    </template>
                                </up-cell>
                                <!-- 4 -->
                                <up-cell>
                                    <template #title>
                                        <view>
                                            4、对飞机有安全隐患梯架、设备在指定位置并与地面固定物系留，其中外单位梯架需通报机场和相关单位处理，并在未得到处理前安排人员进行监护
                                        </view>
                                    </template>
                                </up-cell>
                                <up-cell title="是否完成">
                                    <template #value>
                                        <view>
                                            <global-radio
                                                radioAlign="right"
                                                v-model="formData.monitoringComplete"
                                                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.monitoringMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.monitoringFiles"
                                            :file-list="getWorkVo.monitoringFiles"
                                            :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.hazardComplete"
                                                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.hazardMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.hazardFiles"
                                            :file-list="getWorkVo.hazardFiles"
                                            :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.taComplete"
                                                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.taMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.taFiles"
                                            :file-list="getWorkVo.taFiles"
                                            :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.endComplete"
                                                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.endMeasure"
                                            :height="40"
                                            border="none"
                                            :disabled="getDisabled"
                                        ></up-textarea>
                                    </template>
                                </up-cell>
                                <up-cell>
                                    <template #label>
                                        <global-upload
                                            v-model="formData.endFiles"
                                            :file-list="getWorkVo.endFiles"
                                            :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 { savePatrolWorkApi, 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?.patrolIsOpen == '0') {
        return uni.$mocpMessage.warning('气象信息已失效')
    }
    navigateTo('/panel/windDamageManagement/weather', { terminal: details.value?.terminal })
}
//保存
const formData = reactive({
    basicId: '',
    checkComplete: undefined,
    checkFiles: '',
    checkMeasure: '',
    endComplete: undefined,
    endFiles: '',
    endMeasure: '',
    endTime: undefined,
    hazardComplete: undefined,
    hazardFiles: '',
    hazardMeasure: '',
    id: '',
    monitoringComplete: undefined,
    monitoringFiles: '',
    monitoringMeasure: '',
    parkingComplete: undefined,
    parkingFiles: '',
    parkingMeasure: '',
    startComplete: undefined,
    startFiles: '',
    startMeasure: '',
    startTime: undefined,
    wheelComplete: undefined,
    wheelFiles: '',
    wheelMeasure: ''
})
const handleRightClick = async () => {
    const res = await savePatrolWorkApi(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>
