123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- // pages/user/user.js
- const app = getApp()
- const host = app.globalData.host;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- sexArray: ["女","男"], //性别
- recordArray: ["小学", "初中", "高中", "大专", "本科", "硕士", "博士"], //学历
- sex: 0,
- record: 0,
- show: false,
- data:{
- },
- img: ''
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- wx.showLoading({
- title: '加载中',
- })
- this.getData()
- },
- getData:function(){
-
- wx.request({
- url: host + '/api/wx/authinfo',
- header: {
- openid: app.globalData.openid
- },
- success: res => {
- console.log(res)
- wx.hideLoading()
- if (res.statusCode == 403) {
- this.save()
- } else {
- let edu = this.data.recordArray.indexOf(res.data.data.education)
- this.setData({
- data: res.data.data,
- sex: res.data.data.sex=='男' ? 1:0,
- record: edu
- })
- }
- }
- })
- },
- save:function(){
- var _this=this
- wx.showLoading({
- title: '正在登录',
- })
- wx.getStorage({
- key: 'userInfo',
- success: function(res) {
- console.log(res)
- wx.request({
- url: host + '/api/wx/auth',
- method: 'POST',
- data: {
- nickname: res.data.nickName,
- avatar: res.data.avatarUrl,
- openid: app.globalData.openid,
- },
- success: res => {
- wx.hideLoading()
- _this.getData();
-
- }
- })
- },
- })
-
- },
- inputChange:function(e){
- var data=this.data.data
- data[e.target.dataset.name] = e.detail.value
- console.log(data)
- this.setData({
- data: data
- })
- },
- pickerChange:function(e){
- if (e.target.dataset.name == 'sex') {
- this.setData({
- sex: e.detail.value
- })
- };
- if (e.target.dataset.name == 'record') {
- this.setData({
- record: e.detail.value
- })
- };
- },
- preview:function(){
- var _this=this;
- wx.previewImage({
- current: _this.data.data.classhour_imgs, // 当前显示图片的http链接
- urls: _this.data.data.classhour_imgs // 需要预览的图片http链接列表
- })
- },
- showImg: function (e) {
- this.setData({
- show: true,
- img: '../../images/zj' + e.target.dataset.id + '.jpg'
- })
- // var _this = this;
- // wx.previewImage({
- // current: '../../images/zj' + e.target.dataset.id + '.jpg', // 当前显示图片的http链接
- // urls: ['../../images/zj' + e.target.dataset.id + '.jpg'] // 需要预览的图片http链接列表
- // })
- },
- hideImg: function (e) {
- this.setData({
- show: false
- })
- },
- takePhoto: function (e) {
- let id = e.target.dataset.id
- var _this = this
- wx.chooseImage({
- count: 1,
- success: function (res) {
- console.log(res.tempFilePaths[0])
- wx.showLoading({
- title: '正在上传',
- })
- wx.uploadFile({
- url: host + '/api/wx/uploadfile',
- filePath: res.tempFilePaths[0],
- name: 'file',
- formData: {
- 'file': res.tempFilePaths[0]
- },
- success: res => {
- wx.hideLoading()
- var data = JSON.parse(res.data)
- var _data = _this.data.data
- console.log(_data)
- if (id == 1) { //正面
- _data.idnoimg_face = data.data.url
- }
- if (id == 2) { //反面
- _data.idnoimg_back = data.data.url
- }
- if (id == 3) { //半身照
- _data.halfbody_img = data.data.url
- }
- if (id == 4) { //学历照
- _data.education_img = data.data.url
- }
- if (id == 5) {
- _data.oldcard_img = data.data.url
- }
-
- _this.setData({
- data:_data,
-
- })
- },
- fail: res => {
- wx.hideLoading()
- wx.showToast({
- title: res.data.message,
- icon: 'none',
- duration: 2000
- })
- }
- })
- },
- })
- },
- post:function(){
- var data=this.data.data
- data.sex=this.data.sex==1?'男':'女'
- data.education = this.data.recordArray[this.data.record]
- console.log(data)
- wx.showLoading({
- title: '',
- })
- wx.request({
- url: host + '/api/wx/authinfo',
- header: {
- openid: app.globalData.openid
- },
- data:data,
- method:'PUT',
- success: res => {
- wx.hideLoading()
- wx.showToast({
- title: '提交成功',
- icon: 'success',
- duration: 2000
- })
- },
- fail: res => {
- wx.hideLoading()
- wx.showToast({
- title: res.data.message,
- icon: 'none',
- duration: 2000
- })
- }
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|