feedback.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. var util = require('../../../utils/util.js');
  2. var check = require('../../../utils/check.js');
  3. var api = require('../../../config/api.js');
  4. var app = getApp();
  5. Page({
  6. data: {
  7. array: ['请选择反馈类型', '商品相关', '功能异常', '优化建议', '其他'],
  8. index: 0,
  9. content: '',
  10. contentLength: 0,
  11. mobile: '',
  12. hasPicture: false,
  13. picUrls: [],
  14. files: []
  15. },
  16. chooseImage: function(e) {
  17. if (this.data.files.length >= 5) {
  18. util.showErrorToast('只能上传五张图片')
  19. return false;
  20. }
  21. var that = this;
  22. wx.chooseImage({
  23. count: 1,
  24. sizeType: ['original', 'compressed'],
  25. sourceType: ['album', 'camera'],
  26. success: function(res) {
  27. that.setData({
  28. files: that.data.files.concat(res.tempFilePaths)
  29. });
  30. that.upload(res);
  31. }
  32. })
  33. },
  34. upload: function(res) {
  35. var that = this;
  36. const uploadTask = wx.uploadFile({
  37. url: api.StorageUpload,
  38. filePath: res.tempFilePaths[0],
  39. name: 'file',
  40. success: function(res) {
  41. var _res = JSON.parse(res.data);
  42. if (_res.errno === 0) {
  43. var url = _res.data.url
  44. that.data.picUrls.push(url)
  45. that.setData({
  46. hasPicture: true,
  47. picUrls: that.data.picUrls
  48. })
  49. }
  50. },
  51. fail: function(e) {
  52. wx.showModal({
  53. title: '错误',
  54. content: '上传失败',
  55. showCancel: false
  56. })
  57. },
  58. })
  59. uploadTask.onProgressUpdate((res) => {
  60. console.log('上传进度', res.progress)
  61. console.log('已经上传的数据长度', res.totalBytesSent)
  62. console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend)
  63. })
  64. },
  65. previewImage: function(e) {
  66. wx.previewImage({
  67. current: e.currentTarget.id, // 当前显示图片的http链接
  68. urls: this.data.files // 需要预览的图片http链接列表
  69. })
  70. },
  71. bindPickerChange: function(e) {
  72. this.setData({
  73. index: e.detail.value
  74. });
  75. },
  76. mobileInput: function(e) {
  77. this.setData({
  78. mobile: e.detail.value
  79. });
  80. },
  81. contentInput: function(e) {
  82. this.setData({
  83. contentLength: e.detail.cursor,
  84. content: e.detail.value,
  85. });
  86. },
  87. clearMobile: function(e) {
  88. this.setData({
  89. mobile: ''
  90. });
  91. },
  92. submitFeedback: function(e) {
  93. if (!app.globalData.hasLogin) {
  94. wx.navigateTo({
  95. url: "/pages/auth/login/login"
  96. });
  97. }
  98. let that = this;
  99. if (that.data.index == 0) {
  100. util.showErrorToast('请选择反馈类型');
  101. return false;
  102. }
  103. if (that.data.content == '') {
  104. util.showErrorToast('请输入反馈内容');
  105. return false;
  106. }
  107. if (that.data.mobile == '') {
  108. util.showErrorToast('请输入手机号码');
  109. return false;
  110. }
  111. wx.showLoading({
  112. title: '提交中...',
  113. mask: true,
  114. success: function() {
  115. }
  116. });
  117. util.request(api.FeedbackAdd, {
  118. mobile: that.data.mobile,
  119. feedType: that.data.array[that.data.index],
  120. content: that.data.content,
  121. hasPicture: that.data.hasPicture,
  122. picUrls: that.data.picUrls
  123. }, 'POST').then(function(res) {
  124. wx.hideLoading();
  125. if (res.errno === 0) {
  126. wx.showToast({
  127. title: '感谢您的反馈!',
  128. icon: 'success',
  129. duration: 2000,
  130. complete: function() {
  131. that.setData({
  132. index: 0,
  133. content: '',
  134. contentLength: 0,
  135. mobile: '',
  136. hasPicture: false,
  137. picUrls: [],
  138. files: []
  139. });
  140. }
  141. });
  142. } else {
  143. util.showErrorToast(res.errmsg);
  144. }
  145. });
  146. },
  147. onLoad: function(options) {
  148. },
  149. onReady: function() {
  150. },
  151. onShow: function() {
  152. },
  153. onHide: function() {
  154. // 页面隐藏
  155. },
  156. onUnload: function() {
  157. // 页面关闭
  158. }
  159. })