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.

834 lines
24 KiB

5 years ago
// pages/order/components/contact/index.js
import userApi from "../../../../utils/https/user"
import commonApi from "../../../../utils/https/common"
import util from "../../../../utils/util.js"
5 years ago
let app = getApp()
Component({
/**
* 组件的属性列表
*/
options: {
styleIsolation: 'apply-shared',
addGlobalClass: true
},
properties: {
maxNum:{
type:String,
value:"-1"
5 years ago
},
type:{
type:String,
value:""
},
productNum:{
type:Number,
value:1,
observer(nv, ov, path) {
if (nv) {
let num = nv-this.data.selectLinkman.length
this.setData({
showNum:num
})
if (nv<ov) {
this.delMan()
}
}
}
},
is_authentication:{// 是否实名,0否1是,默认实名
type:String,
value:''
},
is_real_name:{// 是否是一证一票,0否1是,
type:String,
value:''
5 years ago
}
},
/**
* 组件的初始数据
*/
data: {
selectLinkman:[],
linkmanList:[],
showMask:false,
5 years ago
editId:null,
isGroup:null,
showManList:[],
stagingManList:[], // 暂存用户信息
showNum:0,
showAdd:false,
formData:{},
types:[],
selectIndex:0,
person:{},
personId:null,
r:[],
phone:null,//非实名时需要传的电话
manList:[],
seldManList:[],
keyboardHeight: 0
5 years ago
},
lifetimes: {
attached: function() {
wx.onKeyboardHeightChange(res => {
if (res.height > 0) {
this.setData({
keyboardHeight: res.height
});
} else {
this.setData({
keyboardHeight: 0
});
}
});
5 years ago
// 在组件实例进入页面节点树时执行
console.log(this.properties.productNum);
console.log(this.properties.is_real_name);
// if (this.properties.is_real_name == '1') {
this.setData({
showNum:this.properties.productNum
})
// }
// 不实名时直接获取手机号
if (this.properties.is_authentication) {
commonApi.user_post("uservice/user/getMyInfo",{}).then(res=>{
if(res.code==1){
this.setData({
phone:res.data.mobile
})
11 months ago
console.log('setLinkman',this.properties.is_authentication)
this.triggerEvent("setLinkman",{phone:this.data.phone})
}
})
}
5 years ago
// 获取默认联系人
// commonApi.user_post("token/check").then(res=>{
// this.setData({
// isGroup:app.globalData.product.isGroup
// })
// if(res.code==1){
// userApi.user_post("user/getDefaultContact",{
// contactType:"CONTACT"
// }).then(res=>{
// if(res.data){
// let length =[res.data].length
// this.setData({
// selectLinkman:[res.data],
// showNum:this.data.showNum-length,
// showManList:[res.data]
// })
// this.triggerEvent("setLinkman",[res.data])
// }
// this.getLinkmanList()
// })
// }
// })
this.getLinkmanList()
// 获取证件列表
userApi.user_post("user/getCardTypeList", {}).then(r => {
console.log(r)
let data = [];
r.data.map(item=>{
data.push(item.title)
})
this.setData({
types: r.data,
typeList:data
})
})
5 years ago
},
detached: function() {
// 在组件实例被从页面节点树移除时执行
},
},
pageLifetimes: {
show: function() {
// 页面被展示
if(this.data.editId){
let editId = this.data.editId;
userApi.user_post("user/getContactInfoById",{
id:editId
}).then(res=>{
let selectLinkman = this.data.selectLinkman,linkmanList = this.data.linkmanList;
selectLinkman.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;
5 years ago
item.document_type = res.data.document_type;
item.document_type_text = res.data.document_type_text;
5 years ago
}
})
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;
5 years ago
item.document_type = res.data.document_type;
item.document_type_text = res.data.document_type_text;
5 years ago
}
else if(res.data.is_default==1 && item.is_default==1){
item.is_default = 0;
}
})
this.setData({
linkmanList:linkmanList,
selectLinkman:selectLinkman
})
})
}
else {
commonApi.user_post("token/check").then(res=>{
if(res.code==1){
this.getLinkmanList()
}
})
}
},
hide: function() {
// 页面被隐藏
},
resize: function(size) {
// 页面尺寸变化
}
},
/**
* 组件的方法列表
*/
methods: {
delTel() {
this.setData({
phone: ''
})
this.triggerEvent("setLinkman",{phone:this.data.phone})
},
5 years ago
gotoEdit:function(e){
userApi.user_post("user/getContactInfoById", { id: e.currentTarget.dataset.item.id }).then(res => {
console.log(res);
res.data.isDefault = res.data.is_default == '1' ? true : false;
res.data.username = res.data.name;
res.data.mobile = res.data.tel;
res.data.idNumber = res.data.id_number;
console.log(res.data);
this.setData({
showMask:!this.data.showMask,
formData: res.data,
idTypeId: res.data.idcard_type,
editId:e.currentTarget.dataset.item.id,
selectIndex:this.data.types.findIndex(item=>item.type == res.data.idcard_type && item.code == res.data.document_type)
})
5 years ago
})
this.showAddMask()
5 years ago
},
showLinkman:function(){
// console.log(this.data.linkmanList);
let linkmanList = this.data.linkmanList,seldManList = this.data.seldManList
linkmanList.map(linkman=>{
linkman.selected = 0;
seldManList.map(item=>{
if(item.id==linkman.id){
linkman.selected = 1;
}
})
})
5 years ago
this.setData({
showMask:!this.data.showMask,
linkmanList,
seldManList
5 years ago
})
},
showAddMask:function(){
this.setData({
showAdd:!this.data.showAdd,
showMask:!this.data.showMask
})
},
addMask:function(){
this.setData({
showAdd:!this.data.showAdd
})
},
5 years ago
cancel:function(){
let selectLinkman = this.data.selectLinkman,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()
},
selectType:function(e){
this.setData({
selectIndex:e.detail.value
})
},
// 保存
save:function(){
if (!this.data.formData.username){
wx.showToast({
title: '请输入姓名!',
icon:"none"
})
return false;
}
if (!this.data.formData.mobile) {
wx.showToast({
title: '请输入手机号码!',
icon: "none"
})
return false;
}
if (!util.isTel(this.data.formData.mobile)) {
wx.showToast({
title: '请输入正确的手机号码!',
icon: "none"
})
return false;
}
// if (!this.data.idTypeId) {
// wx.showToast({
// title: '请选择证件类型!',
// icon: "none"
// })
// return false;
// }
// if (!this.data.formData.idNumber) {
// wx.showToast({
// title: '请输入证件号!',
// icon: "none"
// })
// return false;
// }
let data = this.data.formData;
data.idcard_type = this.data.types[this.data.selectIndex].type;
data.is_default = data.isDefault?'1':'0';
data.document_type = this.data.types[this.data.selectIndex].code;
data.id_number = this.data.formData.idNumber;
let service ="addNewContact";
if(this.data.editId){
data.contactId = this.data.editId;
service = "editContactById";
}
userApi.user_post("user/"+service,data).then(res=>{
if(res.code==1){
wx.showToast({
title: '保存成功!',
icon:"success",
success:function(){
// util.back();
}
})
this.setData({
showAdd:!this.data.showAdd,
formData:{},
editId:null
})
this.getLinkmanList()
}
})
},
//取消添加出行人
del:function(){
this.setData({
editId:null,
formData:{},
showAdd:!this.data.showAdd
})
},
// 输入监听 不是双向绑定啊 绝望
nameInput:function(e){
var formData = this.data.formData;
formData.username = e.detail.value;
this.setData({
formData: formData
})
},
idNumberInput:function(e){
var formData = this.data.formData;
formData.idNumber = e.detail.value;
this.setData({
formData: formData
})
},
telInput:function(e){
var formData = this.data.formData;
formData.mobile = e.detail.value;
this.setData({
formData: formData
})
},
phoneInput:function(e){
this.setData({
phone: e.detail.value
})
this.triggerEvent("setLinkman",{phone:this.data.phone})
},
// 设为默认
setAddDefault:function(e){
var formData = this.data.formData;
formData.isDefault = e.detail.value;
this.setData({
formData: formData
})
},
5 years ago
confirm:function(){
let linkmanList = this.data.linkmanList,selectLinkman = [];
console.log(linkmanList);
// 2. 将选中的出行人展示到页面中
let newManlist = []
let manList = this.data.manList
let newSeldManList = []
linkmanList.map((item,index) => {
if (item.selected === 1) {
newManlist.push(item)
newSeldManList.push(item)
}
})
manList.map(item => {
if (!newManlist.some(s => s.id === item.id)) {
if (newManlist.length < 3) {
newManlist.push({...item, selected: 0})
}
5 years ago
}
})
console.log('-----',newManlist);
// 需要 改成 根据父组件的购买数量
let showNum = this.properties.productNum
// let showNum = this.data.showNum
showNum = showNum-selectLinkman.length
let showManList = this.data.showManList
showManList = [...selectLinkman]
// if(this.properties.maxNum!=-1 && selectLinkman.length>Number(this.properties.maxNum)){
// wx.showToast({
// title: '最多只能选择'+this.properties.maxNum+"个出行人",
// icon:'none'
// })
// return;
// }
this.triggerEvent("setLinkman",newSeldManList)
5 years ago
this.setData({
selectLinkman:selectLinkman,
manList:newManlist,
seldManList:newSeldManList,
showManList:showManList,
showNum:showNum
5 years ago
})
this.showLinkman()
},
getLinkmanList:function(){
// 直接获取1000条出行人信息 就不要分页了
userApi.user_post("user/getContactOrConsignee",{
contactType:"CONTACT",
offset:0,
9 months ago
limit:1000,
tm_flag: true,
5 years ago
}).then(res=>{
let list = res.data;
// list.map(item=>{
// this.data.selectLinkman.map(linkman=>{
// if(linkman.id==item.id){
// item.selected = 1;
// }
// })
// })
// 这里不和默认出行人匹配,直接截取前三个
list.map((item,index)=> {
if (index== 0) {
item.selected = 1
}else {
item.selected = 0
}
})
let manList = list.slice(0,3)
let seldManList = []
list.map((item,index)=> {
if (item.selected == 1) {
seldManList.push(item)
}
5 years ago
})
this.triggerEvent("setLinkman",seldManList)
5 years ago
this.setData({
linkmanList:list,
manList,
selectLinkman:list,
seldManList:seldManList
5 years ago
})
})
},
delMan() {
let seldManList = this.data.seldManList,selectLinkman = this.data.selectLinkman,manList=this.data.manList,linkmanList=this.data.linkmanList
let newManlist = JSON.parse(JSON.stringify(manList))
let newSeldManList =JSON.parse(JSON.stringify(seldManList))
// 3.减少时 选择的用户信息跟着修改
if (seldManList.length === this.properties.productNum +1) {
newSeldManList.pop()
newManlist.forEach(f => {
if(newSeldManList.some(s => s.id === f.id)) {
f.selected = 1
} else {
f.selected = 0
}
})
}
this.triggerEvent("setLinkman",newSeldManList)
this.setData({
// seldManList,
selectLinkman,
manList: newManlist,
seldManList: newSeldManList
5 years ago
})
},
// 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
// })
// }
// })
// },
5 years ago
delLinkman:function(e){
// if (seldManList.length === 1) return
5 years ago
wx.showLoading({
title: '加载中',
})
let index = e.currentTarget.dataset.index,selectLinkman = this.data.selectLinkman,showManList = this.data.showManList,linkmanList=JSON.parse(JSON.stringify(this.data.linkmanList)),manList = this.data.manList,seldManList= this.data.seldManList;
5 years ago
selectLinkman.splice(index,1);
let item = e.currentTarget.dataset.item
seldManList = seldManList.filter(f => f.id !== item.id)
manList.forEach(f => {
if(f.id === item.id) {
f.selected = 0
}
})
// debugger
linkmanList.forEach(linkman=> {
if (linkman.id === item.id) {
linkman.selected =0
}
})
showManList.splice(index,1);
5 years ago
this.triggerEvent("setLinkman",selectLinkman)
this.setData({
selectLinkman:selectLinkman,
showManList:showManList,
showNum:selectLinkman.length>0?this.data.showNum+1:1,
linkmanList,
seldManList,
manList
5 years ago
})
wx.hideLoading()
},
select:function(e) {
// debugger
let item = e.target.dataset.item,seldManList = [],manList = this.data.manList,linkmanList = this.data.linkmanList,list = []
if (this.properties.productNum > linkmanList.filter(f=> f.selected === 1).length ) {
// 票数大于信息数 继续勾选
if (this.properties.is_real_name == '1' && this.properties.productNum != 1) { // 一证一票
// this.selectIt(item)
// 一证一票 且 票数大于1
// 1. 当选择的出行人小于购票数量时,才能继续添加出行人
if (linkmanList.filter(f => f.selected === 1).length < this.properties.productNum || item.selected === 1) {
linkmanList.forEach(linkman=> {
if (linkman.id == item.id) {
linkman.selected = linkman.selected === 1 ? 0 : 1
}
})
}
} else {
// let flag = manList.some(obj => obj.id === item.id)
// if (flag) {
manList.map(man=> {
if (man.id == item.id) {
man.selected =1
}else {
man.selected =0
}
})
linkmanList.map(linkman=> {
if (linkman.id == item.id) {
linkman.selected =1
}else {
linkman.selected =0
}
})
// }
}
}else if( (this.properties.productNum == 1 && this.properties.productNum == linkmanList.filter(f=> f.selected === 1).length)) {
// debugger
// 票数为1,切换选择:如果在manList内,就直接切换,不在则将出行人放入manList内
let flag = manList.some(obj => obj.id === item.id)
if (flag) {
manList.map(man=> {
if (man.id == item.id) {
man.selected =1
}else {
man.selected =0
}
})
linkmanList.map(linkman=> {
if (linkman.id == item.id) {
linkman.selected =1
}else {
linkman.selected =0
}
})
console.log(manList,linkmanList);
}else {
item.selected = 1
manList.unshift(item)
manList = manList.slice(0,3)
manList.map(man=> {
if (man.id == item.id) {
man.selected =1
}else {
man.selected =0
}
})
linkmanList.map(linkman=> {
if (linkman.id == item.id) {
linkman.selected =1
}else {
linkman.selected =0
}
})
}
}else {
// debugger
if (item.selected === 1) {
linkmanList.forEach(f => {
if(f.id === item.id) {
f.selected = 0
}
})
} else {
wx.showToast({
title: '您只需选择'+this.properties.productNum+'位游客',
icon: "none"
});
return
}
}
// this.triggerEvent("setLinkman",seldManList)
this.setData({
// manList,
linkmanList,
// seldManList,
selectLinkman:manList
})
// if (this.properties.is_real_name == '1') { // 一证一票
// this.selectIt(item)
// } else {
// this.selectOne(item)
// }
},
// 一证一票不让他多选
selectOne:function(e) {
// debugger
console.log(e);
let item = e,linkmanList = this.data.linkmanList,num = 0
linkmanList.map(linkman=>{
if(linkman.selected==1){
num++;
}
})
console.log(num);
linkmanList.map(linkman=>{
if(item.id==linkman.id){
// linkman.selected = linkman.selected==1?0:1;
linkman.selected = 1
}else {
linkman.selected = 0
}
})
console.log(linkmanList);
this.setData({
linkmanList
})
},
// 可多选
5 years ago
selectIt:function(e){
console.log(e,app.globalData.product)
console.log(e);
// let item = e.currentTarget.dataset.item,linkmanList = this.data.linkmanList,num = 0,traveller_limit_num = this.properties.maxNum!=-1?this.properties.maxNum:(app.globalData.product.sku.sku_model && app.globalData.product.sku.sku_model.limit_type!=0?app.globalData.product.sku.sku_model.traveller_limit_num:-1);
let item = e,linkmanList = this.data.linkmanList,num = 0,traveller_limit_num = this.properties.maxNum!=-1?this.properties.maxNum:(app.globalData.product.sku.sku_model && app.globalData.product.sku.sku_model.limit_type!=0?app.globalData.product.sku.sku_model.traveller_limit_num:-1);
5 years ago
// 先计算出全部选中的出行人
5 years ago
linkmanList.map(linkman=>{
5 years ago
if(linkman.selected==1){
num++;
5 years ago
}
5 years ago
})
console.log(traveller_limit_num,num,item)
// 如果是要新增选中 并且当前选中数量已经超过或者等于了最大出行人限制
5 years ago
if((app.globalData.kjId || this.properties.type=='activity' || app.globalData.product.isGroup==1) && num==1 && item.selected!=1){
5 years ago
wx.showToast({
5 years ago
title: app.globalData.product.isGroup==1?'单次只能选择一个发起人':'最多只能选择一个出行人',
5 years ago
icon:'none'
})
return;
}
else if((app.globalData.gp_id || app.globalData.team_id) && num>=app.globalData.product.maxNum && item.selected!=1){
wx.showToast({
title: '最多只能选择'+app.globalData.product.maxNum+'个出行人',
icon:'none'
})
return;
}
5 years ago
else if(this.properties.maxNum!=-1 && item.selected!=1 && num>=traveller_limit_num && traveller_limit_num!=-1){
5 years ago
wx.showToast({
title: '最多只能选择'+this.properties.maxNum+"个出行人",
icon:'none'
})
return;
}
5 years ago
else if(item.selected!=1 && traveller_limit_num!=0 && num>=traveller_limit_num && traveller_limit_num!=-1){
5 years ago
wx.showToast({
3 years ago
title: '本产品单笔限购'+traveller_limit_num+"份",
5 years ago
icon:'none'
})
return;
}
linkmanList.map(linkman=>{
if(item.id==linkman.id){
linkman.selected = linkman.selected==1?0:1;
5 years ago
}
})
// let manList = linkmanList.slice(0,3)
5 years ago
this.setData({
linkmanList:linkmanList,
// manList,
})
},
// 勾选展示
selcetFrame(e) {
let item = e.currentTarget.dataset.item
let index = e.currentTarget.dataset.index
let manList = this.data.manList,seldManList = this.data.seldManList,linkmanList = this.data.linkmanList
if (this.properties.productNum !== 1 && this.properties.productNum === seldManList) {
wx.showToast({
title: '您只需选择'+this.properties.productNum+'位游客',
icon: "none"
});
return // 出行人和购票数量相同的情况就return
}
if (this.properties.is_real_name == '1') { // 一证一票
// this.selectIt(item)
let count = 0
manList.forEach(people=> {
if (people.selected == 1) {
count++
}
})
if (count< this.properties.productNum) { // 选中的出行人数量小于票数
manList.map(man=>{
if(item.id==man.id){
man.selected = man.selected==1?0:1;
}
})
if(seldManList.length < this.properties.productNum && item.selected === 0) {
seldManList.push(item)
} else {
seldManList = seldManList.filter(f => f.id !== item.id)
}
}else { // 否则换掉
if ( this.properties.productNum == 1) {
if (item.selected == 1) {
manList.forEach(man=>{
if (man.id === item.id) {
man.selected = 0
}
})
seldManList = []
} else {
manList.forEach(man=>{
if (man.id === item.id) {
man.selected = 1
}else {
man.selected = 0
}
})
seldManList = [item]
}
// manList.map((item)=> {
// if (item.selected == 1) {
// seldManList.push(item)
// }
// })
}else {
// return
if(item.selected === 1) {
manList.forEach(f => {
if(f.id === item.id) {
f.selected = 0
}
})
seldManList = seldManList.filter(f => f.id !== item.id)
}
}
}
}else {
if (item.selected == 1) {
manList.forEach(man=>{
if (man.id === item.id) {
man.selected = 0
}
})
seldManList = []
} else {
manList.forEach(man=>{
if (man.id === item.id) {
man.selected = 1
}else {
man.selected = 0
}
})
seldManList = [item]
}
}
this.triggerEvent("setLinkman",seldManList)
this.setData({
manList,
seldManList,
linkmanList
5 years ago
})
}
}
})