facephoto.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. // if (that.data.pathscount==1){
  102. // wx.redirectTo({
  103. // url: '/pages/success/index',
  104. // })
  105. // }else{
  106. // if (isShowPhoto=='true'){
  107. // wx.redirectTo({
  108. // url: '/pages/success/index',
  109. // })
  110. // }
  111. // }
  112. }else{
  113. wx.showToast({
  114. title: JSON.parse(res.data).youtuMessage.result.error_msg,
  115. icon:'none'
  116. })
  117. }
  118. }
  119. })
  120. },
  121. /**
  122. * 生命周期函数--监听页面加载
  123. */
  124. onLoad: function (options) {
  125. let that=this
  126. wx.request({
  127. url: api.getYouTuImage,
  128. data:{loginId:wx.getStorageSync('loginId')},
  129. success(res){
  130. that.setData({
  131. ditufile: res.data.img?api.total.split('.if')[0] + res.data.img:'',
  132. fengmianfile: res.data.showImg? api.total.split('.if')[0] + res.data.showImg:''
  133. })
  134. }
  135. })
  136. },
  137. /**
  138. * 生命周期函数--监听页面初次渲染完成
  139. */
  140. onReady: function () {
  141. },
  142. /**
  143. * 生命周期函数--监听页面显示
  144. */
  145. onShow: function () {
  146. },
  147. /**
  148. * 生命周期函数--监听页面隐藏
  149. */
  150. onHide: function () {
  151. },
  152. /**
  153. * 生命周期函数--监听页面卸载
  154. */
  155. onUnload: function () {
  156. },
  157. /**
  158. * 页面相关事件处理函数--监听用户下拉动作
  159. */
  160. onPullDownRefresh: function () {
  161. },
  162. /**
  163. * 页面上拉触底事件的处理函数
  164. */
  165. onReachBottom: function () {
  166. },
  167. /**
  168. * 用户点击右上角分享
  169. */
  170. onShareAppMessage: function () {
  171. }
  172. })