|
|
|
@ -18,82 +18,94 @@ Component({ |
|
|
|
* 组件的初始数据 |
|
|
|
*/ |
|
|
|
data: { |
|
|
|
selectLinkman:null, |
|
|
|
linkmanList:[], |
|
|
|
showMask:false, |
|
|
|
editId:null |
|
|
|
selectLinkman: null, |
|
|
|
linkmanList: [], |
|
|
|
showMask: false, |
|
|
|
editId: null |
|
|
|
}, |
|
|
|
lifetimes: { |
|
|
|
attached: function() { |
|
|
|
attached: function () { |
|
|
|
// 在组件实例进入页面节点树时执行
|
|
|
|
// 获取默认联系人
|
|
|
|
commonApi.user_post("token/check").then(res=>{ |
|
|
|
if(res.code==1){ |
|
|
|
userApi.user_post("user/getDefaultContact",{ |
|
|
|
contactType:"CONSIGNEE" |
|
|
|
}).then(res=>{ |
|
|
|
console.log(res) |
|
|
|
this.setData({ |
|
|
|
selectLinkman:res.data |
|
|
|
}) |
|
|
|
if(res.data){ |
|
|
|
this.triggerEvent("setAddress",res.data) |
|
|
|
} |
|
|
|
// 获取默认联系人 如果有临时存储的联系人则不获取默认联系人
|
|
|
|
commonApi.user_post("token/check").then(res => { |
|
|
|
if (res.code == 1) { |
|
|
|
console.log(wx.getStorageSync('linkMan')); |
|
|
|
if (wx.getStorageSync('linkMan')) { |
|
|
|
this.getLinkmanList() |
|
|
|
}) |
|
|
|
} else { |
|
|
|
userApi.user_post("user/getDefaultContact", { |
|
|
|
contactType: "CONSIGNEE" |
|
|
|
}).then(res => { |
|
|
|
this.setData({ |
|
|
|
selectLinkman: res.data |
|
|
|
}) |
|
|
|
if (res.data) { |
|
|
|
this.triggerEvent("setAddress", res.data) |
|
|
|
} |
|
|
|
this.getLinkmanList() |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
detached: function() { |
|
|
|
detached: function () { |
|
|
|
// 在组件实例被从页面节点树移除时执行
|
|
|
|
}, |
|
|
|
}, |
|
|
|
pageLifetimes: { |
|
|
|
show: function() { |
|
|
|
show: function () { |
|
|
|
// 页面被展示
|
|
|
|
if(this.data.editId){ |
|
|
|
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; |
|
|
|
if(selectLinkman.id==editId){ |
|
|
|
userApi.user_post("user/getContactInfoById", { |
|
|
|
id: editId |
|
|
|
}).then(res => { |
|
|
|
let selectLinkman = this.data.selectLinkman, |
|
|
|
linkmanList = this.data.linkmanList; |
|
|
|
if (selectLinkman.id == editId) { |
|
|
|
selectLinkman.name = res.data.name; |
|
|
|
selectLinkman.tel = res.data.tel; |
|
|
|
selectLinkman.address = res.data.address; |
|
|
|
selectLinkman.is_default = res.data.is_default; |
|
|
|
} |
|
|
|
linkmanList.map(item=>{ |
|
|
|
if(item.id==editId){ |
|
|
|
linkmanList.map(item => { |
|
|
|
if (item.id == editId) { |
|
|
|
item.name = res.data.name; |
|
|
|
item.tel = res.data.tel; |
|
|
|
item.address = res.data.address; |
|
|
|
item.is_default = res.data.is_default; |
|
|
|
} |
|
|
|
else if(res.data.is_default==1 && item.is_default==1){ |
|
|
|
} else if (res.data.is_default == 1 && item.is_default == 1) { |
|
|
|
item.is_default = 0; |
|
|
|
} |
|
|
|
}) |
|
|
|
this.setData({ |
|
|
|
linkmanList:linkmanList, |
|
|
|
selectLinkman:selectLinkman |
|
|
|
linkmanList: linkmanList, |
|
|
|
selectLinkman: selectLinkman |
|
|
|
}) |
|
|
|
this.triggerEvent("setAddress",res.data) |
|
|
|
this.triggerEvent("setAddress", res.data) |
|
|
|
}) |
|
|
|
} |
|
|
|
else { |
|
|
|
commonApi.user_post("token/check").then(res=>{ |
|
|
|
if(res.code==1){ |
|
|
|
this.getDefault() |
|
|
|
} else { |
|
|
|
commonApi.user_post("token/check").then(res => { |
|
|
|
if (res.code == 1) { |
|
|
|
if (!wx.getStorageSync('linkMan')) { |
|
|
|
this.getDefault() |
|
|
|
}else{ |
|
|
|
this.setData({ |
|
|
|
selectLinkman: wx.getStorageSync('linkMan') |
|
|
|
}) |
|
|
|
this.triggerEvent("setAddress",wx.getStorageSync('linkMan')) |
|
|
|
this.getLinkmanList() |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
}, |
|
|
|
hide: function() { |
|
|
|
hide: function () { |
|
|
|
// 页面被隐藏
|
|
|
|
}, |
|
|
|
resize: function(size) { |
|
|
|
resize: function (size) { |
|
|
|
// 页面尺寸变化
|
|
|
|
} |
|
|
|
}, |
|
|
|
@ -102,23 +114,23 @@ Component({ |
|
|
|
* 组件的方法列表 |
|
|
|
*/ |
|
|
|
methods: { |
|
|
|
gotoEdit:function(e){ |
|
|
|
gotoEdit: function (e) { |
|
|
|
this.setData({ |
|
|
|
editId:e.currentTarget.dataset.item.id |
|
|
|
editId: e.currentTarget.dataset.item.id |
|
|
|
}) |
|
|
|
wx.navigateTo({ |
|
|
|
url: '/pages/user/address/add/index?id='+this.data.editId+'&from=order', |
|
|
|
url: '/pages/user/address/add/index?id=' + this.data.editId + '&from=order', |
|
|
|
}) |
|
|
|
this.setData({ |
|
|
|
editId:null |
|
|
|
editId: null |
|
|
|
}) |
|
|
|
}, |
|
|
|
showLinkman:function(){ |
|
|
|
showLinkman: function () { |
|
|
|
this.setData({ |
|
|
|
showMask:!this.data.showMask |
|
|
|
showMask: !this.data.showMask |
|
|
|
}) |
|
|
|
}, |
|
|
|
cancel:function(){ |
|
|
|
cancel: function () { |
|
|
|
// let selectLinkman = this.data.selectLinkman,linkmanList = this.data.linkmanList;
|
|
|
|
// linkmanList.map(linkman=>{
|
|
|
|
// linkman.selected = 0;
|
|
|
|
@ -131,85 +143,90 @@ Component({ |
|
|
|
// })
|
|
|
|
this.showLinkman() |
|
|
|
}, |
|
|
|
confirm:function(){ |
|
|
|
let linkmanList = this.data.linkmanList,selectLinkman = null; |
|
|
|
linkmanList.map(linkman=>{ |
|
|
|
if(linkman.selected==1){ |
|
|
|
confirm: function () { |
|
|
|
let linkmanList = this.data.linkmanList, |
|
|
|
selectLinkman = null; |
|
|
|
linkmanList.map(linkman => { |
|
|
|
if (linkman.selected == 1) { |
|
|
|
selectLinkman = (linkman); |
|
|
|
} |
|
|
|
}) |
|
|
|
this.setData({ |
|
|
|
selectLinkman:selectLinkman |
|
|
|
selectLinkman: selectLinkman |
|
|
|
}) |
|
|
|
this.triggerEvent("setAddress",selectLinkman) |
|
|
|
this.triggerEvent("setAddress", selectLinkman) |
|
|
|
this.showLinkman() |
|
|
|
}, |
|
|
|
getLinkmanList:function(){ |
|
|
|
getLinkmanList: function () { |
|
|
|
// 直接获取1000条出行人信息 就不要分页了
|
|
|
|
userApi.user_post("user/getContactOrConsignee",{ |
|
|
|
contactType:"CONSIGNEE", |
|
|
|
offset:0, |
|
|
|
limit:1000 |
|
|
|
}).then(res=>{ |
|
|
|
userApi.user_post("user/getContactOrConsignee", { |
|
|
|
contactType: "CONSIGNEE", |
|
|
|
offset: 0, |
|
|
|
limit: 1000 |
|
|
|
}).then(res => { |
|
|
|
let list = res.data; |
|
|
|
this.setData({ |
|
|
|
linkmanList:list |
|
|
|
linkmanList: list |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
|
setDefault:function(e){ |
|
|
|
let item = e.currentTarget.dataset.item,linkmanList = this.data.linkmanList; |
|
|
|
userApi.user_post("user/setDefaultConsignee",{ |
|
|
|
id:item.id |
|
|
|
}).then(res=>{ |
|
|
|
if(res.code==1){ |
|
|
|
setDefault: function (e) { |
|
|
|
let item = e.currentTarget.dataset.item, |
|
|
|
linkmanList = this.data.linkmanList; |
|
|
|
userApi.user_post("user/setDefaultConsignee", { |
|
|
|
id: 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 { |
|
|
|
linkmanList.map(linkman => { |
|
|
|
if (linkman.id == item.id) { |
|
|
|
linkman.is_default = 1; |
|
|
|
} else { |
|
|
|
linkman.is_default = 0; |
|
|
|
} |
|
|
|
}) |
|
|
|
this.setData({ |
|
|
|
linkmanList:linkmanList |
|
|
|
linkmanList: linkmanList |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
|
}, |
|
|
|
delLinkman:function(e){ |
|
|
|
delLinkman: function (e) { |
|
|
|
wx.showLoading({ |
|
|
|
title: '加载中', |
|
|
|
}) |
|
|
|
let index = e.currentTarget.dataset.index,selectLinkman = this.data.selectLinkman; |
|
|
|
selectLinkman.splice(index,1); |
|
|
|
let index = e.currentTarget.dataset.index, |
|
|
|
selectLinkman = this.data.selectLinkman; |
|
|
|
selectLinkman.splice(index, 1); |
|
|
|
this.setData({ |
|
|
|
selectLinkman:selectLinkman |
|
|
|
selectLinkman: selectLinkman |
|
|
|
}) |
|
|
|
wx.hideLoading() |
|
|
|
}, |
|
|
|
del:function(e){ |
|
|
|
let item = e.currentTarget.dataset.item,index = e.currentTarget.dataset.index,that = this,linkmanList=this.data.linkmanList; |
|
|
|
del: function (e) { |
|
|
|
let item = e.currentTarget.dataset.item, |
|
|
|
index = e.currentTarget.dataset.index, |
|
|
|
that = this, |
|
|
|
linkmanList = this.data.linkmanList; |
|
|
|
wx.showModal({ |
|
|
|
title:"提示", |
|
|
|
content:"确定删除吗?", |
|
|
|
success (res) { |
|
|
|
title: "提示", |
|
|
|
content: "确定删除吗?", |
|
|
|
success(res) { |
|
|
|
if (res.confirm) { |
|
|
|
userApi.user_post("user/delConsignee",{ |
|
|
|
id:item.id |
|
|
|
}).then(res=>{ |
|
|
|
if(res.code==1){ |
|
|
|
userApi.user_post("user/delConsignee", { |
|
|
|
id: item.id |
|
|
|
}).then(res => { |
|
|
|
if (res.code == 1) { |
|
|
|
wx.showToast({ |
|
|
|
title: '删除成功', |
|
|
|
icon:"success" |
|
|
|
icon: "success" |
|
|
|
}) |
|
|
|
linkmanList.splice(index,1); |
|
|
|
linkmanList.splice(index, 1); |
|
|
|
that.setData({ |
|
|
|
linkmanList:linkmanList |
|
|
|
linkmanList: linkmanList |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
|
@ -220,26 +237,28 @@ Component({ |
|
|
|
} |
|
|
|
}) |
|
|
|
}, |
|
|
|
selectIt:function(e){ |
|
|
|
selectIt: function (e) { |
|
|
|
let item = e.currentTarget.dataset.item; |
|
|
|
this.setData({ |
|
|
|
selectLinkman:item, |
|
|
|
showMask:false |
|
|
|
selectLinkman: item, |
|
|
|
showMask: false |
|
|
|
}) |
|
|
|
this.triggerEvent("setAddress",item) |
|
|
|
wx.setStorageSync('linkMan', item) |
|
|
|
console.log(wx.getStorageSync('linkMan')); |
|
|
|
this.triggerEvent("setAddress", item) |
|
|
|
}, |
|
|
|
getDefault:function(e){ |
|
|
|
commonApi.user_post("token/check").then(res=>{ |
|
|
|
if(res.code==1){ |
|
|
|
userApi.user_post("user/getDefaultContact",{ |
|
|
|
contactType:"CONSIGNEE" |
|
|
|
}).then(res=>{ |
|
|
|
getDefault: function (e) { |
|
|
|
commonApi.user_post("token/check").then(res => { |
|
|
|
if (res.code == 1) { |
|
|
|
userApi.user_post("user/getDefaultContact", { |
|
|
|
contactType: "CONSIGNEE" |
|
|
|
}).then(res => { |
|
|
|
console.log(res) |
|
|
|
this.setData({ |
|
|
|
selectLinkman:res.data |
|
|
|
selectLinkman: res.data |
|
|
|
}) |
|
|
|
if(res.data){ |
|
|
|
this.triggerEvent("setAddress",res.data) |
|
|
|
if (res.data) { |
|
|
|
this.triggerEvent("setAddress", res.data) |
|
|
|
} |
|
|
|
this.getLinkmanList() |
|
|
|
}) |
|
|
|
|