{"size": 3121, "ext": "js", "max_stars_repo_path": "mobile/web/weixin/src/js/pages/drift-lamp-result.js", "max_stars_repo_name": "qwelao7/afgj", "max_stars_repo_stars_event_min_datetime": "2016-05-11T09:50:54.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-11T09:50:57.000Z", "max_issues_repo_path": "mobile/web/weixin/src/js/pages/drift-lamp-result.js", "max_issues_repo_name": "qwelao7/afgj", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mobile/web/weixin/src/js/pages/drift-lamp-result.js", "max_forks_repo_name": "qwelao7/afgj", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 33.9239130435, "max_line_length": 102, "alphanum_fraction": 0.3854533803}
require('../../css/style.css');
require('../../css/index.css');
var common = require('../lib/common.js');

$(function () {
    'use strict';

    $(document).on("pageInit", "#drift-lamp-result", function (e, id, page) {
        var url = common.getRequest();

        var tpl     = $('#tpl').html(),
            content = $('#content');

        var headimgUrl;

        common.img();
        juicer.register('dateFormat', common.dateFormat);

        $('#back').live('click', function () {
            location.href = 'drift-lamp-index.html';
        });

        function loadData() {
            common.ajax('GET', '/light/light-detail', {'id': url.id}, true, function (rsp) {
                if (rsp.data.code == 0) {
                    var data = rsp.data.info,
                        html = juicer(tpl, data);

                    content.prepend(html);

                    headimgUrl = data.user.headimgurl;
                    
                    getConfig(headimgUrl);
                } else {
                    var template = "<h3 style='margin-top: 4rem;text-align: center;'>很抱歉,暂无数据</h3>";
                    content.prepend(template);
                }
            })
        }

        /**  获取微信配置 **/
        function getConfig(headimg) {
            common.ajax('POST', '/wechat/config', {href: window.location.href}, true, function (rsp) {
                if (rsp.data.code == 0) {
                    var data = rsp.data.info;
                    data = JSON.parse(data);
                    wx.config({
                        debug: false,
                        appId: data.appId,
                        timestamp: data.timestamp,
                        nonceStr: data.nonceStr,
                        signature: data.signature,
                        jsApiList: [
                            'checkJsApi',
                            'onMenuShareTimeline',
                            'onMenuShareAppMessage',
                        ]
                    });
                    wx.ready(function () {
                        var title = '我亲自动手检测了家里的灯光，简单又免费，你也可以试一下!';
                        var desc = '回来啦社区';
                        var imgUrl = headimg;
                        var link = location.href;
                        wx.onMenuShareAppMessage({
                            title: title, // 分享标题
                            desc: desc, // 分享描述
                            link: link, // 分享链接
                            imgUrl: imgUrl, // 分享图标
                            type: '', // 分享类型,music、video或link，不填默认为link
                            dataUrl: '' // 如果type是music或video，则要提供数据链接，默认为空
                        });
                        wx.onMenuShareTimeline({
                            title: title, // 分享标题
                            link: link, // 分享链接
                            imgUrl: imgUrl, // 分享图标
                        });
                    });
                } else {
                    $.alert('获取配置信息失败!');
                }
            })
        }

        loadData();

        var pings = env.pings;pings();

    });

    $.init();
});
