Files
2024-09-27 01:32:49 +08:00

347 lines
8.1 KiB
JavaScript

// user/orderInfo/orderInfo.js
const app = getApp();
const regeneratorRuntime = app.loadAsync()
const model = app.loadModel("index")
const http = app.loadHttp()
import { $wuxDialog, $wuxToast } from '../../extend/wux/dist/index';
Page({
/**
* 页面的初始数据
*/
data: {
system: app.globalData.system, //设备相关信息
pageTitle: "洗衣单详情", //头部标题
isBack: true,//显示返回
isLoading: true,//加载显示关闭
orderInfo: {},//订单详情
isTips: false,//显示反洗
isAdd: false,//增减衣物
isRemarks: false,//备注弹窗
remarks: "",//反洗备注
commodityInfo: {},//反洗衣物的信息
userInfo: {},//个人信息
id:'',//订单id
isopen: '' // 决定是否显示申请退款的按钮
},
// 获取用户会员状态
async memberState() {
let res = await model.storage.getSetting("userInfo")
this.setData({
userInfo: res
})
},
// 去支付
goPay() {
let orderInfo = this.data.orderInfo
let data = {
orederId: orderInfo.id,
order_num: orderInfo.order_number,
realPrice: orderInfo.realPrice,
fjPrice: orderInfo.fjPrice
}
wx.navigateTo({
url: `/user/payment/payment?data=${JSON.stringify(data)}`
})
},
// 获取订单详情
async getOrderInfo(id) {
let res = await http.http.request2({ url: `${http.api.shopOrderDetail}`, method: "POST", data: { order_id: id } })
this.setData({
orderInfo: res.data.data,
isLoading: false
})
},
// 显示反洗
openTips1(e) {
let item = e.currentTarget.dataset.item
this.setData({
isTips: true,
commodityInfo: item
})
},
// 关闭反洗
closeTips1() {
this.setData({
isTips: false
})
},
// 反洗备注
remarksInput(e) {
let val = e.detail.value
this.setData({
remarks: val
})
},
// 确认反洗
async confirmSub() {
let item = this.data.commodityInfo
let data = {
order_id: this.data.orderInfo.id,
order_product: item.id,
product_id: item.mall_product_id,
reason: this.data.orderInfo.remarks
}
let res = await http.http.request2({ url: `${http.api.orderBackWash}`, method: "POST", data: data })
if (res) {
this.closeTips1()
this.getOrderInfo(this.data.orderInfo.id)
app.globalData.isOrderList = true
}
},
// 显示增减衣物
openTips(e) {
let type = e.currentTarget.dataset.type
if (type == "num") {
this.setData({
isAdd: true
})
} else if (type == "remarks") {
this.setData({
isRemarks: true
})
}
},
// 关闭增减衣物
closeTips(e) {
let type = e.currentTarget.dataset.type
if (type == "num") {
this.setData({
isAdd: false
})
} else if (type == "remarks") {
this.setData({
isRemarks: false
})
}
},
// 减少衣物数量
reduce() {
let orderInfo = this.data.orderInfo
--orderInfo.total_count
this.setData({
orderInfo: orderInfo
})
},
// 增加衣物数量
add() {
let orderInfo = this.data.orderInfo
++orderInfo.total_count
this.setData({
orderInfo: orderInfo
})
},
// 备注
remarksInput(e) {
let val = e.detail.value
this.setData({
"orderInfo.remarks": val
})
},
// 洗衣柜增减衣物接口
chCount() {
let that = this
let orderInfo = this.data.orderInfo
let data = {
order_id: orderInfo.id,
count: orderInfo.total_count,
remarks: orderInfo.remarks
}
wx.showModal({
title: '确认打开智能衣柜?',
content: '为避免衣物遗失,请在洗衣柜附近打开衣柜!',
confirmText: '确认',
cancelText: '取消',
success(res) {
if (res.confirm) {
http.http.request2({ url: `${http.api.changeCount}`, method: "POST", data: data })
.then(res => {
// 更新列表
that.getOrderInfo(orderInfo.id)
that.setData({
isAdd: false
})
})
}
}
})
},
// 开箱取衣
openCase(e) {
let that = this
let id = e.currentTarget.dataset.id
let data = {
order_id: id,
lat: "",
lng: ""
}
wx.showModal({
title: '确认打开智能衣柜?',
content: '为避免衣物遗失,请在洗衣柜附近打开衣柜!',
confirmText: '确认',
cancelText: '取消',
success(res) {
if (res.confirm) {
wx.getLocation({
type: 'gcj02',
success(res) {
data.lat = res.latitude
data.lng = res.longitude
wx.showLoading({
title: '开柜中',
})
http.http.request2({ url: `${http.api.openCupboard}`, method: "POST", data: data })
.then(res => {
if (res.data.status == 1) {
wx.hideLoading()
wx.showToast({
title: '开柜成功',
icon: 'none',
duration: 1000
})
// 更新列表
that.getOrderInfo(id)
// 改变变量使返回列表页刷新
app.globalData.isOrderList = true
}
})
}
})
}
}
})
},
refund(event) {
var that = this;
$wuxDialog().prompt({
resetOnClose: true,
title: '退款',
fieldtype: 'text',
placeholder: '输入退款金额',
maxlength: 8,
onConfirm: async function(e, response) {
let res = await http.http.request2({
url: `${http.api.refund}`, method: "POST", data: {
id: event.currentTarget.dataset.id,
refund_fee: response
}
});
if (res.data.status == 1) {
console.log("res: ", res.data.msg)
$wuxToast().show({
type: 'success',
duration: 1500,
color: '#fff',
text: '申请成功,3个工作日内退款',
success: () => {
// that.getOrderInfo(that.data.id)
}
});
}
},
})
},
//取消订单的方法
cancelOrder(e) {
let id = e.currentTarget.dataset.id
var that = this
wx.showModal({
title: '取消订单',
content: '点击确定取消订单',
confirmText: "确认",
cancelText: "取消",
success: (res) => {
if (res.confirm) {
http.http.request2({ url: `${http.api.cancelOrder}`, method: "POST", data: { order_id: id } })
.then(rel => {
if (rel.data.status == 1) {
model.msg.dataMsg({
content: "取消成功",
type: "success"
})
// 更新列表
that.getOrderInfo(id)
// 改变变量使返回列表页刷新
app.globalData.isOrderList = true
}
})
}
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if(options.isopen == "1") {
this.setData({
isopen: options.isopen
})
console.log("显示申请退款按钮")
}
if(!!options.id){
this.setData({
id:options.id
})
this.getOrderInfo(options.id)
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
if(!!this.data.id){
this.getOrderInfo(this.data.id)
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})