You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

269 lines
6.6 KiB

//index.js
//获取应用实例
const app = getApp()
Page({
data: {
items: [],
sessionId:''
},
//事件处理函数
bindViewTap: function () {
wx.navigateTo({
url: '../logs/logs'
})
},
bindFocus: function () {
wx.navigateTo({
title: "goback",
url: '../mcenter/mcenter'
})
},
lookDetail: function (e) {
let str = JSON.stringify(e.currentTarget.dataset.item);
// wx.navigateTo({
// url: '../message/message?jsonStr=' + str
// })
console.log(str);
},
goPay: function (e) {
let str = JSON.stringify(e.currentTarget.dataset.item);
// wx.navigateTo({
// url: '../pay/pay?jsonStr=' + str
// })
console.log(str);
},
goBooking: function (e) {
wx.navigateTo({
url: '../two_code/two_code'
})
},
goCancel: function (e) {
let str = e.currentTarget.dataset.item;
let that = this;
wx.request({//取消订单
url: app.gw.hostUrl + '/mall/wxa/order/cancel',
method: 'put',
data: {
orderNo: str.orderNo,
},
header: {
'Content-Type': 'application/x-www-form-urlencoded',
'sessionId': wx.getStorageSync('sessionId')
},
success: function (res) {
let data = res.data;
let status = data.code;
if (status != 0) {
wx.showToast({
title: data.msg,
icon: 'none',
duration: 2000
})
return;
}
wx.switchTab({
url: '../order/order',
success: function (e) {
var page = getCurrentPages().pop();
if (page == undefined || page == null) return;
console.log(page);
page.onLoad();
}
})
that.onPullDownRefresh() ;
},
fail: function (e) {
wx.showToast({
title: '网络异常!err:authlogin',
icon: 'none',
duration: 2000
})
},
});
},
goRefund: function (e) {
let str = e.currentTarget.dataset.item;
let that = this;
wx.request({//取消订单
url: app.gw.hostUrl + '/mall/wxa/order/refund',
method: 'put',
data: {
orderNo: str.orderNo,
},
header: {
'Content-Type': 'application/x-www-form-urlencoded',
'sessionId': wx.getStorageSync('sessionId')
},
success: function (res) {
let data = res.data;
let status = data.code;
if (status != 0) {
wx.showToast({
title: data.msg,
icon: 'none',
duration: 2000
})
return;
}
wx.switchTab({
url: '../order/order',
success: function (e) {
var page = getCurrentPages().pop();
if (page == undefined || page == null) return;
console.log(page);
page.onShow();
}
})
that.onPullDownRefresh();
},
fail: function (e) {
wx.showToast({
title: '网络异常!err:authlogin',
icon: 'none',
duration: 2000
})
},
});
},
onPullDownRefresh() {
console.log('--------下拉刷新-------')
let that = this;
wx.showNavigationBarLoading() //在标题栏中显示加载
wx.request({
url: app.gw.hostUrl + '/mall/wxa/order/list',
data: { status: '' },
header: {
"Content-Type": "application/json",
'sessionId': wx.getStorageSync('sessionId')
},
method: 'GET',
dataType: 'json',
responseType: 'text',
success: function (res) {
var data = res.data;
var status = data.code;
if (status != 0) {
wx.showToast({
title: data.msg,
duration: 3000
});
return;
}
that.setData({
items: res.data.response
})
},
fail: function (res) {
wx.showToast({
title: '网络异常!err:authlogin',
icon: 'none',
duration: 2000
});
},
complete: function (res) {
// complete
wx.hideNavigationBarLoading() //完成停止加载
wx.stopPullDownRefresh() //停止下拉刷新
},
})
},
rePay: function (e) {
let str = e.currentTarget.dataset.item;
wx.navigateTo({
url: '../detail/detail?jsonStr=' + str
})
},
goLogin: function (e) {
if (wx.getStorageSync('sessionId') == '') {
wx.navigateTo({
url: '../login/login'
})
}else{
wx.switchTab({
url: '../jz/jz'
})
}
},
onLoad: function () {
if(wx.getStorageSync('sessionId')==''){
wx.navigateTo({
url: '../login/login'
})
}else{
let that = this;
that.setData({
sessionId: wx.getStorageSync('sessionId')
})
wx.request({
url: app.gw.hostUrl + '/mall/wxa/order/list',
data: { status: '' },
header: {
"Content-Type": "application/json",
'sessionId': wx.getStorageSync('sessionId')
},
method: 'GET',
dataType: 'json',
responseType: 'text',
success: function (res) {
var data = res.data;
var status = data.code;
if (status != 0) {
wx.showToast({
title: data.msg,
icon: 'none',
duration: 3000
});
return;
}
that.setData({
items: res.data.response
})
},
fail: function (res) {
wx.showToast({
title: '网络异常!err:authlogin',
icon:'none',
duration: 2000
});
},
complete: function (res) { },
})
}
if (app.globalData.userInfo) {
this.setData({
userInfo: app.globalData.userInfo,
hasUserInfo: true
})
console.log(app.globalData.userInfo);
} else if (this.data.canIUse) {
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
app.userInfoReadyCallback = res => {
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
} else {
// 在没有 open-type=getUserInfo 版本的兼容处理
wx.getUserInfo({
success: res => {
app.globalData.userInfo = res.userInfo
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
}
},
getUserInfo: function (e) {
console.log(e)
app.globalData.userInfo = e.detail.userInfo
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true
})
}
})