common.js 25 KB
Newer Older
txy committed
1 2

// 公共变量
txy committed
3
var activityCode = typeof rules !== 'undefined' ? rules.acActivity.code : '';
4 5
var baseUrl = window.location.href.indexOf("test") > 0 ? "https://space-api.check.icaremgt.com" : "http://space-api.icaremgt.com";
var manageUrl = window.location.href.indexOf("test") > 0 ? "https://test.icareyou.net" : "http://www.icareyou.net";
txy committed
6

txy committed
7 8 9
// 防止投票连点
var gb_vote_loaded = false

txy committed
10 11 12
if(typeof data !== 'undefined'){
  data.htmlJson = JSON.parse(data.htmlJson);
}
txy committed
13

14 15 16 17
// 分享用户信息
var shareUserId = '';
var shareUserName = '';

txy committed
18 19 20 21 22 23 24 25 26
// 设置token
function setToken(){
  if(user.token !== '') {
    sessionStorage.setItem('x-token', user.token);
  }else {
    sessionStorage.setItem('x-token', '');
  }
}

胡畅 committed
27 28 29 30 31 32 33 34 35 36 37 38
// 机构id
function orgIdFn(id) {
    var signupOrg = rules.acActivityOrgs
    var org = signupOrg && signupOrg.filter(function(item){
        return id == item.id
    })
    if(org.length == 1) {
        return org[0]
    }else {
        return null
    }
}
txy committed
39 40
// 获取token
function getToken() {
txy committed
41 42 43
  // var t = sessionStorage.getItem('x-token');
  // return t
  return user.token
txy committed
44 45
}

txy committed
46 47
// 获取域名及二级目录
function getBaseOrigin(){
txy committed
48
  var _base = '';
txy committed
49 50 51 52
  var _origin = window.location.origin;
  var _pathname = window.location.pathname;
  var index = _pathname.indexOf('/ACTIVITY');
  var _secondFolder = '';
txy committed
53 54
  
  if(index !== 0){
txy committed
55
      _secondFolder = _pathname.slice(0,index);
txy committed
56
  }
txy committed
57
  _base = _origin + _secondFolder;
txy committed
58 59 60 61 62 63 64 65

  return _base;
}

// 页面跳转
function transPage(_pageNumber, _activityCode, _token, _addParam) {
  var url = '';
  var _base = '';
66 67
  var _urlParam = getRequest();
  var _newUrlParam = '';
txy committed
68
  _base = getBaseOrigin();
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94

  // 报名页之外的页面过滤url参数-userId
  if(_pageNumber !== '2'){
    // 移除userId参数
    delete _urlParam.userId;
    var flag = false;
    if(!$.isEmptyObject(_urlParam)){
      for(var key in _urlParam){
        // 第一次进入
        if(!flag){
          _newUrlParam += '?'+key+'='+_urlParam[key];
          flag = true;
        }else { 
          _newUrlParam += '&'+key+'='+_urlParam[key];
        }
      }
    }else {
      _newUrlParam = '';
    }
  }else {
    // 报名页面正常携带参数
    _newUrlParam = window.location.search;
  }

  if (typeof _newUrlParam !== 'undefined' && _newUrlParam !== '') {
      url = _base + "/ACTIVITY/view/" + _activityCode + "/" + _pageNumber + _newUrlParam + (_addParam !== undefined ? ('&' + _addParam) : '');
txy committed
95
  } else {
txy committed
96
      url = _base + "/ACTIVITY/view/" + _activityCode + "/" + _pageNumber + (_addParam !== undefined ? ('?' + _addParam) : '');
txy committed
97 98
  }

txy committed
99 100 101 102
  // var _form = document.createElement('form');
  // _form.action = url;
  // _form.method = "post";
  // _form.style.display = "none";
txy committed
103

txy committed
104 105 106 107 108 109
  // var inputToken = document.createElement('input');
  // inputToken.value = _token;
  // inputToken.name = 'x-token';
  // _form.appendChild(inputToken);
  // document.body.appendChild(_form);
  // _form.submit();
110 111 112 113 114 115

  // 活动页面内返回到首页不显示广告
  if(_pageNumber === '1' && url.indexOf('noshowad=1') === -1) {
    url = url + '&noshowad=1';
  }

txy committed
116
  window.location.href = url;
txy committed
117 118 119 120 121 122 123 124 125 126 127 128
}

