upload.js 6.8 KB

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