/* * 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园(http://www.learun.cn) 
 * Copyright (c) 2013-2018 北京泉江科技有限公司 
 * 创建人：超级管理员
 * 日  期：2020-04-21 09:23
 * 描  述：扫码入教学楼统计
 */
(function () {
    var page = {
        grid: null,
        init: function ($page) {




            var ua = navigator.userAgent.toLowerCase();
            if (/(html5plus)/i.test(ua)) {
                //if (false) {
                $('.bcidBox').css('display', 'block');
                var scan = new plus.barcode.Barcode('bcid');
                scan.onmarked = function onmarked(type, result) {
                    scan.close();
                    $('.bcidBox').css('display', 'none');

                    var loginInfo = learun.storage.get('userinfo');
                    var buildEntity = {};
                    buildEntity.SId = loginInfo.baseinfo.account;

                    buildEntity.BId = result;//'1d13cb80-d66a-4c55-a633-f88dc0b80df7';

                    var param = {};
                    param.keyValue = '';
                    param.strEntity = JSON.stringify(buildEntity);


                    learun.layer.loading(true, '正在提交数据');
                    learun.httppost(config.webapi + 'learun/EducationalAdministration/R_EnterBuilding/save', param, (data) => {
                        learun.layer.loading(false);
                        if (data) {// 表单数据保存成功
                            learun.layer.toast("扫描成功");
                            learun.nav.closeCurrent();
                            //var prepage = learun.nav.getpage('EducationalAdministration/R_EnterBuilding');
                            //prepage.grid.reload();
                        }
                    });
                };
                scan.start();
            } else if (/micromessenger/.test(ua)) {
                $.ajax({
                    url: config.webapi + "weixinapi/getweixinwebaccess_token?url=" + encodeURIComponent(window.location.href),
                    type: "get",
                    success: function (res) {
                        wx.config({
                            debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                            appId: res.data.appid, // 必填，公众号的唯一标识
                            timestamp: res.data.timestamp, // 必填，生成签名的时间戳
                            nonceStr: res.data.noncestr, // 必填，生成签名的随机串
                            signature: res.data.certificate, // 必填，签名
                            jsApiList: ["scanQRCode"] // 必填，需要使用的JS接口列表
                        });

                        wx.ready(function () {
                            wx.scanQRCode({
                                needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
                                scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码，默认二者都有
                                success: function (res) {
                                    learun.layer.toast(res);
                                    //res.resultStr
                                    var loginInfo = learun.storage.get('userinfo');
                                    var buildEntity = {};
                                    buildEntity.SId = loginInfo.baseinfo.account;

                                    buildEntity.BId = res.resultStr;//'1d13cb80-d66a-4c55-a633-f88dc0b80df7';

                                    var param = {};
                                    param.keyValue = '';
                                    param.strEntity = JSON.stringify(buildEntity);


                                    learun.layer.loading(true, '正在提交数据');
                                    learun.httppost(config.webapi + 'learun/EducationalAdministration/R_EnterBuilding/save', param, (data) => {
                                        learun.layer.loading(false);
                                        if (data) {// 表单数据保存成功
                                            learun.layer.toast("扫描成功");
                                            learun.nav.closeCurrent();
                                            //var prepage = learun.nav.getpage('EducationalAdministration/R_EnterBuilding');
                                            //prepage.grid.reload();
                                        }
                                    });
                                }
                            });
                        })


                    }
                });


            } else {
                learun.layer.warning('请下载app或者到微信浏览器打开网页');
            }
        }
    };
    return page;
})();