// 获取URL中指定参数
function getQueryString(name) {
  var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  var r = window.location.search.substr(1).match(reg);
  if (r != null) {
      return unescape(r[2]);
  }
  return null;
}

129 130 131 132 133 134 135 136 137 138 139 140 141 142
// 获取url所有参数
function getRequest() {
  var url = window.location.search; //获取url中"?"符后的字串
  var theRequest = new Object();
  if (url.indexOf("?") != -1) {
    var str = url.substr(1);
    strs = str.split("&");
    for(var i = 0; i < strs.length; i ++) {
      theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
    }
  }
  return theRequest;
}

txy committed
143

txy committed
144
// 加载HTML结构
谭新宇 committed
145
function loadHtmlJson(callback) {
txy committed
146
  $('body').prepend(json2html(data.htmlJson));
txy committed
147
  var _relationship = JSON.parse(data.relationship);
txy committed
148 149 150 151 152 153
  for(var i=0;i<_relationship.childs.length;i++) {
      var _page = _relationship.childs[i].page
      var _pageNumber = _relationship.childs[i].pageNumber
      $('body').prepend(json2html(JSON.parse(data[_page].htmlJson)));
      $('#html-template-'+_pageNumber).addClass('global-none')
  }
谭新宇 committed
154
  callback && callback()
txy committed
155 156
}

txy committed
157 158
// 获取机构名称
function getOrgNameFn(callback) {
txy committed
159 160
  // var signupId = getQueryString('orgId')
  // var orgId = orgIdFn(signupId).orgId
谭新宇 committed
161 162 163 164 165 166

  // 判断是否需要机构名称
  if(rules.acActivityOrgs.length === 0) {
    return
  }

txy committed
167
  var orgId = getQueryString('orgId')
谭新宇 committed
168 169 170 171 172
  var authId = getQueryString('auth_id')
  var _header = {
    'x-token': getToken()
  }
  if(authId !== null) {
谭新宇 committed
173
    _header['auth-id'] = authId
谭新宇 committed
174 175
  } 

txy committed
176 177 178
  $.ajax({
      type: 'GET',
      url: baseUrl + '/ORG/hospital/community/hospitalInfo/' + orgId,
谭新宇 committed
179
      headers: _header,
txy committed
180 181 182 183 184
      success: function(data) {
          if(data.code == 200) {
            callback && callback(data)
          }
      },
txy committed
185
      error: function(data) {
txy committed
186
          $.dialog({
txy committed
187 188
            type : 'tips',
            autoClose : 3000,
txy committed
189
            infoText : data.responseJSON.message
txy committed
190
        });
txy committed
191 192 193 194
      }
  })
}

胡畅 committed
195
function showQrcode(callback) {
txy committed
196
  var orgId = getQueryString("orgId");
胡畅 committed
197
  var activityCode = getQueryString("activityCode");
txy committed
198 199 200
  var orgQrCode = '';

  for(var k = 0; k < rules.acActivityOrgs.length; k++){
txy committed
201
    if(rules.acActivityOrgs[k].orgId == orgId){
txy committed
202 203 204 205
      orgId = rules.acActivityOrgs[k].orgId;
      orgQrCode = rules.acActivityOrgs[k].qrCodeUrl;
      break;
    }
txy committed
206
  }
txy committed
207

谭新宇 committed
208 209 210 211 212
  var authId = getQueryString('auth_id')
  var _header = {
    'x-token': getToken()
  }
  if(authId !== null) {
谭新宇 committed
213
    _header['auth-id'] = authId
谭新宇 committed
214 215
  } 

胡畅 committed
216 217 218 219 220
  if(orgQrCode == '') {
    var baseurlCode = orgId ? (baseUrl + '/ACTIVITY/' + activityCode + '/qr-code-url?orgId=' + orgId) : (baseUrl + '/ACTIVITY/' + activityCode + '/qr-code-url')
      $.ajax({
        type: 'GET',
        url: baseurlCode,
谭新宇 committed
221
        headers: _header,
胡畅 committed
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
        success: function(data) {
            if(data.status == 200) {
              orgQrCode = data.result.qrCodeUrl
              callback && callback(orgQrCode)
            }
        },
        error: function(data) {
            $.dialog({
              type : 'tips',
              autoClose : 3000,
              infoText : data.responseJSON.message
          });
        }
    })
  }else {
    callback && callback(orgQrCode)
  }
}

