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.
399 lines
9.8 KiB
399 lines
9.8 KiB
// pages/order/roadOrder/index.js
|
|
import userApi from "../../../utils/https/user"
|
|
import commonApi from "../../../utils/https/common"
|
|
let app = getApp()
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
product:null,
|
|
sku:[],
|
|
selectDate:null,
|
|
linkmans:[],
|
|
linkmanFlag:false,
|
|
linkmanList:[],
|
|
selectLinkman:[],
|
|
skuIndex:null,
|
|
reserve_mobile:"",
|
|
remark:"",
|
|
editId:null,
|
|
price:0,
|
|
coupon:app.globalData.couponInfo,
|
|
sku_ids:"",
|
|
prizeId:null
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.setData({
|
|
prizeId:wx.getStorageSync('prizeId')
|
|
})
|
|
userApi.user_post("user/getMyInfo").then(res=>{
|
|
this.setData({
|
|
reserve_mobile:res.data.mobile
|
|
})
|
|
})
|
|
let product = app.globalData.product,linkmans=[],sku_ids=[];
|
|
product.sku.map(item=>{
|
|
let num = Number(item.num);
|
|
linkmans.push(new Array(num));
|
|
sku_ids.push(item.id)
|
|
})
|
|
this.setData({
|
|
product:product.product,
|
|
sku:product.sku,
|
|
selectDate:product.selectDate,
|
|
linkmans:linkmans,
|
|
price:product.price,
|
|
sku_ids:sku_ids.join(",")
|
|
})
|
|
// 获取默认联系人
|
|
this.getLinkmanList()
|
|
},
|
|
|
|
showLinkman:function(e){
|
|
if(!this.data.linkmanFlag) {
|
|
let skuIndex = e.currentTarget.dataset.index,linkmans = this.data.linkmans[skuIndex],linkmanList = this.data.linkmanList;
|
|
linkmanList.map(item=>{
|
|
item.selected = 0;
|
|
linkmans.map(linkman=>{
|
|
if(item.id==linkman.id){
|
|
item.selected = 1;
|
|
}
|
|
})
|
|
})
|
|
linkmanList.map(item=>{
|
|
item.disable = 0;
|
|
this.data.linkmans.map((linkman,index)=>{
|
|
if(index!=skuIndex){
|
|
linkman.map(l=>{
|
|
if(l.id==item.id){
|
|
// 已经被别的规格选择了 那么只能灰掉
|
|
item.disable = 1;
|
|
}
|
|
})
|
|
|
|
}
|
|
})
|
|
})
|
|
this.setData({
|
|
linkmanList:linkmanList
|
|
})
|
|
}
|
|
this.setData({
|
|
linkmanFlag:!this.data.linkmanFlag,
|
|
skuIndex:e?e.currentTarget.dataset.index:null
|
|
})
|
|
},
|
|
gotoEdit:function(e){
|
|
let item = e.currentTarget.dataset.item;
|
|
this.setData({
|
|
editId:item.id
|
|
})
|
|
},
|
|
getLinkmanList:function(){
|
|
// 直接获取1000条出行人信息 就不要分页了
|
|
commonApi.user_post("token/check").then(res=>{
|
|
if(res.code==1){
|
|
userApi.user_post("user/getContactOrConsignee",{
|
|
contactType:"CONTACT",
|
|
offset:0,
|
|
limit:1000
|
|
}).then(res=>{
|
|
let list = res.data;
|
|
this.setData({
|
|
linkmanList:list,
|
|
linkmanFlag:false
|
|
})
|
|
})
|
|
}
|
|
})
|
|
|
|
},
|
|
setDefault:function(e){
|
|
let item = e.currentTarget.dataset.item,linkmanList = this.data.linkmanList;
|
|
userApi.user_post("user/setDefaultContact",{
|
|
contactId:item.id
|
|
}).then(res=>{
|
|
if(res.code==1){
|
|
wx.showToast({
|
|
title: '设置成功',
|
|
icon: 'success'
|
|
})
|
|
linkmanList.map(linkman=>{
|
|
if(linkman.id==item.id){
|
|
linkman.is_default=1;
|
|
}
|
|
else {
|
|
linkman.is_default = 0;
|
|
}
|
|
})
|
|
this.setData({
|
|
linkmanList:linkmanList
|
|
})
|
|
}
|
|
})
|
|
},
|
|
selectIt:function(e){
|
|
let item = e.currentTarget.dataset.item,linkmanList = this.data.linkmanList,skuIndex = this.data.skuIndex,sku = this.data.sku[skuIndex],num=0;
|
|
if(item.disable==1) return;
|
|
linkmanList.map(linkman=>{
|
|
if(item.id==linkman.id){
|
|
if(num >= sku.num && item.selected!=1){
|
|
linkman.selected = 0;
|
|
}
|
|
else {
|
|
linkman.selected = item.selected==1?0:1;
|
|
}
|
|
}
|
|
if(linkman.selected==1){
|
|
num ++;
|
|
}
|
|
})
|
|
if(num>sku.num) return;
|
|
this.setData({
|
|
linkmanList:linkmanList
|
|
})
|
|
},
|
|
cancel:function(){
|
|
let selectLinkman = this.data.linkmans[this.data.skuIndex],linkmanList = this.data.linkmanList;
|
|
linkmanList.map(linkman=>{
|
|
linkman.selected = 0;
|
|
selectLinkman.map(item=>{
|
|
if(item.id==linkman.id){
|
|
linkman.selected = 1;
|
|
}
|
|
})
|
|
})
|
|
this.setData({
|
|
linkmanList:linkmanList
|
|
})
|
|
this.showLinkman()
|
|
},
|
|
confirm:function(){
|
|
let linkmanList = this.data.linkmanList,selectLinkman = [],linkmans = this.data.linkmans,skuIndex = this.data.skuIndex;
|
|
linkmanList.map(linkman=>{
|
|
if(linkman.selected==1){
|
|
selectLinkman.push(linkman);
|
|
}
|
|
})
|
|
linkmans[skuIndex] = selectLinkman;
|
|
this.setData({
|
|
linkmans:linkmans
|
|
})
|
|
this.showLinkman()
|
|
},
|
|
inputTel:function(e){
|
|
this.setData({
|
|
reserve_mobile:e.detail.value
|
|
})
|
|
},
|
|
inputRemark:function(e){
|
|
this.setData({
|
|
remark:e.detail.value
|
|
})
|
|
},
|
|
order:function(){
|
|
let sku = this.data.sku,product = this.data.product,linkmans = this.data.linkmans,product_list = [],reserve_mobile = this.data.reserve_mobile;
|
|
if(!reserve_mobile) {
|
|
wx.showToast({
|
|
title: '请输入联系方式',
|
|
icon:'none'
|
|
})
|
|
return;
|
|
}
|
|
let orderFlag = true;
|
|
sku.map((item,index)=>{
|
|
if(item.num>0){
|
|
let linkman = linkmans[index],visitors=[];
|
|
if(linkman.length<item.num){
|
|
wx.showToast({
|
|
title: '请选择'+item.num +"个出行人",
|
|
icon:"none"
|
|
})
|
|
orderFlag = false;
|
|
}
|
|
for(let i=0;i<linkman.length;i++){
|
|
let l = linkman[i];
|
|
if(!l || !l.id){
|
|
wx.showToast({
|
|
title: '请选择'+item.num +"个出行人",
|
|
icon:"none"
|
|
})
|
|
orderFlag = false
|
|
}
|
|
else {
|
|
visitors.push(l.id)
|
|
}
|
|
}
|
|
product_list.push({
|
|
type : "line",//线路
|
|
product_id: product.id,
|
|
sku_id:item.id,
|
|
product_num:item.num,
|
|
visitors:visitors.join(","),
|
|
reserve_mobile:reserve_mobile,
|
|
use_date:this.data.selectDate.date
|
|
})
|
|
}
|
|
})
|
|
if(orderFlag==false){
|
|
return;
|
|
}
|
|
let data = {
|
|
product_list:product_list,
|
|
coupon_id:this.data.coupon?this.data.coupon.id:null,
|
|
source:"WECHATXCX",
|
|
remark:this.data.remark
|
|
}
|
|
if(this.data.prizeId){
|
|
data.lottery_id = this.data.prizeId
|
|
}
|
|
if(app.globalData.from){
|
|
data.system_name = app.globalData.from;
|
|
}
|
|
if(app.globalData.retailId){
|
|
data.commission_code = app.globalData.retailId;
|
|
app.globalData.retailId = null;
|
|
}
|
|
if(app.globalData.category_id){
|
|
data.category_id = app.globalData.category_id;
|
|
}
|
|
commonApi.user_post("order/create",{
|
|
data:JSON.stringify(data)
|
|
}).then(res=>{
|
|
|
|
})
|
|
|
|
},
|
|
//获取最高优惠券
|
|
getNewCoupon(e){
|
|
this.setData({
|
|
coupon:e.detail
|
|
})
|
|
},
|
|
// 一日游合同确认签字
|
|
// ondayConfirm:function(){
|
|
// let linkmans = this.data.linkmans,tourist_info=[],sku=this.data.sku;
|
|
// sku.map((item,index)=>{
|
|
// if(item.num>0){
|
|
// let linkman = linkmans[index];
|
|
// if(linkman.length<item.num){
|
|
// wx.showToast({
|
|
// title: '请先选择出行人',
|
|
// icon:"none"
|
|
// })
|
|
// orderFlag = false;
|
|
// }
|
|
// for(let i=0;i<linkman.length;i++){
|
|
// let l = linkman[i];
|
|
// if(!l || !l.id){
|
|
// wx.showToast({
|
|
// title: '请先选择出行人',
|
|
// icon:"none"
|
|
// })
|
|
// orderFlag = false
|
|
// }
|
|
// else {
|
|
// tourist_info.push({
|
|
// user_id:l.id,
|
|
// name:l.name,
|
|
// tel:l.tel,
|
|
// id_number:l.id_number,
|
|
// is_main:tourist_info.length===0
|
|
// })
|
|
// }
|
|
// }
|
|
// }
|
|
// })
|
|
// commonApi.user_post("Oneday/getContractUrl",{
|
|
// total_price:this.data.price,
|
|
// supplier_id:this.data.product.supplier_id,
|
|
// product_id:this.data.product.id,
|
|
// tourist_info:tourist_info
|
|
// }).then(res=>{
|
|
// console.log(res)
|
|
// })
|
|
// },
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
if(this.data.editId){
|
|
// 如果是去编辑的
|
|
let editId = this.data.editId;
|
|
userApi.user_post("user/getContactInfoById",{
|
|
id:editId
|
|
}).then(res=>{
|
|
let linkmans = this.data.linkmans,linkmanList = this.data.linkmanList;
|
|
linkmans.map(linkman=>{
|
|
linkman.map(item=>{
|
|
if(item.id==editId){
|
|
item.name = res.data.name;
|
|
item.tel = res.data.tel;
|
|
item.id_number = res.data.id_number;
|
|
item.is_default = res.data.is_default;
|
|
}
|
|
else if(res.data.is_default==1){
|
|
item.is_default = 0;
|
|
}
|
|
})
|
|
})
|
|
linkmanList.map(item=>{
|
|
if(item.id==editId){
|
|
item.name = res.data.name;
|
|
item.tel = res.data.tel;
|
|
item.id_number = res.data.id_number;
|
|
item.is_default = res.data.is_default;
|
|
}
|
|
})
|
|
this.setData({
|
|
linkmanList:linkmanList,
|
|
linkmans:linkmans
|
|
})
|
|
})
|
|
}
|
|
else {
|
|
this.getLinkmanList()
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
}
|
|
})
|