upload.js 5.3 KB

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