// 关注弹出框
function appendAttentionDialog() {
  showQrcode(function(orgQrCode){
    var str = '<section id="html-container-attention" style="display: none;">'+
      '<div>'+
        '<div class="c-modal-wrap">'+
          '<div class="mshe-mask"></div> '+
          '<div class="c-modal">'+
            '<div class="modal-dialog">'+
              '<div c_type="dialog" c_typename="dialog_playerVote1" class="modal-content" style="background: rgb(255, 255, 255);">'+
              '<div class="modal-header">'+
                '<img src="http://qnfile.icareyou.net/363a344aa7424d219a5fc86eff7265751561343712294.jpg" class="header-pic">'+
              '</div>'+ 
              '<div class="modal-body">'+
谭新宇 committed
255
                '<p class="struct">长按后继续活动</p>'+
胡畅 committed
256 257
                '<div>'+
                  '<img src="'+ orgQrCode +'" alt="" style="width: 100%;">'+
txy committed
258 259
                '</div>'+
              '</div>'+
胡畅 committed
260 261 262 263 264 265 266 267 268
              '<div class="modal-close">'+
                '<img src="http://qnfile.icareyou.net/ddae57885c424abdb13d37c78038c6a01561343787282.jpg">'+
              '</div>'+
              '</div>'+
            '</div>'+
          '</div>'+
        '</div>'+
      '</div>'+
    '</section>';
txy committed
269

胡畅 committed
270
    $('body').prepend(str);
txy committed
271

胡畅 committed
272 273 274 275
     // 事件绑定
    $("#html-container-attention .modal-close").off("click").on("click", function(){
      $("#html-container-attention").fadeOut();
    });
txy committed
276

胡畅 committed
277 278
    // 获取机构名称
    getOrgNameFn(function(data){
谭新宇 committed
279
      var orgName = '长按'+  data.records.orgName +'后继续活动';
胡畅 committed
280
      $('#html-container-attention .modal-body .struct').text(orgName);
txy committed
281
    });
胡畅 committed
282 283 284 285 286 287 288 289 290 291

    // 未关注过默认显示弹出框  
    if (!user.attention){
      $("#html-container-attention").fadeIn('normal', function() {
        // $(document).scrollTop(0);
      });
    }
    
  })
   
txy committed
292 293
}

txy committed
294 295
// 显示强关弹出框
function showAttentionDialog() {
txy committed
296
  $("#html-container-attention").fadeIn('normal', function() {
297
    // $(document).scrollTop(0);
txy committed
298
  });
txy committed
299
}
txy committed
300

txy committed
301 302 303 304 305 306 307
// 隐藏强关弹出框
function hideAttentionDialog() {
  $("#html-container-attention").hide();
}

// 不在审核页面插入强关弹出框
if(typeof user !== 'undefined' && $("#examineTitle").length === 0){
txy committed
308 309
  appendAttentionDialog();
}
txy committed
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324

// 判断是否关注
function isAttention(successCallback,errorCallback) {
  // 未关注
  if(!user.attention){
    if(errorCallback) {
      errorCallback();
    }else {
      // 强关弹出框
      showAttentionDialog();
    }
  } else {
    successCallback && successCallback();
  }
}
txy committed
325

