<template>
    <global-page title="基础信息" showFooterBtn @handleFooterClick="handleSubmit">
        <view class="mocp-form">
            <up-form labelPosition="left" labelWidth="auto" :model="formData">
                <up-form-item label="报文生成时间" :borderBottom="true" prop="generateTime">
                    <up-input border="none" inputAlign="right" clearable v-model="formData.generateTime" disabled disabledColor="#fff"></up-input>
                </up-form-item>
                <up-form-item label="预报风速" :borderBottom="true" prop="windSpeed" required>
                    <up-input border="none" inputAlign="right" clearable v-model="formData.windSpeed" disabled disabledColor="#fff"></up-input>
                </up-form-item>
                <up-form-item label="预计开始时间" :borderBottom="true" prop="startTime">
                    <up-input border="none" inputAlign="right" clearable v-model="formData.startTime" disabled disabledColor="#fff"></up-input>
                </up-form-item>
                <up-form-item label="基地值班" :borderBottom="true">
                    <custom-admin-picker
                        pickAlign="right"
                        clearable
                        v-model="formData.dutyUid"
                        :searchValue="getBasicVo.dutyName"
                    ></custom-admin-picker>
                </up-form-item>
                <up-form-item label="航站" :borderBottom="true" prop="terminal" required>
                    <up-input border="none" inputAlign="right" clearable v-model="formData.terminal" disabled disabledColor="#fff"></up-input>
                </up-form-item>
                <up-form-item label="机号" :borderBottom="true" prop="ac" required v-if="tabIndex > 0">
                    <up-input border="none" inputAlign="right" clearable v-model="formData.ac" disabled disabledColor="#fff"></up-input>
                </up-form-item>
                <up-form-item :label="tabIndex == 0 ? '巡场人员' : '操作人'" :borderBottom="true">
                    <custom-admin-picker
                        pickAlign="right"
                        clearable
                        v-model="formData.operateUid"
                        :searchValue="getBasicVo.operateName"
                    ></custom-admin-picker>
                </up-form-item>
            </up-form>
        </view>
    </global-page>
</template>

<script setup>
import { onLoad } from '@dcloudio/uni-app'
import { reactive } from 'vue'
import { savePwdBasicApi } from 'mocp/api/windDamageManagement'
import { storeToRefs } from 'pinia'
import useWindDamageManagementStore from 'mocp/store/windDamageManagement'

const windDamageManagementStore = useWindDamageManagementStore()
const { getBasicVo, tabIndex, details } = storeToRefs(windDamageManagementStore)
// 表单数据
const formData = reactive({
    generateTime: '',
    terminal: '',
    ac: '',
    startTime: '',
    dutyUid: '',
    id: '',
    operateUid: '',
    type: 1,
    windSpeed: ''
})
// 页面初始化
onLoad(() => {
    formData.generateTime = details.value.generateTime
    formData.terminal = details.value.terminal
    formData.ac = getBasicVo.value.ac
    formData.startTime = details.value.startTime
    formData.dutyUid = getBasicVo.value.dutyUid
    formData.id = getBasicVo.value.id
    formData.operateUid = getBasicVo.value.operateUid
    formData.type = tabIndex.value + 1
    formData.windSpeed = getBasicVo.value.windSpeed
})
//提交表单
const handleSubmit = async () => {
    const res = await savePwdBasicApi(formData, { loading: true })
    if (res.code == 200) {
        uni.$mocpJump.navigateBack()
        uni.$mocpMessage.success(res.message)
        windDamageManagementStore.getAllTaskInfoByWeather()
        uni.$emit('windDamageManagementReload')
    } else {
        uni.$mocpMessage.error(res.message)
    }
}
</script>
<style lang="scss" scoped>
.mocp-form {
    background: #fff;
    padding: 0 32rpx;
}
</style>
