<template>
	<view class="tabPage" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
		<cus-header title='发布问卷' :showback="false"></cus-header>
		<image :style="{'top':mt+'px'}" :src="imgBase+'publish_bg.png'" mode="widthFix"></image>
		<div class="list">
			<div class="list-item adfacjb" v-for="(item,index) in list" :key="index" @click="handleTurnPage(item)">
				<div class="list-item-left">
					<div class="list-item-left-title">{{item.title}}</div>
					<div class="list-item-left-type">{{typeDict[item.type]||'默认版'}}</div>
				</div>
				<image class="list-item-right" :src="imgBase+'publish_arrow_right.png'" v-if="item.type<3"></image>
			</div>
		</div>
		<div class="dialog adffcac" v-if="buyShow">
			<div class="dialog-box adffcac" :class="{'zyb':type==2}">
				<image :src="imgBase+'new_free_close.png'" @click="buyShow=false"></image>
				<div class="dialog-box-list adf">
					<div class="dialog-box-list-item adffcac" v-for="(item,index) in buyImgList" :key="index">
						<image :src="item.img"></image>
						<text>{{item.text}}</text>
					</div>
				</div>
				<div class="dialog-box-btn" @click="handleBuy">立即购买</div>
			</div>
		</div>
		<Notice :show="noticeShow" @close="noticeShow=false" @handleKnow="handleKnow"></Notice>
		<Tabbar :tabbarIndex="1"></Tabbar>
	</view>
</template>

<script>
	import Tabbar from '@/components/CusTabbar/index.vue'
	import Notice from '@/components/CusNotice/index.vue'
	export default {
		components:{ Tabbar, Notice },
		data(){
			return {
				list:[],
				type:1,
				questionnaireId:'',
				questionnaireName:'',
				typeDict:{
					1:'基础版',
					2:'专业版',
					3:'专家版，敬请期待'
				},
				buyShow:true,
				buyImgList:[
					{img:this.$imgBase+'buy_img1.png',text:'全球前沿研究'},
					{img:this.$imgBase+'buy_img2.png',text:'扎实理论基础'},
					{img:this.$imgBase+'buy_img3.png',text:'一键全面评估'},
					{img:this.$imgBase+'buy_img4.png',text:'专业教练解读'}
				],
				noticeShow:false,
			}
		},
		onLoad(options) {
			this.getList()
		},
		methods:{
			getList(){
				this.$api.get('/core/questionnaire/list').then(({data:res})=>{
					if(res.code!==0) return this.$showToast(res.msg)
					this.list = res.data
				})
			},
			handleTurnPage(item){
				this.type = item.type;
				this.questionnaireName = item.title;
				if(item.type==3) return this.$showToast('敬请期待专家版~')
				this.$api.get(`/que/order/getUseFrequency/${JSON.parse(uni.getStorageSync('userInfo')).id}/${item.type}`).then(({data:res})=>{
					if(res.code!==0) return this.$showToast(res.msg)
					if(res.data>0){
						this.questionnaireId = item.id;
						this.noticeShow = true;
					}else this.buyShow = true;
				})
			},
			handleBuy(){
				uni.navigateTo({
					url:'/pagesPublish/rechargeCenter'
				})
			},
			handleKnow(){
				this.noticeShow = false;
				if(this.type==1){
					uni.navigateTo({
						url:'/pagesPublish/fillTeamInfo?type='+this.type+'&questionnaireId='+this.questionnaireId+'&next=true'+'&title='+this.questionnaireName
					})
				}else if(this.type==2){
					uni.navigateTo({
						url:'/pagesHome/questionnaireEdit?type=2&questionnaireId='+this.questionnaireId+'&questionnaireName='+this.questionnaireName+'&teamQuestionnaireId='+this.questionnaireId
					})
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.tabPage{
		padding: 0;
		
		&>image{
			width: 100%;
			position: absolute;
			left: 0;
			right: 0;
		}
		
		.list{
			margin-top: 369rpx;
			position: relative;
			padding: 0 24rpx;
			&-item{
				margin-top: 20rpx;
				background: #FFFFFF;
				border-radius: 24rpx;
				padding: 40rpx 30rpx;
				&:first-child{
					margin-top: 0;
				}
				&-left{
					width: calc(100% - 50rpx);
					padding-right: 30rpx;
					box-sizing: border-box;
					&-title{
						font-family: PingFang-SC, PingFang-SC;
						font-weight: bold;
						font-size: 30rpx;
						color: #002846;
						line-height: 42rpx;
						text-overflow: ellipsis;
						overflow: hidden;
						white-space: nowrap;
					}
					&-type{
						background: #FFF7DC;
						border-radius: 8rpx;
						margin-top: 20rpx;
						padding: 2rpx 13rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						font-size: 24rpx;
						color: #BA9B31;
						line-height: 33rpx;
						letter-spacing: 2rpx;
						display: inline-block;
					}
				}
				&-right{
					width: 50rpx;
					height: 50rpx;
				}
			}
		}
	
		.dialog{
			position: fixed;
			left: 0;
			right: 0;
			top: 0;
			bottom: 0;
			z-index: 1000;
			background: rgba(0, 0, 0, .6);
			padding-bottom: 140rpx;
			box-sizing: border-box;
			justify-content: flex-end;
			
			&-box{
				width: calc(100% - 48rpx);
				background: url('https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/buy_bg.png') no-repeat;
				background-size: 100% 100%;
				padding: 305rpx 30rpx 40rpx;
				box-sizing: border-box;
				position: relative;
				&.zyb{
					background: url('https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/buy_bg_zyb.png') no-repeat;
					background-size: 100% 100%;
				}
				&>image{
					width: 48rpx;
					height: 48rpx;
					position: absolute;
					top: 0;
					right: 30rpx;
				}
				&-list{
					width: 100%;
					justify-content: space-between;
					&-item{
						width: calc(25% - 16rpx);
						image{
							width: 80rpx;
							height: 80rpx;
						}
						text{
							font-family: PingFangSC, PingFang SC;
							font-weight: 400;
							font-size: 22rpx;
							color: #6F4611;
							line-height: 30rpx;
							text-align: center;
							margin-top: 24rpx;
						}
					}
				}
				&-btn{
					width: calc(100% - 70rpx);
					height: 88rpx;
					background: linear-gradient( 90deg, #EBB56C 0%, #FCEAD0 100%);
					border-radius: 44rpx;
					margin-top: 60rpx;
					font-family: PingFang-SC, PingFang-SC;
					font-weight: bold;
					font-size: 32rpx;
					color: #6F4611;
					line-height: 88rpx;
					text-align: center;
					letter-spacing: 2rpx;
				}
			}
		}
	}
</style>