<template>
	<view>
		<view class="tabbar cu-bar flex-between bg-white" :class="isShowAnimate ? 'fadeInUp' : ''"
			:style="{'background-color':tabBar.bgColor,'border-top-color':tabBar.borderColor}" v-show="onTabbar">
			<block v-for="(item, index) in tabBar.list" :key="index">
				<view class="action tabbar-item" :style="{color:index==currTabIndex?'#207cf7':''}"
					@click="clickTab(item,index)">
					<block v-if="item.showType=='img'">
						<!-- <image :style="{marginRight:item.text=='提问'?'50rpx':''}" class="tabbar-icon"
							:src="index==currTabIndex? item.selectedIconPath : item.iconPath">
						</image> -->
						<image class="tabbar-icon" :src="index==currTabIndex? item.selectedIconPath : item.iconPath">
						</image>
					</block>
					<block v-if="item.showType=='iconfont'">
						<view :class="['tabbar-icon',item.fontClass]"
							:style="{'color':index==currTabIndex?'#207cf7':'','font-size':item.text=='应用'?'26px':'22px',marginTop:item.text=='应用'?'-3px':'',marginBottom:item.text=='应用'?'5px':''}">
						</view>
					</block>
					<view class="tabbar-text" :style="{marginLeft:item.text=='提问'?'-8rpx':''}">{{ item.text }}</view>
					<view class="tabbar-item-num" v-if="item.num">{{item.num}}</view>
				</view>
			</block>
		</view>
	</view>
</template>

