index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <template>
  2. <view>
  3. <!-- index.wxml -->
  4. <view class="wrap">
  5. <view class="item">
  6. <view class="item_r flex">
  7. <view class="time" @tap="beginTimeFun">{{ begin_at }}</view>
  8. <view class="line"></view>
  9. <view class="time" @tap="endTimeFun">{{ end_at }}</view>
  10. </view>
  11. <view class="item_search" @tap="bindSearch">查询</view>
  12. </view>
  13. <view class="item flex-start">优惠券总数量:{{ couponsNum }}</view>
  14. <view class="item flex-start">优惠券总金额:{{ couponsTotalPrice }}</view>
  15. </view>
  16. <!-- loading -->
  17. <van-overlay :show="loading" :z-index="100">
  18. <van-loading custom-class="custom_loading" />
  19. </van-overlay>
  20. <!-- 开始时间 -->
  21. <van-popup :show="showBegin" position="bottom">
  22. <van-datetime-picker type="date" title="选择开始时间" :value="currentBegin" @confirm="confirmBeginTime" @cancel="closeBeginTimePop" />
  23. </van-popup>
  24. <!-- 选择结束时间 -->
  25. <van-popup :show="showEnd" position="bottom">
  26. <van-datetime-picker type="date" title="选择结束时间" :value="currentEnd" @confirm="confirmEndTime" @cancel="closeEndTimePop" />
  27. </van-popup>
  28. </view>
  29. </template>
  30. <script>
  31. // index.js
  32. let myPro = require('../../../utils/wxRequest.js');
  33. let util = require('../../../utils/util.js');
  34. export default {
  35. data() {
  36. return {
  37. begin_at: '',
  38. end_at: '',
  39. showBegin: false,
  40. showEnd: false,
  41. currentBegin: new Date().getTime(),
  42. currentEnd: new Date().getTime(),
  43. couponsNum: 0,
  44. couponsTotalPrice: 0,
  45. loading: false // 全局loading
  46. };
  47. },
  48. onLoad: function (options) {
  49. // Do some initialize when page load.
  50. },
  51. onShow: function () {
  52. // Do something when page show.
  53. let that = this;
  54. that.setData({
  55. begin_at: util.formatTime(new Date(), 1),
  56. end_at: util.formatTime(new Date(), 1)
  57. });
  58. that.bindSearch();
  59. },
  60. onReady: function () {
  61. // Do something when page ready.
  62. },
  63. onHide: function () {
  64. // Do something when page hide.
  65. },
  66. onUnload: function () {
  67. // Do something when page close.
  68. },
  69. onPullDownRefresh: function () {
  70. // Do something when pull down.
  71. },
  72. onReachBottom: function () {
  73. // Do something when page reach bottom.
  74. },
  75. onPageScroll: function () {
  76. // Do something when page scroll
  77. },
  78. onResize: function () {
  79. // Do something when page resize
  80. },
  81. methods: {
  82. // 开始时间
  83. beginTimeFun() {
  84. let that = this;
  85. that.setData({
  86. showBegin: true
  87. });
  88. },
  89. // 选择开始时间
  90. confirmBeginTime(event) {
  91. console.log('开始时间', event);
  92. let that = this;
  93. let selectTime = new Date(event.detail);
  94. let begin_at = util.formatTime(selectTime, 1);
  95. that.setData({
  96. begin_at: begin_at,
  97. currentBegin: event.detail,
  98. showBegin: false
  99. });
  100. },
  101. // 关闭开始时间
  102. closeBeginTimePop() {
  103. let that = this;
  104. that.setData({
  105. showBegin: false
  106. });
  107. },
  108. // 结束时间
  109. endTimeFun() {
  110. let that = this;
  111. that.setData({
  112. showEnd: true
  113. });
  114. },
  115. // 确认结束时间
  116. confirmEndTime(event) {
  117. // console.log('结束时间',event)
  118. let that = this;
  119. let selectTime = new Date(event.detail);
  120. let end_at = util.formatTime(selectTime, 1); // 检查结束时间
  121. if (event.detail < that.currentBegin) {
  122. uni.showToast({
  123. title: '结束时间不可小于开始时间',
  124. icon: 'none'
  125. });
  126. return;
  127. }
  128. that.setData({
  129. end_at: end_at,
  130. currentEnd: event.detail,
  131. showEnd: false
  132. });
  133. },
  134. // 关闭结束时间
  135. closeEndTimePop() {
  136. let that = this;
  137. that.setData({
  138. showEnd: false
  139. });
  140. },
  141. // 查询
  142. bindSearch() {
  143. let that = this;
  144. if (!that.begin_at) {
  145. uni.showToast({
  146. title: '请选择开始时间',
  147. icon: 'none'
  148. });
  149. return;
  150. }
  151. if (!that.end_at) {
  152. uni.showToast({
  153. title: '请选择结束时间',
  154. icon: 'none'
  155. });
  156. return;
  157. }
  158. if (that.currentEnd < that.currentBegin) {
  159. uni.showToast({
  160. title: '结束时间不可小于开始时间',
  161. icon: 'none'
  162. });
  163. return;
  164. }
  165. that.setData({
  166. loading: true
  167. }); // 开始时间和结束时间比较
  168. let params = {
  169. begin_at: that.begin_at,
  170. end_at: that.end_at
  171. };
  172. myPro
  173. .wxRequest('store/tx/coupon', 'GET', params)
  174. .then((res) => {
  175. that.setData({
  176. loading: false,
  177. couponsNum: res.result.couponCount ? res.result.couponCount : 0,
  178. couponsTotalPrice: res.result.coupon_price_count ? res.result.coupon_price_count : 0
  179. });
  180. })
  181. .catch((err) => {
  182. console.log('报错信息', err);
  183. that.setData({
  184. loading: false
  185. });
  186. uni.showToast({
  187. title: err,
  188. icon: 'none'
  189. });
  190. });
  191. }
  192. }
  193. };
  194. </script>
  195. <style>
  196. /**index.wxss**/
  197. .wrap {
  198. width: 690rpx;
  199. /* background:rgba(255,255,255,1);
  200. box-shadow:0rpx 0rpx 21rpx 0rpx rgba(0, 0, 0, 0.09); */
  201. border-radius: 10rpx;
  202. margin: 0 auto;
  203. }
  204. .item {
  205. width: 690rpx;
  206. /* height:100rpx; */
  207. margin-top: 30rpx;
  208. display: flex;
  209. align-items: center;
  210. position: relative;
  211. }
  212. .item .item_l {
  213. padding-right: 20rpx;
  214. display: flex;
  215. }
  216. .item .title {
  217. font-size: 32rpx;
  218. color: rgba(0, 0, 0, 0.87);
  219. }
  220. .item .item_r {
  221. padding-right: 20rpx;
  222. }
  223. .item .item_r.flex {
  224. display: flex;
  225. align-items: center;
  226. }
  227. .time {
  228. width: 240rpx;
  229. height: 50rpx;
  230. background: rgba(255, 255, 255, 1);
  231. border: 1rpx solid rgba(0, 0, 0, 0.12);
  232. border-radius: 10rpx;
  233. text-align: center;
  234. color: rgba(89, 89, 89, 1);
  235. }
  236. .line {
  237. width: 18rpx;
  238. height: 2rpx;
  239. background: rgba(0, 0, 0, 0.12);
  240. margin: 0 12rpx;
  241. }
  242. /* 查询 */
  243. .item_search {
  244. width: 100rpx;
  245. height: 50rpx;
  246. margin-left: 20rpx;
  247. background: #d54c43;
  248. border-radius: 45rpx;
  249. font-size: 24rpx;
  250. color: #ffffff;
  251. display: flex;
  252. align-items: center;
  253. justify-content: center;
  254. }
  255. </style>