Files
CompanyProject/衣莎项目/源码/YiShaXiYi/user/order/order.js
2024-09-27 01:32:49 +08:00

502 lines
13 KiB
JavaScript

// user/order/order.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,//加载显示关闭
current: '',//当前所在的标签的 key 值
orderData: [],//订单列表数据
page: 1,//当前列表第几页
isState: true,//如果没数据了false
isTips: false,//增减衣服数量弹窗
isRemarks: false,//备注弹窗
changeCount: {},//增减衣物数量时当前选中的衣物
userInfo: {},//个人信息
ShowSupplement: false, // 是否显示补款弹窗
SupplementClickItem: {}, // 保存用户点击列表中的某个对象
defaultPayType: 2, // 支付方式默认显示 1 会员卡, 2 微信
defaultCard: 0, // 存放当前用户选中的会员卡数值下标
cardList: [] // 存放会员卡
},
// 支付方式被选择点击事件
PayTypeChange(e) {
this.setData({ defaultPayType: e.detail.value })
},
// 会员卡列表被点击选择
CardTypeChange(e) {
this.setData({ defaultCard: e.detail.value })
},
// 点击弹窗的 确定 按钮进行补款时候触发
async submitSupplement() {
console.log("支付方式: ", this.data.defaultPayType);
console.log("订单id: ", this.data.SupplementClickItem.id);
console.log("补款金额: ", this.data.SupplementClickItem.extra_money);
console.log("会员卡id: ", this.data.cardList[this.data.defaultCard].id);
let data = {}
// 如果为微信支付
if (this.data.defaultPayType == 2) {
data = {
pay_type: this.data.defaultPayType,
order_id: this.data.SupplementClickItem.id,
extra_money: this.data.SupplementClickItem.extra_money,
};
// 如果为会员卡支付
} else {
data = {
pay_type: this.data.defaultPayType,
order_id: this.data.SupplementClickItem.id,
extra_money: this.data.SupplementClickItem.extra_money,
id: this.data.cardList[this.data.defaultCard].id
};
}
let submitStatus = await http.http.request2({ url: http.api.latePay, method: "POST", data: data });
// 如果为微信支付
if (this.data.defaultPayType == 2) {
this.wxPay(submitStatus)
// 会员卡支付
} else {
this.setData({
ShowSupplement: false
})
// 重置某些值
this.setData({
page: 1,
orderData: []
});
// 更新列表
this.orderList()
}
},
// 补款按钮被点击处理事件
async Supplement(e) {
wx.showLoading({ title: '加载中..' })
// 请求所有会员卡分类的数据
let card_1 = await http.http.request2({ url: `${http.api.userCard}/1`, method: "POST", data: { kind: '' } })
let card_2 = await http.http.request2({ url: `${http.api.userCard}/2`, method: "POST", data: { kind: '' } })
let card_3 = await http.http.request2({ url: `${http.api.userCard}/3`, method: "POST", data: { kind: '' } })
// 保存会员卡数据
this.setData({
cardList: [...card_1.data.data, ...card_2.data.data, ...card_3.data.data ]
});
// 保存点击的对象
this.setData({ SupplementClickItem: e.currentTarget.dataset.items });
wx.hideLoading();
// 显示弹窗
this.setData({ ShowSupplement: true });
},
// 微信支付
wxPay(order) {
let that = this;
wx.requestPayment({
timeStamp: order.data.data.timeStamp,
nonceStr: order.data.data.nonceStr,
package: order.data.data.package,
signType: 'md5',
paySign: order.data.data.paySign,
success: res => {
if (res.errMsg == "requestPayment:ok") {
wx.showToast({
title: '支付成功',
icon: 'none',
duration: 2000,
success: () => {
that.setData({
ShowSupplement: false
})
// 重置某些值
that.setData({
page: 1,
orderData: []
})
// 更新列表
that.orderList()
}
});
}
},
fail(res) {
wx.showToast({
title: '取消支付',
icon: 'none',
duration: 1000
})
}
})
},
// 关闭弹窗
CloseViewInfo() {
this.setData({
ShowSupplement: false
})
},
// tab选中事件
handleChange({ detail }) {
this.setData({
current: detail.key,
orderData: [],
page: 1
});
this.orderList()
},
// 打开订单详情
openOrder(e) {
console.log("isopen: ", e.currentTarget.dataset.isopen)
wx.navigateTo({
url: `/user/orderInfo/orderInfo?id=${e.currentTarget.dataset.id}&isopen=${e.currentTarget.dataset.isopen}`
})
},
// 申请退款
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.setData({
page: 1,
orderData: []
})
// 更新列表
that.orderList()
}
});
}
},
})
},
//取消订单的方法
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.setData({
page: 1,
orderData: []
})
that.orderList()
}
})
}
}
})
},
// 订单列表
async orderList() {
wx.showLoading({
title: '加载中',
})
let data = {
status: parseInt(this.data.current),
page: this.data.page,
limit: 5
}
let res = await http.http.request2({ url: `${http.api.orderList}`, method: "POST", data: data })
if (res.data.data.list.length < 5) {
this.setData({
isState: false
})
}
let orderData = [...this.data.orderData, ...res.data.data.list]
this.setData({
orderData: orderData,
isLoading: false
})
wx.hideLoading()
// 请求完列表页变为false防止重复刷新
app.globalData.isOrderList = false
},
// 获取用户会员状态
async memberState() {
let res = await model.storage.getSetting("userInfo")
this.setData({
pageTitle: res.cupboard_num != -1 ? "我的衣柜订单" : "我的洗衣单",
userInfo: res
})
},
// 显示增减衣物
openTips(e) {
let type = e.currentTarget.dataset.type
let item = e.currentTarget.dataset.item
if (type == "num") {
this.setData({
isTips: true,
changeCount: item
})
} else if (type == "remarks") {
this.setData({
isRemarks: true
})
}
},
// 关闭增减衣物
closeTips(e) {
let type = e.currentTarget.dataset.type
if (type == "num") {
this.setData({
isTips: false,
changeCount: {}
})
} else if (type == "remarks") {
this.setData({
isRemarks: false
})
}
},
// 增加衣物数量
add() {
let changeCount = this.data.changeCount
++changeCount.total_count
this.setData({
changeCount: changeCount
})
},
// 减少衣物数量
reduce() {
let changeCount = this.data.changeCount
--changeCount.total_count
this.setData({
changeCount: changeCount
})
},
// 备注
remarksInput(e) {
let val = e.detail.value
this.setData({
"changeCount.remarks": val
})
},
// 开箱取衣
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.setData({
page: 1,
orderData: []
})
// 更新列表
that.orderList()
}
})
}
})
}
}
})
},
// 洗衣柜增减衣物接口
chCount() {
let that = this
let changeCount = this.data.changeCount
let data = {
order_id: changeCount.id,
count: changeCount.total_count,
remarks: changeCount.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.setData({
page: 1,
orderData: []
})
// 更新列表
that.orderList()
that.setData({
isTips: false
})
})
}
}
})
},
// 确认收货
receivingGoods(e) {
let that = this
let id = e.detail.target.dataset.id
let formId = e.detail.formId
wx.showModal({
title: '确认收货',
content: '请检查是否有缺失,再点击确认收货!',
confirmText: '确认',
cancelText: '取消',
success(res) {
if (res.confirm) {
http.http.request2({ url: `${http.api.receivOrder}`, method: "POST", data: { order_id: id, form_id: formId } })
.then(res => {
// 重置某些值
that.setData({
page: 1,
orderData: []
})
// 更新列表
that.orderList()
})
}
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this
// 获取页面参数显示对应tab
that.setData({
current: options.orderState || '1'
})
this.orderList()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
let that = this
this.memberState()
app.setWatching('isOrderList', (v) => {
if (v) {
that.setData({
orderData: [],
page: 1
})
that.orderList()
}
});
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
if (this.data.isState) {
this.setData({
page: ++this.data.page
})
this.orderList()
}
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})