feedback.js 5.8 KB

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