user.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // pages/user/user.js
  2. const app = getApp()
  3. const host = app.globalData.host;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. sexArray: ["女","男"], //性别
  10. recordArray: ["小学", "初中", "高中", "大专", "本科", "硕士", "博士"], //学历
  11. sex: 0,
  12. record: 0,
  13. show: false,
  14. data:{
  15. }
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. wx.request({
  22. url: host+'/api/wx/authinfo',
  23. header: {
  24. openid: app.globalData.openid
  25. },
  26. success:res=>{
  27. let edu = this.data.recordArray.indexOf(res.data.data.education)
  28. this.setData({
  29. data:res.data.data,
  30. sex:res.data.data.sex,
  31. record:edu
  32. })
  33. }
  34. })
  35. },
  36. inputChange:function(e){
  37. var data=this.data.data
  38. data[e.target.dataset.name] = e.detail.value
  39. console.log(data)
  40. this.setData({
  41. data: data
  42. })
  43. },
  44. pickerChange:function(e){
  45. if (e.target.dataset.name == 'sex') {
  46. this.setData({
  47. sex: e.detail.value
  48. })
  49. };
  50. if (e.target.dataset.name == 'record') {
  51. this.setData({
  52. record: e.detail.value
  53. })
  54. };
  55. },
  56. showImg: function (e) {
  57. this.setData({
  58. show: true
  59. })
  60. if (e.target.dataset.name == 0) {
  61. }
  62. },
  63. hideImg: function (e) {
  64. this.setData({
  65. show: false
  66. })
  67. },
  68. takePhoto: function (e) {
  69. let id = e.target.dataset.id
  70. var _this = this
  71. wx.chooseImage({
  72. count: 1,
  73. success: function (res) {
  74. console.log(res.tempFilePaths[0])
  75. wx.showLoading({
  76. title: '正在上传',
  77. })
  78. wx.uploadFile({
  79. url: host + '/api/wx/uploadfile',
  80. filePath: res.tempFilePaths[0],
  81. name: 'file',
  82. formData: {
  83. 'file': res.tempFilePaths[0]
  84. },
  85. success: res => {
  86. wx.hideLoading()
  87. var data = JSON.parse(res.data)
  88. var _data = _this.data.data
  89. console.log(_data)
  90. if (id == 1) { //正面
  91. _data.idnoimg_face = data.data.url
  92. }
  93. if (id == 2) { //反面
  94. _data.idnoimg_back = data.data.url
  95. }
  96. if (id == 3) { //半身照
  97. _data.halfbody_img = data.data.url
  98. }
  99. if (id == 4) { //学历照
  100. _data.education_img = data.data.url
  101. }
  102. _this.setData({
  103. data:_data
  104. })
  105. }
  106. })
  107. },
  108. })
  109. },
  110. post:function(){
  111. var data=this.data.data
  112. data.sex=this.data.sex
  113. data.education = this.data.recordArray[this.data.record]
  114. wx.showLoading({
  115. title: '',
  116. })
  117. wx.request({
  118. url: host + '/api/wx/authinfo',
  119. header: {
  120. openid: app.globalData.openid
  121. },
  122. method:'PUT',
  123. success: res => {
  124. wx.showToast({
  125. title: '提交成功',
  126. icon: 'success',
  127. duration: 2000
  128. })
  129. }
  130. })
  131. },
  132. /**
  133. * 生命周期函数--监听页面初次渲染完成
  134. */
  135. onReady: function () {
  136. },
  137. /**
  138. * 生命周期函数--监听页面显示
  139. */
  140. onShow: function () {
  141. },
  142. /**
  143. * 生命周期函数--监听页面隐藏
  144. */
  145. onHide: function () {
  146. },
  147. /**
  148. * 生命周期函数--监听页面卸载
  149. */
  150. onUnload: function () {
  151. },
  152. /**
  153. * 页面相关事件处理函数--监听用户下拉动作
  154. */
  155. onPullDownRefresh: function () {
  156. },
  157. /**
  158. * 页面上拉触底事件的处理函数
  159. */
  160. onReachBottom: function () {
  161. },
  162. /**
  163. * 用户点击右上角分享
  164. */
  165. onShareAppMessage: function () {
  166. }
  167. })