Top

控件值存储缓存数据的及时更新

 

 

  1   
  2 //更新数据
  3 /**
  4 * 计划代收
  5 * @param  {object} $obj 删除按钮
  6 * @return {[type]}      [description]
  7 */
  8 Transfer.planCollection = function($tab, $that, isView) {
  9     var idList = [], //中转列表 Id
 10         outRemarkId = $tab.find('.T-arrange').find('input[name=outRemarkId]'),
 11         $tr = $that.closest('tr'),
 12         arrangeId = $tr.attr('data-entity-id'),
 13         subject = $that.attr("data-type")=="bus" ? 0 : 1,
 14         isConfirmAccount = $that.attr('data-isConfirmAccount');
 15     outRemarkId.each(function() {
 16         if ($(this).val().trim()) {
 17             idList.push($(this).val());
 18         }
 19     });
 20 
 21     $.ajax({
 22         url: KingServices.build_url(service_name, "getCollectionList"),
 23         type: "POST",
 24         data: {
 25             outRemarkIds: idList.join(','),
 26             arrangeId: arrangeId,
 27             subject: subject
 28         },
 29         success: function(data) {
 30             if (showDialog(data)) {
 31                 data.isConfirmAccount = isConfirmAccount;
 32                 data.isView = isView;
 33 
 34                 //读取缓存数据
 35                 var colGroItemList = $that.closest('tr').find('[name=collectionList]').val() || "[]";
 36                 colGroItemList = JSON.parse(colGroItemList);
 37                 
 38                 if (!!colGroItemList && colGroItemList.length > 0 ) {
 39                     for (var i = 0; i <  colGroItemList.length; i++) {
 40                         data.collectionList[i].collectionGroup = colGroItemList[i].collectionGroup;
 41                         data.collectionList[i].collectionItem = colGroItemList[i].collectionItem;
 42                     };
 43                 }
 44 
 45                 var html = planCollectionTemplate(data);
 46                 var _Title = '编辑计划代收';
 47                 if (!!isView) {
 48                     _Title = '查看计划代收';
 49                 };
 50                
 51                 layer.open({
 52                     type: 1,
 53                     title: _Title,
 54                     skin: 'layui-layer-rim',
 55                     area: '1200px',
 56                     zIndex: 1028,
 57                     content: html,
 58                     scrollbar: false,
 59                     success: function(obj, index) {
 60                         var $LayerId = $(obj);
 61                         //save
 62                         $LayerId.on('click','.T-btn-save',function(){
 63                             var collection  = $LayerId.find('input[name=collection]'),
 64                                 collectionList = [],
 65                                 collectGroItemList = [],
 66                                 count = 0,
 67                                 $layerTr = $LayerId.find('#T-transfer-bus').children('tr');
 68                             $layerTr.each(function(index) {
 69                                 var $that = $(this),
 70                                     collectionGroup=$layerTr.eq(index).find('[name=collectionGroup]').val()*1 || 0,
 71                                     collectionItem=$layerTr.eq(index).find('[name=collectionItem]').val()*1 || 0,
 72                                     planCollection = {
 73                                         id : $that.attr("id"),
 74                                         touristGroupId : $that.attr("touristGroupId"),
 75                                         collectionGroup : collectionGroup,
 76                                         collectionItem : collectionItem
 77                                     };
 78                                 count+=collectionGroup;
 79                                 count+=collectionItem;
 80                                 collectionList.push(planCollection);
 81                             });
 82                             $tr.find('[name=collectionList]').val(JSON.stringify(collectionList));//代收信息
 83                             $that.val(count); //代收金额合计
 84                             layer.close(index);
 85                            
 86                         })
 87 
 88                         //layer-close
 89                         $LayerId.on('click','.T-btn-close',function(){
 90                             layer.close(index);
 91                         });
 92                     }
 93                 });
 94 
 95             }
 96         }
 97     })
 98 }
 99 
100 
101 
102 /**
103  * [spliceColGroIteArr 移除代收安排记录]
104  * @param  {[type]} outRemarkId 计划ID
105  * @return {[type]}             [description]
106  */
107 Transfer.spliceColGroIteArr = function($tab, tGroupId, outRemarkId, $tbodyArr){
108 
109     var $hotelTr = $tab.find('tbody.T-hotel-plan').children('tr'),
110         $hotelTaskTr = $tbodyArr.children('tr'),  //酒店中转安排
111         $busTr = $tab.find('tbody.T-bus-plan').children('tr'),
112         $busTaskTr = $tbodyArr.children('tr');  //车中转安排
113     var isTGroup = false;
114     //当删除酒店中转记录有多个相同游客小组ID
115     $hotelTaskTr.each(function(index) {
116         var outId = $hotelTaskTr.eq(index).find('[name=outRemarkId]').val(),
117             touristGroupId =  $hotelTaskTr.eq(index).attr('data-touristgroupId');
118         if (tGroupId == touristGroupId && outId != outRemarkId) {
119             isTGroup = true;
120         }
121     });
122 
123     //当删除车安排中转记录有多个相同游客小组ID
124     $busTaskTr.each(function(index) {
125         var outId = $busTaskTr.eq(index).find('[name=outRemarkId]').val(),
126             touristGroupId =  $busTaskTr.eq(index).attr('data-touristgroupId');
127         if (tGroupId == touristGroupId && outId != outRemarkId) {
128             isTGroup = true;
129         }
130     });
131 
132     //当删除安排中转记录有多个相同游客小组ID时不刷新缓存数据
133     if (isTGroup) {
134         return;
135     }
136     
137     //房安排
138     $hotelTr.each(function(index) {
139          
140         //读取缓存数据
141         var collectionList = $hotelTr.eq(index).find('[name=collectionList]').val(),
142             count = 0,
143             collectGroItemList=[];
144         //实例化对象
145         collectGroItemList = JSON.parse(collectionList);
146 
147         //分割缓存数据
148         if (!!collectGroItemList && collectGroItemList.length > 0 ) {
149             for(var i = 0, len = collectGroItemList.length; i < len; i++){
150                 //小组ID
151                 if (collectGroItemList[i].touristGroupId == tGroupId) {
152                     collectGroItemList.splice(i, 1);
153                     break;
154                 }
155             }
156 
157             //重置计算
158             for(var i = 0, len = collectGroItemList.length; i < len; i++){
159                 count+=collectGroItemList[i].collectionGroup;
160                 count+=collectGroItemList[i].collectionItem;
161             }
162             $hotelTr.eq(index).find('.T-collection').val(count);
163 
164             //更新缓存数据
165             $hotelTr.eq(index).find('[name=collectionList]').val(JSON.stringify(collectGroItemList));
166         }       
167 }); 

 

posted @ 2016-05-22 21:47  Avenstar  阅读(177)  评论(0)    收藏  举报