facephoto.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. const api = require('../../../utils/api.js');
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. ditu:'/images/photo.png',
  8. fengmian:'/images/photo.png'
  9. },
  10. ditu:function(res){
  11. let that=this
  12. wx.chooseImage({
  13. count: 1,
  14. sizeType: ['original', 'compressed'],
  15. sourceType: ['album', 'camera'],
  16. success(res) {
  17. // tempFilePath可以作为img标签的src属性显示图片
  18. that.data.dtFilePaths = res.tempFilePaths
  19. that.setData({
  20. ditufile: that.data.dtFilePaths
  21. })
  22. }
  23. })
  24. },
  25. fengmian:function(){
  26. let that = this
  27. wx.chooseImage({
  28. count: 1,
  29. sizeType: ['original', 'compressed'],
  30. sourceType: ['album', 'camera'],
  31. success(res) {
  32. // tempFilePath可以作为img标签的src属性显示图片
  33. that.data.fmFilePaths = res.tempFilePaths
  34. that.setData({
  35. fengmianfile: that.data.fmFilePaths
  36. })
  37. }
  38. })
  39. },
  40. submit:function(){
  41. let that=this
  42. wx.showLoading({
  43. title: '正在上传',
  44. })
  45. if (!that.data.ditufile&&!that.data.fengmianfile){
  46. if (!that.data.dtFilePaths) {
  47. wx.showToast({
  48. title: '请上传底库照',
  49. icon: 'none'
  50. })
  51. return false
  52. } else if (!that.data.fmFilePaths){
  53. wx.showToast({
  54. title: '请上传封面照',
  55. icon: 'none'
  56. })
  57. return false
  58. }
  59. } else if (!that.data.dtFilePaths && !that.data.fmFilePaths){
  60. wx.showToast({
  61. title: '请先上传新的照片',
  62. icon: 'none'
  63. })
  64. return false
  65. }
  66. that.data.pathscount=0
  67. if (that.data.dtFilePaths){
  68. that.data.pathscount++
  69. } else if (that.data.fmFilePaths){
  70. that.data.pathscount++
  71. }
  72. if(that.data.dtFilePaths){
  73. that.upload(that.data.dtFilePaths,'false')
  74. }
  75. if(that.data.fmFilePaths){
  76. that.upload(that.data.fmFilePaths,'true')
  77. }
  78. },
  79. upload: function (file, isShowPhoto){
  80. let that=this
  81. wx.uploadFile({
  82. url: api.updateUserHeadImage,
  83. filePath: file[0],
  84. header: { 'content-type': 'application/x-www-form-urlencoded;charset=utf-8', },
  85. name: 'file',
  86. formData: {
  87. 'fileType': 'image',
  88. 'loginId': wx.getStorageSync('loginId'),
  89. 'isShowPhoto': isShowPhoto
  90. },
  91. success(res) {
  92. wx.hideLoading()
  93. if (JSON.parse(res.data).youtuMessage.error_code==0){
  94. if (that.data.pathscount==1){
  95. wx.redirectTo({
  96. url: '/pages/success/index',
  97. })
  98. }else{
  99. if (isShowPhoto=='true'){
  100. wx.redirectTo({
  101. url: '/pages/success/index',
  102. })
  103. }
  104. }
  105. }
  106. }
  107. })
  108. },
  109. /**
  110. * 生命周期函数--监听页面加载
  111. */
  112. onLoad: function (options) {
  113. let that=this
  114. wx.request({
  115. url: api.getYouTuImage,
  116. data:{loginId:wx.getStorageSync('loginId')},
  117. success(res){
  118. that.setData({
  119. ditufile: res.data.img?api.total.split('.if')[0] + res.data.img:'',
  120. fengmianfile: res.data.showImg? api.total.split('.if')[0] + res.data.showImg:''
  121. })
  122. }
  123. })
  124. },
  125. /**
  126. * 生命周期函数--监听页面初次渲染完成
  127. */
  128. onReady: function () {
  129. },
  130. /**
  131. * 生命周期函数--监听页面显示
  132. */
  133. onShow: function () {
  134. },
  135. /**
  136. * 生命周期函数--监听页面隐藏
  137. */
  138. onHide: function () {
  139. },
  140. /**
  141. * 生命周期函数--监听页面卸载
  142. */
  143. onUnload: function () {
  144. },
  145. /**
  146. * 页面相关事件处理函数--监听用户下拉动作
  147. */
  148. onPullDownRefresh: function () {
  149. },
  150. /**
  151. * 页面上拉触底事件的处理函数
  152. */
  153. onReachBottom: function () {
  154. },
  155. /**
  156. * 用户点击右上角分享
  157. */
  158. onShareAppMessage: function () {
  159. }
  160. })