/**
* v_wifiAddHelp.js
* Version: 0.1
* User: wy
* Date: 2017-09-07
* Copyright(c)  2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
* 配置Wi-Fi页面
*/

import {iot, uPublic, uComponents} from '../../public/public.js';

iot.ready(init);
function init() {
    //通用 按钮、dialog、loading组件
    uPublic.componentsInit(['u-button','u-dialog','u-loading']);
	let opener = plus.webview.currentWebview().opener();
	if(opener.id == 'scanCodeAdd'){
		setTimeout(function () {
			plus.webview.close(opener,"none",0,{});
		}, 500);
	}
    const app = new Vue({
        data:{            
            //配置组件
            componentsConfig: initComponentsConfig(),
            extras: {}
        },
        mounted(){      
        	this.extras = iot.navigator.getExtras();
        	window.addEventListener('returnPage',function(event){
				console.log("stopFindDevice");
				iot.business.sds.stopFindDevices({
				    success: (response) => {
				    	console.log(response);
				    },
				    error: (error) => {
				    	console.log(error);
				    }
				});
			});
        },
        methods:{
            //tap <
            onBackTap(){
                backTap();
            },
            //tap 开始配置Wi-Fi
            onWifiAddButtonTap(){
                wifiAddButtonTap(this);   
            }                
        }   
    }).$mount('#app');
}

//配置组件参数
function initComponentsConfig() {
    return {
        //开始配置Wi-Fi button 参数
        wifiAddButton: {   
            initParam: {
                class: 'custom-help-button',
                text: Vue.t('btn.wifiAdd')
            }
        },
        dialog: {
            initParam: {
                class: 'custom-dialog'
            }
        },
        loading: {
            initParam: {
                class: 'custom-loading'
            }
        }                
    }
}

//tap <
function backTap(){
    iot.navigator.back();
}

//tap 开始配置Wi-Fi
function wifiAddButtonTap(self){
    iot.navigator.openWindow({
        url: './wifiAdd.html',
        id: 'wifiAdd',
        extras: {
        	productId: self.extras.productId
        }
    });  
}