<template>
    <global-page
        title="工作任务指令"
        isDataList
        refresherEnabled
        loadingMoreEnabled
        auto
        ref="paging"
        :params="searchData"
        showNavRight
        navRightType="icon"
        navRightIcon="saixuan-01"
        @handleRightClick="handleRightClick"
        :api="getWorkTaskListApi"
        :padding="24"
    >
        <template #default="{ item }">
            <view class="item" @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 useWorkAssignmentStore from 'mocp/store/work-assignment'
import { storeToRefs } from 'pinia'
import { onUnload } from '@dcloudio/uni-app'
import { getWorkTaskListApi } from 'mocp/api/work-assignment'

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