<script>
	// const iviteInfo = `?uniacid=${uni.getStorageSync('uniacid1')}&spm=123`
	import {
		mapMutations,
		mapActions,
		mapState,
		mapGetters
	} from 'vuex';
	export default {
		props: {
			onTabbar: {
				type: Boolean,
				default: true
			},
			infonum: {
				type: String,
				default: ''
			},
			isShowAnimate: {
				type: Boolean,
				default: false
			},
			isglobalpartjob: {
				type: String,
				default: '1'
			},
			themecolor: {
				type: String,
				default: '#207CF7'
			},
			is_aipainting: {
				type: String,
				default: ''
			},
			currTabIndex: {
				type: Number,
				default: 0
			},
		},
		computed: {
			...mapGetters(['appInfo'])
		},
		data() {
			return {
				showBig: false,
				// currTabIndex: 0,
				spm: '',
				spmplatform: 0,
				platform: this.$platform.get(),

				iviteInfo: `?uniacid=${uni.getStorageSync('uniacid')}&spm=`,
				tabBar: {
					color: '#333333',
					// selectedColor: '#26B3A0',
					selectedColor: '#207CF7',
					showType: "iconfont", //img/图片模式,iconfont/字体图标模式
					borderColor: "#d3d3d3",
					bgColor: "#ffffff",
					list: [{
							pagePath: "/",
							// pagePath: "/pages/painting/painting",
							// navigateType: "switchTab",
							navigateType: "navigateTo",
							showBig: false,
							fontClass: "tn-icon-image",
							"iconPath": "/static/images/tabs/joblist.png",
							"selectedIconPath": "/static/images/tabs/joblists.png",

							"text": "绘画",
							showType: "iconfont",
						},
						{
							pagePath: "/pages/template/template",
							navigateType: "navigateTo",
							showBig: false,
							fontClass: "tn-icon-cube",
							"iconPath": "/static/images/tabs/joblist.png",
							"selectedIconPath": "/static/images/tabs/joblists.png",
							"text": "应用",
							showType: "iconfont",
						},
						{
							pagePath: "/pages/painting/painting",
							// pagePath: "/",
							navigateType: "navigateTo",
							showBig: false,
							fontClass: "tn-icon-home-capsule",
							// "iconPath": "/static/images/tabs/index.png",
							// "selectedIconPath": "/static/images/tabs/indexs.png",

							"iconPath": "/static/tiwen_icon.png",
							"selectedIconPath": "/static/tiwen_icon_a.png",
							"text": "提问",
							showType: "img",
						},
						{
							// pagePath: "/pages/signin/signin",
							pagePath: "/pages/digitalMen/index",
							navigateType: "navigateTo",
							showBig: false,
							fontClass: "tn-icon-funds",
							// "iconPath": "/static/images/tabs/joblist.png",
							// "selectedIconPath": "/static/images/tabs/joblists.png",
							"iconPath": "/static/szr_icon.png",
							"selectedIconPath": "/static/szr_icon_a.png",
							// "text": "任务"
							"text": "数字人",
							showType: "img",
						},
						{
							pagePath: "/pages/user/user",
							navigateType: "navigateTo",
							showBig: false,
							fontClass: "tn-icon-my",
							"iconPath": "/static/images/tabs/mine.png",
							"selectedIconPath": "/static/images/tabs/mines.png",
							"text": "我的",
							showType: "iconfont",
						}
					]
				},


			};
		},

		onReady() {

			try {
				uni.hideTabBar({
					animation: false
				})
			} catch (e) {
				//TODO handle the exception
			}
			// setTimeout(function(){
			// 	uni.showTabBar({});
			// },600);
		},
		mounted() {
			// console.log(this.is_aipainting);
			if (this.tabBar.list.length > 4 && this.is_aipainting == '2') {
				// this.tabBar.list.splice(2, 1)
			}

			try {
				uni.hideTabBar({
					animation: false
				})
			} catch (e) {
				//TODO handle the exception
			}


			this.spmplatform = ['H5', 'wxOfficialAccount', 'wxMiniProgram', 'App'].indexOf(this.platform) + 1;
			this.spm = this.$store.getters.userInfo.id + '.1.0.' + this.spmplatform + '.1';

			this.iviteInfo = this.iviteInfo + this.spm
			// console.log('邀请分享信息：', this.$store.getters.userInfo, this.spmplatform, this.spm);
		},
		methods: {
			clickTab(item, index) {
				// this.currTabIndex = index

				// this.$emit('tabChange',this.currTabIndex)

				console.log('当前选中的你一下tabbar:', item, this.currTabIndex);

				if (item.showBig == true) {
					this.showBig = true
				} else {
					uni[item.navigateType]({
						url: uni.getStorageSync('token') ? item.pagePath + this.iviteInfo : item.pagePath
					});
					this.showBig = false
					// this.showBig = true
				}
			},
			toggleDialog() {

				this.showBig = !this.showBig
			},
			toPost(e) {
				this.toggleDialog();
				uni.navigateTo({
					url: '/pages/' + e
				})
			},
			// 路由跳转
			jump(path, parmas) {
				if (Boolean(uni.getStorageSync('userInfo').telnum)) {
					this.$Router.push({
						path: path,
						query: parmas
					});
				} else {
					this.$store.commit('LOGIN_TIP', true);
				}

			}
		},
		computed: {
			...mapState({
				showLoginTip: state => state.user.showLoginTip,
			}),
			nowPath() {
				return getCurrentPages()[0] && getCurrentPages()[0].route;
			},
		}
	};
</script>

