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.3 KiB

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