<template>
    <global-page-search @reset="handleReset" @confirm="handleConfirm">
        <up-form labelPosition="left" labelWidth="auto">
            <up-form-item label="状态" prop="state" :borderBottom="true">
                <global-picker v-model="formData.state" pickAlign="right" clearable dictkey="fleet_state" />
            </up-form-item>
            <up-form-item label="航司" prop="aviation" :borderBottom="true">
                <global-picker v-model="formData.aviation" pickAlign="right" :options="getAirlineSelect('技术支援-机队状态管理')" clearable filter />
            </up-form-item>
            <up-form-item label="机号" prop="machineNumber" :borderBottom="true">
                <global-picker pickAlign="right" v-model="formData.machineNumber" :options="deviceNumList" clearable filter />
            </up-form-item>
            <up-form-item label="机型" prop="model" :borderBottom="true">
                <global-picker v-model="formData.model" pickAlign="right" :options="getTypeSelect('技术支援-机队状态管理')" clearable filter />
            </up-form-item>
            <up-form-item label="ATA章节" prop="ata" :borderBottom="true">
                <global-picker
                    v-model="formData.ata"
                    pickAlign="right"
                    :options="formData.model ? baseStore.getATAChecked(formData.model) : []"
                    clearable
                    filter
                    @change="changeAta"
                />
            </up-form-item>
            <up-form-item label="故障现象标签" prop="faultLabel" :borderBottom="true">
                <global-picker
                    v-model="formData.faultLabel"
                    label-field="faultTag"
                    value-field="faultTag"
                    pickAlign="right"
                    :options="faultTagList"
                    clearable
                    filter
                />
            </up-form-item>
            <up-form-item label="故障描述" prop="faultDescribe" :borderBottom="true">
                <up-input v-model="formData.faultDescribe" inputAlign="right" border="none" placeholder="请输入" clearable></up-input>
            </up-form-item>
            <up-form-item label="发生日期" :borderBottom="true">
                <global-calendar pickAlign="right" v-model:startTime="formData.startTime" v-model:endTime="formData.stopTime" clearable />
            </up-form-item>
            <up-form-item label="专业类别" prop="professionalType" :borderBottom="true">
                <global-picker pickAlign="right" v-model="formData.professionalType" clearable paramsType="MajorCategory"></global-picker>
            </up-form-item>
        </up-form>
    </global-page-search>
</template>

<script setup>
import useBaseStore from 'mocp/store/base'
import { storeToRefs } from 'pinia'
import { cloneDeep } from 'lodash'
import { ref } from 'vue'
import useFleetStore from 'mocp/store/fleet'
import { selectFaultTagByATAApi } from 'mocp/api/fleet'
import { getAirlineSelect, getTypeSelect } from 'mocp/utils/permission'

//获取下拉框选项
const baseStore = useBaseStore()
const {
    selectList: { deviceNumList }
} = useBaseStore()
const fleetStore = useFleetStore()
//获取查询表单数据
const { searchData } = storeToRefs(fleetStore)
const formData = ref(cloneDeep(searchData.value))
const handleReset = () => {
    fleetStore.resetForm()
    uni.$mocpJump.navigateTo('/panel/fleet/list')
    uni.$emit('fleetReload')
}
const handleConfirm = () => {
    fleetStore.setState('searchData', formData.value)
    uni.$mocpJump.navigateTo('/panel/fleet/list')
    uni.$emit('fleetReload')
}
//故障现象标签
const faultTagList = ref([])
const changeAta = async (value, data) => {
    if (value) {
        const res = await selectFaultTagByATAApi({ ataId: data.id }, { loading: true })
        if (res.code == 200) {
            faultTagList.value = res.data
        } else {
            faultTagList.value = []
        }
    } else {
        faultTagList.value = []
        formData.faultLabel = ''
    }
}
</script>
<style lang="scss" scoped></style>
