upload.js 4.3 KB

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