<template>
  <view class="voice-no-auth">
        <image class="img" :src="globalImgUrls.activityNoAuth" mode="widthFix"></image>
		<view style="margin-bottom:15px">您暂无权限查看线上路演</view>
		<view v-if="info.type==='contact'" style="margin-bottom:15px">若想查看可以联系对口销售</view>
		<view v-else style="margin-bottom:15px">若想查看可以申请开通</view>
		<view v-if="info.type==='contact'">
			{{info.name||''}}:<text @click="handleCall" style="color:#E3B377">{{info.mobile||''}}</text>
		</view>
		<view class="global-btn-yellow-change btn" @click="handleApply" v-else style="margin-top:30px">立即申请</view>
  </view>
</template>

<script>
import {apiApplyPermission} from '@/api/user'
export default {    
    props: {
        info:null
    },
    watch:{
        info(){
            this.handleAutoApply()
        }
    },
    
    methods: {
        handleCall(){

            uni.makePhoneCall({
                phoneNumber: this.info.mobile,
                success: (result) => {},
                fail: (error) => {}
            })
        },

        handleAutoApply(){
            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:10,
                        from_page:'线上路演'
                    }).then(res=>{
                        if(res.code===200){
                            console.log('主动申请成功');
                        }
                    }) 
                }
            }
        },

        async handleApply(){
            await this.checkUserIsBind()
            const {customer_info}=this.info
            if(customer_info.has_apply){
                uni.showToast({
                  title:'您已提交过申请,请耐心等待',
                  icon:'none'
                })
            }else{
                if (!customer_info.status || customer_info.status != '流失') {
                    uni.navigateTo({
                        url: "/pages-applyPermission/applyPermission?source=10&from_page=线上路演"
                    })
                }else{
                    apiApplyPermission({
                        company_name:customer_info.company_name,
                        real_name:customer_info.name,
                        source:10,
                        from_page:'线上路演'
                    }).then(res=>{
                        uni.navigateTo({url:'/pages-applyPermission/applyResult'})
                    })
                }
            }
        }
    }
}
</script>

<style lang="scss" scoped>
.voice-no-auth{
    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>