<template>
	<scroll-view class="wuc-tab" :class="tabClass" :style="tabStyle" scroll-with-animation scroll-x
		:scroll-left="scrollLeft" style="background: #fff">
		<div v-if="!textFlex">
			<div class="wuc-tab-item" :class="[index === tabCur ? selectClass + ' cur':'']"
				v-for="(item,index) in tabList" :key="index" :id="index" @tap="tabSelect(index,$event)">
				<text :class="item.icon"></text>
				<span>{{item.name}}</span>
				<text class="cur-line"></text>
			</div>
		</div>

		<div class="flex text-center" v-if="textFlex">
			<div class="wuc-tab-item flex-sub" :class="index === tabCur ? selectClass + ' cur':''"
				v-for="(item,index) in tabList" :key="index" :id="index" @tap="tabSelect(index,$event)">
				<text :class="item.icon"></text>
				<span>{{item.name}}</span>
				<text class="cur-line"></text>
			</div>
		</div>
	</scroll-view>
</template>
<script>
	export default {
		name: 'wuc-tab',
		data() {
			return {};
		},
		props: {
			tabList: {
				type: Array,
				default () {
					return [];
				}
			},
			tabCur: {
				type: Number,
				default () {
					return 0;
				}
			},
			tabClass: {
				type: String,
				default () {
					return '';
				}
			},
			tabStyle: {
				type: String,
				default () {
					return '';
				}
			},
			textFlex: {
				type: Boolean,
				default () {
					return true;
				}
			},
			selectClass: {
				type: String,
				default () {
					return 'text-blue';
				}
			}
		},
		methods: {
			tabSelect(index, e) {
				if (this.currentTab === index) return false;
				this.$emit('update:tabCur', index);
				this.$emit('change', index);
			}
		},
		computed: {
			scrollLeft() {
				return (this.tabCur - 1) * 60;
			}
		}
	};
</script>
<style>
	div,
	scroll-view,
	swiper {
		box-sizing: border-box;
	}

	.wuc-tab {
		white-space: nowrap;
	}

	.wuc-tab-item {
		display: inline-block;
		height: 90upx;
		line-height: 90upx;
		padding: 0 10px;
		font-size: 16px;
		color: #999;
		border-bottom: solid 1px #f5f5f5;
	}

	.wuc-tab-item.cur {
		color: #4779ff;
		position: relative;
	}

	.cur .cur-line {
		position: absolute;
		width: 50px;
		height: 2px;
		background: #4779ff;
		bottom: -1px;
		left: 36%;
		border-radius: 4px;
	}

	.wuc-tab.fixed {
		position: fixed;
		width: 100%;
		top: 0;
		z-index: 1024;
		box-shadow: 0 1upx 6upx rgba(0, 0, 0, 0.1);
	}

	.flex {
		display: flex;
	}

	.text-center {
		text-align: center;
	}

	.flex-sub {
		flex: 1;
	}

	.text-blue {
		font-weight: bold;
	}

	.text-white {
		color: #ffffff;
	}

	.bg-white {
		background-color: #ffffff;
	}

	.bg-blue {
		background-color: #c00000;
	}

	.text-orange {
		color: #f37b1d
	}

	.text-xl {
		font-size: 16px;
	}
</style>