<template>
	<div class="icon-items-list" :class="'icon-items-list-'+type">
		<div class="icon-items-icons" v-for="(item,index) in list" :key="item.id" :style="{width:itemWidth}" @click="toPage(item,index)">
			<div class="icon-items-imgse" >
				<image class="imgs" :class="item.auth?'':'uni-img-gray'" :fade-show='true' :src="item.icon"></image>
				<u-badge class="tag" :absolute="false" type="error"  v-if="item.nums" :count="item.nums"></u-badge>
			</div>
			<div class="icon-items-text">{{item.name.slice(0,14)}}</div>
		</div>
		<div class="nodata" v-if="list.length==0">
			<u-empty :text="noDataText" mode="list"></u-empty>
		</div>
	</div>
</template>

<script>
	export default {
		name: "iconItemsList",
		props:{
			// 套餐服务项 或配件id
			list:{
				type: Array,
				default: function(){
					return []
				}
			},
			itemWidth: {
				type: String,
				default: '25%'
			},
			type: {
				type: String,
				default: 'icon'
			},
			noDataText: {
				type: String,
				default: '暂无数据'
			}
		},
		data() {
			return {
				datas: this.list
			}
		},
		methods: {
			toPage(item,index){
				if(!item.auth){
					// uni.showToast({icon: 'none',title: '您还未登录'})
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return
				}
				if(item.url&&item.url!=''){
					if(item.target == 'page'){
						uni.navigateTo({
							url: item.url
						})
					}
					if(item.target == 'tabPage'){
						uni.switchTab({
							url: item.url
						})
					}
					if(item.target == 'fun'){
						this.$emit('callback',item.url)
					}
				}
			}
		}
	}
</script>

<style lang="less">
	.icon-items-list{
		align-items: center;
		display: flex;
		flex-wrap: wrap;
		.nodata{
			text-align: center;
			font-size: 24upx;
			width: 100%;
			color: #999999;
		}
	}
	.icon-items-list-icon{
		.icon-items-imgse{
			position: relative;
			width: 100upx;
			height: 100upx;
			margin-bottom: 6upx;
			.imgs{
				width: 100upx;
				height: 100upx;
			}
			.tag{
				position: absolute;
				top: -5upx;
				right: -5upx;
			}
		}
		.icon-items-text{
			font-size: 28upx;
			color: #666666;
		}
	}
	.icon-items-icons{
		text-align: center;
		margin: 20upx 0;
		display: flex;
		align-items: center;
		flex-direction: column;
		justify-content: center;
	}
</style>
