<template>
    <global-page
        title="支援申请"
        isDataList
        refresherEnabled
        loadingMoreEnabled
        auto
        ref="paging"
        :params="searchData"
        showNavRight
        navRightType="icon"
        navRightIcon="saixuan-01"
        @handleRightClick="handleRightClick"
        :api="getSupportRequestListApi"
        :padding="24"
        showFooterBtn
        footerBtnText="新建"
        @handleFooterClick="handleFooterClick"
    >
        <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('sa_state', item.state)"></custom-state>
                        <text class="txt u-line-1" v-if="item.supportNumber">{{ item.supportNumber }}</text>
                    </view>
                </view>
                <view class="item-content u-line-3">
                    {{ item.faultDescription || '无' }}
                </view>
                <view class="item-footer">
                    <view class="left">
                        <text class="txt u-line-1" v-if="item.machineNumber">{{ item.machineNumber }}</text>
                        <text class="txt u-line-1" v-if="item.model">{{ item.model }}</text>
                        <text class="txt u-line-1" v-if="item.aviation">
                            {{ useGetDictByValue('', item.aviation, { data: baseStore.getAirlineSelect }) }}
                        </text>
                    </view>
                    <view class="label">
                        <text class="txt u-line-1" v-if="item.terminal">{{ item.terminal }}</text>
                    </view>
                </view>
            </view>
        </template>
    </global-page>
</template>

<script setup>
import { ref } from 'vue'
import { useGetDictByValue } from 'mocp/hooks/use-dict/useDict'
import { storeToRefs } from 'pinia'
import { onUnload } from '@dcloudio/uni-app'
import { getSupportRequestListApi } from 'mocp/api/support-application'
import useSupportApplicationStore from 'mocp/store/support-application'
import useBaseStore from 'mocp/store/base'

const baseStore = useBaseStore()
//跳转
const supportApplicationStore = useSupportApplicationStore()
const { searchData } = storeToRefs(supportApplicationStore)
const goDetails = (data) => {
    uni.$mocpJump.navigateTo('/panel/support-application/details', { id: data.id }).then(() => {
        supportApplicationStore.setState('details', data)
    })
}
//筛选
const handleRightClick = () => {
    uni.$mocpJump.navigateBack()
}
//刷新
const paging = ref()
uni.$on('supportApplicationReload', () => {
    paging.value?.reload()
})
//新建
const handleFooterClick = () => {
    uni.$mocpJump.navigateTo('/panel/support-application/add')
}
onUnload(() => {
    uni.$off('supportApplicationReload')
})
</script>
<style lang="scss" scoped>
@import 'mocpStatic/css/list.scss';
</style>
