123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- define(['$', 'template', 'IScroll', 'user', 'product', 'native', 'config', 'address', 'api'], function ($, template, IScroll, user, product, native, config, address, api) {
- var backHash;
- var myDate = new Date();
- var year = myDate.getFullYear();
- var month = myDate.getMonth();
- var ordersLength=false;
- function back (event) {
- event.preventDefault();
- $(document).trigger('spa:navigate', {
- hash: backHash,
- pushData: {
- dontNeedReload: true
- }
- });
- }
- function payCharge(a,b,time){
- var c=parseInt($(a).text());
- if(b){
- if(time=='month'){
- if(c<12){
- c++;
- }
- }else {
- c++;
- }
- }else {
- if(c>1){
- c--;
- }
- }
- $(a).text(c)
- }
- // 刷新样式
- function time(view,pageData){
- year=$('.year-span').text();
- month=$('.month-span').text();
- var startTime = year+'-'+month+'-01';
- var endTime = year+'-'+month+'-30';
- api.getUserTotalOrder({
- user_id: user.id,
- start_time: startTime,
- end_time: endTime,
- }, function (res) {
- if (res.success) {
- if(res.message.result.length==0){
- ordersLength=true;
- }
- $('.total').text(res.message.total);
- var tpl = template('myOrder/list', {
- orders: res.message.result,
- ordersLength:ordersLength,
- });
- $('.list-content', view).html(tpl);
- setTimeout(function () {
- pageData.scroll = new IScroll('#orderContainer');
- }, 100);
- } else {
- $doc.trigger('spa:openpanel', ['simpleAlert', {
- message: '暂无订单数据!'
- }])
- }
- })
- }
- var cachePageData = {}; //page内部的数据传递
- return {
- title: '余额明细',
- body: '',
- init: function (pageData, dtd) {
- /* this是什么? */
- var $view = this;
- var $doc = $(document);
- // 返回
- $view.on('swipeRight', function (event) {
- back.call(this, event);
- });
- $.newTouch('.back-button', function (event) {
- back.call(this, event);
- }, $view);
- $view.on('tapBackButton', function (event) {
- back.call(this, event);
- });
- //tab切换
- $.newTouch('.order-type-control .control-item', function (event) {
- event.preventDefault();
- var type = $(this).data('order-type');
- $('.type-container', $view).hide();
- switch (type) {
- case 1:
- $('#descContainer').show();
- setTimeout(function () {
- pageData.scroll = new IScroll('#productDescScroll');
- }, 100);
- break;
- case 2:
- $('#reviewContainer').show();
- time($view,pageData);
- break;
- }
- }, $view);
- // 切换时间
- $.newTouch('.time-year', function (event) {
- event.preventDefault();
- if($('.o2o-modal').css('display')=='none'){
- $('.o2o-modal').css('display','block')
- }
- $('.modal-box-year').text($('.year-span').text());
- $('.modal-box-month').text($('.month-span').text());
- }, $view);
- // 加减
- $.newTouch('.btn-year-add',function(event){
- event.preventDefault();
- payCharge($('.modal-box-year'),true,'year');
- },$view);
- $.newTouch('.btn-year-sub',function(event){
- event.preventDefault();
- payCharge($('.modal-box-year'),false,'year');
- },$view);
- $.newTouch('.btn-month-add',function(event){
- event.preventDefault();
- payCharge($('.modal-box-month'),true,'month');
- },$view);
- $.newTouch('.btn-month-sub',function(event){
- event.preventDefault();
- payCharge($('.modal-box-month'),false,'month');
- },$view);
- // 取消
- $.newTouch('.cancel',function(event){
- event.preventDefault();
- $('.o2o-modal').css('display','none')
- },$view);
- // 确定
- $.newTouch('.determine',function(event){
- event.preventDefault();
- $('.o2o-modal').css('display','none')
- $('.year-span').text($('.modal-box-year').text());
- $('.month-span').text($('.modal-box-month').text());
- time($view,pageData);
- },$view);
- // 去评价
- $.newTouch('.order-btn-review', function (event) {
- var obj = $(this);
- if (obj.hasClass('disable')) {
- return false;
- }
- var orderID = obj.data('order-id');
- $doc.trigger('spa:openpanel', ['postReview', {
- orderID: orderID,
- didPostReview: function () {
- obj.addClass('disable').text('已评价');
- }
- }]);
- }, $view);
- dtd.resolve();
- },
- beforeopen: function (pageData, dtd) {
- /*获取上一页跳转的路由名称*/
- var pushData = pageData.pushData;
- backHash = pushData.backHash ? pushData.backHash : '';
- var $view = this;
- var $doc = $(document);
- api.getBalanceLog({
- id: user.id
- }, function (res) {
- if (res.success) {
- var balanceLog = res.message;
- if (!cachePageData.massage) {
- if(month<11){
- month=(parseInt(month)+1);
- }
- var startTime = year+'-'+month+'-01';
- var endTime = year+'-'+month+'-30';
- api.getUserTotalOrder({
- user_id: user.id,
- start_time: startTime,
- end_time: endTime,
- }, function (res) {
- if (res.success) {
- var ordersLength=res.message.result.length;
- var tpl = template('balanceLog/index', {
- balanceLog: balanceLog,
- year: year,
- month: month,
- title:'余额明细',
- userBalance: user.balance,
- total: res.message.total,
- orders: res.message.result,
- ordersLength:ordersLength,
- showNavBar: !config.isWX && !config.isChubao,
- });
- $('.spa-page-body', $view).html(tpl);
- setTimeout(function () {
- pageData.scroll = new IScroll('#productDescScroll');
- }, 100);
- } else {
- $doc.trigger('spa:openpanel', ['simpleAlert', {
- message: '暂无订单数据!'
- }])
- }
- })
- }
- } else if (res.error) {
- console.log('失败!');
- }
- });
- dtd.resolve();
- },
- afteropen: function (pageData, dtd) {
- var $view = this;
- var $doc = $(document);
- dtd.resolve();
- },
- beforeclose: function (pageData, dtd) {
- dtd.resolve();
- }
- }
- })
|