// pages/my/my_order/my_order.js import { dateFormat } from '../../../utils/util' var app = getApp(); let time = null; Page({ /** * 页面的初始数据 */ data: { ip: app.globalData.ipUrl, type: 0, page: 1, num: 10, orderList: [] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // 登录 wx.getStorage({ key: 'user', success: data => { this.setData({ userData: data.data, login: true, }) console.log('身份', this.data.userData) }, }) if (options.state) { console.log(options.state) var type = options.state this.setData({ type: type, }) } }, countDown(data) { for (var i = 0; i < data.length; i++) { if (data[i].orderRefundTimes && data[i].status == 63) { let orderRefundTimes = new Date(data[i].orderRefundTimes.replace(/-/g, '/')).getTime(); let cDateTime = new Date().getTime(); let time = orderRefundTimes - cDateTime; if (time > 0) { let timeStr = dateFormat(time) data[i]["timeStr"] = timeStr; data[i]["time"] = time; } } } this.setData({ orderList: data }) }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.setData({ page: 1, orderList: [] }) this.orderList(); }, //订单数据 orderList: function () { if (time) { clearTimeout(time); } console.log(11111) wx.showLoading({ title: '加载中..', }) wx.request({ url: app.globalData.ip + '/wisdommining/api/order/getOrderList', method: 'GET', header: { "content-type": "application/x-www-form-urlencoded", }, data: { userId: app.globalData.userId, status: this.data.type, page: this.data.page, num: this.data.num, addressId: undefined, currentOrder: undefined }, success: res => { console.log(res) wx.hideLoading() if (res.data.code == 1) { if (res.data.value.records.length > 0) { var orderList = this.data.orderList; var data = res.data.value.records; for (var i = 0; i < data.length; i++) { if (data[i].orderRefundTimes && data[i].status == 63) { let orderRefundTimes = new Date(data[i].orderRefundTimes.replace(/-/g, '/')).getTime(); let cDateTime = new Date().getTime(); let time = orderRefundTimes - cDateTime; if (time > 0) { let timeStr = dateFormat(time) console.log(timeStr) data[i]["timeStr"] = timeStr; data[i]["time"] = time; } } for (var j = 0; j < data[i].goodsList.length; j++) { if (data[i].goodsList[j].wisdGoodsSpec !== null) { data[i].goodsList[j].price = data[i].goodsList[j].wisdGoodsSpec.specBulyPrice == null ? data[i].goodsList[j].wisdGoodsSpec.specPrice : data[i].goodsList[j].wisdGoodsSpec.specBulyPrice; } } orderList.push(data[i]) } this.setData({ orderList: orderList, page: this.data.page + 1 }) time = setInterval(() => { this.countDown(orderList); }, 1000) } else { if (this.data.page != 1) { wx.showToast({ title: '暂无更多~', icon: 'none' }) } } } else { wx.showModal({ title: '提示!', content: res.data.message, showCancel: false, }) } } }) }, //type type: function (e) { var type = e.currentTarget.dataset.type; this.setData({ type: type, page: 1, orderList: [] }) this.orderList(); }, //物流 express: function (e) { app.globalData.expressData = JSON.stringify(e.currentTarget.dataset.item); wx.navigateTo({ url: '/pages/expresswx/expresswx', }) }, viewLogisticsDetails(e) { const { logisticsNum, logisticsName } = e.currentTarget.dataset wx.navigateTo({ url: `/pages/logistics_details/logistics_details?logisticsNum=${logisticsNum}&logisticsName=${logisticsName}`, }) }, updateAddress(e) { const { id: orderId, orderAddress } = e.currentTarget.dataset this.setData({ currentOrder: orderId }) wx.navigateTo({ url: '/pages/my/my_address/my_address?orderAddress=true&updateAddress=true' + "&oriAddr=" + orderAddress, }) }, //查看进度 after: function (e) { wx.navigateTo({ url: '/pages/my/after_sales/after_sales?num=' + e.currentTarget.dataset.num + '&id=' + e.currentTarget.dataset.id, }) }, //退换货记录 jilu: function (e) { let id = e.currentTarget.dataset.id; let num = e.currentTarget.dataset.num; let sq = e.currentTarget.dataset.sq; wx.navigateTo({ url: '/pages/my/after_jilu/after_jilu?id=' + id + '&num=' + num + '&sq=' + sq, }) }, //申请退款 apply1: function (e) { let id = e.currentTarget.dataset.id; wx.showModal({ title: '提示', content: '确认申请退款?', success: s => { if (s.confirm) { wx.showLoading({ title: '提交中', mask: true, }) wx.request({ url: app.globalData.ip + '/wisdommining/api/order/afterSales', method: 'POST', header: { "content-type": "application/x-www-form-urlencoded", }, data: { orderRefund: '', orderId: id, orderRefundImg: '', status: 62 }, success: res => { console.log(res) wx.hideLoading() if (res.data.code == 1) { wx.showToast({ title: '提交成功', icon: 'success', success: sss => { setTimeout(() => { this.setData({ page: 1, orderList: [] }) this.orderList(); }, 1000); } }) } else { wx.showModal({ title: '获取数据失败!', content: res.data.message, showCancel: false, }) } } }) } } }) }, //申请售后 apply: function (e) { let id = e.currentTarget.dataset.id; let num = e.currentTarget.dataset.num; let sq = e.currentTarget.dataset.sq; wx.navigateTo({ url: '/pages/my/applyAfter_sales/applyAfter_sales?id=' + id + '&num=' + num + '&sq=' + sq, }) }, //支付订单 pay: function (e) { let id = e.currentTarget.dataset.id wx.navigateTo({ url: '/pages/pay/pay?id=' + id, }) }, // 删除订单 del(e) { let index = e.currentTarget.dataset.index let orderId = this.data.orderList[index].id wx.showModal({ title: '提示信息', content: '您确认删除当前订单吗?', success: ee => { if (ee.confirm) { wx.request({ url: app.globalData.ip + '/wisdommining/api/order/delOrder', method: 'POST', header: { "content-type": "application/x-www-form-urlencoded", }, data: { orderId: orderId, }, success: res => { console.log(res) wx.hideLoading() if (res.data.code == 1) { wx.showToast({ title: '删除成功~', icon: 'none', success: eee => { setTimeout((t) => { this.setData({ page: 1, orderList: [], }) this.orderList(); }, 1000); } }) } else { wx.showModal({ title: '提示!', content: res.data.message, showCancel: false, }) } } }) } } }) }, //确认收货 confirm: function (e) { wx.showModal({ title: '提示!', content: '确认已收到商品吗?', success: s => { if (s.confirm) { wx.showLoading({ title: '加载中..', }) wx.request({ url: app.globalData.ip + '/wisdommining/api/order/confirmOrder', method: 'POST', header: { "content-type": "application/x-www-form-urlencoded", }, data: { orderId: e.currentTarget.dataset.id }, success: res => { console.log(res) wx.hideLoading() if (res.data.code == 1) { wx.showToast({ title: '收货成功~', icon: 'none', success: ss => { setTimeout(() => { this.setData({ page: 1, orderList: [], }) this.orderList(); }, 1000); } }) } else { wx.showModal({ title: '确认失败!', content: res.data.message, showCancel: false, }) } } }) } } }) }, //订单详情 toOrderDetail(e) { wx.navigateTo({ url: '/pages/order_details/order_details?orderNumber=' + e.currentTarget.dataset.num, }) }, requestUpdateAddress() { const { addressId, currentOrder } = this.data console.log(addressId, currentOrder,); wx.request({ url: app.globalData.ip + '/wisdommining/api/order/requestUpdateAddress', method: "GET", data: { addressId, orderId: currentOrder }, success: (result) => { setTimeout(() => { if (result.data.code == 1) { wx.showToast({ title: result.data.message, }) } else { wx.showToast({ title: "服务器内部错误", icon: "error" }) } }, 1500); } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { this.orderList() } })