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.
 

217 lines
5.0 KiB

// pages/user/address/add/index.js
import util from "../../../../utils/util.js"
import user from "../../../../utils/https/user.js"
let app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
isDefault:true,
region: [],
customItem: '',
typeItem:null,
formData:{
},
id:null, // 为null的时候是新增,否则是编辑
types:[],
safeBottom:app.globalData.safeBottom,
selectIndex:0
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
id: options.id || null
})
// 获取证件列表
user.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
})
if (this.data.id) {
user.user_post("user/getContactInfoById", { id: this.data.id }).then(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;
this.setData({
formData: res.data,
idTypeId: res.data.idcard_type,
selectIndex:r.data.findIndex(item=>item.type == res.data.idcard_type && item.code == res.data.document_type)
})
})
}
})
// 如果id存在那么需要获取地址详情
},
// 设为默认
setDefault:function(e){
var formData = this.data.formData;
formData.isDefault = e.detail.value;
this.setData({
formData: formData
})
},
// 输入监听 不是双向绑定啊 绝望
nameInput:function(e){
var formData = this.data.formData;
formData.username = e.detail.value;
this.setData({
formData: formData
})
},
telInput:function(e){
var formData = this.data.formData;
formData.mobile = e.detail.value;
this.setData({
formData: formData
})
},
idNumberInput:function(e){
var formData = this.data.formData;
formData.idNumber = e.detail.value;
this.setData({
formData: formData
})
},
// 选择证件类型
selectType:function(e){
this.setData({
selectIndex:e.detail.value
})
// let data = [];
// for(let i=0;i<this.data.types.length;i++){
// data.push(this.data.types[i].title)
// }
// wx.showActionSheet({
// itemList: data,
// success(res) {
// that.setData({
// typeItem:that.data.types[res.tapIndex],
// idTypeId: that.data.types[res.tapIndex].id,
// })
// console.log(res);
// },
// fail(res) {
// // Android 6.7.2 及以上版本 和 iOS 点击蒙层不会关闭模态弹窗,所以尽量避免使用「取消」分支中实现业务逻辑
// console.log(res.errMsg)
// }
// })
},
// 保存
submit: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.id){
data.contactId = this.data.id;
service = "editContactById";
}
user.user_post("user/"+service,data).then(res=>{
if(res.code==1){
wx.showToast({
title: '保存成功!',
icon:"success",
success:function(){
util.back();
}
})
}
})
},
cancel:function(){
util.back()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
}
})