const app = getApp();
|
import moment from 'moment'
|
import tool2 from "../../../assets/js/toolClass.js"
|
import {
|
getPublicImage
|
} from "../../../assets/js/middleGround/tool.js";
|
Page({
|
|
/**
|
* 页面的初始数据
|
*/
|
data: {
|
active: 0,
|
tabList: [{
|
label: '全部',
|
value: 'all',
|
},
|
{
|
label: '待支付',
|
value: 'WaitPay',
|
},
|
{
|
label: '已完成',
|
value: 'Success',
|
},
|
{
|
label: '已取消',
|
value: 'Cancel',
|
}
|
],
|
searchText: "",
|
list: [],
|
//分页
|
page: 1,
|
limit: 12,
|
pageTotalCount: 0,
|
bottomLoading: false,
|
isMoreData: false,
|
// 返回顶部
|
isBackTop: false,
|
setScrollValue: 0,
|
skeletonLoding: true,
|
queryFilter: [],
|
isPaySuccess: false,
|
isPayComplete: false,
|
},
|
|
/**
|
* 生命周期函数--监听页面加载
|
*/
|
onLoad(options) {
|
console.log(options);
|
this.getDataList(false)
|
},
|
|
/**
|
* 生命周期函数--监听页面初次渲染完成
|
*/
|
onReady() {
|
|
},
|
tabBookClick(item) {
|
let that = this;
|
let info = this.data.tabList[item.detail.value]
|
that.setData({
|
skeletonLoding: true,
|
active: item.detail.value,
|
queryFilter: info.value == 'all' ? [] : [{
|
field: 'State',
|
value: info.value
|
}],
|
list: [],
|
page: 1,
|
bottomLoading: false,
|
isMoreData: false,
|
searchText: ""
|
})
|
that.getDataList(false);
|
},
|
|
getDataList(isReachBottom) {
|
var searchArr = [];
|
if (this.data.searchText != undefined && this.data.searchText != "") {
|
searchArr.push({
|
compareType: "Contains",
|
field: "orderNumber",
|
keywords: this.data.searchText,
|
})
|
}
|
const data = {
|
start: this.data.page * this.data.limit - this.data.limit,
|
size: this.data.limit,
|
filterList: this.data.queryFilter,
|
searchList: searchArr,
|
sort: {
|
type: 'Desc',
|
field: 'CreateDate'
|
}
|
}
|
app.MG.store.getUserOrderList(data).then((res) => {
|
try {
|
if (res.datas.length > 0) {
|
res.datas.forEach((item, index) => {
|
item.payPrice = tool2.toDecimal2(item.payPrice)
|
item.createDate = moment(item.createDate).format("YYYY-MM-DD HH:mm:ss");
|
item.finishedDate = moment(item.finishedDate).format("YYYY-MM-DD HH:mm:ss");
|
if (item.state == "Success") {
|
item.colorName = 'success';
|
item.CustomState = "已完成";
|
}
|
if (item.state == "Cancel") {
|
item.colorName = 'cancal';
|
item.CustomState = "已取消";
|
}
|
if (item.state == "WaitPay") {
|
item.colorName = 'waitPay';
|
item.CustomState = "待支付";
|
}
|
if (item.state == "WaitDeliver") {
|
item.colorName = 'waitDeliver';
|
item.CustomState = "正在支付";
|
}
|
if (item.state == "GroupPaySuccess") {
|
item.colorName = 'success';
|
item.CustomState = "等待拼团"
|
}
|
if (item.state == "ReFounding") {
|
item.colorName = 'ReFounding';
|
item.CustomState = "退款中"
|
}
|
if (item.state == "ReFoundFinished") {
|
item.colorName = 'ReFoundFinished';
|
item.CustomState = "退款完成"
|
}
|
let oldlist = [];
|
oldlist = item.saleMethodLinks
|
oldlist.forEach(istrue => {
|
istrue.name = istrue.orderSaleMethod.product.name
|
istrue.payPrice = tool2.toDecimal2(istrue.payPrice)
|
istrue.icon = getPublicImage(istrue.orderSaleMethod.product.icon, "", 400)
|
})
|
|
})
|
let dataList = res.datas;
|
//触底加载新数据并保留老数据
|
if (isReachBottom) {
|
dataList = [...this.data.list, ...dataList] //将新数据加入老数据中
|
}
|
this.setData({
|
list: dataList,
|
pageTotalCount: res.totalSize,
|
bottomLoading: false,
|
isMoreData: dataList.length > 0 ? false : true,
|
skeletonLoding: false,
|
loading: false
|
})
|
} else {
|
this.setData({
|
skeletonLoding: false,
|
loading: false
|
})
|
}
|
} catch (error) {
|
console.log(error)
|
}
|
})
|
},
|
onSearchOrder(e) {
|
this.setData({
|
searchText: e.detail.value,
|
})
|
this.getDataList(false);
|
},
|
async goBookDetails(e) {
|
|
console.log(e.currentTarget.dataset);
|
const {
|
book,
|
remarks
|
} = e.currentTarget.dataset;
|
let parentData = null;
|
let bookId = book.orderSaleMethod.product.id;
|
|
parentData = await app.MG.store.getProductBySaleMethod({
|
'saleMethodId': book.orderSaleMethod.id
|
})
|
if (parentData.parentProduct.length > 0) {
|
bookId = parentData.parentProduct[parentData.parentProduct.length - 1].id;
|
}
|
wx.navigateTo({
|
url: `/packageBookService/pages/bookServices/detail/index?id=${bookId}&name=${book.name}`,
|
});
|
},
|
|
/**
|
* 页面相关事件处理函数--监听用户下拉动作
|
*/
|
onPullDownRefresh() {
|
if (this._freshing) return
|
this.setData({
|
// list: [],
|
page: 1,
|
limit: 12,
|
pageTotalCount: 0,
|
bottomLoading: false,
|
isMoreData: false,
|
searchText: ''
|
})
|
this._freshing = true;
|
this.setData({
|
triggered: false,
|
})
|
this.getDataList(false);
|
this._freshing = false
|
},
|
|
/**
|
* 页面上拉触底事件的处理函数
|
*/
|
onReachBottom() {
|
this.setData({
|
bottomLoading: true,
|
isMoreData: false
|
})
|
let bool = false;
|
if (this.data.pageTotalCount > this.data.list.length) {
|
bool = true;
|
this.setData({
|
page: this.data.page + 1,
|
})
|
} else {
|
setTimeout(() => {
|
this.setData({
|
bottomLoading: false,
|
isMoreData: true
|
})
|
}, 100)
|
return false;
|
}
|
this.getDataList(bool);
|
},
|
|
onCancel(e) {
|
let that = this;
|
let {
|
orderNum
|
} = e.currentTarget.dataset
|
wx.showModal({
|
title: '提示', //提示的标题
|
content: '确定要取消订单?', //提示的内容
|
success: function (res) {
|
if (res.confirm) {
|
app.MG.store.cancelOrder({
|
orderNum: orderNum
|
}).then((res) => {
|
if (res) {
|
wx.showToast({
|
title: "订单已取消",
|
icon: 'success',
|
duration: 1000
|
})
|
that.getDataList(false)
|
}
|
|
})
|
} else if (res.cancel) {
|
console.log('用户点击了取消')
|
}
|
}
|
})
|
|
},
|
//立即支付、再次购买
|
onPayment(e) {
|
var that = this;
|
const {
|
orderNum
|
} = e.currentTarget.dataset
|
const data = {
|
orderNum: orderNum,
|
};
|
app.MG.store.getOrderByOrderNum(data).then(res => {
|
app.MG.store.makeWeChatPay({
|
orderNum: res.orderNumber,
|
platform: "WeChatAppCustom"
|
})
|
.then(payRes => {
|
const payVal = JSON.parse(payRes);
|
wx.requestPayment({
|
"appId": payVal.appId,
|
"timeStamp": payVal.timeStamp,
|
"nonceStr": payVal.nonceStr,
|
"package": payVal.package,
|
"signType": payVal.signType,
|
"paySign": payVal.paySign,
|
"success": function (res) {
|
if (res.errMsg == 'requestPayment:ok') {
|
that.setData({
|
isPaySuccess: true
|
})
|
}
|
},
|
"fail": function (res) {
|
console.log(res, "失败")
|
},
|
"complete": function (res) {
|
if (res.errMsg == 'requestPayment:ok') {
|
that.setData({
|
isPayComplete: true
|
})
|
}
|
if (that.data.isPaySuccess && that.data.isPayComplete) {
|
that.navToBack()
|
}
|
}
|
})
|
});
|
});
|
|
},
|
|
//删除订单
|
onDel(e) {
|
const {
|
orderNum
|
} = e.currentTarget.dataset
|
|
},
|
|
/**
|
* 用户点击右上角分享
|
*/
|
onShareAppMessage() {
|
|
}
|
})
|