<template>
    <global-page title="筛选">
        <view class="search-form">
            <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="baseStore.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="baseStore.getTypeSelect"
                        clearable
                        filter
                    />
                </up-form-item>

                <up-form-item
                    v-if="formData.model != ''"
                    label="ATA章节"
                    prop="ata"
                    :borderBottom="true">
                    <global-picker
                        v-model="formData.ata"
                        pickAlign="right"
                        :options="baseStore.getATAChecked(formData.model)"
                        clearable
                        filter
                    />
                </up-form-item>

                <up-form-item
                    label="发生日期(开始)"
                    prop="startTime"
                    :borderBottom="true">
                    <global-date
                        v-model="formData.startTime"
                        pickAlign="right"
                        clearable
                    />
                </up-form-item>

                <up-form-item
                    label="发生日期(结束)"
                    prop="stopTime"
                    :borderBottom="true">
                    <global-date
                        v-model="formData.stopTime"
                        pickAlign="right"
                        clearable
                    />
                </up-form-item>
            </up-form>
        </view>
        <template #bottom>
            <view class="footer-btn">
                <up-row gutter="10">
                    <up-col span="6">
                        <global-button
                            type="primary"
                            plain
                            size="large"
                            :radius="5"
                            @tap="handleReset">
                            重置
                        </global-button>
                    </up-col>
                    <up-col span="6">
                        <global-button
                            type="primary"
                            size="large"
                            :radius="5"
                            @tap="handleConfirm">
                            确定
                        </global-button>
                    </up-col>
                </up-row>
            </view>
        </template>
    </global-page>
</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'

//获取下拉框选项
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')
}
</script>
<style
    lang="scss"
    scoped>
.search-form {
    padding: 24rpx 24rpx 0 24rpx;
    background: #fff;
}

.footer-btn {
    padding: 24rpx 32rpx;
    background-color: #fff;
}
</style>
