<template>
    <global-page
        title="运行决策"
        isDataList
        refresherEnabled
        loadingMoreEnabled
        auto
        ref="paging"
        :params="searchData"
        showNavRight
        navRightType="icon"
        navRightIcon="saixuan-01"
        @handleRightClick="handleRightClick"
        :api="getDecisionApi"
        :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('md_state', item.state)"></custom-state>
                    </view>
                    <view class="right">
                        <text class="txt u-line-1" v-if="item.machineNumber">{{ item.machineNumber }}</text>
                        <text class="txt u-line-1" v-if="item.aviation">{{ item.aviation }}</text>
                    </view>
                </view>
                <view class="item-content u-line-3">
                    {{ item.faultDescription || '无' }}
                </view>
                <view class="item-footer">
                    <view class="label">
                        <global-icon icon="calendar"></global-icon>
                        <text class="txt">
                            {{ timeStampFormat(item.filledTime, { format: 'YYYY/MM/DD HH:mm' }) }}
                        </text>
                    </view>
                </view>
            </view>
        </template>
    </global-page>
</template>

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

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