Files
sphc/pages/order_details/order_details.js

400 lines
11 KiB
JavaScript
Raw Normal View History

2024-05-06 15:34:15 +08:00
// pages/cartPay/cartPay.js
import { dateFormat2 } from '../../utils/util'
const app = getApp();
let time = null;
Page({
/**
* 页面的初始数据
*/
data: {
goods: [],
ticker: '--:--',
leftoverDay: "",
shops: false,//商铺进入
},
//商品详情
goodsDetails(e) {
let id = e.currentTarget.dataset.id;
wx.navigateTo({
url: '/pages/goodsDetails/goodsDetails?goodsId=' + id,
})
},
//物流
express: function (e) {
app.globalData.expressData = JSON.stringify(e.currentTarget.dataset.item);
wx.navigateTo({
url: '/pages/expresswx/expresswx',
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if (options.shops) {
this.setData({
shops: true
})
}
wx.showLoading({
title: '加载中..',
})
if (time) {
clearTimeout(time);
}
wx.request({
url: app.globalData.ip + '/wisdommining/api/order/getOrderDetail',
method: 'GET',
header: {
"content-type": "application/x-www-form-urlencoded",
},
data: {
userId: app.globalData.userId,
orderNumber: options.orderNumber,
},
success: res => {
console.log(res)
wx.hideLoading()
if (res.data.code == 1) {
let goods = res.data.value;
let total = 0;
let numAll = 0;
if (goods.orderPayWay != 3) {
for (let i = 0; i < goods.goodsList.length; i++) {
total = total + parseFloat(goods.goodsList[i].wisdGoodsSpec.specBulyPrice == null ? goods.goodsList[i].wisdGoodsSpec.specPrice : goods.goodsList[i].wisdGoodsSpec.specBulyPrice) * goods.goodsList[i].goodsNum;
numAll = numAll + goods.goodsList[i].goodsNum;
goods.goodsList[i].price = goods.goodsList[i].wisdGoodsSpec.specBulyPrice == null ? goods.goodsList[i].wisdGoodsSpec.specPrice : goods.goodsList[i].wisdGoodsSpec.specBulyPrice;
}
} else {
total = 0;
numAll = 1
}
this.setData({
goods: goods,
total: total,
2024-05-17 17:14:40 +08:00
numAll: numAll,
logistics: goods.logistics ? JSON.parse(goods.logistics) : null
2024-05-06 15:34:15 +08:00
})
if (goods.status == 1) {
this.setData({
setIntervalTime: setInterval((t) => {
var t = new Date();
var t_s = t.getTime();//转化为时间戳毫秒数
var daoqiT = new Date(goods.cancelTime.replace(/-/g, '/'));//到期时间
var time = parseInt((daoqiT - t_s) / 1000);
if (time > 0) {
var timeM = parseInt(time / 60);
var timeS = time % 60;
var ticker = '';
if (timeM < 10) {
timeM = '0' + timeM
}
if (timeS < 10) {
timeS = '0' + timeS
}
ticker = timeM + '' + timeS
this.setData({
time: time - 1,
ticker: ticker
})
} else {
this.setData({
time: 'time - 1',
ticker: '',
})
clearInterval(this.data.setIntervalTime)
}
}, 1000)
})
}
if (goods.status == 3) {
// 获取发货时间
let orderDeliverTime = goods.orderDeliverTime
console.log("=======")
let orderDeliverTimeMillisecond = (new Date(orderDeliverTime.replace(/-/g, '/'))).getTime() + 15 * 24 * 60 * 60 * 1000; //得到毫秒数
// 获取现在的毫秒值
console.log(orderDeliverTimeMillisecond)
let nowTime = new Date().getTime()
// 计算已经过了的时间
let surplusDay = orderDeliverTimeMillisecond - nowTime
if (surplusDay > 0) {
let timeStr = dateFormat2(surplusDay)
console.log(timeStr)
this.setData({
leftoverDay: timeStr,
leftoverDayI: orderDeliverTimeMillisecond,
})
// const self = this;
time = setInterval(() => {
console.log("======")
this.countDown()
}, 1000)
// data[i]["timeStr"] = timeStr;
// data[i]["time"] = time;
}
// let days = Math.floor(surplusDay/(24*3600*1000)); //计算出天数
// let leftoverDay = 15 - days //计算剩余天数
// this.setData({
// leftoverDay
// })
}
} else {
wx.showModal({
title: '提示!',
content: res.data.message,
showCancel: false,
})
}
}
})
},
2024-05-17 17:14:40 +08:00
//申请售后
apply: function (e) {
const { id, num, sq, packageId } = e.currentTarget.dataset
console.log(packageId);
wx.navigateTo({
url: '/pages/my/applyAfter_sales/applyAfter_sales?id=' + id + '&num=' + num + '&sq=' + sq + "&packageId=" + packageId,
})
},
2024-05-06 15:34:15 +08:00
countDown() {
let leftoverDayI = this.data.leftoverDayI;
let nowTime = new Date().getTime()
// 计算已经过了的时间
let surplusDay = leftoverDayI - nowTime
if (surplusDay > 0) {
let timeStr = dateFormat2(surplusDay)
this.setData({
leftoverDay: timeStr
})
}
},
pay(e) {
this.payM({
orderNumber: this.data.goods.orderNumber
})
},
//支付
payM(options) {
wx.showLoading({
title: '支付中',
mask: true
})
wx.request({
url: app.globalData.ip + '/wisdommining/api/pay/payOrder',
method: 'PUT',
header: {
"content-type": "application/x-www-form-urlencoded",
},
data: {
userId: app.globalData.userId,
orderNumber: options.orderNumber
},
success: res => {
wx.hideLoading();
console.log(res)
if (res.data.code == 1) {
//调用微信支付API
wx.requestPayment({
timeStamp: res.data.value.timeStamp,
nonceStr: res.data.value.nonceStr,
package: res.data.value.package,
signType: 'MD5',
paySign: res.data.value.paySign,
success(res) {
console.log(res)
wx.showToast({
title: '支付成功',
icon: 'success',
duration: 1500,
success() {
setTimeout(() => {
wx.navigateBack()
}, 1000);
}
})
},
fail(res) {
console.log(res)
wx.hideLoading()
wx.showToast({
title: '支付失败',
icon: 'none',
duration: 2000,
})
}
})
} 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: this.data.goods.id
},
success: res => {
console.log(res)
wx.hideLoading()
if (res.data.code == 1) {
wx.showToast({
title: '操作成功~',
icon: 'none',
success: ss => {
setTimeout(() => {
wx.navigateBack()
}, 1000);
}
})
} else {
wx.showModal({
title: '确认失败!',
content: res.data.message,
showCancel: false,
})
}
}
})
}
}
})
},
2024-05-11 17:21:15 +08:00
// 评价订单
2024-05-17 17:14:40 +08:00
rate(e) {
2024-05-11 17:21:15 +08:00
wx.navigateTo({
url: '/pages/rate/rate',
})
},
2024-05-06 15:34:15 +08:00
// 删除订单
del(e) {
let orderId = this.data.goods.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) => {
wx.navigateBack()
}, 1000);
}
})
} else {
wx.showModal({
title: '提示!',
content: res.data.message,
showCancel: false,
})
}
}
})
}
}
})
},
// 图片预览
codeImg(e) {
let src = e.currentTarget.dataset.img;
wx.previewImage({
current: e.currentTarget.dataset.img, // 当前显示图片的http链接
urls: [e.currentTarget.dataset.img] // 需要预览的图片http链接列表
})
},
callCustomService() {
wx.makePhoneCall({
phoneNumber: '15955151737',
})
},
2024-05-08 17:32:39 +08:00
viewLogisticsDetails(e) {
2024-05-17 17:14:40 +08:00
const { logistics, logisticsName, orderNumber } = e.currentTarget.dataset
2024-05-06 15:34:15 +08:00
wx.navigateTo({
2024-05-17 17:14:40 +08:00
url: `/pages/logistics_details/logistics_details?orderNumber=${orderNumber}&logistics=${logistics}&logisticsName=${logisticsName}`,
2024-05-06 15:34:15 +08:00
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
})