define(['zepto', 'medtap'], function($, medtap) { var main = { id: medtap.getRequest('id'), init: function() { main.getDetail(); }, bind: function() { $('.drug_img').unbind().bind('click', function() { var imgArray = []; var curImageSrc = $(this).attr('src'); imgArray.push(curImageSrc); wx.previewImage({ current: curImageSrc, urls: imgArray }); }) }, getDetail: function() { medtap._ajax({ url: '/operation/article/getArticle', type: 'get', data: { articleId: main.id }, success: function(res) { if (res.success == true) { var content = res.content.articleInfoItem; main.share(content); document.title = content.articleTitle; var htmlContent = content.content; $('.title').html(content.articleTitle); $('.timer').html(content.setUpDate); $('.drugDetail').html(htmlContent); $('.drug_img').attr('src', content.articlePcImg); var drugInfo = $('.detail p').first().contents(); // 药品描述 var drugName = content.articleTitle.split('(')[0]; //药品名称 /* var grayName = content.articleTitle.split('(')[1]; var str = grayName.substring(0,grayName.length-1);//通用名 */ $('.drug_name').html(drugName); $('.drug_manufactor').html(content.keywords) /* $('.drugDesc').html(drugInfo[0].textContent); */ $('.detail p:first-child').remove(); /* $('.drugDetail p span').css('line-height', 'auto'); $('.drugDetail p strong span').css('line-height', 'auto') */ var tagList = content.keywords.split(','); var tagHtml = ''; for (var i = 0; i < tagList.length; i++) { tagHtml += '<span class="tagGray">' + tagList[i] + '</span>'; } $('.drugTag').html(tagHtml); /* var meta = document.getElementsByTagName('meta'); meta['keywords'].setAttribute('content',content.keywords); meta['description'].setAttribute('content',content.articleDesc); */ main.bind(); $('.drugDetail p').each(function (index, el) { var a = $(this).css('text-indent'); if(a.indexOf('em') != -1){ $(this).css('text-indent','0.5rem') } }); $('.booking').unbind().bind('click', function() { $('.qrCode_box').show(); $('.content_mod').show(); }); $('.close').unbind().bind('click', function() { $('.qrCode_box').hide(); $('.content_mod').hide(); }) } } }) }, share: function(data) { var shareContent = data; var title = shareContent.articleTitle; var content = ''; var imgUrl = shareContent.articleImg; var linkUrl = window.location.href; medtap._ajax({ url: '/wechat/fetchWechatTicket', type: 'get', async: false, portType:main.portType, data: { url: window.location.href }, success: function(data) { var res = data.content; wx.config({ debug: false, appId: res.appId, // 必填,公众号的唯一标识 timestamp: res.timestamp, // 必填,生成签名的时间戳 nonceStr: res.nonceStr, // 必填,生成签名的随机串 signature: res.signature, // 必填,签名,见附录1 jsApiList: [ 'updateTimelineShareData', 'updateAppMessageShareData', 'previewImage' //图片预览 ] }) }, error: function() {} }); //分享配置 wx.ready(function() { //分享给朋友 wx.updateAppMessageShareData({ title: title, desc: content, // 分享描述 link: linkUrl, imgUrl: imgUrl, // 分享图标 type: 'link', // 分享类型,music、video或link,不填默认为link dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空 success: function() { if (!(/iphone|ipad/gi).test(navigator.userAgent)) {} }, cancel: function() { if (!(/iphone|ipad/gi).test(navigator.userAgent)) {} } }); //分享到朋友圈 wx.updateTimelineShareData({ title: title, // 分享标题 link: linkUrl, imgUrl: imgUrl, // 分享图标 success: function() { if (!(/iphone|ipad/gi).test(navigator.userAgent)) {} }, cancel: function() { if (!(/iphone|ipad/gi).test(navigator.userAgent)) {} } }); }); } } main.init() })