123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- down: false,
- shopping: [],
- // shopping: [
- // {
- // list: [
- // 'sss',
- // 'sss',
- // 'sss',
- // ],
- // isExpire:false
- // },
- // {
- // list: [
- // 'sss',
- // 'sss',
- // 'sss',
- // ],
- // isExpire:true
- // },
- // ],
- isNum:false,
- code:'',
- pageindex: 1,
- currtime: '',
- totalprice: 0,
- freight: 0
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({totalprice: parseFloat(options.totalprice),freight:parseFloat(options.freight)})
- },
- onShow: function(){
- this.getdata()
- this.setData({currtime: this.getcurrtime()})
- },
- gob(e){
- console.log(e.target.dataset.item)
- let pages = getCurrentPages();
- let prevPage = pages[pages.length - 2];
- prevPage.setData({
- citem: e.target.dataset.item,
- })
- wx.navigateBack({});
- },
- getcurrtime(){
- let that = this
- let time = new Date()
- let year = time.getFullYear()
- let month = time.getMonth() + 1
- let date = time.getDate()
- let hours = time.getHours()
- let minute = time.getMinutes()
- let second = time.getSeconds()
-
- if (month < 10) { month = '0' + month }
- if (date < 10) { date = '0' + date }
- if (hours < 10) { hours = '0' + hours }
- if (minute < 10) { minute = '0' + minute }
- if (second < 10) { second = '0' + second }
- // console.log(year + '-' + month + '-' + date + ' ' + hours + ':' + minute + ':' + second)
- return year + '-' + month + '-' + date + ' ' + hours + ':' + minute + ':' + second
- },
- getdata(){
- var that = this;
- wx.showLoading()
- app.api.useApi(app.globalData.baseAppUrl + "api/user/coupon", {}, "get").then(function (res) {
- console.log(res)
- wx.hideLoading()
- if (that.data.pageindex == 1) {
- that.setData({shopping: []})
- }
- if (res.message.data.data.length > 0) {
- that.setData({shopping: that.data.shopping.concat(res.message.data.data)})
- } else {
- that.setData({pageindex: that.data.pageindex -= 1})
- }
- }).catch(function (err) { console.log(err) })
- },
- changeBtn(e) {
- if (e.detail.value || e.detail.value != '') {
- this.setData({
- code: e.detail.value,
- isNum:true
- })
- }else{
- this.setData({
- code: e.detail.value,
- isNum:false
- })
- }
-
- },
- onReady: function () {
- this.toast = this.selectComponent("#toast");
- },
- listenerLogin: function () {
- let that = this
- // this.toast.showToast('优惠券无效');
- wx.showLoading()
- app.api.useApi(app.globalData.baseAppUrl + "api/coupon/code", {code:that.data.code}, "post").then(function (res) {
- console.log(res)
- if (res.code != 200) {
- wx.showLoading({
- title: res.message.msg,
- })
- setTimeout(function () {
- wx.hideLoading()
- }, 1000);
- } else {
- wx.showLoading({
- title: res.message.msg,
- })
- setTimeout(() => {
- that.getdata()
- }, 1000);
- }
- }).catch(function (err) { console.log(err) })
- },
- exchange(){
- if (!this.data.isNum) return
- this.listenerLogin()
- },
- clearValue(){
- this.setData({
- code:'',
- isNum:false
- })
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- this.setData({pageindex:this.data.pageindex+=1})
- this.getdata()
- },
- })
|