<template>
    <up-collapse-item :title="`防风害管理（${getWindDamageManagementNum}）`" v-if="getWindDamageManagementNum > 0">
        <global-page
            :fixed="false"
            :height="height"
            :showNavbar="false"
            :custom="false"
            isDataList
            refresherEnabled
            loadingMoreEnabled
            :params="{
                userId: userStore.userInfo?.id
            }"
            :api="getPwdPatrolListApi"
            @handleQuery="handleQuery"
            auto
        >
            <template #default="{ item }">
                <template v-for="option in item.basicInfoList" :key="option.id">
                    <up-swipe-action>
                        <up-swipe-action-item
                            @click="handleDelete(item)"
                            :options="[
                                {
                                    text: '移除',
                                    style: {
                                        backgroundColor: '#f53f3f'
                                    }
                                }
                            ]"
                        ></up-swipe-action-item>
                    </up-swipe-action>
                    <view class="item" @tap="goDetails(item, option.id)">
                        <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">巡场检查单</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 { getPwdPatrolListApi } 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'

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, basicId) => {
    windDamageManagementStore.setState('basicId', basicId)
    windDamageManagementStore.setState('weatherId', data.id)
    windDamageManagementStore.setState('weatherSource', data.weatherSource)
    uni.$mocpJump.navigateTo('/panel/windDamageManagement/patrolDetails')
}
//删除
const handleDelete = (data) => {
    console.log(data)
}
const handleQuery = ({ res }) => {
    myToDoStore.setState('windDamageManagementNum', parseInt(res.data.total) || 0)
}
</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>
