balanceLog.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. define(['$', 'template', 'IScroll', 'user', 'product', 'native', 'config', 'address', 'api'], function ($, template, IScroll, user, product, native, config, address, api) {
  2. var backHash;
  3. var myDate = new Date();
  4. var year = myDate.getFullYear();
  5. var month = myDate.getMonth();
  6. var ordersLength=false;
  7. function back (event) {
  8. event.preventDefault();
  9. $(document).trigger('spa:navigate', {
  10. hash: backHash,
  11. pushData: {
  12. dontNeedReload: true
  13. }
  14. });
  15. }
  16. function payCharge(a,b,time){
  17. var c=parseInt($(a).text());
  18. if(b){
  19. if(time=='month'){
  20. if(c<12){
  21. c++;
  22. }
  23. }else {
  24. c++;
  25. }
  26. }else {
  27. if(c>1){
  28. c--;
  29. }
  30. }
  31. $(a).text(c)
  32. }
  33. // 刷新样式
  34. function time(view,pageData){
  35. year=$('.year-span').text();
  36. month=$('.month-span').text();
  37. var startTime = year+'-'+month+'-01';
  38. var endTime = year+'-'+month+'-30';
  39. api.getUserTotalOrder({
  40. user_id: user.id,
  41. start_time: startTime,
  42. end_time: endTime,
  43. }, function (res) {
  44. if (res.success) {
  45. if(res.message.result.length==0){
  46. ordersLength=true;
  47. }
  48. $('.total').text(res.message.total);
  49. var tpl = template('myOrder/list', {
  50. orders: res.message.result,
  51. ordersLength:ordersLength,
  52. });
  53. $('.list-content', view).html(tpl);
  54. setTimeout(function () {
  55. pageData.scroll = new IScroll('#orderContainer');
  56. }, 100);
  57. } else {
  58. $doc.trigger('spa:openpanel', ['simpleAlert', {
  59. message: '暂无订单数据!'
  60. }])
  61. }
  62. })
  63. }
  64. var cachePageData = {}; //page内部的数据传递
  65. return {
  66. title: '余额明细',
  67. body: '',
  68. init: function (pageData, dtd) {
  69. /* this是什么? */
  70. var $view = this;
  71. var $doc = $(document);
  72. // 返回
  73. $view.on('swipeRight', function (event) {
  74. back.call(this, event);
  75. });
  76. $.newTouch('.back-button', function (event) {
  77. back.call(this, event);
  78. }, $view);
  79. $view.on('tapBackButton', function (event) {
  80. back.call(this, event);
  81. });
  82. //tab切换
  83. $.newTouch('.order-type-control .control-item', function (event) {
  84. event.preventDefault();
  85. var type = $(this).data('order-type');
  86. $('.type-container', $view).hide();
  87. switch (type) {
  88. case 1:
  89. $('#descContainer').show();
  90. setTimeout(function () {
  91. pageData.scroll = new IScroll('#productDescScroll');
  92. }, 100);
  93. break;
  94. case 2:
  95. $('#reviewContainer').show();
  96. time($view,pageData);
  97. break;
  98. }
  99. }, $view);
  100. // 切换时间
  101. $.newTouch('.time-year', function (event) {
  102. event.preventDefault();
  103. if($('.o2o-modal').css('display')=='none'){
  104. $('.o2o-modal').css('display','block')
  105. }
  106. $('.modal-box-year').text($('.year-span').text());
  107. $('.modal-box-month').text($('.month-span').text());
  108. }, $view);
  109. // 加减
  110. $.newTouch('.btn-year-add',function(event){
  111. event.preventDefault();
  112. payCharge($('.modal-box-year'),true,'year');
  113. },$view);
  114. $.newTouch('.btn-year-sub',function(event){
  115. event.preventDefault();
  116. payCharge($('.modal-box-year'),false,'year');
  117. },$view);
  118. $.newTouch('.btn-month-add',function(event){
  119. event.preventDefault();
  120. payCharge($('.modal-box-month'),true,'month');
  121. },$view);
  122. $.newTouch('.btn-month-sub',function(event){
  123. event.preventDefault();
  124. payCharge($('.modal-box-month'),false,'month');
  125. },$view);
  126. // 取消
  127. $.newTouch('.cancel',function(event){
  128. event.preventDefault();
  129. $('.o2o-modal').css('display','none')
  130. },$view);
  131. // 确定
  132. $.newTouch('.determine',function(event){
  133. event.preventDefault();
  134. $('.o2o-modal').css('display','none')
  135. $('.year-span').text($('.modal-box-year').text());
  136. $('.month-span').text($('.modal-box-month').text());
  137. time($view,pageData);
  138. },$view);
  139. // 去评价
  140. $.newTouch('.order-btn-review', function (event) {
  141. var obj = $(this);
  142. if (obj.hasClass('disable')) {
  143. return false;
  144. }
  145. var orderID = obj.data('order-id');
  146. $doc.trigger('spa:openpanel', ['postReview', {
  147. orderID: orderID,
  148. didPostReview: function () {
  149. obj.addClass('disable').text('已评价');
  150. }
  151. }]);
  152. }, $view);
  153. dtd.resolve();
  154. },
  155. beforeopen: function (pageData, dtd) {
  156. /*获取上一页跳转的路由名称*/
  157. var pushData = pageData.pushData;
  158. backHash = pushData.backHash ? pushData.backHash : '';
  159. var $view = this;
  160. var $doc = $(document);
  161. api.getBalanceLog({
  162. id: user.id
  163. }, function (res) {
  164. if (res.success) {
  165. var balanceLog = res.message;
  166. if (!cachePageData.massage) {
  167. if(month<11){
  168. month=(parseInt(month)+1);
  169. }
  170. var startTime = year+'-'+month+'-01';
  171. var endTime = year+'-'+month+'-30';
  172. api.getUserTotalOrder({
  173. user_id: user.id,
  174. start_time: startTime,
  175. end_time: endTime,
  176. }, function (res) {
  177. if (res.success) {
  178. var ordersLength=res.message.result.length;
  179. var tpl = template('balanceLog/index', {
  180. balanceLog: balanceLog,
  181. year: year,
  182. month: month,
  183. title:'余额明细',
  184. userBalance: user.balance,
  185. total: res.message.total,
  186. orders: res.message.result,
  187. ordersLength:ordersLength,
  188. showNavBar: !config.isWX && !config.isChubao,
  189. });
  190. $('.spa-page-body', $view).html(tpl);
  191. setTimeout(function () {
  192. pageData.scroll = new IScroll('#productDescScroll');
  193. }, 100);
  194. } else {
  195. $doc.trigger('spa:openpanel', ['simpleAlert', {
  196. message: '暂无订单数据!'
  197. }])
  198. }
  199. })
  200. }
  201. } else if (res.error) {
  202. console.log('失败!');
  203. }
  204. });
  205. dtd.resolve();
  206. },
  207. afteropen: function (pageData, dtd) {
  208. var $view = this;
  209. var $doc = $(document);
  210. dtd.resolve();
  211. },
  212. beforeclose: function (pageData, dtd) {
  213. dtd.resolve();
  214. }
  215. }
  216. })