b2bServices.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. define([ 'angular', 'common/utils', 'big'], function(angular, utils) {
  2. 'use strict';
  3. angular.module('common.b2bServices', [ 'common.utils', 'ngResource' ])
  4. .factory('SearchFilter', function() {
  5. return {
  6. /**
  7. * 改变单据日期范围
  8. */
  9. getDateCondition: function (zone, condition) {
  10. var fromDate = new Date();
  11. var toDate = new Date();
  12. //去除时分秒限制,dateFrom设置成0时0分0秒,dateTo设置成23时59分59秒
  13. fromDate.setHours(0, 0, 0, 0);
  14. toDate.setHours(23, 59, 59, 999);
  15. if (zone == -1) { // 自定义时间,什么都不做
  16. } else if (zone == 1) {
  17. fromDate.setMonth(fromDate.getMonth() - 1);
  18. condition.dateFrom = fromDate;
  19. condition.dateTo = toDate;
  20. } else if (zone == 3) {
  21. fromDate.setMonth(fromDate.getMonth() - 3);
  22. condition.dateFrom = fromDate;
  23. condition.dateTo = toDate;
  24. } else if (zone == 6) {
  25. fromDate.setMonth(fromDate.getMonth() - 6);
  26. condition.dateFrom = fromDate;
  27. condition.dateTo = toDate;
  28. } else {
  29. condition.dateFrom = null;
  30. condition.dateTo = null;
  31. }
  32. return condition;
  33. },
  34. /**
  35. * 改变单据交货日期范围
  36. */
  37. getDeliveryCondition: function (zone, condition) {
  38. var date = new Date();
  39. if (zone == -1) {
  40. condition.deliveryFrom = null;
  41. condition.deliveryTo = null;
  42. } else if (zone == 1) {
  43. date.setMonth(date.getMonth() + 1);
  44. condition.deliveryTo = date;
  45. condition.deliveryFrom = new Date();
  46. } else if (zone == 2) {
  47. date.setMonth(date.getMonth() + 2);
  48. condition.deliveryTo = date;
  49. condition.deliveryFrom = new Date();
  50. }
  51. return condition;
  52. },
  53. /**
  54. * 将日期转化为整数日期
  55. */
  56. getDateTime: function (date) {
  57. if (angular.isDate(date)) {
  58. return date.getTime();
  59. } else {
  60. return null;
  61. }
  62. },
  63. /**
  64. * 将date转成time
  65. *
  66. * @param date
  67. * @returns {string}
  68. */
  69. formatDateTime: function (date) {
  70. var y = date.getFullYear();
  71. var m = date.getMonth() + 1;
  72. m = m < 10 ? ('0' + m) : m;
  73. var d = date.getDate();
  74. d = d < 10 ? ('0' + d) : d;
  75. var h = date.getHours();
  76. var minute = date.getMinutes();
  77. var sec = date.getSeconds();
  78. minute = minute < 10 ? ('0' + minute) : minute;
  79. return y + '-' + m + '-' + d+' '+h+':'+minute+':'+sec;
  80. }
  81. };
  82. }).factory('B2bCommerce', ['$resource', function($resource) {
  83. return $resource('b2b/sale', {}, {
  84. accessUrl : {
  85. url: 'b2b/sale/accessUrl',
  86. method: 'GET'
  87. }
  88. });
  89. }]);
  90. });