commentinfo.js 3.7 KB

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