<template>
    <global-popup v-model="show" title="TA文件" background="#F7F8FA" :round="32" closeable>
        <up-cell-group v-if="taList.length">
            <template v-for="(item, index) in taList" :key="index">
                <up-cell :title="item.fileName" @tap="downloadFile(item.fileUrl)" />
            </template>
        </up-cell-group>
        <view class="global-empty" v-else>
            <global-empty></global-empty>
        </view>
    </global-popup>
</template>

<script setup>
import { getPwdTaByAcApi } from 'mocp/api/windDamageManagement'
import { downloadFile } from 'mocp/utils/tool'
import { ref } from 'vue'

const show = ref(false)
const taList = ref([])
const open = (params) => {
    taList.value = []
    getPwdTaByAc(params)
}
const getPwdTaByAc = async (params) => {
    const res = await getPwdTaByAcApi(params, { loading: true })
    if (res.code == 200) {
        if (res.data?.files) {
            taList.value = JSON.parse(res.data?.files)
        }
        if (taList.value.length == 0) {
            uni.$mocpMessage.warning('暂无对应文件')
        }
        if (taList.value.length == 1) {
            downloadFile(taList.value[0].fileUrl)
        }
        if (taList.value.length > 1) {
            show.value = true
        }
    } else {
        uni.$mocpMessage.error(res.message)
    }
}
defineExpose({
    open
})
</script>
<style lang="scss" scoped>
.global-empty {
    padding: 24rpx 0;
}
:deep(.u-cell__title-text) {
    word-break: break-all;
}
</style>
