feedback.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // pages/welfareMall/feedback/feedback.js
  2. import WelfareMall from '../../../api/welfareMall'
  3. import Upload from '../../../api/upload'
  4. import {getMobileCache, getPhoneNumber as getPhoneNumberSync} from '../../../utils/user'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. t_length: 0,
  11. avatarUrl: [],
  12. avatarUrlShow: [],
  13. chooseViewShowBanner: true,
  14. content: '',
  15. basePath: '',
  16. hideWindowValue: false,
  17. },
  18. bindText: function (e) {
  19. var t_text = e.detail.value.length;
  20. var text = e.detail.value;
  21. this.setData({
  22. t_length: t_text,
  23. content: text,
  24. })
  25. },
  26. /** 图片选择 */
  27. bindViewTap: function(){
  28. var that = this;
  29. if(this.data.avatarUrlShow.length < 4){
  30. wx.chooseImage({
  31. // 设置最多可以选择的图片张数,默认9,如果我们设置了多张,那么接收时//就不在是单个变量了,
  32. count: 1,
  33. sizeType: ['original', 'compressed'], // original 原图,compressed 压缩图,默认二者都有
  34. sourceType: ['album', 'camera'], // album 从相册选图,camera 使用相机,默认二者都有
  35. success: function(res){
  36. // 获取成功,将获取到的地址赋值给临时变量
  37. console.log(res);
  38. if (res.tempFilePaths.count == 0) {
  39. return;
  40. }
  41. //图片上传到金山云
  42. var tempFilePaths = res.tempFilePaths
  43. wx.uploadFile({
  44. url: Upload.uploadPic(),
  45. filePath: tempFilePaths[0],
  46. name: 'file',
  47. formData:{
  48. 'basePath':'welfareMall',
  49. },
  50. success: function (res) {
  51. //提交路径
  52. var urlImg = JSON.parse(res.data).data.url;
  53. //展示路径
  54. var destPath = JSON.parse(res.data).data.destPath;
  55. var imgArrNow = that.data.avatarUrl;
  56. var imgArrNowShow = that.data.avatarUrlShow;
  57. imgArrNow.push(urlImg);
  58. imgArrNowShow.push(destPath);
  59. if(that.data.avatarUrlShow.length > 4){
  60. wx.showToast({
  61. title: '最多添加4张图片',
  62. icon: 'none',
  63. duration: 1500
  64. })
  65. return
  66. }
  67. that.setData({
  68. //将临时变量赋值给已经在data中定义好的变量
  69. avatarUrl:imgArrNow,
  70. avatarUrlShow:imgArrNowShow
  71. })
  72. that.chooseViewShowBanner();
  73. },
  74. fail: function(err) {
  75. console.log(err);
  76. },
  77. })
  78. },
  79. fail: function(res) {
  80. // fail
  81. },
  82. complete: function(res) {
  83. // complete
  84. }
  85. })
  86. } else {
  87. wx.showToast({
  88. title: '最多添加4张图片',
  89. icon: 'none',
  90. duration: 1500
  91. })
  92. }
  93. },
  94. /** 删除图片Banner */
  95. deleteImvBanner: function(e) {
  96. var avatarUrlShow = this.data.avatarUrlShow;
  97. var avatarUrl = this.data.avatarUrl;
  98. var itemIndex = e.currentTarget.dataset.id;
  99. avatarUrlShow.splice(itemIndex, 1);
  100. avatarUrl.splice(itemIndex, 1);
  101. this.setData({
  102. avatarUrlShow: avatarUrlShow
  103. })
  104. //判断是否隐藏选择图片
  105. this.chooseViewShowBanner();
  106. },
  107. /** 是否隐藏图片选择Banner*/
  108. chooseViewShowBanner: function() {
  109. if (this.data.avatarUrlShow.length > 3) {
  110. this.setData({
  111. chooseViewShowBanner: false
  112. })
  113. } else {
  114. this.setData({
  115. chooseViewShowBanner: true
  116. })
  117. }
  118. },
  119. /** 图片预览 */
  120. previewImage: function(e){
  121. var that = this,
  122. //获取当前图片的下标
  123. index = e.currentTarget.dataset.index,
  124. //数据源
  125. avatarUrlShow = this.data.avatarUrlShow;
  126. wx.previewImage({
  127. //当前显示下标
  128. current: avatarUrlShow[index],
  129. //数据源
  130. urls: avatarUrlShow
  131. })
  132. },
  133. /**
  134. * 提交
  135. */
  136. toSubmit: function() {
  137. if(this.data.content == null || this.data.content == '' || this.data.content == undefined){
  138. wx.showToast({
  139. title: '意见内容必填',
  140. icon: 'none',
  141. duration: 1500
  142. })
  143. return
  144. }
  145. WelfareMall.feedBackAdd({
  146. mobile: getMobileCache(),
  147. photoList: this.data.avatarUrl,
  148. content: this.data.content,
  149. }).then(res => {
  150. if (res.code == 200) {
  151. this.hideWindow()
  152. }
  153. }).catch(_ => {
  154. console.log(_)
  155. })
  156. },
  157. /**
  158. * 弹框
  159. */
  160. hideWindow(){
  161. this.setData({
  162. hideWindowValue:true
  163. })
  164. },
  165. goPerson(){
  166. wx.switchTab({
  167. url: '../personal/personal'
  168. })
  169. },
  170. /**
  171. * 生命周期函数--监听页面加载
  172. */
  173. onLoad: function (options) {
  174. },
  175. /**
  176. * 生命周期函数--监听页面初次渲染完成
  177. */
  178. onReady: function () {
  179. },
  180. /**
  181. * 生命周期函数--监听页面显示
  182. */
  183. onShow: function () {
  184. },
  185. /**
  186. * 生命周期函数--监听页面隐藏
  187. */
  188. onHide: function () {
  189. },
  190. /**
  191. * 生命周期函数--监听页面卸载
  192. */
  193. onUnload: function () {
  194. },
  195. /**
  196. * 页面相关事件处理函数--监听用户下拉动作
  197. */
  198. onPullDownRefresh: function () {
  199. },
  200. /**
  201. * 页面上拉触底事件的处理函数
  202. */
  203. onReachBottom: function () {
  204. },
  205. /**
  206. * 用户点击右上角分享
  207. */
  208. onShareAppMessage: function () {
  209. }
  210. })