txy committed
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
// 是否报名
function isSignUp(successCallback,errorCallback) {
  var _t = getToken();
  // 已报名
  if(user.reviewStatus !== '') {
      switch (user.reviewStatus) {
          // 0-待审核
          case 0:
              alert('您的报名信息正在审核中...');
          break;
          // 1-审核通过
          case 1:
            if(successCallback){
              successCallback();
            }else {
              alert('您当前已通过报名,请到个人主页去拉票!');
            }
          break;
          // 2-审核未通过
          case 2:
              alert('审核未通过!');
              transPage('2',activityCode,_t);
          break;
          default:
              break;
      }
  } else {// 未报名
    if(errorCallback) {
      errorCallback();
    }else {
      // 跳转到报名页面 
      transPage('2',activityCode,_t);
    }
  }
txy committed
360 361 362 363 364 365 366 367
}

// 获取活动名称
function getActivityTitle() {
  var activityCode = getQueryString('activityCode');
  var params = {
    activityCode: activityCode
  }
谭新宇 committed
368 369 370 371 372 373

  var authId = getQueryString('auth_id')
  var _header = {
    'x-token': getToken()
  }
  if(authId !== null) {
谭新宇 committed
374
    _header['auth-id'] = authId
谭新宇 committed
375 376
  } 

txy committed
377 378 379 380
  $.ajax({
      type: 'GET',
      url: baseUrl + '/ACTIVITY/'+ activityCode +'/settings',
      data: params,
谭新宇 committed
381
      headers: _header,
txy committed
382 383 384 385
      success: function(data) {
          if(data.status == 200) {
            var title = data.result.settings.szText.h5Title;
            document.title = title;
txy committed
386

387
            // JS动态修改微信浏览器中的title
txy committed
388
            var $body = $('body');
389
            var $iframe = $('<iframe src="" style="display:none;"></iframe>');
txy committed
390 391 392 393 394
            $iframe.on('load',function() {
              setTimeout(function() {
                  $iframe.off('load').remove();
              }, 0);
            }).appendTo($body);
txy committed
395 396 397 398 399 400 401 402 403 404
          }
      },
      error: function() {
          $.dialog({
              type : 'tips',
              autoClose : 3000,
              infoText : '请求超时,请尝试刷新页面!'
          });
      }
  })
txy committed
405 406
}

txy committed
407
// 加载loading
txy committed
408
function showLoading(msg){
txy committed
409 410
  $.dialog({
    type : 'info',
txy committed
411
    infoText : msg ? msg : '加载中…',
谭新宇 committed
412
    infoIcon : 'http://qnfile.icareyou.net/427df437f5364507bc000988070e50511572340309108?imageMogr2/size-limit/100k',
txy committed
413 414 415 416 417
    direction: '',
	  align: 'center'
  });
}
// 关闭loading
txy committed
418 419
function hideLoading(callback) {
  $.dialog.close(callback);
txy committed
420 421
}

