upload.js 7.9 KB

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