<template>
    <div class="page">
        <!--    <button @click="postmsg">模拟激活成功</button>-->
        <div class="box">
            <button @click="informationReturn">短验用户信息回传</button>
            <button @click="ordersync">推送订购关系数据</button>
        </div>

    </div>
</template>

<script>
    import { postOrdersync, postInformationReturn } from '../../src/api'
    export default {
        name: "linshi",
        mounted() {
            window.addEventListener('message', res => {
                if (res.data.type === "onOK" || res.data.type === "onBuy" || res.data.type === "onActive") {
                    alert(res.data.type + ':' + res.data.data.userid)
                }
            }, false);
        },
        methods: {
            // 模拟弹窗
            postmsg() {
                let iframe = window.document.getElementById('iframe')
                iframe.contentWindow.postMessage({
                    type: 'onBuyCallback',
                    data: {
                        status: 999,
                        msg: '错误信息'
                    }
                }, '*')
            },

            // 推送订购关系数据
            ordersync() {
                console.log('/ordersync')
                postOrdersync({
                    "area": "",
                    "cancelchannel": "",
                    "canceltime": "",
                    "cpid": "0000",
                    "endtime": "",
                    "orderchannel": "",
                    "ordertime": "",
                    "province": "",
                    "spid": "",
                    "type": "",
                    "userid": ""
                }).then(res=>{
                    alert(res.message)
                }).catch(error=>{
                    alert(error.errorinfo)
                })
            },

            // 推送订购关系数据
            informationReturn() {
                postInformationReturn({
                    "AUTH_NO": "00000000",
                    "PRODUCT_ID": "00000000",
                    "PRODUCT_NAME": "00000000",
                    "SEQUENCE_ID": "00000000",
                    "SERVICE_ID": "00000000",
                    "TARGET_CODE": "00000000"
                }).then(res=>{
                    alert(res.MSG)
                }).catch(error=>{
                    alert(error.MSG)
                })
            }
        }
    }
</script>

<style lang="scss" scoped>
    .page {
        margin-top: 10%;

        .box {
            width: 100%;
            margin-top: 30px;
            display: flex;
            justify-content: space-around;
        }

        iframe {
            height: 80vh;
            width: 750px;
        }
    }
</style>