txy committed
422 423 424 425 426 427 428 429 430
/* ***********************弹出框控制全部逻辑************************** */
// 投票
function voteClickFn(params, successCallback, errorCallback){ 

  if(gb_vote_loaded) {
    return
  }
  gb_vote_loaded = true;

431 432 433
  shareUserId = params.userId;
  shareUserName  = params.userName;
  
谭新宇 committed
434 435 436 437 438
  var authId = getQueryString('auth_id')
  var _header = {
    'x-token': getToken()
  }
  if(authId !== null) {
谭新宇 committed
439
    _header['auth-id'] = authId
谭新宇 committed
440 441
  }

txy committed
442 443 444 445
  $.ajax({
    type: 'PUT',
    url: baseUrl + '/ACTIVITY/sz/vote/' + activityCode,
    data: params,
谭新宇 committed
446
    headers: _header,
txy committed
447
    success: function(data) {
txy committed
448
        
txy committed
449 450 451 452
        if(data.status == 200) {
          // 已报名-通过审核
          if(user.reviewStatus === 1) {
            $('#html-template-4 .struct span').text(data.result.voteNumDay)
txy committed
453
            $('#html-template-4').fadeIn('normal', function() {
454
              // $(document).scrollTop(0);
txy committed
455
            });
txy committed
456 457
          }else {
            $('#html-template-6 .struct span').text(data.result.voteNumDay)
txy committed
458
            $('#html-template-6').fadeIn('normal', function() {
459
              // $(document).scrollTop(0);
txy committed
460
            });
txy committed
461 462
          }
          successCallback && successCallback(data); 
txy committed
463
          hideLoading();
txy committed
464 465 466 467
        }else if(data.status == 201) {
          // 已报名-通过审核
          if(user.reviewStatus === 1) {
            $('#html-template-5 .struct span').text(rules.settings.szRule.voteNumDay)
txy committed
468
            $('#html-template-5').fadeIn('normal', function() {
469
              // $(document).scrollTop(0);
txy committed
470
            });
txy committed
471 472
          }else {
            $('#html-template-7 .struct span').text(rules.settings.szRule.voteNumDay)
txy committed
473
            $('#html-template-7').fadeIn('normal', function() {
474
              // $(document).scrollTop(0);
txy committed
475
            });
txy committed
476 477
          }
          errorCallback && errorCallback(data); 
txy committed
478
          hideLoading();
txy committed
479
        }else {
txy committed
480 481

          hideLoading(function(){
txy committed
482 483
            // 异常处理
            $.dialog({
txy committed
484
              contentHtml : '<p style="text-align:center;">'+ data.message +'</p>'
txy committed
485
            });
txy committed
486
          });
txy committed
487 488 489 490
        }
        gb_vote_loaded = false;
    },
    error: function(data){
txy committed
491 492 493
        hideLoading(function(){
          // 异常处理
          $.dialog({
txy committed
494
            contentHtml : '<p style="text-align:center;">'+ data.responseJSON.message +'</p>'
txy committed
495
          });
txy committed
496
        });
txy committed
497
                
txy committed
498 499 500
        gb_vote_loaded = false;
    }
  });
txy committed
501 502 503 504 505 506 507 508 509 510 511 512
}

// 参赛选手投票-有票
function playerHasVoteDialogBind(){
  // 继续投票
  $('#html-template-4 .vote-btn-1').off("click").on('click',function(){
      $('#html-template-4').fadeOut();
  });

  // 我要拉票
  $('#html-template-4 .vote-btn-2').off("click").on('click',function(){
      $('#html-template-4').hide();
txy committed
513 514 515
      $('#html-template-8').fadeIn('normal', function() {
        $(document).scrollTop(0);
      });
516 517 518 519 520
      // 设置分享参数
      setWxShare({
        userId: shareUserId,
        userName: shareUserName
      });
txy committed
521 522 523 524 525 526 527 528 529 530
  });

  // 关闭按钮
  $('#html-template-4 .modal-close').off("click").on('click',function(){
      $('#html-template-4').fadeOut();
  });
}

// 参赛选手投票-无票
function playerNoVoteDialogBind(){
txy committed
531
  // 查看排行
txy committed
532 533
  $('#html-template-5 .vote-btn-1').off("click").on('click',function(){
      $('#html-template-5').fadeOut();
txy committed
534 535 536 537 538 539 540 541 542 543 544
      var _url = window.location.href;
      var indexKey = 'view/'+ activityCode + '/1';
      // 当前是首页则触发切换按钮
      if(_url.indexOf(indexKey) > -1){
        $("#act3152823482970").click();
      }else {
        // 当前非首页则跳转
        var _t = getToken();
        var _addParam = 'toRanger=1'
        transPage('1',activityCode,_t,_addParam);
      }
txy committed
545 546 547 548 549
  });

  // 我要拉票
  $('#html-template-5 .vote-btn-2').off("click").on('click',function(){
      $('#html-template-5').hide();
txy committed
550 551 552
      $('#html-template-8').fadeIn('normal', function() {
        $(document).scrollTop(0);
      });
553 554 555 556 557
      // 设置分享参数
      setWxShare({
        userId: shareUserId,
        userName: shareUserName
      });
txy committed
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
  });

  // 关闭按钮
  $('#html-template-5 .modal-close').off("click").on('click',function(){
      $('#html-template-5').fadeOut();
  });
}

