upload.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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.code == 0){
  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. fail:res=>{
  124. wx.hideLoading()
  125. wx.showToast({
  126. title: res.data.message,
  127. icon: 'none',
  128. duration: 2000
  129. })
  130. }
  131. })
  132. },
  133. showImg:function(e){
  134. this.setData({
  135. show: true,
  136. img: '../../images/zj' + e.target.dataset.id + '.jpg'
  137. })
  138. },
  139. hideImg: function (e) {
  140. this.setData({
  141. show: false
  142. })
  143. },
  144. takePhoto:function(e){
  145. var id=e.target.dataset.id
  146. var _this=this
  147. wx.chooseImage({
  148. count:1,
  149. success: function(res) {
  150. wx.uploadFile({
  151. url: host+'/api/wx/uploadfile',
  152. filePath: res.tempFilePaths[0],
  153. name: 'file',
  154. formData: {
  155. 'file': res.tempFilePaths[0]
  156. },
  157. success:res=>{
  158. wx.hideLoading()
  159. var data=JSON.parse(res.data)
  160. wx.showToast({
  161. title: '上传成功',
  162. icon: 'none',
  163. duration: 2000
  164. })
  165. if(id == 1){ //正面
  166. _this.setData({
  167. idnoimg_face: data.data.url
  168. })
  169. }
  170. if (id == 2) { //反面
  171. _this.setData({
  172. idnoimg_back: data.data.url
  173. })
  174. }
  175. if (id == 3) { //半身照
  176. _this.setData({
  177. halfbody_img: data.data.url
  178. })
  179. }
  180. if (id == 4) { //学历照
  181. _this.setData({
  182. education_img: data.data.url
  183. })
  184. }
  185. if (id == 5) {
  186. _this.setData({
  187. oldcard_img: data.data.url
  188. })
  189. }
  190. },
  191. fail: res => {
  192. wx.hideLoading()
  193. wx.showToast({
  194. title: res,
  195. icon: 'none',
  196. duration: 2000
  197. })
  198. }
  199. })
  200. },
  201. })
  202. },
  203. /**
  204. * 生命周期函数--监听页面初次渲染完成
  205. */
  206. onReady: function () {
  207. },
  208. /**
  209. * 生命周期函数--监听页面显示
  210. */
  211. onShow: function () {
  212. },
  213. /**
  214. * 生命周期函数--监听页面隐藏
  215. */
  216. onHide: function () {
  217. },
  218. /**
  219. * 生命周期函数--监听页面卸载
  220. */
  221. onUnload: function () {
  222. },
  223. /**
  224. * 页面相关事件处理函数--监听用户下拉动作
  225. */
  226. onPullDownRefresh: function () {
  227. },
  228. /**
  229. * 页面上拉触底事件的处理函数
  230. */
  231. onReachBottom: function () {
  232. },
  233. /**
  234. * 用户点击右上角分享
  235. */
  236. onShareAppMessage: function () {
  237. }
  238. })