upload.js 6.0 KB

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