<template>
	<view class="task-tab">
		<scroll-view class="scroll-Y row" scroll-x="true">
			<view class="z-tabs-scroll-view row-justify-sb center" style="position: relative;">
				<view class="column-c tab-item p-lr30 p-t30 p-b20" v-for="(item,index) in navList" :key="index"
					@click="setType(index)">
					<image class="wh-60 r-circle" :class="index===current?'double-border':''" :src="item.product_icon"
						mode="aspectFill">
					</image>
					<view class="m-t16 sys-size-24 text-center sys-weight-600"
						:class="{'default-text':index===current}">
						{{item.briefness_name}}
					</view>
					<!-- <view class="half-circle m-t20" :class="{'half-circle1':current==1}" v-if="current==index"></view> -->
				</view>
				<view class="half-circle m-t20"></view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {getTaskType} from "@/api/task";

  export default {
		data() {
			return {
				current: 0,
        navList: [
          {
            id:0,
            briefness_name: '全部',
            product_icon: '/static/img/task/task-all.png'
          }
        ]
      }
    },
    mounted() {
      this.getTaskType()
    },
    methods: {
      getTaskType(){
        getTaskType().then(res=>{
          if(res.code===1){
            this.navList.push(...res.data)

          }
        })
      },
      setType(current) {
        // this.$nextTick(() => {
        // 	uni.createSelectorQuery().in(this).select(".z-tabs-scroll-view").fields({
				// 		scrollOffset: true
				// 	}, data => {
				// 		if (data) {
				// 			this.currentScrollLeft = data.scrollLeft;
				// 			console.log(data);
				// 		} else {}
				// 	}).exec();
				// })
				if (current !== this.current) {
					this.current = current
          this.$emit('setProductId',this.navList[current].id)
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.task-tab {
		margin: 0 20rpx;
		border-radius: 30rpx;
		background: #fff;
	}

	.default-text {
		color: #10B261;
	}

	.half-circle {
		width: 20rpx;
		height: 10rpx;
		background-color: #3eaf7c;
		border-top-left-radius: 10rpx;
		border-top-right-radius: 10rpx;
		position: absolute;
		bottom: 0;
		left: calc(25%/2 - 10rpx);
	}

	.half-transition {
		transition: all .5s ease;
	}

	.tab-item {
		width: 25%;
	}

	.double-border {
		box-shadow: 0 0 0 6rpx #fff, 0 0 0 12rpx #10B261;
	}
</style>