<template>
  <view class="noauthority-page">
      <image class="img" :src="globalImgUrls.activityNoAuth" mode="widthFix"></image>
      <view>您暂无权限参加此活动</view>
      <view v-if="info.type=='contact'">若想参加，可以联系对口销售</view>
      <view v-else>若想参加可以申请开通</view>
      <view class="global-btn-yellow-change btn" @click="handleContact" v-if="info.type=='contact'">联系销售</view>
      <view class="global-btn-yellow-change btn" @click="handleGoApply" v-else>立即申请</view>
      <view class="global-btn-yellow-plain btn" @click="handleBack">返回</view>

      <!-- 弹窗 -->
        <van-popup :show="pupData.show" @close="pupData.show=false" :close-on-click-overlay="false">
            <view class="global-pup">
                <view class="content">
                    <rich-text :nodes="pupData.content"></rich-text>
                </view>
                <view class="flex bot">
                    <view @click="pupData.show=false">知道了</view>
                </view>
            </view>
        </van-popup>
  </view>
</template>

<script>
import {apiApplyPermission} from '@/api/user'
export default {
    name:"noAuthority",
    data () {
        return {
            info:{},
            pupData:{
				show:false,
				content:'',//弹窗html字符串
			}
        }
    },
    onLoad(options){
       this.info=JSON.parse(options.data)
       
       if(this.info.type=='contact'&&!this.info.customer_info.has_apply){
           if(this.info.customer_info.status=='冻结'||(this.info.customer_info.status=='试用'&&this.info.customer_info.is_suspend==1)){
               apiApplyPermission({
                    company_name:this.info.customer_info.company_name,
                    real_name:this.info.customer_info.name,
                    source:2,
                    from_page:'活动详情'
                }).then(res=>{
                    if(res.code===200){
                        console.log('主动申请成功');
                    }
                }) 
           }
       }
    },
    methods: {
        async handleGoApply(){
            if(this.info.type=='apply'){
                if(this.info.customer_info.has_apply){// 已经申请过
                    this.pupData.show=true
					this.pupData.content=`<p>您已提交过申请，请耐心等待</p>`
                    // uni.redirectTo({
                    //     url:"/pages-applyPermission/applyResult"
                    // })
                }else{
                    if(!this.info.customer_info.status||this.info.customer_info.status!='流失'){
                        uni.redirectTo({
                            url:"/pages-applyPermission/applyPermission?source=2&from_page=活动详情"
                        })
                    }else{//主动调一次申请权限接口 
                        const res=await apiApplyPermission({
                            company_name:this.info.customer_info.company_name,
                            real_name:this.info.customer_info.name,
                            source:2,
                            from_page:'活动详情'
                        })
                        if(res.code===200){
                            this.pupData.show=true
					        this.pupData.content=`<p>申请已提交</p><p>请等待销售人员与您联系</p>`
                            // uni.redirectTo({
                            //     url:"/pages-applyPermission/applyResult"
                            // })
                        }
                    }
                }
                
            }
            
        },

        handleContact(){
            uni.makePhoneCall({
                phoneNumber: this.info.mobile
            });
        },

        handleBack(){
            uni.navigateBack({
                fail:()=>{
                    uni.switchTab({ url: '/pages/activity/activity' })
                }
            })
        }

    }
}
</script>

<style lang="scss" scoped>
.noauthority-page{
    padding: 34rpx;
    text-align: center;
    font-size: $global-font-size-lg;
    .img{
        width: 100%;
        margin-bottom: 50rpx;
    }
    .btn{
        width: 380rpx;
        line-height: 70rpx;
        margin-left: auto;
        margin-right: auto;
        margin-top: 40rpx;
    }
}
</style>