<template>
    <up-collapse-item :title="`运行决策（${getMoveDecisionNum}）`" v-if="getMoveDecisionNum > 0">
        <global-page
            :fixed="false"
            :height="height"
            :showNavbar="false"
            :custom="false"
            isDataList
            refresherEnabled
            loadingMoreEnabled
            :api="getDecisiongetDecisionToDoApi"
            @handleQuery="handleQuery"
            auto
        >
            <template #default="{ item }">
                <up-swipe-action>
                    <up-swipe-action-item
                        @click="handleDelete(item)"
                        :options="[
                            {
                                text: '移除',
                                style: {
                                    backgroundColor: '#f53f3f'
                                }
                            }
                        ]"
                    >
                        <view class="item" @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>
                    </up-swipe-action-item>
                </up-swipe-action>
            </template>
        </global-page>
    </up-collapse-item>
</template>

<script setup>
import { timeStampFormat } from 'mocp/utils/tool'
import { useGetDictByValue } from 'mocp/hooks/use-dict/useDict'
import useMoveDecisionStore from 'mocp/store/move-decision'
import { getDecisiongetDecisionToDoApi } from 'mocp/api/my-toDo'
import useMyToDoStore from 'mocp/store/my-toDo'
import { storeToRefs } from 'pinia'

const myToDoStore = useMyToDoStore()
const { getMoveDecisionNum } = storeToRefs(myToDoStore)
const ps = defineProps({
    height: {
        type: String,
        default: ''
    }
})
//跳转
const moveDecisionStore = useMoveDecisionStore()
const goDetails = (data) => {
    uni.$mocpJump.navigateTo('/panel/move-decision/details', { id: data.id }).then(() => {
        moveDecisionStore.setState('details', data)
    })
}
//删除
const handleDelete = (data) => {
    console.log(data)
}
const handleQuery = ({ res }) => {
    myToDoStore.setState('moveDecisionNum', parseInt(res.data.total) || 0)
}
</script>
<style lang="scss" scoped>
@import 'mocpStatic/css/list.scss';
</style>
