<template>
    <global-page
        :title="formData.id > 0 ? '编辑例行维护工作单' : '新建例行维护工作单'"
        :showNavRight="formData.id > 0 ? false : true"
        navRightText="今天签单"
        @handleRightClick="navigateTo('/panel/electronicBill/routineWork/list')"
        showFooterBtn
        footerBtnText="客户方代表签字"
        @handleFooterClick="handleFooterClick"
    >
        <up-form ref="formRef" labelPosition="left" labelWidth="auto" :model="formData" :rules="rules" errorType="toast">
            <view class="mocp-title">基本信息</view>
            <view class="mocp-form">
                <up-form-item label="航站" prop="station" :borderBottom="true" required>
                    <global-picker pickAlign="right" v-model="formData.station" clearable :options="getTerminalSelect()" filter></global-picker>
                </up-form-item>
                <up-form-item label="日期" prop="date" :borderBottom="true" required>
                    <global-date pickAlign="right" clearable v-model="formData.date" defaultToday></global-date>
                </up-form-item>
                <up-form-item label="机号" prop="acreg" :borderBottom="true" required>
                    <global-picker
                        pickAlign="right"
                        v-model="formData.acreg"
                        :options="allAc"
                        clearable
                        filter
                        customize
                        @change="changeAcreg"
                    ></global-picker>
                </up-form-item>
                <up-form-item label="飞机所属单位" prop="aircaraftoperator" :borderBottom="true" required>
                    <global-picker
                        pickAlign="right"
                        v-model="formData.aircaraftoperator"
                        :options="allAirline"
                        clearable
                        filter
                        customize
                    ></global-picker>
                </up-form-item>
                <up-form-item label="机型" prop="model" :borderBottom="true" required>
                    <global-picker v-model="formData.model" pickAlign="right" :options="allAcType" clearable filter customize></global-picker>
                </up-form-item>
                <up-form-item label="进港航班号" prop="flightNoIn" :borderBottom="true" required>
                    <up-input v-model="formData.flightNoIn" inputAlign="right" border="none" placeholder="请输入" clearable></up-input>
                </up-form-item>
                <up-form-item label="出港航班号" prop="flightNoOut" :borderBottom="true" required>
                    <up-input v-model="formData.flightNoOut" inputAlign="right" border="none" placeholder="请输入" clearable></up-input>
                </up-form-item>
                <up-form-item label="航段" prop="legs" :borderBottom="true" required>
                    <up-input v-model="formData.legs" inputAlign="right" border="none" placeholder="请输入" clearable></up-input>
                </up-form-item>
            </view>
            <view class="mocp-title">过站维护TR</view>
            <view class="mocp-form">
                <up-form-item label="过站维护TR" prop="tr" :borderBottom="true">
                    <global-switch v-model="formData.tr" switchAlign="right" :disabled="formData.overnightAfPf == '1'"></global-switch>
                </up-form-item>
                <up-form-item label="一般勤务" prop="serviceTr" :borderBottom="true">
                    <global-switch
                        v-model="formData.serviceTr"
                        switchAlign="right"
                        :disabled="formData.tr == '1' || formData.overnightAfPf == '1'"
                    ></global-switch>
                </up-form-item>
                <up-form-item label="例行检查" prop="routineInspection" :borderBottom="true">
                    <global-switch
                        v-model="formData.routineInspection"
                        switchAlign="right"
                        :disabled="formData.tr == '1' || formData.overnightAfPf == '1'"
                    ></global-switch>
                </up-form-item>
                <up-form-item label="飞机放行" prop="fly" :borderBottom="true">
                    <global-switch
                        v-model="formData.fly"
                        switchAlign="right"
                        :disabled="formData.tr == '1' || formData.overnightAfPf == '1'"
                    ></global-switch>
                </up-form-item>
            </view>
            <view class="mocp-title">过夜维护AF+PF</view>
            <view class="mocp-form">
                <up-form-item label="过夜维护AF+PF" prop="overnightAfPf" :borderBottom="true">
                    <global-switch v-model="formData.overnightAfPf" switchAlign="right"></global-switch>
                </up-form-item>
            </view>
            <view class="mocp-title">设备使用记录</view>
            <view class="mocp-form">
                <up-form-item label="电源车(单位/小时)" prop="groundPower" :borderBottom="true">
                    <global-number-input v-model="formData.groundPower" :precision="2"></global-number-input>
                </up-form-item>
                <up-form-item label="气源车(单位/次)" prop="airStarter" :borderBottom="true">
                    <global-number-input v-model="formData.airStarter"></global-number-input>
                </up-form-item>
                <up-form-item label="牵引车(单位/次)" prop="towPus" :borderBottom="true">
                    <global-number-input v-model="formData.towPus"></global-number-input>
                </up-form-item>
                <up-form-item label="空调车(单位/小时)" prop="airConditioning" :borderBottom="true">
                    <global-number-input v-model="formData.airConditioning" :precision="2"></global-number-input>
                </up-form-item>
                <up-form-item label="其他" prop="others1" :borderBottom="true">
                    <up-input v-model="formData.others1" inputAlign="right" border="none" placeholder="请输入" clearable></up-input>
                </up-form-item>
                <up-form-item label="其他" prop="others2" :borderBottom="true">
                    <up-input v-model="formData.others2" inputAlign="right" border="none" placeholder="请输入" clearable></up-input>
                </up-form-item>
            </view>
            <view class="mocp-title">辅助信息</view>
            <view class="mocp-form">
                <up-form-item label="备降" prop="diversion" :borderBottom="true">
                    <global-switch v-model="formData.diversion" switchAlign="right"></global-switch>
                </up-form-item>
                <up-form-item label="返航" prop="returnFlight" :borderBottom="true">
                    <global-switch v-model="formData.returnFlight" switchAlign="right"></global-switch>
                </up-form-item>
                <up-form-item label="无故障过站待命" prop="onCall" :borderBottom="true">
                    <global-switch v-model="formData.onCall" switchAlign="right"></global-switch>
                </up-form-item>
                <up-form-item label="备注" prop="remark" :borderBottom="true">
                    <up-input v-model="formData.remark" inputAlign="right" border="none" placeholder="请输入" clearable></up-input>
                </up-form-item>
            </view>
        </up-form>
    </global-page>
