upload.js 6.0 KB

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