| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- // index.js
- let myPro = require("../../../utils/wxRequest.js");
- let util = require("../../../utils/util.js");
- Page({
- data: {
- begin_at: '',
- end_at: '',
- showBegin: false,
- showEnd: false,
- currentBegin: new Date().getTime(),
- currentEnd: new Date().getTime(),
- couponsNum: 0,
- couponsTotalPrice: 0,
- loading: false // 全局loading
- },
- onLoad: function (options) {
- // Do some initialize when page load.
- },
- onShow: function () {
- // Do something when page show.
- let that = this;
- that.setData({
- begin_at: util.formatTime(new Date(),1),
- end_at: util.formatTime(new Date(),1)
- });
- that.bindSearch();
- },
- onReady: function () {
- // Do something when page ready.
- },
- onHide: function () {
- // Do something when page hide.
- },
- onUnload: function () {
- // Do something when page close.
- },
- onPullDownRefresh: function () {
- // Do something when pull down.
-
- },
- onReachBottom: function () {
- // Do something when page reach bottom.
- },
- onPageScroll: function () {
- // Do something when page scroll
-
- },
- onResize: function () {
- // Do something when page resize
- },
- // 开始时间
- beginTimeFun(){
- let that = this;
- that.setData({
- showBegin: true
- })
- },
- // 选择开始时间
- confirmBeginTime(event){
- console.log('开始时间',event);
- let that = this;
- let selectTime = new Date(event.detail);
- let begin_at = util.formatTime(selectTime,1);
- that.setData({
- begin_at: begin_at,
- currentBegin: event.detail,
- showBegin: false
- })
- },
- // 关闭开始时间
- closeBeginTimePop(){
- let that = this;
- that.setData({
- showBegin: false
- })
- },
- // 结束时间
- endTimeFun(){
- let that = this;
- that.setData({
- showEnd: true
- })
- },
- // 确认结束时间
- confirmEndTime(event){
- // console.log('结束时间',event)
- let that = this;
- let selectTime = new Date(event.detail);
- let end_at = util.formatTime(selectTime,1);
- // 检查结束时间
- if(event.detail < that.data.currentBegin){
- wx.showToast({
- title: "结束时间不可小于开始时间",
- icon: "none"
- });
- return;
- };
- that.setData({
- end_at: end_at,
- currentEnd: event.detail,
- showEnd: false
- });
- },
- // 关闭结束时间
- closeEndTimePop(){
- let that = this;
- that.setData({
- showEnd: false
- })
- },
- // 查询
- bindSearch(){
- let that = this;
- if(!that.data.begin_at){
- wx.showToast({
- title: "请选择开始时间",
- icon: "none"
- });
- return;
- };
- if(!that.data.end_at){
- wx.showToast({
- title: "请选择结束时间",
- icon: "none"
- });
- return;
- };
- if(that.data.currentEnd < that.data.currentBegin){
- wx.showToast({
- title: "结束时间不可小于开始时间",
- icon: "none"
- });
- return;
- };
- that.setData({
- loading: true
- });
- // 开始时间和结束时间比较
- let params = {
- begin_at: that.data.begin_at,
- end_at: that.data.end_at
- };
- myPro.wxRequest("store/tx/coupon","GET",params).then(res=>{
- that.setData({
- loading: false,
- couponsNum: res.result.couponCount ? res.result.couponCount : 0,
- couponsTotalPrice: res.result.coupon_price_count ? res.result.coupon_price_count : 0
- });
- }).catch(err=>{
- console.log('报错信息',err);
- that.setData({
- loading: false
- });
- wx.showToast({
- title: err,
- icon: "none"
- })
- })
- }
- });
|