user.js 3.8 KB

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