<!--
 * @Author: 王翠碧 1254597151@qq.com
 * @Date: 2023-05-22 22:41:29
 * @LastEditors: micky 1254597151@qq.com
 * @LastEditTime: 2023-10-05 17:58:55
 * @FilePath: \uniapp\src\components\widgets\my-service\my-service.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <view class="my-service bg-white mx-[25rpx] mt-[20rpx] rounded-lg">
        <view
            v-if="content.title_display && content.title"
            class="title px-[30rpx] py-[20rpx] font-medium text-xl title-active"
        >
            <view>{{ content.title }}</view>
        </view>
        <!-- 横排 -->
        <view v-if="content.style === 1" class="flex flex-wrap pt-[40rpx] pb-[20rpx]">
            <template v-for="(item, index) in content.data" :key="index">
                <view
                    v-if="item.name === '订单服务' ? userInfo.staff : true"
                    class="flex flex-col items-center w-1/4 mb-[15px]"
                    @click="handleClick(item)"
                >
                    <u-image width="52" height="52" :src="getImageUrl(item.image)" alt="" />
                    <view class="mt-[7px]">{{ item.name }}</view>
                </view>
            </template>
        </view>
        <!-- 竖排 -->
        <view v-if="content.style === 2" class="flex-container">
            <template v-for="(item, index) in content.data" :key="index">
                <view
                    v-if="item.name === '订单服务' ? userInfo.staff : true"
                    class="item flex items-center border-light border-solid border-0 border-b h-[100rpx] mx-[24rpx]"
                    @click="handleClick(item)"
                    id="113"
                >
                    <u-image width="48" height="48" :src="getImageUrl(item.image)" alt="" />
                    <view class="ml-[20rpx] flex-1">{{ item.name }}</view>
                    <view class="text-muted">
                        <u-icon name="arrow-right" color="#DCDEE2" />
                    </view>
                </view>
            </template>
        </view>
        <CustomerService ref="customerService" />
    </view>
</template>
<script lang="ts" setup>
import { useAppStore } from '@/stores/app'
import { navigateTo } from '@/utils/util'
import { useUserStore } from '@/stores/user'
import { storeToRefs } from 'pinia'
import { ref, onUnmounted, onMounted } from 'vue'
const userStore = useUserStore()
const { userInfo } = storeToRefs(userStore)
import CustomerService from './components/customer-service.vue'

const props = defineProps({
    content: {
        type: Object,
        default: () => ({})
    },
    styles: {
        type: Object,
        default: () => ({})
    }
})
const customerService = ref() // 显示(输入核销码)：是 | 否

const { getImageUrl } = useAppStore()
const handleClick = (item: any) => {
    if (item?.link?.query?.url == 'customer-service') {
        //联系客服弹出弹框，不需要跳转页面
        customerService.value.open('center')
    } else {
        navigateTo(item.link)
    }
}

console.log('userInfo', userInfo.value)
console.log('content', props.content)
</script>

<style lang="scss">
.flex-container {
    .item:last-child {
        border: none;
    }
}
</style>
