<template>
	<view class="default_page adffc" :style="{'height':h+'px', 'padding-top':mt+'px'}">
		<cus-header :title='title' bgColor="transparent"></cus-header>
		<image class="top_bg" :src="imgBase+'questionnaire_top_bg.png'" mode="widthFix"></image>
		<!-- <view class="tab adfac">
			<view class="tab-pre" :class="{'active':tindex===0}" @click="changeTab(0)">我收到的</view>
			<view class="tab-pre" :class="{'active':tindex===1}" @click="changeTab(1)">我创建的</view>
		</view> -->
		<view class="query adfacjb">
			<u-icon name="search" size="38rpx" color="#B3BFC8"></u-icon>
			<view class="query-inp">
				<u-input v-model="keyword" border="none" fontSize="26rpx" color="#002846" clearable
				 placeholder="请输入团队名称查询" @confirm="getList"></u-input>
			</view>
		</view>
		<view class="box">
			<template v-if="tindex===0">
				<receive-list :list="receiveList" @scrolltolower="receiveScrolltolower"></receive-list>
			</template>
			<template v-else-if="tindex===1">
				<create-list :list="createList" @scrolltolower="createScrolltolower"></create-list>
			</template>
		</view>
	</view>
</template>

<script>
	import ReceiveList from './components/receiveList.vue'
	import CreateList from './components/createList.vue'
	export default {
		components:{ ReceiveList, CreateList },
		data(){
			return {
				title:'问卷管理',
				tindex:0,
				keyword:'',
				receiveList:[],
				createList:[],
				teamUserShow:false,
			}
		},
		onShow() {
			if(this.tindex===0){
				this.receiveList = [];
				this.getReceiveList();
			}else if(this.tindex===1){
				this.createList = [];
				this.getCreateList();
			}
		},
		onLoad(options) {
			if(options.type==='receive'){
				this.title = 'PREILL评估';
				this.tindex = 0;
				this.receiveList = [];
				this.getReceiveList();
			} 
			else if(options.type==='create'){
				this.title = '问卷管理';
				this.tindex = 1;
				this.createList = [];
				this.getCreateList();
			} 
		},
		methods:{
			changeTab(index){
				if(this.tindex===index) return
				this.tindex = index;
				if(index===0){
					this.receiveList = [];
					this.getReceiveList();
				}else if(index===1){
					this.createList = [];
					this.getCreateList();
				}
			},
			getReceiveList(){
				this.$api.get('/core/teammember/que/personalList',{teamName:this.keyword}).then(({data:res})=>{
					if(res.code!==0) return this.$showToast(res.msg)
					this.receiveList = res.data
				})
			},
			getCreateList(){
				this.$api.get('/core/teammember/que/createList',{teamName:this.keyword}).then(({data:res})=>{
					if(res.code!==0) return this.$showToast(res.msg)
					this.createList = res.data
				})
			},
			receiveScrolltolower(){
				console.log(1);
			},
			createScrolltolower(){
				console.log(2);
			}
		}
	}
</script>

<style scoped lang="scss">
	.default_page{
		padding: 0 24rpx 40rpx;
		background: #F7F7F7;
		box-sizing: border-box;
		
		.top_bg{
			width: 100%;
			position: absolute;
			left: 0;
			top: 0;
		}
	
		.query{
			width: calc(100% - 12rpx);
			margin: 40rpx 6rpx 0;
			height: 72rpx;
			background: #FFFFFF;
			border-radius: 36rpx;
			padding: 0 36rpx;
			box-sizing: border-box;
			position: relative;
			&-inp{
				width: calc(100% - 55rpx);
			}
		}
	
		.box{
			flex: 1;
		}
	
		.tab{
			margin-top: 20rpx;
			position: relative;
			&-pre{
				width: 50%;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 30rpx;
				color: #002846;
				line-height: 42rpx;
				text-align: center;
				&.active{
					font-weight: bold;
					font-size: 32rpx;
					line-height: 45rpx;
					position: relative;
					&::after{
						content: '';
						width: 48rpx;
						height: 6rpx;
						background: linear-gradient( 90deg, #33A7A7 0%, #64BBBB 100%);;
						border-radius: 9rpx;
						position: absolute;
						left: 50%;
						margin-left: -24rpx;
						bottom: -22rpx;
					}
				}
			}
		}
	}
</style>