commentinfo.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // pages/commentinfo/commentinfo.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. shopStars: 0,
  8. productStars: 0,
  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. changeShopStars: function (e) {
  80. this.setData({
  81. shopStars: e.currentTarget.dataset.i
  82. })
  83. },
  84. changeProductStars: function (e) {
  85. this.setData({
  86. productStars: e.currentTarget.dataset.i
  87. })
  88. },
  89. changeComment: function (e) {
  90. // console.log(e.detail)
  91. // console.log(e.detail.value.length)
  92. var length = e.detail.value.length;
  93. if (length > this.data.limitNum) {
  94. this.setData({
  95. outLimit: true
  96. })
  97. }
  98. this.setData({
  99. wordsNum: e.detail.value.length
  100. })
  101. },
  102. setCommenText: function (e) {
  103. console.log("调用了")
  104. console.log(e.detail)
  105. this.setData({
  106. commentText: e.detail.value
  107. })
  108. },
  109. /**
  110. * 生命周期函数--监听页面加载
  111. */
  112. onLoad: function (options) {
  113. var textWidth = wx.getSystemInfoSync().windowWidth * (750 / wx.getSystemInfoSync().windowWidth) * 0.9;
  114. this.setData({
  115. textWidth
  116. })
  117. },
  118. /**
  119. * 生命周期函数--监听页面初次渲染完成
  120. */
  121. onReady: function () {
  122. },
  123. /**
  124. * 生命周期函数--监听页面显示
  125. */
  126. onShow: function () {
  127. },
  128. /**
  129. * 生命周期函数--监听页面隐藏
  130. */
  131. onHide: function () {
  132. },
  133. /**
  134. * 生命周期函数--监听页面卸载
  135. */
  136. onUnload: function () {
  137. },
  138. /**
  139. * 页面相关事件处理函数--监听用户下拉动作
  140. */
  141. onPullDownRefresh: function () {
  142. },
  143. /**
  144. * 页面上拉触底事件的处理函数
  145. */
  146. onReachBottom: function () {
  147. },
  148. /**
  149. * 用户点击右上角分享
  150. */
  151. onShareAppMessage: function () {
  152. }
  153. })