// 投票者-有票
function visitorHasVoteDialogBind(){
  // 继续投票
  $('#html-template-6 .vote-btn-1').off("click").on('click',function(){
      $('#html-template-6').fadeOut();
  });

  // 我要拉票
  $('#html-template-6 .vote-btn-2').off("click").on('click',function(){
      $('#html-template-6').hide();
txy committed
576 577 578
      $('#html-template-8').fadeIn('normal', function() {
        $(document).scrollTop(0);
      });
579 580 581 582 583
      // 设置分享参数
      setWxShare({
        userId: shareUserId,
        userName: shareUserName
      });
txy committed
584 585 586 587 588 589 590 591 592 593 594 595 596
  });

  // 关闭按钮
  $('#html-template-6 .modal-close').off("click").on('click',function(){
      $('#html-template-6').fadeOut();
  });
}

// 投票者-无票
function visitorNoVoteDialogBind(){
  // 我要参赛
  $('#html-template-7 .vote-btn-1').off("click").on('click',function(){
      $('#html-template-7').fadeOut();
txy committed
597
      var _t = getToken();
谭新宇 committed
598 599 600 601 602 603 604 605 606 607 608
      
      var _votingStartTime = _settings.szRule.votingStartTime.replace(/-/g,'/');
      var _cTime = currentTime.replace(/-/g, '/');
      var endTime = new Date(_votingStartTime).getTime() - new Date(_cTime).getTime();
      
      // 2019-12-9 跳转特殊处理金港镇晒照活动,投票开始时候不能报名
      if(activityCode === 'HD1191209101728' && endTime/1000 < 0) {
          alert('当前活动投票已经开始,不可再报名!');
          return
      }

txy committed
609 610
      // 跳转到报名
      transPage('2',activityCode,_t);
txy committed
611 612 613 614 615
  });

  // 我要拉票
  $('#html-template-7 .vote-btn-2').off("click").on('click',function(){
      $('#html-template-7').hide();
txy committed
616 617 618
      $('#html-template-8').fadeIn('normal', function() {
        $(document).scrollTop(0);
      });
619 620 621 622 623
      // 设置分享参数
      setWxShare({
        userId: shareUserId,
        userName: shareUserName
      });
txy committed
624 625 626 627 628 629 630 631 632 633 634 635
  });

  // 关闭按钮
  $('#html-template-7 .modal-close').off("click").on('click',function(){
      $('#html-template-7').fadeOut();
  });
}

// 拉票/活动秘籍
function voteShateDialogBind(){
  // 关闭分享弹出框
  $("#html-template-8 .modal-close").off("click").on("click", function() {
txy committed
636
      $('#html-template-8').hide();
txy committed
637 638 639 640 641 642 643 644 645 646
  });
}

// 所有投票弹出框按钮事件绑定
function voteDialogBindFn() {
  playerHasVoteDialogBind();
  playerNoVoteDialogBind();
  visitorHasVoteDialogBind();
  visitorNoVoteDialogBind();
  voteShateDialogBind();
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673
}

