feedback.js 5.4 KB

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