/** * Created by zhaoxueliang on 2020/5/22. */ $(function () { // 页面编码 var PAGE_CODE = { // 最近阅读 'RECENT_READ': 'recent_read', // 书架 'BOOK_SHELF': 'book_shelf', // 书籍详情页 'BOOK_DETAIL': 'book_detail', // 追更页 'TYPING': 'typing', // 阅读页 'BOOK_READING': 'book_reading', // 充值页 'CHARGE': 'charge', // 个人中心 'MY': 'my', // 排行榜 'RANKING_LIST': 'ranking_list', // 分类首页 'CATEGORY_MAIN': 'category_main', // 分类二级页 'CATEGORY_SUB': 'category_sub', // 书城首页 'BOOK_STORE': 'book_store', }; // 广告位置编号 var AD_POSITION_CODE = { // 书籍详情页广告位 'BOOK_DETAIL': 1, // 书籍详情页浮窗广告位 'BOOK_DETAIL_FLOW': 22, // 追更、完结页广告位 'TYPING': 2, // 最近阅读广告位 'RECENT_READ': 4, // 书架/阅读记录广告位 'BOOK_SHELF': 5, // 阅读页底部广告位 'BOOK_READING_BOTTOM': 3, // 阅读页顶部菜单悬浮广告位 'BOOK_READING_MENU': 6, // 阅读页中间插屏广告位1 'BOOK_READING_MIDDLE_PRIMARY': 7, // 阅读页中间插屏广告位2 'BOOK_READING_MIDDLE_LARGE': 8, // 阅读页中间插屏广告位3 'BOOK_READING_MIDDLE_THIRD': 9, // 充值页返回弹窗广告位 'CHARGE_LEAVE': 10, // 阅读页下一章弹窗广告位 'BOOK_READING_NEXT_CHAPTER': 11, // 阅读页顶部轮播广告位 'BOOK_READING_TOP_BANNER': 18, // 阅读页跳转广告章节广告位 'BOOK_READING_DELIVER': 19, // 签到弹窗广告位 'MY_CHECKIN_ALERT': 12, // 个人中心插屏广告位 'MY_CONTENT': 13, // 排行榜插屏广告位 'RANKING_LIST': 14, // 分类首页插屏广告位 'CATEGORY_MAIN': 15, // 分类二级页插屏广告位 'CATEGORY_SUB': 16, // 书城首页顶部轮播广告位 'BOOK_STORE_TOP_BANNER': 17, // 书城首页中间内容插屏广告位 'BOOK_STORE_MIDDLE_BANNER': 20, // 书城首页悬浮窗广告位 'BOOK_STORE_FLOW': 21, }; var PAGE_POSITION_MAP = { 'recent_read': [4], 'book_shelf': [5], 'book_detail': [1, 22], 'typing': [2], 'book_reading': [3, 6, 7, 8, 9, 11, 18, 19], 'charge':[10], 'my':[12, 13], 'ranking_list':[14], 'category_main':[15], 'category_sub':[16], 'book_store':[17, 20, 21] }; var REQUEST_INTERVAL = 60 * 60 * 1000; var STORE_TIME = 'storeTime'; var LOCAL_AD_DATA = 'local_AD_data'; var LATEST_VERSION = 'latestVersion'; var READING_BANNER_CLOSE_TIME = 'reading_banner_close_time'; var API_URL = { GET_AD_STRATEGY: '/api/aduserapi/advert' }; var simpleAD = { userId: _getUserId(), channelId: _getChannelId() }; // 当前章节是否需要跳转到广告章节页 var shouldGoToADChapter = false; var read_chapter = 0; //拿到广告数据后插入广告 simpleAD.render = function (pageCode) { var localADData = JSON.parse(localStorage.getItem(LOCAL_AD_DATA)); var latestVersion = localStorage.getItem(LATEST_VERSION) || ''; var lastStoreTime = localADData && localADData[STORE_TIME]; var now = new Date().getTime(); if (localADData && (now - lastStoreTime < REQUEST_INTERVAL) && latestVersion == window.$adLatestVersion) { _renderPageAD(localADData, pageCode); } else { $.ajax({ type: 'POST', url: API_URL.GET_AD_STRATEGY, data: { pagecode: pageCode, uid: this.userId, channel_id: this.channelId }, success: function (res) { if (res.code == 1 && (res.data instanceof Object)) { var storeData = {}; storeData[STORE_TIME] = new Date().getTime(); $.extend(storeData, res.data); localStorage.removeItem(LATEST_VERSION); localStorage.setItem(LATEST_VERSION,window.$adLatestVersion); localStorage.removeItem(LOCAL_AD_DATA); localStorage.setItem(LOCAL_AD_DATA, JSON.stringify(storeData)); _renderPageAD(storeData, pageCode); }else{ localStorage.removeItem(LOCAL_AD_DATA); } }, error: function (error) { } }); } }; //下章节弹窗广告显示 simpleAD.showReadAlert = function(){ if(window.$isAdPick != '1'){ return false; } var readedChapter = localStorage.getItem('readedChapterNum'); if(!readedChapter){ return false; } var readedChapterNum = JSON.parse(readedChapter).num; if(readedChapterNum >= read_chapter){ // 用户当天阅读章节数达到后台下发的章节数后,清空当前缓存的章节数,重新开始计数,以实现每隔若干章弹一次“温馨提示”的需求 localStorage.removeItem('readedChapterNum'); } if(read_chapter == readedChapterNum){ var ADElement = $('.ad-read-alert').find('.ad-image'); if(ADElement.length == 0){ return false; } var target = ADElement[0]; var mId = target.dataset.mId; var adIds = target.dataset.adIds; var position = target.dataset.position; //发送报点 _sendLog(adIds,position,mId); $('.ad_chapter_num').text(readedChapterNum); $('.ad-read-alert').show(); return true; } return false; }; //充值页广告弹窗 simpleAD.showRechargeAlert = function(){ var ADElement = $('.ad-recharge-alert').find('.ad-image'); if(ADElement.length == 0){ return false; } var target = ADElement[0]; var mId = target.dataset.mId; var adIds = target.dataset.adIds; var position = target.dataset.position; _sendLog(adIds,position,mId); $('.ad-recharge-alert').show(); return true; }; simpleAD.getADChapterUrl = function(url){ var search = url.split('?')[1]; if(!shouldGoToADChapter|| !search){ return ''; } var book_id = _getQueryString(search,'book_id'); var chapter_id = _getQueryString(search,'chapter_id'); //不能拼死漏掉末尾参数??????????????? return 'ad_chapter?'+search+"&chapter_name="+window.ad_chapter_name; }; function _getQueryString(url,name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = url.match(reg); if (r != null) return decodeURI(r[2]); return ''; } // 从cookie中获取userId function _getUserId() { return $.fn.cookie('user_id') || ''; } // 从cookie中获取channelId function _getChannelId() { return $.fn.cookie('channel_id') || ''; } // 渲染当前页面广告 function _renderPageAD(localADData, pageCode) { //服务端缓存在本地数据,广告点位、渠道 var positions = localADData.positions; var materials = localADData.materials; if(!positions || !materials){ return ; } //判断如果是充值页就不加载福利广告,tabbar单独解析福利广告 console.log(pageCode); if(pageCode !='charge'){ window.ad_welfare && window.ad_welfare(localADData, pageCode); } //当前页设有有的广告点 var localPositions = PAGE_POSITION_MAP[pageCode]; for (var i = 0; i < localPositions.length; i++) { var positionIndex = localPositions[i]; //当前页某点地广告策略数组集 var positionData = positions[positionIndex]; if (!positionData) { continue; } //某点广告的插入函数参数:策略集合、渠道、当前页具体点位、某页面 _renderPositionAD(positionData, materials, positionIndex,pageCode); } } // 渲染当前页面某点广告 function _renderPositionAD(positionData, materials, positionIndex,pageCode) { // 策略中的权重 var maxWeight = 0; // 各权重包含的策略 var classifyStrategies = {}; var strategyKeys = Object.keys(positionData); var count = 0; for (var i = 0; i < strategyKeys.length; i++) { var strategyId = strategyKeys[i]; //点中的某一个策略对象{} var strategy = positionData[strategyId]; var weight = strategy.weight; if (!classifyStrategies[weight]) { classifyStrategies[weight] = []; } var now = new Date().getTime(); // 只收集在推广期内的广告 $.extend(strategy,{ad_ids:strategyId}); if(strategy.show_starttime * 1000 < now && strategy.show_endtime * 1000 > now){ classifyStrategies[weight].push(strategy); if (weight > maxWeight) { maxWeight = weight; } count+=1; } } if(count == 0){ return; } var maxWeightStrategy = classifyStrategies[maxWeight]; //多少个广告策略 var maxWeightStrategySize = maxWeightStrategy && maxWeightStrategy.length; var resultIndex = maxWeightStrategySize > 1 ? Math.floor(Math.random() * maxWeightStrategySize) : 0; if(positionIndex == AD_POSITION_CODE.BOOK_READING_NEXT_CHAPTER){ read_chapter = maxWeightStrategy[resultIndex].chapter_num; } _renderAD(maxWeightStrategy[resultIndex],positionIndex,pageCode,materials); } function _renderAD(ADData,positionIndex,pageCode,materials){ switch (pageCode){ case PAGE_CODE.BOOK_DETAIL: _renderDetailAD(ADData,positionIndex,materials); break; case PAGE_CODE.BOOK_READING: _renderReadingAD(ADData,positionIndex,materials); break; case PAGE_CODE.BOOK_SHELF: _renderShelfAD(ADData,positionIndex,materials); break; case PAGE_CODE.RECENT_READ: _renderRecentAD(ADData,positionIndex,materials); break; case PAGE_CODE.TYPING: _renderTypingAD(ADData,positionIndex,materials); break; case PAGE_CODE.CHARGE: _renderChargeAD(ADData,positionIndex,materials); break; case PAGE_CODE.MY: _renderMyAD(ADData,positionIndex,materials); break; case PAGE_CODE.RANKING_LIST: _renderRankingListAD(ADData,positionIndex,materials); break; case PAGE_CODE.CATEGORY_MAIN: _renderCategoryMainAD(ADData,positionIndex,materials); break; case PAGE_CODE.CATEGORY_SUB: _renderCategorySubAD(ADData,positionIndex,materials); break; case PAGE_CODE.BOOK_STORE: _renderBookStoreAD(ADData,positionIndex,materials); } } function _renderDetailAD(ADData,positionIndex,materials){ if(AD_POSITION_CODE.BOOK_DETAIL_FLOW == positionIndex){ _renderFlow(ADData,positionIndex,materials); }else{ if(ADData.is_slide == 1){ _renderSlide(ADData,positionIndex,materials); }else{ _renderLarge(ADData,positionIndex,materials); } } } function _renderReadingAD(ADData,positionIndex,materials){ if(window.location.pathname.indexOf('ad_chapter')>0){ positionIndex == AD_POSITION_CODE.BOOK_READING_DELIVER && _renderADChapter(ADData,positionIndex,materials); return; } switch (positionIndex){ case AD_POSITION_CODE.BOOK_READING_BOTTOM: if(ADData.is_slide == 1){ _renderSlide(ADData,positionIndex,materials); }else{ _renderLarge(ADData,positionIndex,materials); } break; case AD_POSITION_CODE.BOOK_READING_MENU: _renderSmall(ADData,positionIndex,materials); break; case AD_POSITION_CODE.BOOK_READING_MIDDLE_PRIMARY: var programs = $('.read_main_p').find('p'); length = programs.length; if(length>0) { // 垃圾代码 ··· var params = _getADMaskParams(positionIndex); // 垃圾代码结束 var position = Math.floor(length * .25); _renderPrimary(ADData,positionIndex,materials,programs,position,params.hasBeStillToday,params.showMask); } break; case AD_POSITION_CODE.BOOK_READING_MIDDLE_LARGE: var programs = $('.read_main_p').find('p'); length = programs.length; if(length>0) { // 垃圾代码 ··· var params = _getADMaskParams(positionIndex); // 垃圾代码结束 var position = Math.floor(length * .5); _renderLarge(ADData,positionIndex,materials,programs,position,params.hasBeStillToday,params.showMask); } break; case AD_POSITION_CODE.BOOK_READING_MIDDLE_THIRD: var programs = $('.read_main_p').find('p'); length = programs.length; if(length>0) { // 垃圾代码 ··· var params = _getADMaskParams(positionIndex); // 垃圾代码结束 var position = Math.floor(length * .75); _renderPrimary(ADData,positionIndex,materials,programs,position,params.hasBeStillToday,params.showMask); } break; case AD_POSITION_CODE.BOOK_READING_NEXT_CHAPTER: _renderLarge(ADData,positionIndex,materials); break; case AD_POSITION_CODE.BOOK_READING_DELIVER: _renderADChapter(ADData,positionIndex,materials); break; case AD_POSITION_CODE.BOOK_READING_TOP_BANNER: var lastCloseTime = localStorage.getItem(READING_BANNER_CLOSE_TIME) || 0; //浮窗广告时间间隔,测试调到5分钟 上线得调回到15 var latingTime = 15*60*1000; if($('.ad_welfare_banner').css('display') == 'none' && new Date().getTime()-lastCloseTime >= latingTime){ // $('.ad_position_18').show(); if(ADData.is_slide == 1){ _renderSlide(ADData,positionIndex,materials); }else{ _renderLarge(ADData,positionIndex,materials); } $('.ad_position_18_close').unbind().bind('click',function(e){ //?????????????? e.stopPropagation(); $('.ad_position_18').hide(); localStorage.setItem(READING_BANNER_CLOSE_TIME,new Date().getTime()); }); }else{ console.log("福利广告已显示"); $('.ad_position_18').hide(); } } } function _getADMaskParams(positionIndex){ var hasBeStillToday = 'no'; var showMask = Math.random() < window.$ad_rate_chapter; var today = new Date(new Date().toLocaleDateString()).getTime(); var stillClickPositionStatus = localStorage.getItem('still_click_position_'+positionIndex); stillClickPositionStatus = stillClickPositionStatus ? JSON.parse(stillClickPositionStatus) : null; if(stillClickPositionStatus){ var lastRecord = stillClickPositionStatus.time; if(lastRecord'); _renderLarge(ADData,positionIndex,materials); } }else{ contain.find('.ad_position_14').remove(); var existedAD = contain.find('.ad-image'); // 页面上已存在广告,不再渲染新的广告 if(existedAD.length>0){ return; } var position = length >= 4 ? 2 : (length-1); _renderLarge(ADData,positionIndex,materials,programs,position); } } function _renderCategoryMainAD(ADData,positionIndex,materials){ if(ADData.is_slide == 1){ _renderSlide(ADData,positionIndex,materials); }else{ _renderLarge(ADData,positionIndex,materials); } } function _renderCategorySubAD(ADData,positionIndex,materials){ var contain = $('.r_img_ul'); var programs = contain.find('.section-block'); length = programs.length; if(length == 0){ if($('.ad_position_16').find('.ad-image').length == 0){ _renderLarge(ADData,positionIndex,materials); } }else{ var existedAD = contain.find('.ad-image'); // 页面上已存在广告,不再渲染新的广告 if(existedAD.length>0){ return; } var position = length >= 4 ? 2 : (length-1); _renderLarge(ADData,positionIndex,materials,programs,position); } } function _renderBookStoreAD(ADData,positionIndex,materials){ if(AD_POSITION_CODE.BOOK_STORE_FLOW == positionIndex){ _renderFlow(ADData,positionIndex,materials); } if(AD_POSITION_CODE.BOOK_STORE_TOP_BANNER == positionIndex){ _renderBookStoreSlide(ADData,positionIndex,materials); } if(AD_POSITION_CODE.BOOK_STORE_MIDDLE_BANNER == positionIndex){ var contain = $('.body_sytle'); var programs = contain.find('.i_module_box'); length = programs.length; _renderLarge(ADData,positionIndex,materials,programs,0); } } function _renderSlide(ADData,positionIndex,materials){ if(!ADData || ADData.material_ids && ADData.material_ids.length<1){ return; } var materialItems = _getSortedMaterials(ADData,materials,3); if(!materialItems || materialItems.length == 0){ return; } if(positionIndex==AD_POSITION_CODE.BOOK_READING_TOP_BANNER){ $('.ad_position_18').show(); } var randomMaterialItems = materialItems; var template = (positionIndex == AD_POSITION_CODE.BOOK_READING_BOTTOM ? '':'
')+ '
'+ '
'+ '
'; var baiduCode = []; var js_code = ''; for(var j = 0;j'+ '
'+ '
'; } else if(randomMaterialItem.type == 1){ js_code = randomMaterialItem.js_code; template+= '
'+ '
'+ '
'; } else if(randomMaterialItem.type == 2){ baiduCode.push(randomMaterialItem.ad_baidu); template+= '
'+ '
'+ '
'; } _sendLog(ADData.ad_ids,positionIndex,randomMaterialItem.material_id); } template+='
'+ '
'+ '
'+ '
'+ (positionIndex == AD_POSITION_CODE.BOOK_READING_BOTTOM ? '':''); $('.ad_position_'+positionIndex).append(template); // 渲染js和百度广告 var jsElement = $('.ad_position_'+positionIndex+' .js_ad'); jsElement.length && js_code && postscribe(jsElement[0], js_code); for(var k=0;k'+ '
'; var baiduCode = []; var js_code = ''; for(var j = 0;j'+ '
'+ '
'; } else if(randomMaterialItem.type == 1){ js_code = randomMaterialItem.js_code; template+= '
'+ '
'+ '
'; } else if(randomMaterialItem.type == 2){ baiduCode.push(randomMaterialItem.ad_baidu); template+= '
'+ '
'+ '
'; } _sendLog(ADData.ad_ids,positionIndex,randomMaterialItem.material_id); } template+=''+ '
'+ ''+ ''; $('.ad_position_'+positionIndex).append(template); // 渲染js和百度广告 var jsElement = $('.ad_position_'+positionIndex+' .js_ad'); jsElement.length && js_code && postscribe(jsElement[0], js_code); for(var k=0;k'+ ''+ ''+ ''; $('.ad_position_'+positionIndex).append(template); }else if(materialItem.type==1){ var containElement = $('
'); $('.ad_position_'+positionIndex).append(containElement); postscribe(containElement[0], materialItem.js_code); }else if(materialItem.type==2){ $('.ad_position_'+positionIndex).append('
'); (window.slotbydup = window.slotbydup || []).push({ id: materialItem.ad_baidu, container: materialItem.ad_baidu, async: true }); } _sendLog(ADData.ad_ids,positionIndex,materialItem.material_id); _addListener(); } function _renderPrimary(ADData,positionIndex,materials,willInsertElements,insertPosition,hasBeStillToday,showMask){ if(!ADData || ADData.material_ids && ADData.material_ids.length<1){ return; } var materialItems = _getSortedMaterials(ADData,materials,1); if(!materialItems || materialItems.length == 0){ return; } var materialItem = materialItems[0]; if(materialItem.type == 0){ var template = '
'+ ''+ ''+ // 垃圾代码:展示范围 (hasBeStillToday && hasBeStillToday == 'no' && showMask ?'
':'')+ '
'; if(willInsertElements && insertPosition) { $(willInsertElements[insertPosition]).after(template); } }else if(materialItem.type==1){ var container = $('
'+ // 垃圾代码:展示范围 (hasBeStillToday && hasBeStillToday == 'no' && showMask ?'
':'')+ '
'); if(willInsertElements && insertPosition) { $(willInsertElements[insertPosition]).after(container); postscribe(container[0], materialItem.js_code); } }else if(materialItem.type==2){ if(willInsertElements && insertPosition) { $(willInsertElements[insertPosition]).after('
'); (window.slotbydup = window.slotbydup || []).push({ id: materialItem.ad_baidu, container: materialItem.ad_baidu, async: true }); } } _sendLog(ADData.ad_ids,positionIndex,materialItem.material_id); _addListener(); } function _renderLarge(ADData,positionIndex,materials,willInsertElements,insertPosition,hasBeStillToday,showMask){ if(!ADData || ADData.material_ids && ADData.material_ids.length<1){ return; } var materialItems = _getSortedMaterials(ADData,materials,1); if(!materialItems || materialItems.length == 0){ return; } if(positionIndex==AD_POSITION_CODE.BOOK_READING_TOP_BANNER){ $('.ad_position_18').show(); } var materialItem = materialItems[0]; if(materialItem.type == 0){ var template = ((positionIndex == AD_POSITION_CODE.BOOK_READING_BOTTOM || positionIndex == AD_POSITION_CODE.BOOK_READING_NEXT_CHAPTER || positionIndex == AD_POSITION_CODE.BOOK_READING_MIDDLE_LARGE || positionIndex == AD_POSITION_CODE.RANKING_LIST || positionIndex == AD_POSITION_CODE.BOOK_READING_TOP_BANNER) ? '':'
')+ '
'+ ''+ ''+ // 垃圾代码:展示范围 (hasBeStillToday && hasBeStillToday == 'no' && showMask ?'
':'')+ '
'+ ((positionIndex == AD_POSITION_CODE.BOOK_READING_BOTTOM || positionIndex == AD_POSITION_CODE.BOOK_READING_NEXT_CHAPTER || positionIndex == AD_POSITION_CODE.BOOK_READING_MIDDLE_LARGE || positionIndex == AD_POSITION_CODE.RANKING_LIST) ? '':'
'); if(willInsertElements && insertPosition>=0) { $(willInsertElements[insertPosition]).after(template); }else{ $('.ad_position_'+positionIndex).append(template); } }else if(materialItem.type==1){ var container = $('
'+ // 垃圾代码:展示范围 (hasBeStillToday && hasBeStillToday == 'no' && showMask ?'
':'')+ '
'); if(willInsertElements && insertPosition>=0) { $(willInsertElements[insertPosition]).after(container); }else{ $('.ad_position_'+positionIndex).append(container); } postscribe(container[0], materialItem.js_code); }else if(materialItem.type==2){ if(willInsertElements && insertPosition>=0) { $(willInsertElements[insertPosition]).after('
'); }else{ $('.ad_position_'+positionIndex).append('
'); } (window.slotbydup = window.slotbydup || []).push({ id: materialItem.ad_baidu, container: materialItem.ad_baidu, async: true }); } // 下一章所对应广告在弹窗中,不能在初始化时直接打点曝光 ,此项曝光在弹窗显示时打点,见:simpleAD.showReadAlert if(positionIndex != AD_POSITION_CODE.BOOK_READING_NEXT_CHAPTER){ _sendLog(ADData.ad_ids,positionIndex,materialItem.material_id); } _addListener(); if(positionIndex == AD_POSITION_CODE.MY_CONTENT){ $('.ad_other_item').hide(); } } function _renderFlow(ADData,positionIndex,materials){ if(!ADData || ADData.material_ids && ADData.material_ids.length<1){ return; } var materialItems = _getSortedMaterials(ADData,materials,1); if(!materialItems || materialItems.length == 0){ return; } var materialItem = materialItems[0]; var template = '
'+ ''+ '
'; $('.ad_position_'+positionIndex).append(template); _sendLog(ADData.ad_ids,positionIndex,materialItem.material_id); _addListener(); } function _renderAlert(ADData,positionIndex,materials){ if(!ADData || ADData.material_ids && ADData.material_ids.length<1){ return; } var materialItems = _getSortedMaterials(ADData,materials,1); if(!materialItems || materialItems.length == 0){ return; } var materialItem = materialItems[0]; var materialItem = materialItems[0]; if(materialItem.type == 0){ var template = '
'+ ''+ ''+ '
'; $('.ad_position_'+positionIndex).append(template); }else if(materialItem.type==1){ var container = $('
'); $('.ad_position_'+positionIndex).append(container); postscribe(container[0], materialItem.js_code); }else if(materialItem.type==2){ $('.ad_position_'+positionIndex).append('
'); (window.slotbydup = window.slotbydup || []).push({ id: materialItem.ad_baidu, container: materialItem.ad_baidu, async: true }); } _addListener(); } function _renderADChapter(ADData,positionIndex,materials){ if(window.location.pathname.indexOf('ad_chapter')>0){ _renderLarge(ADData,positionIndex,materials); }else{ // TODO:获取当前章节索引 if((window.ad_chapter_index-ADData.chapter_start_num)%ADData.chapter_step_num == 0){ shouldGoToADChapter = true; }else{ shouldGoToADChapter = false; } var materialItems = _getSortedMaterials(ADData,materials,1); // 如果没有匹配到可展示素材,也不应该跳转到阅读页整屏插屏广告页 if(!materialItems || materialItems.length == 0){ shouldGoToADChapter = false; } } } function _getSortedMaterials(ADData,materials,count){ var materialItems = []; var jsMaterialItems = []; var baiduMaterialItems = []; var weightClassifyItems = {}; var materialKeys = ADData.material_ids || []; for (var i = 0;i now){ materialItem = $.extend(true,{material_id:materialItemKey},materialItem); var weight = materialItem.weight; !weightClassifyItems[weight] && (weightClassifyItems[weight] = []); weightClassifyItems[weight].push(materialItem); } } var weightClassifyItemsKeys = Object.keys(weightClassifyItems); weightClassifyItemsKeys.sort(function(pre,next){ return next -pre; }); for(var j=0;j