upload.js 5.7 KB

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