feedback.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. if (!check.isValidPhone(this.data.mobile)) {
  112. this.setData({
  113. mobile: ''
  114. });
  115. util.showErrorToast('请输入手机号码');
  116. return false;
  117. }
  118. wx.showLoading({
  119. title: '提交中...',
  120. mask: true,
  121. success: function() {
  122. }
  123. });
  124. util.request(api.FeedbackAdd, {
  125. mobile: that.data.mobile,
  126. feedType: that.data.array[that.data.index],
  127. content: that.data.content,
  128. hasPicture: that.data.hasPicture,
  129. picUrls: that.data.picUrls
  130. }, 'POST').then(function(res) {
  131. wx.hideLoading();
  132. if (res.errno === 0) {
  133. wx.showToast({
  134. title: '感谢您的反馈!',
  135. icon: 'success',
  136. duration: 2000,
  137. complete: function() {
  138. that.setData({
  139. index: 0,
  140. content: '',
  141. contentLength: 0,
  142. mobile: '',
  143. hasPicture: false,
  144. picUrls: [],
  145. files: []
  146. });
  147. }
  148. });
  149. } else {
  150. util.showErrorToast(res.errmsg);
  151. }
  152. });
  153. },
  154. onLoad: function(options) {
  155. },
  156. onReady: function() {
  157. },
  158. onShow: function() {
  159. },
  160. onHide: function() {
  161. // 页面隐藏
  162. },
  163. onUnload: function() {
  164. // 页面关闭
  165. }
  166. })