upload.js 5.1 KB

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