<template>
    <up-collapse-item :title="`防风害管理（${getWindDamageManagementNum}）`" v-if="getWindDamageManagementNum > 0">
        <global-page
            ref="paging"
            :fixed="false"
            :height="height"
            :showNavbar="false"
            :custom="false"
            isDataList
            refresherEnabled
            loadingMoreEnabled
            localPaging
            :params="{
                userId: userStore.userInfo?.id
            }"
            :api="getPwdTaskListForMobileApi"
            @handleQuery="handleQuery"
            auto
        >
            <template #default="{ item }">
                <template v-for="option in item.basicInfoList" :key="option.id">
                    <view class="item" @tap="goDetails(item, option)">
                        <view class="item-title">
                            <view class="left">
                                <custom-state :value="useGetDictByValue('wdm_isOpen', item.isOpen)"></custom-state>
                                <view style="margin-left: 12rpx">
                                    <global-tag type="primary" border :background="false">{{ taskList[option.taskType].name }}</global-tag>
                                </view>
                            </view>
                            <view class="right">
                                <global-tag :type="useGetDictByValue('wdm_rxStatusType', option.rxStatus)" style="margin-left: 12rpx">
                                    {{ useGetDictByValue('wdm_rxStatus', option.rxStatus) }}
                                </global-tag>
                            </view>
                        </view>
                        <view class="item-content">
                            <view class="row" v-if="option.ac">机号:{{ option.ac }}</view>
                            <view class="row" v-if="item.terminal">航站:{{ baseStore.getTerminalObject[item.terminal] }}</view>
                            <view class="u-line-3">{{ option.windSpeed || '无' }}</view>
                        </view>
                        <view class="item-footer">
                            <view class="label">
                                <global-icon icon="calendar"></global-icon>
                                <text class="txt">
                                    {{ timeStampFormat(option.proposedTime) }}
                                </text>
                            </view>
                            <view class="label u-line-1">
                                <global-icon icon="idcard"></global-icon>
                                <text class="txt">操作人:{{ option.name || '-' }}</text>
                            </view>
                        </view>
                        <view class="item-extra">
                            <view class="mocp-color-danger-6" style="display: flex" v-if="option.isAbnormal == '1'">
                                <up-icon name="info-circle" color="#f53f3f"></up-icon>
                                <text style="margin-left: 4rpx">疑似异常，请关注</text>
                            </view>
                        </view>
                    </view>
                </template>
            </template>
        </global-page>
    </up-collapse-item>
</template>

<script setup>
import useUserStore from 'mocp/store/user'
import useMyToDoStore from 'mocp/store/my-toDo'
import { storeToRefs } from 'pinia'
import { getPwdTaskListForMobileApi } from 'mocp/api/windDamageManagement'
import useWindDamageManagementStore from 'mocp/store/windDamageManagement'
import { useGetDictByValue } from 'mocp/hooks/use-dict/useDict'
import { timeStampFormat } from 'mocp/utils/tool'
import useBaseStore from 'mocp/store/base'
import { ref } from 'vue'
import { onUnload } from '@dcloudio/uni-app'

const taskList = {
    1: {
        index: 0,
        name: '巡场检查单',
        url: '/panel/windDamageManagement/patrolDetails'
    },
    2: {
        index: 1,
        name: '操作单',
        url: '/panel/windDamageManagement/operateDetails'
    },
    3: {
        index: 2,
        name: '系留单',
        url: '/panel/windDamageManagement/mooringDetails'
    },
    4: {
        index: 3,
        name: '防沙尘暴签署单',
        url: '/panel/windDamageManagement/sandstormDetails'
    }
}
const userStore = useUserStore()
const baseStore = useBaseStore()
const myToDoStore = useMyToDoStore()
const windDamageManagementStore = useWindDamageManagementStore()
const { getWindDamageManagementNum } = storeToRefs(myToDoStore)
const ps = defineProps({
    height: {
        type: String,
        default: ''
    }
})
//跳转
const goDetails = (data, option) => {
    windDamageManagementStore.setState('tabIndex', taskList[option.taskType].index)
    windDamageManagementStore.setState('basicId', option.id)
    windDamageManagementStore.setState('weatherId', data.id)
    windDamageManagementStore.setState('weatherSource', data.weatherSource)
    uni.$mocpJump.navigateTo(taskList[option.taskType].url)
}
const handleQuery = ({ res }) => {
    myToDoStore.setState('windDamageManagementNum', myToDoStore.countWindDamageManagementNum(res.data))
}
//刷新
const paging = ref()
uni.$on('windDamageManagementReload', () => {
    paging.value?.reload()
})
onUnload(() => {
    uni.$off('windDamageManagementReload')
})
</script>
<style lang="scss" scoped>
@import 'mocpStatic/css/list.scss';
.item-extra {
    margin-top: 12rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
</style>
