upload.js 3.9 KB

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