user.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. img: ''
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad: function (options) {
  22. wx.request({
  23. url: host+'/api/wx/authinfo',
  24. header: {
  25. openid: app.globalData.openid
  26. },
  27. success:res=>{
  28. let edu = this.data.recordArray.indexOf(res.data.data.education)
  29. this.setData({
  30. data:res.data.data,
  31. sex:res.data.data.sex,
  32. record:edu
  33. })
  34. }
  35. })
  36. },
  37. inputChange:function(e){
  38. var data=this.data.data
  39. data[e.target.dataset.name] = e.detail.value
  40. console.log(data)
  41. this.setData({
  42. data: data
  43. })
  44. },
  45. pickerChange:function(e){
  46. if (e.target.dataset.name == 'sex') {
  47. this.setData({
  48. sex: e.detail.value
  49. })
  50. };
  51. if (e.target.dataset.name == 'record') {
  52. this.setData({
  53. record: e.detail.value
  54. })
  55. };
  56. },
  57. preview:function(){
  58. var _this=this;
  59. wx.previewImage({
  60. current: _this.data.data.idnoimg_face, // 当前显示图片的http链接
  61. urls: [_this.data.data.idnoimg_face] // 需要预览的图片http链接列表
  62. })
  63. },
  64. showImg: function (e) {
  65. this.setData({
  66. show: true,
  67. img: '../../images/zj' + e.target.dataset.id + '.jpg'
  68. })
  69. // var _this = this;
  70. // wx.previewImage({
  71. // current: '../../images/zj' + e.target.dataset.id + '.jpg', // 当前显示图片的http链接
  72. // urls: ['../../images/zj' + e.target.dataset.id + '.jpg'] // 需要预览的图片http链接列表
  73. // })
  74. },
  75. hideImg: function (e) {
  76. this.setData({
  77. show: false
  78. })
  79. },
  80. takePhoto: function (e) {
  81. let id = e.target.dataset.id
  82. var _this = this
  83. wx.chooseImage({
  84. count: 1,
  85. success: function (res) {
  86. console.log(res.tempFilePaths[0])
  87. wx.showLoading({
  88. title: '正在上传',
  89. })
  90. wx.uploadFile({
  91. url: host + '/api/wx/uploadfile',
  92. filePath: res.tempFilePaths[0],
  93. name: 'file',
  94. formData: {
  95. 'file': res.tempFilePaths[0]
  96. },
  97. success: res => {
  98. wx.hideLoading()
  99. var data = JSON.parse(res.data)
  100. var _data = _this.data.data
  101. console.log(_data)
  102. if (id == 1) { //正面
  103. _data.idnoimg_face = data.data.url
  104. }
  105. if (id == 2) { //反面
  106. _data.idnoimg_back = data.data.url
  107. }
  108. if (id == 3) { //半身照
  109. _data.halfbody_img = data.data.url
  110. }
  111. if (id == 4) { //学历照
  112. _data.education_img = data.data.url
  113. }
  114. if (id == 5) {
  115. _data.oldcard_img = data.data.url
  116. }
  117. _this.setData({
  118. data:_data,
  119. })
  120. },
  121. fail: res => {
  122. wx.hideLoading()
  123. wx.showToast({
  124. title: res.data.message,
  125. icon: 'none',
  126. duration: 2000
  127. })
  128. }
  129. })
  130. },
  131. })
  132. },
  133. post:function(){
  134. var data=this.data.data
  135. data.sex=this.data.sex
  136. data.education = this.data.recordArray[this.data.record]
  137. wx.showLoading({
  138. title: '',
  139. })
  140. wx.request({
  141. url: host + '/api/wx/authinfo',
  142. header: {
  143. openid: app.globalData.openid
  144. },
  145. method:'PUT',
  146. success: res => {
  147. wx.hideLoading()
  148. wx.showToast({
  149. title: '提交成功',
  150. icon: 'success',
  151. duration: 2000
  152. })
  153. },
  154. fail: res => {
  155. wx.hideLoading()
  156. wx.showToast({
  157. title: res.data.message,
  158. icon: 'none',
  159. duration: 2000
  160. })
  161. }
  162. })
  163. },
  164. /**
  165. * 生命周期函数--监听页面初次渲染完成
  166. */
  167. onReady: function () {
  168. },
  169. /**
  170. * 生命周期函数--监听页面显示
  171. */
  172. onShow: function () {
  173. },
  174. /**
  175. * 生命周期函数--监听页面隐藏
  176. */
  177. onHide: function () {
  178. },
  179. /**
  180. * 生命周期函数--监听页面卸载
  181. */
  182. onUnload: function () {
  183. },
  184. /**
  185. * 页面相关事件处理函数--监听用户下拉动作
  186. */
  187. onPullDownRefresh: function () {
  188. },
  189. /**
  190. * 页面上拉触底事件的处理函数
  191. */
  192. onReachBottom: function () {
  193. },
  194. /**
  195. * 用户点击右上角分享
  196. */
  197. onShareAppMessage: function () {
  198. }
  199. })