import { defineStore } from 'pinia'

const useAogStore = defineStore('aog', {
    state: () => {
        return {
            searchData: {
                state: '1',
                machineNumber: '',
                model: '',
                aviation: '',
                terminal: '',
                major: null,
                aogLevel: null,
                happenDateStart: null,
                happenDateEnd: null,
                aogStartTimeStart: null,
                aogStartTimeEnd: null,
                happenAddr: '',
                faultDesc: ''
            },
            details: undefined
        }
    },
    getters: {},
    actions: {
        resetForm() {
            this.searchData = {
                state: '1',
                machineNumber: '',
                model: '',
                aviation: '',
                terminal: '',
                major: null,
                aogLevel: null,
                happenDateStart: null,
                happenDateEnd: null,
                aogStartTimeStart: null,
                aogStartTimeEnd: null,
                happenAddr: '',
                faultDesc: ''
            }
        },
        setState(...args) {
            this.$patch({ [args[0]]: args[1] })
        }
    },
    // 配置持久化
    persist: {
        // 调整为兼容多端的API
        storage: {
            setItem(key, value) {
                uni.setStorageSync(key, value)
            },
            getItem(key) {
                return uni.getStorageSync(key)
            }
        }
    }
})
export default useAogStore
