<template>
    <global-page
        title="AOG列表"
        isDataList
        refresherEnabled
        loadingMoreEnabled
        auto
        ref="paging"
        :params="searchData"
        showNavRight
        navRightType="icon"
        navRightIcon="saixuan-01"
        @handleRightClick="handleRightClick"
        :api="getWorkTaskListApi"
        :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('wa_state', item.state)"></custom-state>
                        <text class="txt u-line-1" v-if="item.machineNumber">{{ item.machineNumber }}</text>
                    </view>
                    <view class="right">
                        <global-tag :type="useGetDictByValue('wa_isSuccessType', item.isSuccess)">
                            {{ useGetDictByValue('wa_isSuccess', item.isSuccess) }}
                        </global-tag>
                    </view>
                </view>
                <view class="item-content u-line-3">
                    {{ item.taskDescription || '无' }}
                </view>
                <view class="item-footer">
                    <view class="label">
                        <global-icon icon="calendar"></global-icon>
                        <text class="txt">
                            {{ timeStampFormat(item.feedbackTime, { format: 'YYYY/MM/DD' }) }}
                        </text>
                    </view>
                </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 { storeToRefs } from 'pinia'
import { onUnload } from '@dcloudio/uni-app'
import { getWorkTaskListApi } from 'mocp/api/work-assignment'
import useAogStore from 'mocp/store/aog'

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