You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

286 lines
6.9 KiB

5 years ago
// pages/user/order/list.js
import commonApi from "../../../utils/https/common"
import util from "../../../utils/util"
let app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
list:[],
keywords:"",
orderState:app.globalData.orderState,
5 years ago
type:"",
lon:"",
lat:""
5 years ago
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
type:options.type
})
5 years ago
wx.getLocation({
type: 'gcj02',
success: (r)=>{
this.setData({
lon:r.longitude,
lat:r.latitude
})
this.getList();
},
fail:()=>{
this.getList();
5 years ago
}
})
5 years ago
},
5 years ago
gotoWeb:function(e){
let web = e.currentTarget.dataset.web;
app.globalData.weburl = web;
wx.navigateTo({
url: '/pages/pbService/web/index',
})
},
5 years ago
changeKeyword:function(e){
this.setData({
keywords:e.detail.value
})
},
refundInfo:function(e){
let id = e.currentTarget.dataset.id;
wx.navigateTo({
url: 'refundInfo/index?id='+id,
})
},
gotoComment:function(e){
let id = e.currentTarget.dataset.id;
wx.navigateTo({
url: '/pages/order/comment/index?id='+id,
})
},
// 再次预定
order:function(e){
let item = e.currentTarget.dataset.item;
util.orderMoreTime(item)
},
pay:function(e){
let id = e.currentTarget.dataset.id;
wx.navigateTo({
url: '/pages/order/pay/index?id='+id,
})
},
search:function(){
this.setData({
realKeyword:this.data.keywords,
list:[],
total:1
})
this.getList()
},
getList:function(){
let list = this.data.list;
if(list.length>=this.data.total) return;
commonApi.user_post("order/list",{
state:this.data.type,
offset:this.data.list.length,
limit:10,
keywords:this.data.keywords
}).then(res=>{
5 years ago
let ajaxes = [],indexes=[]
res.data.list.map((item,index)=>{
5 years ago
let orderNum = 0;
item.order_product_list.map(order=>{
orderNum = orderNum + order.product_num;
3 years ago
///
5 years ago
// 景点线路场馆酒店四类产品的订单 如果是已支付未出票的显示出票中
if(order.state=='PAID' && (order.product_model=='venue' || order.product_model=='ticket' || order.product_model=='hotel' || order.product_model=='line')){
item.orderStateText="出票中"
}
3 years ago
if(order.state=='WAIT_USE' && (order.product_model=='venue' || order.product_model=='ticket' || order.product_model=='hotel' || order.product_model=='line')){
item.orderStateText="已出票"
}
5 years ago
})
5 years ago
if(item.order_product_list.length==1 && item.order_product_list[0].scene_id && item.state!='UNPAID' && item.state!='CLOSED' && item.state.indexOf("REFUND")==-1 && this.data.lon && this.data.lat){
5 years ago
let ajax = commonApi.user_post("order/tripplan",{
point_type: "gd",
child_order_id:item.order_product_list[0].child_order_id,
lat:this.data.lat,
lon:this.data.lon
})
ajaxes.push(ajax);
indexes.push(index);
}
5 years ago
item.orderNum = orderNum;
})
5 years ago
console.log(ajaxes)
if(ajaxes.length==0){
this.setData({
total:res.data.total,
list:list.concat(res.data.list)
})
return;
}
5 years ago
Promise.all(ajaxes).then((r)=>{
r.map((item,index)=>{
if(item && item.data && item.data.url){
res.data.list[indexes[index]].guihuaUrl = item.data.url
}
5 years ago
})
this.setData({
total:res.data.total,
list:list.concat(res.data.list)
5 years ago
})
5 years ago
})
5 years ago
5 years ago
})
3 years ago
5 years ago
},
gotoDetail:function(e){
let item = e.currentTarget.dataset.item;
4 years ago
item = this.getChild(item)
5 years ago
util.gotoOrder(item)
},
4 years ago
5 years ago
gotoProductDetail:function(e){
let item = e.currentTarget.dataset.item;
4 years ago
5 years ago
util.orderMoreTime({order_product_list:[item]})
},
4 years ago
getChild(list){
let arr = {order_product_list:[]}
for (let i = 0; i < list.order_product_list.length; i++) {
if (list.order_product_list[i].product_model=="ticket") {
arr.order_product_list.push(list.order_product_list[i])
break
}
}
if (arr.order_product_list.length>0) {
list.order_product_list = []
list.order_product_list.push(arr.order_product_list[0])
console.log(list);
return list
}else{
return list
}
},
5 years ago
changeType:function(e){
let type = e.currentTarget.dataset.type;
this.setData({
type:type,
list:[],
total:1
})
this.getList()
},
refund:function(e){
let index = e.currentTarget.dataset.index,list = this.data.list,item = list[index],that = this;
wx.showModal({
title:"提示",
content:"确定取消吗?",
success:function(res){
if(res.confirm){
// 确定取消
commonApi.user_post("order/refund",{
order_id:item.order_id
}).then(res=>{
if(res.code==1){
wx.showToast({
title: '已取消',
icon:'success'
})
if(that.data.type){
list.splice(index,1);
}
else {
list[index].state='WAIT_REFUND';
}
that.setData({
list:list
})
}
})
}
}
})
},
cancel:function(e){
let index = e.currentTarget.dataset.index,list = this.data.list,item = list[index],that = this;
wx.showModal({
title:"提示",
content:"确定取消吗?",
success:function(res){
if(res.confirm){
// 确定取消
commonApi.user_post("order/close",{
order_id:item.order_id
}).then(res=>{
if(res.code==1){
wx.showToast({
title: '已取消',
icon:'success'
})
if(that.data.type){
list.splice(index,1);
}
else {
list[index].state='CLOSED';
}
that.setData({
list:list
})
}
})
}
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
3 years ago
this.setData({
list:[]
})
this.getList()
5 years ago
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
this.getList()
}
})