commentinfo.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // pages/commentinfo/commentinfo.js
  2. import uploadApi from '../../api/upload'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. shopStars: 5,
  9. productStars: 5,
  10. textWidth: 0,
  11. wordsNum: 0,
  12. limitNum: 100,
  13. outLimit: false,
  14. commentText: "",
  15. imgs: [],
  16. },
  17. // 上传图片
  18. chooseImg: function (e) {
  19. var that = this;
  20. var imgs = this.data.imgs;
  21. if (imgs.length >= 9) {
  22. this.setData({
  23. lenMore: 1
  24. });
  25. setTimeout(function () {
  26. that.setData({
  27. lenMore: 0
  28. });
  29. }, 2500);
  30. return false;
  31. }
  32. wx.chooseImage({
  33. // count: 1, // 默认9
  34. sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
  35. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  36. success: function (res) {
  37. // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
  38. var tempFilePaths = res.tempFilePaths;
  39. var imgs = that.data.imgs;
  40. // console.log(tempFilePaths + '----');
  41. for (var i = 0; i < tempFilePaths.length; i++) {
  42. if (imgs.length >= 9) {
  43. that.setData({
  44. imgs: imgs
  45. });
  46. return false;
  47. } else {
  48. imgs.push(tempFilePaths[i]);
  49. }
  50. }
  51. uploadApi.uploadCommentImgs(tempFilePaths)
  52. that.setData({
  53. imgs: imgs
  54. });
  55. }
  56. });
  57. },
  58. // 删除图片
  59. deleteImg: function (e) {
  60. var imgs = this.data.imgs;
  61. var index = e.currentTarget.dataset.index;
  62. imgs.splice(index, 1);
  63. this.setData({
  64. imgs: imgs
  65. });
  66. },
  67. // 预览图片
  68. previewImg: function (e) {
  69. //获取当前图片的下标
  70. var index = e.currentTarget.dataset.index;
  71. //所有图片
  72. var imgs = this.data.imgs;
  73. wx.previewImage({
  74. //当前显示图片
  75. current: imgs[index],
  76. //所有图片
  77. urls: imgs
  78. })
  79. },
  80. sendComment: function (e) {
  81. wx.showModal({
  82. title: '评论成功!',
  83. content: '评论可以在我的评论中查看',
  84. showCancel: false,
  85. confirmText: "确定"
  86. })
  87. },
  88. //给店铺评分
  89. changeShopStars: function (e) {
  90. this.setData({
  91. shopStars: e.currentTarget.dataset.i
  92. })
  93. },
  94. //给产品评分
  95. changeProductStars: function (e) {
  96. this.setData({
  97. productStars: e.currentTarget.dataset.i
  98. })
  99. },
  100. //根据当前的评论字数更改字数的num
  101. changeComment: function (e) {
  102. // console.log(e.detail)
  103. // console.log(e.detail.value.length)
  104. var length = e.detail.value.length;
  105. if (length > this.data.limitNum) {
  106. this.setData({
  107. outLimit: true
  108. })
  109. }
  110. this.setData({
  111. wordsNum: e.detail.value.length
  112. })
  113. },
  114. //填写评论文字内容
  115. setCommenText: function (e) {
  116. this.setData({
  117. commentText: e.detail.value
  118. })
  119. },
  120. /**
  121. * 生命周期函数--监听页面加载
  122. */
  123. onLoad: function (options) {
  124. var textWidth = wx.getSystemInfoSync().windowWidth * (750 / wx.getSystemInfoSync().windowWidth) * 0.9;
  125. this.setData({
  126. textWidth
  127. })
  128. },
  129. /**
  130. * 生命周期函数--监听页面初次渲染完成
  131. */
  132. onReady: function () {
  133. },
  134. /**
  135. * 生命周期函数--监听页面显示
  136. */
  137. onShow: function () {
  138. },
  139. /**
  140. * 生命周期函数--监听页面隐藏
  141. */
  142. onHide: function () {
  143. },
  144. /**
  145. * 生命周期函数--监听页面卸载
  146. */
  147. onUnload: function () {
  148. },
  149. /**
  150. * 页面相关事件处理函数--监听用户下拉动作
  151. */
  152. onPullDownRefresh: function () {
  153. },
  154. /**
  155. * 页面上拉触底事件的处理函数
  156. */
  157. onReachBottom: function () {
  158. },
  159. /**
  160. * 用户点击右上角分享
  161. */
  162. onShareAppMessage: function () {
  163. }
  164. })