You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

446 lines
10 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// pages/nickName/index.js
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
level:1,
niceName:'',
btnClick:false,
user:{},
nicknameArrayAll: [],
nicknameArrayShow: [],
pageNum: 1,
userDetails: {},
nickNameUsed: -1,
switch1Checked:true,
},
switch1Change:function(e){
var check = this.data.switch1Checked;
if (check) {
this.data.switch1Checked = false;
console.log("已取消选中");
wx.showToast({
title: '请先阅读并同意《服务协议》及《隐私政策》',
icon: 'none',
duration: 2000
})
} else {
this.data.switch1Checked = true;
console.log("已选中");
}
this.setData({
switch1Checked: this.data.switch1Checked,
});
// if(!e.detail.value){
// }
},
getData() {
var that = this;
wx.request({
url: app.globalData.ip + '/user/nickname/getUserNicknameDict',
data: {
status: 0
},
header: app.globalData.header,
method: "GET",
success: function (res) {
console.log(res);
if (res.data.status == 200) {
that.data.nicknameArrayAll = res.data.data;
that.getPage();
} else {
}
}
})
},
TT: function (e) {
var that = this;
if (that.data.user.idauth == 1) {
app.dialog("已实名认证", "实名认证后不能修改身份证照片", "知道了");
return;
}
console.log(e.currentTarget.dataset.id); //判断点击的第几个
this.setData({
which: e.currentTarget.dataset.id
});
var type;
if (this.data.which == 1) {
type = 2;
} else {
type = 3;
}
that.uploadImageOperator(type);
},
uploadImageOperator: function(type) {
var that = this;
wx.chooseImage({
count: 1, // 默认9
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
wx.showLoading({
title: '上传中',
mask: true
})
// 返回选定照片的本地文件路径列表tempFilePath可以作为img标签的src属性显示图片
var tempFilePaths = res.tempFilePaths;
var formData = {'type' : type, 'userId': app.globalData.userId};
wx.uploadFile({
url: app.globalData.ip + '/user/auth/uploadImage',
filePath: res.tempFilePaths[0],
name: 'uploadFile',
header: app.globalData.header2, // 设置请求的 header
formData: formData, // HTTP 请求中其他额外的 form data
success: function (res1) {
console.log(res1);
if (res1.statusCode == 200) {
var result = JSON.parse(res1.data)
if (result.status == 200) {
if (type == 2) {
if(result.data.realName == ""){
wx.showToast({
icon: "none",
title: '请重新上传身份证照片',
duration: 2000
})
return;
}
that.data.user['idcardImgFrontm'] = result.data.miniUrl;
that.data.user['idcardImgFront'] = result.data.url;
that.data.user['IDCard'] = result.data.IDCard;
that.data.user['realName'] = result.data.realName;
} else if (type == 3) {
that.data.user['idcardImgBackm'] = result.data.miniUrl;
that.data.user['idcardImgBack'] = result.data.url;
}
that.setData({
user: that.data.user
});
} else {
that.setData({
popErrorMsg: result.msg,
pop: 1,
});
setTimeout(() => {
that.setData({
popErrorMsg: '',
pop: 0,
});
return;
}, 2000)
}
}
//判断是否可以进入下一步
if (!that.isEmptyCheck(that.data.user.idcardImgFront) && !that.isEmptyCheck(that.data.user.idcardImgBack)) {
that.setData({
btnDisabled: false
});
}
wx.hideLoading();
},
fail: function (res2) {
wx.hideLoading();
}
})
}
})
},
isEmptyCheck: function (str) {
if (str == null || str == '' || str == 'null' || str == 'undefined' || typeof str == 'undefined') {
return true;
}
return false;
},
isNotEmptyCheck: function (str) {
return !this.isEmptyCheck(str);
},
nextStep() {
var that = this;
if (that.isEmptyCheck(that.data.user.idcardImgFront)) {
wx.showToast({
icon: "none",
title: '身份证不能为空',
duration: 2000
})
return;
}
if (that.isEmptyCheck(that.data.user.idcardImgBack)) {
wx.showToast({
icon: "none",
title: '身份证不能为空',
duration: 2000
})
return;
}
if (that.isEmptyCheck(that.data.user.realName)) {
wx.showToast({
icon: "none",
title: '姓名不能为空',
duration: 2000
})
return;
}
if (that.isEmptyCheck(that.data.user.IDCard)) {
wx.showToast({
icon: "none",
title: '证件号不能为空',
duration: 2000
})
return;
}
wx.request({
url: app.globalData.ip + '/user/auth/saveRealName',
data: {
realName: that.data.user.realName,
IDCard: that.data.user.IDCard
},
header: app.globalData.header,
method: "POST",
success: function (res) {
console.log(res);
if (res.data.status == 200) {
that.setData({
level:2
})
} else {
}
}
})
},
chooseName(e){
let name = e.currentTarget.dataset.name;
let idx = e.currentTarget.dataset.idx;
this.data.nicknameArrayShow.forEach(item => {
item.checked = false;
});
this.data.nicknameArrayShow[idx].checked = true;
this.setData({
niceName:name,
nicknameArrayShow: this.data.nicknameArrayShow
})
},
close:function(){
this.setData({
btnClick:false,
})
},
sureName:function(){
var that = this;
wx.request({
url: app.globalData.ip + '/corp/user/setCorpUserNickname',
data: {
nickname: that.data.niceName
},
header: app.globalData.header,
method: "POST",
success: function (res) {
console.log(res);
if (res.data.status == 200) {
that.setData({
level:3,
userDetails: res.data.data
})
} else {
wx.showToast({
icon: "none",
title: res.data.msg,
duration: 2000
})
}
}
})
this.setData({
btnClick:false,
})
},
sureNiceName:function(){
var that = this;
if (that.isEmptyCheck(that.data.niceName)) {
wx.showToast({
icon: "none",
title: '花名不能为空',
duration: 2000
})
that.setData({
nickNameUsed:-1
})
return;
}
wx.request({
url: app.globalData.ip + '/corp/user/checkUserNicknameUsed',//检查花名是否可用
data: {
nickname: that.data.niceName
},
header: app.globalData.header,
method: "POST",
success: function (res) {
console.log(res);
if (res.data.status == 200) {
var nickNameUsed = 0;
if (res.data.data == true) {
nickNameUsed = 1;
}
that.setData({
nickNameUsed: nickNameUsed
})
if (nickNameUsed == 0) {
that.setData({
btnClick:true,
})
}
} else {
wx.showToast({
icon: "none",
title: res.data.msg,
duration: 2000
})
}
}
})
},
goUsed(){
wx.navigateTo({
url: '/pages/nickNameUsed/index',
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
var that = this;
if (options && options.level) {
that.setData({
level: options.level
});
}
//登录=================================start
if (app.globalData.isLogin) {
that.getData();
} else {
// 由于 userLogin 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
app.userLoginCallback = res => {
that.getData();
}
}
},
getPage() {
this.data.nicknameArrayShow = [];
var pageSize = 20;
var start = (this.data.pageNum - 1) * pageSize;
var end = this.data.pageNum * pageSize;
if(end > this.data.nicknameArrayAll.length) {
end = this.data.nicknameArrayAll.length;
this.data.pageNum = 1;
} else {
this.data.pageNum = this.data.pageNum + 1;
}
for(; start < end; start++) {
var item = this.data.nicknameArrayAll[start];
item['checked'] = false;
this.data.nicknameArrayShow.push(item);
}
console.log(this.data.nicknameArrayShow);
this.setData({
nicknameArrayShow: this.data.nicknameArrayShow
});
},
bindinputNickName: function (e) {
var val = e.detail.value;
console.log(e);
if(e.detail.value == ''){
this.setData({
nickNameUsed: -1
});
}
this.setData({
niceName: val
});
},
okIKnow() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})