<template>
    <Cn-page :loading="loading">
        <view slot="body">
            <view class="platform">
                <view class="platform-bg"></view>
                <!-- <view class="platform-title">全国特种设备无损检测公共服务云平台</view> -->
                <view class="platform-des" v-if="list.length">当前手机号绑定单位</view>
                <view class="platform-des" v-else>通过手机号获取单位</view>
                <view class="platform-content" v-if="list.length">
                    <navigator
                        hover-class="none"
                        :url="'/pages/login/login?alias=' + item.alias + '&name=' + item.companyName + '&account=' + phone.trim()"
                        class="platform-content-card"
                        v-for="item in list"
                        :key="item.alias"
                    >
                        <view class="platform-content-card-title">{{ item.companyName }}</view>
                        <view class="platform-content-card-des">{{ item.alias }}</view>
                    </navigator>
                    <div style="height:280rpx"></div>
                    <view class="platform-footer iphone">
                        <view class="platform-footer-tips">以上不是您需访问的平台？</view>
                        <view class="platform-footer-btn" @click="showPopup">输入智慧云手机号/账号</view>
                    </view>
                </view>
                <view class="platform-content center" v-else>
                    <view>
                        <view class="platform-footer-btn" @click="showPopup">输入智慧云手机号/账号</view>
                        <!-- #ifdef MP -->
                        <button
                            v-if="canGetPhoneNumber"
                            type="primary"
                            class="platform-footer-btn"
                            open-type="getPhoneNumber"
                            @getphonenumber="onGetUserPhone"
                        >本机号码一键获取</button>
                        <!-- <view
                            type="primary"
                            class="platform-footer-btn"
                            @click="wxLogin"
                        >微信一键登录</view> -->
                        <!-- #endif -->
                    </view>
                </view>
                <uni-popup ref="inputPhone" type="center" :animation="false">
                    <view class="input-box">
                        <input
                            type="text"
                            class="input-box-main"
                            placeholder-class="input-box-main-placeholder"
                            placeholder="请输入智慧云手机号/账号"
                            v-model="phone"
                        />
                        <view class="input-box-btn">
                            <view class="input-box-btn-item" @click="cancel">取消</view>
                            <view class="input-box-btn-item" @click="load">确定</view>
                        </view>
                    </view>
                </uni-popup>
            </view>
        </view>
    </Cn-page>
</template>
<script>
export default {
    data() {
        return {
            loading: false,
            phone: "",
            list: [],
            canGetPhoneNumber: true
        };
    },
    components: {},
    methods: {
        showPopup() {
            this.$refs.inputPhone.open();
        },
        load() {
            this.$request({
                url: "/cloud/getPlatformByAccout",
                data: {
                    accout: this.phone.trim()
                },
                method: "POST"
            }).then(res => {
                console.warn(res);
                this.list = res.data;
                this.$refs.inputPhone.close();
            });
        },
        cancel() {
            this.$refs.inputPhone.close();
        },
        onGetUserPhone(e) {
            console.warn(e);
            this.$request({
                url: "/org/wxxcx/getPhoneNum",
                data: {
                    code: e.detail.code,
                },
                method: "POST"
            }).then(res=>{
               let data = JSON.parse(res.data)
               this.phone = data.phoneNumber
               this.load()
            })
        }
    },
    onLoad() {
        // #ifdef MP-WEIXIN
        uni.hideHomeButton();
        // #endif
    }
};
</script>
<style lang='less'>
.platform {
    position: relative;
    z-index: 2;
    .platform-bg {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 320rpx;
        background: skyblue;
        z-index: -1;
    }
    .platform-title {
        padding: 40rpx 20rpx 0;
        font-size: 28rpx;
        color: #fff;
    }
    .platform-des {
        padding: 36rpx 20rpx 0;
        font-size: 24rpx;
        color: #fff;
    }
    .platform-content {
        padding: 28rpx 20rpx;
        font-size: 24rpx;
        margin-top: 60rpx;
        border-radius: 28rpx 28rpx 0 0;
        min-height: 50vh;
        background: #f5f6fa;
        .platform-content-card {
            margin-bottom: 20rpx;
            padding: 33rpx 28rpx;
            border-radius: 14rpx;
            background: #fff;
            .platform-content-card-title {
                font-weight: 600;
                font-size: 28rpx;
                color: #111;
            }
            .platform-content-card-des {
                font-size: 24rpx;
                margin-top: 23rpx;
                color: #999;
            }
        }
    }
    .platform-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        height: 280rpx;
        width: 100%;
        background: #fff;
        .platform-footer-tips {
            font-size: 28rpx;
            color: #000;
        }
    }
    .platform-footer-btn {
        margin: 0 auto;
        height: 80rpx;
        width: 480rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-top: 40rpx;
        background: #449dff;
        font-size: 24rpx;
        color: #fff;
        border-radius: 40rpx;
        overflow: hidden;
    }
    .input-box {
        box-sizing: border-box;
        padding: 80rpx 60rpx 0;
        height: 400rpx;
        width: 680rpx;
        border-radius: 16rpx;
        background: #fff;
        .input-box-main {
            box-sizing: border-box;
            height: 80rpx !important;
            line-height: 80rpx !important;
            border-radius: 4rpx;
            font-size: 28rpx;
            color: #333;
            padding: 0 40rpx;
            margin-top: 40rpx;
            background: #f9f9f9;
        }
        .input-box-btn {
            margin-top: 80rpx;
            display: flex;
            justify-content: center;
            .input-box-btn-item {
                height: 64rpx;
                width: 200rpx;
                background: #449dff;
                display: flex;
                justify-content: center;
                align-items: center;
                color: #fff;
                font-size: 24rpx;
                border-radius: 8rpx;
            }
            .input-box-btn-item:first-of-type {
                box-sizing: border-box;
                margin-right: 37rpx;
                background: #fff;
                border: 1px solid #666666;
                color: #666666;
            }
        }
    }
}
</style>