facephoto.js 4.4 KB

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