index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // index.js
  2. let myPro = require("../../../utils/wxRequest.js");
  3. let util = require("../../../utils/util.js");
  4. Page({
  5. data: {
  6. begin_at: '',
  7. end_at: '',
  8. showBegin: false,
  9. showEnd: false,
  10. currentBegin: new Date().getTime(),
  11. currentEnd: new Date().getTime(),
  12. couponsNum: 0,
  13. couponsTotalPrice: 0,
  14. loading: false // 全局loading
  15. },
  16. onLoad: function (options) {
  17. // Do some initialize when page load.
  18. },
  19. onShow: function () {
  20. // Do something when page show.
  21. let that = this;
  22. that.setData({
  23. begin_at: util.formatTime(new Date(),1),
  24. end_at: util.formatTime(new Date(),1)
  25. });
  26. that.bindSearch();
  27. },
  28. onReady: function () {
  29. // Do something when page ready.
  30. },
  31. onHide: function () {
  32. // Do something when page hide.
  33. },
  34. onUnload: function () {
  35. // Do something when page close.
  36. },
  37. onPullDownRefresh: function () {
  38. // Do something when pull down.
  39. },
  40. onReachBottom: function () {
  41. // Do something when page reach bottom.
  42. },
  43. onPageScroll: function () {
  44. // Do something when page scroll
  45. },
  46. onResize: function () {
  47. // Do something when page resize
  48. },
  49. // 开始时间
  50. beginTimeFun(){
  51. let that = this;
  52. that.setData({
  53. showBegin: true
  54. })
  55. },
  56. // 选择开始时间
  57. confirmBeginTime(event){
  58. console.log('开始时间',event);
  59. let that = this;
  60. let selectTime = new Date(event.detail);
  61. let begin_at = util.formatTime(selectTime,1);
  62. that.setData({
  63. begin_at: begin_at,
  64. currentBegin: event.detail,
  65. showBegin: false
  66. })
  67. },
  68. // 关闭开始时间
  69. closeBeginTimePop(){
  70. let that = this;
  71. that.setData({
  72. showBegin: false
  73. })
  74. },
  75. // 结束时间
  76. endTimeFun(){
  77. let that = this;
  78. that.setData({
  79. showEnd: true
  80. })
  81. },
  82. // 确认结束时间
  83. confirmEndTime(event){
  84. // console.log('结束时间',event)
  85. let that = this;
  86. let selectTime = new Date(event.detail);
  87. let end_at = util.formatTime(selectTime,1);
  88. // 检查结束时间
  89. if(event.detail < that.data.currentBegin){
  90. wx.showToast({
  91. title: "结束时间不可小于开始时间",
  92. icon: "none"
  93. });
  94. return;
  95. };
  96. that.setData({
  97. end_at: end_at,
  98. currentEnd: event.detail,
  99. showEnd: false
  100. });
  101. },
  102. // 关闭结束时间
  103. closeEndTimePop(){
  104. let that = this;
  105. that.setData({
  106. showEnd: false
  107. })
  108. },
  109. // 查询
  110. bindSearch(){
  111. let that = this;
  112. if(!that.data.begin_at){
  113. wx.showToast({
  114. title: "请选择开始时间",
  115. icon: "none"
  116. });
  117. return;
  118. };
  119. if(!that.data.end_at){
  120. wx.showToast({
  121. title: "请选择结束时间",
  122. icon: "none"
  123. });
  124. return;
  125. };
  126. if(that.data.currentEnd < that.data.currentBegin){
  127. wx.showToast({
  128. title: "结束时间不可小于开始时间",
  129. icon: "none"
  130. });
  131. return;
  132. };
  133. that.setData({
  134. loading: true
  135. });
  136. // 开始时间和结束时间比较
  137. let params = {
  138. begin_at: that.data.begin_at,
  139. end_at: that.data.end_at
  140. };
  141. myPro.wxRequest("store/tx/coupon","GET",params).then(res=>{
  142. that.setData({
  143. loading: false,
  144. couponsNum: res.result.couponCount ? res.result.couponCount : 0,
  145. couponsTotalPrice: res.result.coupon_price_count ? res.result.coupon_price_count : 0
  146. });
  147. }).catch(err=>{
  148. console.log('报错信息',err);
  149. that.setData({
  150. loading: false
  151. });
  152. wx.showToast({
  153. title: err,
  154. icon: "none"
  155. })
  156. })
  157. }
  158. });