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.

292 lines
8.6 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/attence/index.js
// const app = getApp();
// var commonUtil = require('../../../utils/commonUtil.js');
const app = getApp();
const commonUtil = require("../../../utils/commonUtil.js");
var inputContent = {}
Page({
/**
* 页面的初始数据
*/
data: {
sexIndex: 0,
sex: commonUtil.getSexArray(),
birthday: '2000-09-01',
educationIndex: 0,
education: commonUtil.getEducationArray(),
isMarryIndex: 0,
isMarry: commonUtil.getIsMarryArray(),
//
_num: 0,
disabled:0, //0不可点
getmsg: "获取验证码",
inputContent: {},
pop:0,
leftORright:true,
//
userDetails: {}
},
onLoad: function (options) {
// this.getUserDetails();
},
onShow: function (options) {
this.getUserDetails();
console.log("=================");
console.log(this.data.userDetails);
},
loginOut:function(){
wx.showModal({
title: '退出登录',
content: '确定要退出登录吗?',
success (res) {
if (res.confirm) {
console.log('用户点击确定');
app.logout();
wx.navigateBack({
delta: 1
})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
},
getUserDetails: function() {
var that = this;
wx.request({
url: app.globalData.ip + '/user/getUserDetails',
data: {},
header: app.globalData.header,
method: "POST",
success: function (res) {
console.log(res);
if (res.data.status == 200) {
that.data.userDetails = res.data.data;
that.data.sexIndex = commonUtil.initSexPicker(that.data.userDetails.sex);
that.data.educationIndex = commonUtil.initEducationPicker(that.data.userDetails.education);
that.data.isMarryIndex = commonUtil.initIsMarryPicker(that.data.userDetails.isMarry);
that.data.birthday = that.data.userDetails.birthday;
that.setData({
userDetails: that.data.userDetails,
sexIndex: that.data.sexIndex,
birthday: that.data.birthday,
educationIndex: that.data.educationIndex,
isMarryIndex: that.data.isMarryIndex,
});
} else if (res.data.status == 9999) {
// app.dialogNotLogin();
} else {
app.showTips(that, res.data.msg);
}
}
})
},
nav:function(e){
var tag = e.currentTarget.dataset.tag;
if (tag == 4 && this.data.userDetails.IDAuth == 1) {
//不跳转
} else {
wx.navigateTo({
url: e.currentTarget.dataset.href
})
}
},
sendMsg:function(){
this.setData({
disabled: 0
})
var timer = 1;
if (timer == 1) {
timer = 0
var that = this
var time = 6
var inter = setInterval(function () {
that.setData({
getmsg: time + "s",
disabled: 0
})
time--
if (time < 0) {
timer = 1
clearInterval(inter)
that.setData({
getmsg: "重新获取",
disabled: 1
})
}
}, 1000)
}
},
bindPickerChange: function (e) {
console.log('picker发送选择改变携带值为', e.detail.value)
var that = this;
var tag = e.currentTarget.dataset.tag;
if (tag == 0) {
// if (e.detail.value != 0) {
this.updateUser('sex', commonUtil.getSexValue(e.detail.value));
that.data.userDetails['sex'] = commonUtil.getSexValue(e.detail.value);
this.setData({
sexIndex: e.detail.value,
userDetails: that.data.userDetails
})
// }
} else if (tag == 1) {
this.updateUser('birthday', e.detail.value);
this.setData({
birthday: e.detail.value
})
} else if (tag == 2) {
this.updateUser('education', commonUtil.getEducationValue(e.detail.value));
that.data.userDetails['education'] = commonUtil.getEducationValue(e.detail.value);
this.setData({
educationIndex: e.detail.value,
userDetails: that.data.userDetails
})
} else if (tag == 3) {
this.updateUser('isMarry', commonUtil.getIsMarryValue(e.detail.value));
that.data.userDetails['isMarry'] = commonUtil.getIsMarryValue(e.detail.value);
this.setData({
isMarryIndex: e.detail.value,
userDetails: that.data.userDetails
})
}
},
updateUser: function(userParam, paramValue) {
var that = this;
wx.request({
url: app.globalData.ip + '/user/updateUserInfo',
data: {
userParam: userParam,
paramValue: paramValue
},
header: app.globalData.header,
method: "POST",
success: function (res) {
console.log(res);
if (res.data.status == 200) {
} else if (res.data.status == 9999) {
app.dialogNotLogin();
} else {
app.showTips(that, res.data.msg);
}
}
})
},
changeUserImgsrc: function(type) {
var that = this;
wx.chooseImage({
count: 1, // 默认9
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
// 返回选定照片的本地文件路径列表tempFilePath可以作为img标签的src属性显示图片
var tempFilePaths = res.tempFilePaths;
// var formData = {'userId': app.globalData.userId};
wx.uploadFile({
url: app.globalData.ip + '/user/changeUserImgsrc',
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) {
that.data.userDetails['imgSrc'] = result.data.url;
that.setData({
userDetails: that.data.userDetails
});
} else {
app.showTips(that, result.msg);
}
} else if (res.data.status == 9999) {
app.dialogNotLogin();
}
},
fail: function (res2) {
}
})
}
})
},
chooseUserLifeImage: function(e) {
var that = this;
// var type = e.currentTarget.dataset.type;
var type = 21;
wx.chooseImage({
count: 1, // 默认9
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
app.load("上传中");
// 返回选定照片的本地文件路径列表tempFilePath可以作为img标签的src属性显示图片
var tempFilePaths = res.tempFilePaths;
var formData = {'type' : type};
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('==================0');
console.log(res1);
console.log('==================0');
if (res1.statusCode == 200) {
var result = JSON.parse(res1.data)
if (result.status == 200) {
that.data.userDetails.lifePhoto = result.data.url;
that.setData({
userDetails: that.data.userDetails
});
app.success("上传成功");
} else {
app.showTips(that, result.msg);
}
}
wx.hideLoading();
},
fail: function (res2) {
wx.hideLoading();
}
})
}
})
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
// wx.redirectTo({
// url: '../index/index'
// })
},
})