upload.js 4.9 KB

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