<style lang="scss">
	.tabbar {
		display: flex;
		justify-content: space-around;
		/* height: 8vh; */
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 9999;
		height: 98rpx;
		background-color: #ffffff;
		// border-top: 1px solid rgba(193, 192, 201, 0.5);
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
		box-shadow: 0 -10rpx 20rpx 0 rgba(137, 148, 143, .1);
		min-height: 128rpx;
		padding: 0;
		height: calc(100rpx + env(safe-area-inset-bottom) / 2);
		padding-bottom: calc(env(safe-area-inset-bottom) / 2);
	}

	.tabbar::before {
		content: "";
		width: 100%;
		height: 152rpx;
		// background: url(https://ls11.cn/attachment/images/9/2019/09/TW284XJ028xWXH1mCh7pw7WhZjK4Jj.png) no-repeat;
		background-position: center;
		background-size: cover;
		position: absolute;
		left: 0;
		bottom: 0;
		z-index: -1;
		padding-bottom: 0;
		padding-bottom: calc(constant(safe-area-inset-bottom) - 12rpx);
		padding-bottom: calc(env(safe-area-inset-bottom) - 12rpx);
	}

	.flex-between {
		display: -webkit-box;
		display: -webkit-flex;
		display: -ms-flexbox;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
	}

	.tabbar-item {
		width: 33%;
		display: -webkit-inline-box;
		display: -webkit-inline-flex;
		display: -ms-inline-flexbox;
		display: inline-flex;
		flex-basis: 33%;
		flex-direction: column;
		align-items: center;
		justify-content: space-around;
	}

	.tabbar-item.active {
		color: #fe8b1e;
	}

	.tabbar-item.big {
		position: relative;
		top: -23rpx;
		// font-size: 130%;

		.tabbar-icon {
			width: 92rpx;
			height: 92rpx;
		}
	}

	.tabbar-icon {
		width: 46rpx;
		height: 46rpx;
		display: block;
		margin: 0 auto;
		margin-bottom: 4rpx;
		// font-size: 46rpx;
		// line-height: 10rpx;
	}

	.tabbar-text {
		width: 100%;
		font-size: 12px;
		letter-spacing: 0;
		text-align: center;
		line-height: 14px;
		display: block;
		font-weight: 600;

		padding-left: 8rpx;
		// color: #333;
	}

	.tabbar-item-num {
		position: absolute;
		top: 1vw;
		font-size: 20rpx;
		padding: 4rpx;
		border-radius: 50%;
		background-color: #ff4a39;
		color: #ffffff;
		width: 28rpx;
		height: 28rpx;
		text-align: center;
		line-height: 28rpx;
		left: 45rpx;
		margin: auto;
		right: 0;
	}

	.bg {
		position: fixed;
		z-index: 1007;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background-color: #000;
		opacity: .8;
	}

	.fixed-fabu {
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 1008;
		background-color: #fff;
		width: 100%;
		padding: 30rpx;
		border-top-left-radius: 12rpx;
		border-top-right-radius: 12rpx;

		h2 {
			font-size: 18px;
			color: #333;
			font-weight: 400;
			text-align: center;
			margin: 20rpx 0;
		}

		.ul {
			padding: 0 50rpx;
		}
	}

	.close {
		width: 44px;
		height: 44px;
		display: block;
		margin: 35px auto;
	}

	@keyframes fabu_animate_in {
		0% {
			transform: scale(1);
		}

		50% {
			transform: scale(1.2);
		}

		100% {
			transform: scale(1);
		}
	}

	.ani_fabu_in {
		animation: fabu_animate_in .5s 0s ease-in-out;
		animation-fill-mode: both;
		animation-iteration-count: 1
	}

	@keyframes close_rotate {
		0% {
			transform: rotate(0deg)
		}

		100% {
			transform: rotate(360deg)
		}
	}

	.close_rotate {
		animation: close_rotate .5s .1s ease-in-out;
		animation-fill-mode: both;
		animation-iteration-count: 1
	}

	.btn-personal-rec {
		border-radius: 10rpx;
		line-height: 150rpx;
		height: 150rpx;
		font-size: 50rpx;
		color: #fff;
		font-weight: bold;
		margin: 40rpx auto;
		display: flex;
		align-items: center;
		justify-content: center;
		box-shadow: 0rpx 14rpx 34rpx rgba(41, 57, 88, 0.4);
	}

	.btn-personal-rec .btn-img {
		margin-right: 20rpx;
		width: 70rpx;
		height: 70rpx;
	}

	.recruit {
		background: linear-gradient(to right, #03a9f48c, #03A9F4);
	}

	.partjob {
		background: linear-gradient(to right, #FF98008c, #FF9800);
		// line-height: 100rpx;
	}

	.resume {
		background: linear-gradient(to right, #FF57228c, #FF5722);
	}

	@keyframes fadeInUp {
		from {
			opacity: 0;
			-webkit-transform: translate3d(0, 100%, 0);
			transform: translate3d(0, 100%, 0);
		}

		to {
			opacity: 1;
			-webkit-transform: translate3d(0, 0, 0);
			transform: translate3d(0, 0, 0);
		}
	}

	.fadeInUp {
		animation-name: fadeInUp;
		animation-duration: .5s;
		animation-delay: 0s;
	}
</style>