<template>
    <u-popup
        :show="popupShow"
        round="10"
        :closeOnClickOverlay="true"
        :closeable="false"
        @close="popupShow = false"
    >
        <view class="popup">
            <view class="items">
                <view
                    v-for="(item, index) in itemList"
                    :key="index"
                    class="item"
                    @click="toPage(item)"
                >
                    <view :style="{ background: item.bgColor }" class="circle">
                        <TIcon :name="item.icon" :size="24" color="#fff" />
                    </view>
                    <div>{{ item.name }}</div>
                </view>
            </view>
            <view class="cancel" @click="popupHidden">取消</view>
        </view>
    </u-popup>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { apiConfig } from '@/api/app'

const emit = defineEmits(['handleConfirmAudit', 'closeAuditModal'])
const popupShow = ref(false)
const itemList = [
    {
        name: '扫码报修',
        icon: 'icon-scan',
        bgColor: '#0E66FB',
        route: '/bundle/pages/scan/scan?type=3'
    },
    {
        name: '在线报修',
        icon: 'icon-baoxiuneirong',
        bgColor: '#46B97B',
        route: '/bundle/pages/client/online'
    },
    {
        name: '电话报修',
        icon: 'icon-dianhua',
        bgColor: '#FF6756'
    }
]
const toPage = async (val: any) => {
    if (val.route) {
        uni.navigateTo({
            url: val.route
        })
    } else {
        const res = await apiConfig()
        uni.makePhoneCall({
            phoneNumber: res?.servicePhone
        })
    }
}

const showPopup = () => {
    popupShow.value = true
}
const popupHidden = () => {
    popupShow.value = false
}

defineExpose({
    showPopup
})
</script>

<style lang="scss" scoped>
.popup {
    display: flex;
    flex-direction: column;
    padding-top: 40rpx;
    .items {
        display: flex;
        padding-bottom: 50rpx;
    }
    .item {
        width: 33.33%;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        .circle {
            width: 80rpx;
            height: 80rpx;
            border-radius: 50%;
            margin-bottom: 8rpx;
            text-align: center;
            line-height: 80rpx;
        }
    }
    .cancel {
        border-top: 1px solid #d5d5d5;
        text-align: center;
        padding-top: 22rpx;
        padding-bottom: 30rpx;
    }
}
</style>