</template>

<script setup>
import useElectronicBillStore from 'mocp/store/electronicBill'
import { formData, rules } from './constants/add.compositions'
import { navigateTo } from 'mocp/utils/jump'
import { onUnmounted, ref, watchEffect } from 'vue'
import { changeAcreg } from './constants/add.functionals'
import { getTerminalSelect } from 'mocp/utils/permission'
import { resetData } from './constants/sign.functionals'

const electronicBillStore = useElectronicBillStore()
const {
    selectList: { allAc, allAcType, allAirline }
} = electronicBillStore
//提交
const formRef = ref()
const handleFooterClick = async () => {
    await formRef.value?.validate()
    navigateTo('/panel/electronicBill/routineWork/sign')
}
watchEffect(() => {
    if (formData.tr == '1') {
        formData.serviceTr = '0'
        formData.routineInspection = '0'
        formData.fly = '0'
    }
    if (formData.overnightAfPf == '1') {
        formData.tr = '0'
        formData.serviceTr = '0'
        formData.routineInspection = '0'
        formData.fly = '0'
    }
})
onUnmounted(() => {
    resetData()
})
</script>
<style lang="scss" scoped>
.mocp-form {
    background: #fff;
    margin-bottom: 24rpx;
    padding: 0 32rpx;
}
.mocp-title {
    padding: 0 32rpx 24rpx 32rpx;
    background-color: $mocp-fill-1;
}
</style>