// 设置分享文案
function setWxShare(data) {

  var _userId = data.userId;
  var _userName = data.userName;

  wx.ready(function(){
    // 获取域名
    var _base = getBaseOrigin();
    var _settings = rules.settings;

    var shareData = {
        title: _settings.szText.shareTitile,
        imgUrl: _settings.szText.shareIcon,
        desc: _settings.szText.shareSubtitle,
        link: ""
    }

    var auth_id = getQueryString('auth_id');
    auth_id = auth_id !== null ? '&auth_id='+auth_id : '';

    // 被分享人
    if (_userId !== '') {
      shareData.title = _settings.szText.pullTitile;
      shareData.desc = _settings.szText.pullSubtitle.replace("{{姓名}}", _userName);
txy committed
674
      shareData.link = _base + "/ACTIVITY/view/" + activityCode + "/3?activityCode="+activityCode+"&userId="+ _userId +'&orgId='+getQueryString("orgId") + auth_id;
675 676 677 678
    }else {
      // 分享首页
      shareData.title = _settings.szText.shareTitile;
      shareData.desc = _settings.szText.shareSubtitle;
txy committed
679
      shareData.link = _base + "/ACTIVITY/view/" + activityCode + "/1?activityCode="+activityCode+'&orgId='+getQueryString("orgId") + auth_id;
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713
    }

    /**
     *分享给朋友
    */
    wx.onMenuShareAppMessage({
        title: shareData.title, // 分享标题
        desc: shareData.desc, // 分享描述
        link: shareData.link, // 分享链接
        imgUrl: shareData.imgUrl, // 分享图标
        type: 'link', // 分享类型,music、video或link,不填默认为link
        dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
        success: function () {
            // 用户确认分享后执行的回调函数
        },
        cancel: function () {
            // 用户取消分享后执行的回调函数
        }
    });
    /**
     *分享到朋友圈
    */
    wx.onMenuShareTimeline({
        title: shareData.title, // 分享标题
        desc: shareData.desc, // 分享描述
        link: shareData.link, // 分享链接
        imgUrl: shareData.imgUrl, // 分享图标
        success: function () {
        },
        cancel: function () {
            // 用户取消分享后执行的回调函数
        }
    });
  });
txy committed
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
}

// 图片压缩
function compressImage(file, callback) {

  var reader = new FileReader();
  var img = new Image();

  reader.readAsDataURL(file);
  
  // 缩放图片需要的canvas
  var canvas = document.createElement('canvas');
  var context = canvas.getContext('2d');

  img.onload = function() {
    // 图片原始尺寸
    var originWidth = this.width;
    var originHeight = this.height;
    // 最大尺寸限制
    var maxWidth = 800, 
        maxHeight = 800;

    // 目标尺寸
    var targetWidth = originWidth, 
        targetHeight = originHeight;

    // 图片尺寸超过1024x1024的限制
    if (originWidth > maxWidth || originHeight > maxHeight) {
      if (originWidth / originHeight > maxWidth / maxHeight) {
          // 更宽,按照宽度限定尺寸
          targetWidth = maxWidth;
          targetHeight = Math.round(maxWidth * (originHeight / originWidth));
      } else {
          targetHeight = maxHeight;
          targetWidth = Math.round(maxHeight * (originWidth / originHeight));
      }
    }
        
    // canvas对图片进行缩放
    canvas.width = targetWidth;
    canvas.height = targetHeight;
    // 清除画布
    context.clearRect(0, 0, targetWidth, targetHeight);
    // 图片压缩
    context.drawImage(img, 0, 0, targetWidth, targetHeight);
    // canvas转为blob并上传
    canvas.toBlob(function (blob) {
      callback && callback(blob);     
    }, file.type || 'image/png');
  };

  reader.onload = function(e) {
    img.src = e.target.result;
  };
谭新宇 committed
768 769
}

