<template>
    <view class="obtainInforBox column">
        <view class="obtainInforTitle">请选以下任意代表填写意见</view>
        <scroll-view :scroll-y="true" 
            :enable-back-to-top="true" style="height: 1px;flex: 1;"
            :enable-flex="true"> 
            <radio-group @change="radioChange">
				<label class="obtainInforLab row" v-for="(item, index) in guestInfor.guest" :key="index">
					<view>
                        <radio :value="item.Id" color="#0039B8"/>
					</view>
					<view class="obtainInforLabName">{{item.AllName}}</view>
				</label>
			</radio-group>
        </scroll-view>
        <view class="obtainInforGo"
        :class="[current==0||showLogin?'active':'']" @click="current==0||showLogin?'':setPhone()">
            确定
        </view>
    </view>
</template>
<script>
export default {
    data() {
        return {
            msg:{
                TCID:'',
                HPSLOpenId:'',
                Unoinid: '',
                Phone: '',
                Id: 0,
                OrderId: 0,
            },
            list:[
                {
                    name:'我是业主',
                    value:1
                },
                {
                    name:'我是中介',
                    value:2  
                },
                {
                    name:'我是经纪人',
                    value:3
                },
            ],
            current:0,
            guestInfor: null,
            showLogin: false,
        }
    },
    onLoad(option) {
        this.msg = JSON.parse(decodeURIComponent(option.msg))
        this.QueryUsers()
    },
    methods: {
        // 更新手机号
        setPhone(){
            if(this.guestInfor.code==0&&this.guestInfor.IsEnd==0){
                if(this.showLogin) return;
                if(this.msg.TCID==''||this.msg.HPSLOpenId==''||
                this.msg.Unoinid==''||this.msg.Phone==''||this.msg.Id==''){
                    return uni.showToast({
                        title: '信息不完善，请稍后再试',
                        icon: 'none'
                    })
                }
                this.showLogin = true;
                this.apipost("post_UpdateOrderGuest",this.msg,res => {
                if (res.resultCode == 1) {
                    this.showLogin = false;
                    uni.hideLoading();
                    this.goWebUrl()
                }}, (error) => {
                    uni.hideLoading();
                    uni.showToast({
                        title: error.message,
                        icon: "none",
                    });
                })
            }else{
                this.showLogin = false;
                uni.hideLoading();
                this.goWebUrl()
            }
        },
        radioChange(evt){
            this.current = evt.detail.value;
            this.msg.Id = evt.detail.value;
            for (let i = 0; i < this.guestInfor.guest.length; i++) {
                if(this.guestInfor.guest[i].Id==this.current){
                    this.msg.OrderId = this.guestInfor.guest[i].OrderId
                } 
            }
        },
        QueryUsers(){
            uni.showLoading({
                title: "加载中",
                mask: true,
            })
            this.apipost("post_GetOrderGuest",{
                TCID: this.msg.TCID,
                HPSLOpenId: this.msg.HPSLOpenId,
                Unoinid: this.msg.Unoinid,
            }, (res) => {
            if (res.resultCode == 1) {
                uni.hideLoading();
                this.guestInfor = res.data; 
                this.list = res.data.guest
            }}, (error) => {
                uni.hideLoading();
                uni.showToast({
                    title: error.message,
                    icon: "none",
                });
            })
        },
        goWebUrl() {
            let url = `https://activity.oytour.com/html/ImpressionOpinionSurvey/opinionSurvey.html?TCID=${this.msg.TCID}&GuestId=${this.msg.Id}&OrderId=${this.msg.OrderId}&Phone=${this.msg.Phone}`
            if (url && url.length > 0) {
                uni.redirectTo({
                    url: "/pages/webbox/webbox?u=" + encodeURIComponent(url),
                });
            }
        }
    }
}
</script>
<style lang="scss" scoped>
@import url("@/asset/css/flex.css");
.obtainInforBox{
    background: -webkit-gradient(linear, 0 0, 0 100%, from(#B2E7F7 ), to(#9BCFF3 ));
    padding: 50rpx 41rpx;
    min-height: 100vh;
}
.obtainInforTitle{
    font-family: 068-SSZhengYaTi;
    font-weight: 400;
    font-size: 43rpx;
    color: #080A0A;
    text-align: center;
    margin-bottom:50rpx;
 }
 .obtainInforGo{
    width: 100%;
    line-height: 100rpx;
    color: #fff;
    background: #0039B8;
    border-radius: 18rpx;
    text-align: center;
    font-weight: bold;
    font-size: 36rpx;
    margin-top: 85rpx;
    margin-bottom: 50rpx;
 }
 .obtainInforGo.active{
    background: #eee;
    color: #000; 
 }
 .obtainInforLab{
    padding: 20rpx 0;
 }
 .obtainInforLabName{
    position: relative;
    top: 6rpx;
    left: 10rpx;
 }
</style>