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.
269 lines
7.6 KiB
269 lines
7.6 KiB
// pages/order/components/contact/index.js
|
|
import userApi from "../../../../utils/https/user"
|
|
import commonApi from "../../../../utils/https/common"
|
|
let app = getApp()
|
|
Component({
|
|
/**
|
|
* 组件的属性列表
|
|
*/
|
|
options: {
|
|
styleIsolation: 'apply-shared',
|
|
addGlobalClass: true
|
|
},
|
|
properties: {
|
|
maxNum:{
|
|
type:String,
|
|
value:"-1"
|
|
},
|
|
type:{
|
|
type:String,
|
|
value:""
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 组件的初始数据
|
|
*/
|
|
data: {
|
|
selectLinkman:[],
|
|
linkmanList:[],
|
|
showMask:false,
|
|
editId:null,
|
|
isGroup:null
|
|
},
|
|
lifetimes: {
|
|
attached: function() {
|
|
// 在组件实例进入页面节点树时执行
|
|
// 获取默认联系人
|
|
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){
|
|
this.setData({
|
|
selectLinkman:[res.data]
|
|
})
|
|
this.triggerEvent("setLinkman",[res.data])
|
|
}
|
|
this.getLinkmanList()
|
|
})
|
|
}
|
|
})
|
|
},
|
|
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;
|
|
item.document_type = res.data.document_type;
|
|
item.document_type_text = res.data.document_type_text;
|
|
}
|
|
})
|
|
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;
|
|
item.document_type = res.data.document_type;
|
|
item.document_type_text = res.data.document_type_text;
|
|
}
|
|
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: {
|
|
gotoEdit:function(e){
|
|
this.setData({
|
|
editId:e.currentTarget.dataset.item.id
|
|
})
|
|
},
|
|
showLinkman:function(){
|
|
this.setData({
|
|
showMask:!this.data.showMask
|
|
})
|
|
},
|
|
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()
|
|
},
|
|
confirm:function(){
|
|
let linkmanList = this.data.linkmanList,selectLinkman = [];
|
|
linkmanList.map(linkman=>{
|
|
if(linkman.selected==1){
|
|
selectLinkman.push(linkman);
|
|
}
|
|
})
|
|
if(this.properties.maxNum!=-1 && selectLinkman.length>Number(this.properties.maxNum)){
|
|
wx.showToast({
|
|
title: '最多只能选择'+this.properties.maxNum+"个出行人",
|
|
icon:'none'
|
|
})
|
|
return;
|
|
}
|
|
this.setData({
|
|
selectLinkman:selectLinkman
|
|
})
|
|
this.triggerEvent("setLinkman",selectLinkman)
|
|
this.showLinkman()
|
|
},
|
|
getLinkmanList:function(){
|
|
// 直接获取1000条出行人信息 就不要分页了
|
|
userApi.user_post("user/getContactOrConsignee",{
|
|
contactType:"CONTACT",
|
|
offset:0,
|
|
limit:1000
|
|
}).then(res=>{
|
|
let list = res.data;
|
|
list.map(item=>{
|
|
this.data.selectLinkman.map(linkman=>{
|
|
if(linkman.id==item.id){
|
|
item.selected = 1;
|
|
}
|
|
})
|
|
})
|
|
this.setData({
|
|
linkmanList:list
|
|
})
|
|
})
|
|
},
|
|
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
|
|
})
|
|
}
|
|
})
|
|
},
|
|
delLinkman:function(e){
|
|
wx.showLoading({
|
|
title: '加载中',
|
|
})
|
|
let index = e.currentTarget.dataset.index,selectLinkman = this.data.selectLinkman;
|
|
selectLinkman.splice(index,1);
|
|
this.triggerEvent("setLinkman",selectLinkman)
|
|
this.setData({
|
|
selectLinkman:selectLinkman
|
|
})
|
|
wx.hideLoading()
|
|
},
|
|
selectIt:function(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.traveller_limit_num:-1);
|
|
// 先计算出全部选中的出行人
|
|
linkmanList.map(linkman=>{
|
|
if(linkman.selected==1){
|
|
num++;
|
|
}
|
|
})
|
|
console.log(traveller_limit_num,num,item)
|
|
// 如果是要新增选中 并且当前选中数量已经超过或者等于了最大出行人限制
|
|
if((app.globalData.kjId || this.properties.type=='activity' || app.globalData.product.isGroup==1) && num==1 && item.selected!=1){
|
|
wx.showToast({
|
|
title: app.globalData.product.isGroup==1?'单次只能选择一个发起人':'最多只能选择一个出行人',
|
|
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;
|
|
}
|
|
else if(this.properties.maxNum!=-1 && item.selected!=1 && num>=traveller_limit_num && traveller_limit_num!=-1){
|
|
wx.showToast({
|
|
title: '最多只能选择'+this.properties.maxNum+"个出行人",
|
|
icon:'none'
|
|
})
|
|
return;
|
|
}
|
|
else if(item.selected!=1 && traveller_limit_num!=0 && num>=traveller_limit_num && traveller_limit_num!=-1){
|
|
wx.showToast({
|
|
title: '出行人限购'+traveller_limit_num+"份",
|
|
icon:'none'
|
|
})
|
|
return;
|
|
}
|
|
linkmanList.map(linkman=>{
|
|
if(item.id==linkman.id){
|
|
linkman.selected = linkman.selected==1?0:1;
|
|
}
|
|
})
|
|
this.setData({
|
|
linkmanList:linkmanList
|
|
})
|
|
}
|
|
}
|
|
})
|
|
|