谭新宇 committed
770
/* ---------------------补充功能逻辑--------------------- */
谭新宇 committed
771 772
// 添加进入N秒广告
function appendAdvertisement() {
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810
  // 活动页内跳转不显示广告
  var noshowad = getQueryString('noshowad');
  if(noshowad === null) {
    $("#adImgdiv").remove();
    // 广告时间
    var time = getQueryString('adtime');
    // 临时处理,需要移除
    var acCode = getQueryString('activityCode');
    time = (acCode === 'HD1190904172515' || acCode === 'HD1190904175331') ? '3': time;

    var imgUrl = "http://qnfile.icareyou.net/9cf70c2d689c440cb5a426020fc571021567692920411.jpg?imageMogr2/size-limit/100k";
    // 广告模板
    var tpl = "<div id='adImgdiv' style='position: absolute;top: 0;left: 0;right: 0;bottom: 0;z-index: 9999;background-color: #fff;'>"
            +"<img id='adLoading' src='http://qnfile.icareyou.net/d357016fff92448ebeb6cebf5e73bcd81567699077002' style='left: 50%;width: 0.96rem;top: 40%;position: absolute;margin-left: -0.48rem;'>"
            +"<img id='adImg' src='http://qnfile.icareyou.net/9cf70c2d689c440cb5a426020fc571021567692920411.jpg?imageMogr2/size-limit/100k' style='width: 100%;display:none;'>"
            +"</div>";
    // 添加广告
    if(time !== null || acCode === 'HD1190904172515' || acCode === 'HD1190904175331') {
      // 隐藏首页页面
      $("#html-template-1").hide();

      time = parseInt(time)
      $("body").append(tpl);
      // 图片加载完成
      $("#adLoading").on("load",function(){
        $("#adImg").on("load",function(){
          $("#adLoading").hide();
          // N秒后关闭
          setTimeout(function(){
            $("#adImgdiv").fadeOut(function(){
              $("#adImgdiv").remove();
              $(document).scrollTop(0);
              $("#html-template-1").show();
            });
          }, time*1000);
        }).show();
      });
    }
谭新宇 committed
811
  }
谭新宇 committed
812 813 814 815 816 817 818
}

// 添加赞助商文案
function addSupportMsg() {
  $("#addsupport").remove();

  var addsupport = getQueryString('addsupport');
819 820
  // 临时处理,需要移除
  var acCode = getQueryString('activityCode');
谭新宇 committed
821
  var tpl = "<div></div>";
谭新宇 committed
822
  if(addsupport !== null || acCode === 'HD1190904172515' || acCode === 'HD1190904175331' || acCode === 'HD1190912144641'){
谭新宇 committed
823 824 825
    // 获取机构名称
    getOrgNameFn(function(data){
      var orgName = data.records.orgName;
谭新宇 committed
826 827 828
      var appendSection = $("#html-template-1 .content");
      var appendSection2 = $("#html-template-2 .content");
      var appendSection3 = $("#html-template-3 .content");
谭新宇 committed
829 830 831 832 833 834
      var msg = ""
      //  芙蓉区和天心区
      if(orgName.indexOf("芙蓉区") > -1 || orgName.indexOf("天心区") > -1 ) {
        msg = "飞鹤/百诺恩/小熊BABY/子母母婴店友情赞助,凯歌健康技术支持";
      }else if (orgName.indexOf("高新区") > -1){ // 高新区文案
        msg = "飞鹤/百诺恩/子母母婴店友情赞助,凯歌健康技术支持";
谭新宇 committed
835 836
      } else if (acCode === 'HD1190912144641'){
        msg = "嬉水广场4楼瑞丽摄影友情赞助,凯歌健康技术支持";
谭新宇 committed
837 838 839 840 841
      }

      if(msg !== '') {
        var tpl = "<div style='text-align:center;color:white;font-size: 0.24rem;margin-top: 0.45rem;margin-bottom: 0.3rem;'>"+ msg +"</div>";
        appendSection.after(tpl);
谭新宇 committed
842 843
        appendSection2.after(tpl);
        appendSection3.after(tpl);
谭新宇 committed
844 845 846
      }
    });
  }
谭新宇 committed
847 848 849 850
}

// 展示机构名称标题
function headerShowOrgName() {
851 852 853
  $(".showorgname").remove();
  var appendSection = $('[c_typename="logo"]');
  var showOrgName = getQueryString('showorgname');
854 855 856
  // 临时处理,需要移除
  var acCode = getQueryString('activityCode');
  if(showOrgName !== null || acCode === 'HD1190904172515' || acCode === 'HD1190904175331') {
857 858 859 860 861
    // 获取机构名称
    getOrgNameFn(function(data){
      var orgName = data.records.orgName;
      // 把机构名称填入到页面中
      if(orgName !== '') {
谭新宇 committed
862
        var tpl = "<div class='showorgname'>"+ orgName +"</div>";
863 864 865 866
        appendSection.after(tpl);
      }
    });
  }
txy committed
867
}