(function NativeAppInit() {
    window.device = {};
    var ua = navigator.userAgent.toLocaleLowerCase();
    device.isWX = ua.match(/micromessenger/i) == 'micromessenger';
    device.isIOS = ua.match(/iphone os/i) == 'iphone os'
    device.isAndroid = ua.match(/android/i) == 'android';
    window.NativeApp = {
        // 分享图片或连接到微信朋友圈
        /*
        {
            "share_img":1/0,                        [是否分享为图片,若是图片,只需要传b64、否则其他参数都需要，没有为空 即""]
            "b64":"data:image/png;base64,xxxxx",    [被分享的图片的base64编码]
            "title":"分享的主标题",
            "subtitle":"分享的子标题"
            "url":"分享的连接",
            "thumb":"http://xxxxxx.png"
        }
         */
        share2wxTimlineFunc: function (info) {
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "share2wxTimlineFunc", "param": info });
            } else {
                jssdk.share2wxTimlineFunc(JSON.stringify(info));
            }
        },

        // 分享图片或连接到微信好友
        /*
        {
            "share_img":1/0,                        [是否分享为图片,若是图片,只需要传b64、否则其他参数都需要，没有为空 即""]
            "b64":"data:image/png;base64,xxxxx",    [被分享的图片的base64编码]
            "title":"分享的主标题",
            "subtitle":"分享的子标题"
            "url":"分享的连接",
            "mppath":"微信小程序的路径",
            "thumb":"http://xxxxxx.png"
        }
         */
        share2wxFriendFunc: function (info) {
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "share2wxFriendFunc", "param": info });
            } else {
                jssdk.share2wxFriendFunc(JSON.stringify(info));
            }
        },
        // 保存图片
        /*
         {
            "b64":"data:image/png;base64,xxxxx",    [图片的base64编码]
         }
         */
        saveImg2AlbumFunc: function (info) {
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "saveImg2AlbumFunc", "param": info });
            } else {
                jssdk.saveImg2AlbumFunc(JSON.stringify(info));
            }
        },

        // 隐藏导航栏
        hiddenNavBarFunc: function (info) {
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "hiddenNavBarFunc", "param": info });
            } else {
                jssdk.hiddenNavBarFunc(JSON.stringify(info));
            }
        },

        // 进入小程序
        loadMiniProgramPageFunc: function (info) {
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadMiniProgramPageFunc", "param": info });
            } else {
                jssdk.loadMiniProgramPageFunc(JSON.stringify(info));
            }
        },
        // {}
        loadLoginPage: function (info) { //进入登录页面
            info = info || {};
            if (device.isIOS) {
                return window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadLoginPage", "param": info });
            } else {
                return jssdk.loadLoginPage(JSON.stringify(info));
            }
        },
        // {activity_id}
        loadLotteryGoodsListPage: function (info) { //进入抽奖相关的商品列表奖品
            info = info || {};
            if (device.isIOS) {
                return window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadLotteryGoodsListPage", "param": info });
            } else {
                return jssdk.loadLotteryGoodsListPage(JSON.stringify(info));
            }
        },
        // {
        //    id_str,按ids收索
        // activity_id, 活动id
        // }
        loadPrizeListPage: function (info) { //进入我的奖品
            info = info || {};
            if (device.isIOS) {
                return window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadPrizeListPage", "param": info });
            } else {
                return jssdk.loadPrizeListPage(JSON.stringify(info));
            }
        },
        //  {
        //  "order_id":""//订单id
        //  }
        loadOrderDetail: function (info) { //订单详情
            info = info || {};
            if (device.isIOS) {
                return window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadOrderDetail", "param": info });
            } else {
                return jssdk.loadOrderDetail(JSON.stringify(info));
            }
        },
        //  {
        //  "title":""//标题
        //  "subtitle":""//描述
        //  "thumb":""//缩略图
        //  "content":""//url
        //  "mppath":""//小程序的路劲
        //  }
        showSharePanelFunc: function (info) { //显示分享面板
            info = info || {};
            if (device.isIOS) {
                return window.webkit.messageHandlers.jssdk.postMessage({ "func": "showSharePanelFunc", "param": info });
            } else {
                return jssdk.showSharePanelFunc(JSON.stringify(info));
            }
        },

        popCurrentVCFunc: function (info) { //原生页面退出/返回上一页【从右往左】
            info = info || {};
            if (device.isIOS) {
                return window.webkit.messageHandlers.jssdk.postMessage({ "func": "popCurrentVCFunc", "param": info });
            } else {
                return jssdk.popCurrentVCFunc(JSON.stringify(info));
            }
        },
        getUserInfoFunc: function (info) { //获取用户信息
            info = info || {};
            if (device.isIOS) {
                return window.webkit.messageHandlers.jssdk.postMessage({ "func": "getUserInfoFunc", "param": info });
            } else {
                return jssdk.getUserInfoFunc(JSON.stringify(info));
            }
        },
        getUserTokenFunc: function (info) { //获取用户token
            info = info || {};
            if (device.isIOS) {
                return window.webkit.messageHandlers.jssdk.postMessage({ "func": "getUserTokenFunc", "param": info });
            } else {
                return jssdk.getUserTokenFunc(JSON.stringify(info));
            }
        },
        accountLogouFunc: function (info) { //用户注销
            info = info || {};
            if (device.isIOS) {
                return window.webkit.messageHandlers.jssdk.postMessage({ "func": "accountLogouFunc", "param": info });
            } else {
                return jssdk.accountLogouFunc(JSON.stringify(info));
            }
        },
        loadGoodsDetailFunc: function (info) { //跳转商品详情
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadGoodsDetailFunc", "param": info });
            } else {
                jssdk.loadGoodsDetailFunc(JSON.stringify(info));
            }
        },
        loadHomePageFunc: function (info) { //跳转首页
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadHomePageFunc", "param": info });
            } else {
                jssdk.loadHomePageFunc(JSON.stringify(info));
            }
        },
        loadCategoryPageFunc: function (info) { //跳转分类页
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadCategoryPageFunc", "param": info });
            } else {
                jssdk.loadCategoryPageFunc(JSON.stringify(info));
            }
        },
        showShareViewFunc: function (info) { //显示分享面板
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "showShareViewFunc", "param": info });
            } else {
                jssdk.showShareViewFunc(JSON.stringify(info));
            }
        },

        loadPayViewFunc: function (info) {
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadPayViewFunc", "param": info });
            } else {
                jssdk.showShareViewFunc(JSON.stringify(info));
            }
        },


        //------------------------2.0---------------------------------------------
        loadGoodsDetailFunc: function (info) { //商品详情
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadGoodsDetailFunc", "param": info });
            } else {
                jssdk.loadGoodsDetailFunc(JSON.stringify(info));
            }

        },
        loadCallCenterPageFunc: function (info) { //客服
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadCallCenterPageFunc", "param": info });
            } else {
                jssdk.loadCallCenterPageFunc(JSON.stringify(info));
            }

        },
        loadCategoryPageFunc: function (info) { //分类
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadCategoryPageFunc", "param": info });
            } else {
                jssdk.loadCategoryPageFunc(JSON.stringify(info));
            }

        },
        loadGetCouponPageFunc: function (info) { //获取优惠券
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadGetCouponPageFunc", "param": info });
            } else {
                jssdk.loadGetCouponPageFunc(JSON.stringify(info));
            }

        },
        loadMyOrderPageFunc: function (info) {
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadMyOrderPageFunc", "param": info });
            } else {
                jssdk.loadMyOrderPageFunc(JSON.stringify(info));
            }

        },
        loadMyCollectionPageFunc: function (info) {
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadMyCollectionPageFunc", "param": info });
            } else {
                jssdk.loadMyCollectionPageFunc(JSON.stringify(info));
            }

        },
        loadHomePageFunc: function (info) {
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadHomePageFunc", "param": info });
            } else {
                jssdk.loadHomePageFunc(JSON.stringify(info));
            }

        },
        loadSharePageFunc: function (info) {
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadSharePageFunc", "param": info });
            } else {
                jssdk.loadSharePageFunc(JSON.stringify(info));
            }

        },
        loadLastPageFunc: function (info) {
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadLastPageFunc", "param": info });
            } else {
                jssdk.loadLastPageFunc(JSON.stringify(info));
            }

        },
        loadAccountExitFunc: function (info) {
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadAccountExitFunc", "param": info });
            } else {
                jssdk.loadAccountExitFunc(JSON.stringify(info));
            }

        },
        loadAccountLogoutFunc: function (info) {
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadAccountLogoutFunc", "param": info });
            } else {
                jssdk.loadAccountLogoutFunc(JSON.stringify(info));
            }

        },
        getNativeUserInfoFunc: function (info) {
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "getNativeUserInfoFunc", "param": info });
            } else {
                jssdk.getNativeUserInfoFunc(JSON.stringify(info));
            }

        },
        loadPayPageFunc: function (info) {
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadPayPageFunc", "param": info });
            } else {
                jssdk.loadPayPageFunc(JSON.stringify(info));
            }
        },

        loadSearchPageFunc: function (info) {
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadSearchPageFunc", "param": info });
            } else {
                jssdk.loadSearchPageFunc(JSON.stringify(info));
            }
        },
        loadShoppingCarPageFunc: function (info) {
            info = info || {};
            if (device.isIOS) {
                window.webkit.messageHandlers.jssdk.postMessage({ "func": "loadShoppingCarPageFunc", "param": info });
            } else {
                jssdk.loadShoppingCarPageFunc(JSON.stringify(info));
            }
        },

        setBgColorFunc: function (color) {
                    color = color || "#ffffff";
                    info = {color};
                    if (device.isIOS) {
                        window.webkit.messageHandlers.jssdk.postMessage({ "func": "setBgColorFunc", "param": info });
                    } else {
                        jssdk.setBgColorFunc(JSON.stringify(info));
                    }
                }
    }
})()