<template>
    <global-page
        title="机队状态网"
        isDataList
        refresherEnabled
        loadingMoreEnabled
        auto
        ref="paging"
        :params="searchData"
        showNavRight
        navRightType="icon"
        navRightIcon="saixuan-01"
        @handleRightClick="handleRightClick"
        :api="getFleetListApi"
        :padding="24"
    >
        <template #="{ dataList }">
            <view class="item" v-for="item in dataList" :key="item.id" @tap="goDetails(item)">
                <view class="item-title">
                    <view class="left">
                        <custom-state :value="useGetDictByValue('fleet_state', item.state)"></custom-state>
                        <text class="txt u-line-1 fleetTxt" v-if="item.machineNumber">
                            {{ item.machineNumber }}
                        </text>
                    </view>
                </view>
                <view class="item-content u-line-3 fleetItemCont">
                    {{ item.faultDescribe || '无' }}
                </view>
            </view>
        </template>
    </global-page>
</template>

<script setup>
import { ref } from 'vue'
import { timeStampFormat } from 'mocp/utils/tool'
import { useGetDictByValue } from 'mocp/hooks/use-dict/useDict'
import useFleetStore from 'mocp/store/fleet'
import { storeToRefs } from 'pinia'
import { onUnload } from '@dcloudio/uni-app'
import { getFleetListApi } from 'mocp/api/fleet'

//跳转
const fleetStore = useFleetStore()
const {searchData} = storeToRefs(fleetStore)
const goDetails = (data) => {
    uni.$mocpJump.navigateTo('/panel/fleet/details', {id: data.id}).then(() => {
        fleetStore.setState('details', data)
    })
}
//筛选
const handleRightClick = () => {
    uni.$mocpJump.redirectTo('/panel/fleet/search')
}
//刷新
const paging = ref()
uni.$on('fleetReload', () => {
    paging.value?.reload()
})
onUnload(() => {
    uni.$off('fleetReload')
})
</script>
<style lang="scss" scoped>
@import 'mocpStatic/css/list.scss';
@import './constants/fleet.scss';


</style>
