comment.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <view>
  3. <view class="cu-list menu-avatar comment solids-top">
  4. <block v-for="(item,index) in plist" :key="item.id">
  5. <view class="cu-item">
  6. <view class="cu-avatar round" :style="'background-image:url('+item.user.avatar+');'"></view>
  7. <view class="content">
  8. <view class="padding-bottom-sm flex justify-between">
  9. <view class="text-grey">{{item.user.nickname}}</view>
  10. <view class="text-gray">
  11. {{item.createtime}}
  12. <text class="cuIcon-comment padding-left-sm" :data-puserid="item.userid" :data-nickname="item.user.nickname" @click="replyComment"></text>
  13. </view>
  14. </view>
  15. <view class="text-content padding-bottom-xs">
  16. <text v-if="item.puserid">回复 <text class="text-red">{{item.puser.nickname}}</text>:</text>
  17. {{item.details}}
  18. </view>
  19. </view>
  20. </view>
  21. </block>
  22. </view>
  23. <uni-load-more :status="pstatus"></uni-load-more>
  24. <view class="cu-modal bottom-modal" :class="modalname=='commentModal'?'show':''">
  25. <view class="cu-dialog" style="height: calc(100vh)">
  26. <view class="cu-bar bg-white">
  27. <view class="action text-grey" @tap="hideModal">取消</view>
  28. <view class="action text-green" @click="sendComment">发表</view>
  29. </view>
  30. <view class="padding-xl text-left">
  31. <textarea class="solid padding-sm" style="width: 100%;" v-show="modalname=='commentModal'?true:false" :focus="modalfocus" :fixed="true" :placeholder="placeholder" @input="bindInput" maxlength="140" :value="details"></textarea>
  32. </view>
  33. </view>
  34. </view>
  35. <view class="padding"></view>
  36. <view class="padding"></view>
  37. <view class="cu-bar input foot">
  38. <input :placeholder="placeholder" @tap="showModal" disabled class="solid-bottom"></input>
  39. <button class="cu-btn bg-blue shadow-blur" @click="sendComment">发表</button>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
  45. var _this;
  46. export default {
  47. components: {
  48. uniLoadMore
  49. },
  50. data() {
  51. return {
  52. isRotate: false,
  53. userinfo: {},
  54. articleid: 0,
  55. count: 0,
  56. pstatus: 'more',
  57. ppage: 1,
  58. psize: 20,
  59. plist: [],
  60. modalname: "",
  61. modalfocus: false,
  62. puserid: 0,
  63. placeholder: "说点什么吧...",
  64. details: ""
  65. }
  66. },
  67. onLoad: function(option) {
  68. _this = this;
  69. _this.articleid = option.articleid || 0;
  70. _this.modalname = option.modalname || "";
  71. _this.userinfo = uni.getStorageSync('userinfo');
  72. if (_this.articleid==0){
  73. uni.showModal({
  74. title: '信息提示',
  75. content: '文章资讯不存在',
  76. showCancel: false,
  77. success: function(res) {
  78. if (res.confirm) {
  79. uni.navigateBack({
  80. delta: 1
  81. });
  82. }
  83. }
  84. });
  85. }else{
  86. _this.getMore();
  87. }
  88. if (_this.modalname!=""){
  89. _this.showModal();
  90. }
  91. },
  92. onShareAppMessage: function(res) {
  93. return {
  94. title: "文章资讯评论",
  95. path: "/pages/article/comment?articleid="+_this.articleid
  96. }
  97. },
  98. onShow: function() {
  99. _this.userinfo = uni.getStorageSync('userinfo');
  100. },
  101. onPullDownRefresh: function() {
  102. _this.ppage = 1;
  103. _this.pstatus = 'more';
  104. _this.plist = [];
  105. _this.getMore();
  106. },
  107. onReachBottom: function() {
  108. if (_this.pstatus !== 'more') {
  109. return;
  110. }
  111. _this.getMore();
  112. },
  113. methods: {
  114. showModal: function() {
  115. _this.userinfo = _this.checkLogin("/pages/article/comment?articleid="+_this.articleid);
  116. if (_this.userinfo===false){
  117. _this.sendInitialize();
  118. return false;
  119. }
  120. _this.modalname = "commentModal";
  121. setTimeout(function (){
  122. _this.modalfocus = true;
  123. }, 500);
  124. },
  125. hideModal: function() {
  126. _this.sendInitialize();
  127. },
  128. bindInput: function(e) {
  129. _this.details = e.detail.value;
  130. },
  131. replyComment: function(e) {
  132. _this.puserid = e.currentTarget.dataset.puserid;
  133. _this.placeholder = "回复 "+e.currentTarget.dataset.nickname+":";
  134. _this.showModal();
  135. },
  136. sendInitialize: function() {
  137. _this.modalfocus = false;
  138. _this.modalname = "";
  139. _this.puserid = 0;
  140. _this.placeholder = "说点什么吧...";
  141. _this.details = "";
  142. },
  143. sendComment: function() {
  144. _this.userinfo = _this.checkLogin("/pages/article/comment?articleid="+_this.articleid);
  145. if (_this.userinfo===false){
  146. return false;
  147. }
  148. if(_this.isRotate){
  149. return false;
  150. }
  151. _this.isRotate = true;
  152. _this.$req.ajax({
  153. path: "article/sendcomment",
  154. data: {
  155. userid: _this.userinfo.id || 0,
  156. articleid: _this.articleid,
  157. puserid: _this.puserid,
  158. details: _this.details
  159. }
  160. }).then((data) => {
  161. var comment = data.comment;
  162. _this.plist = comment.concat(_this.plist);
  163. _this.sendInitialize();
  164. _this.isRotate = false;
  165. }).catch((err) => {
  166. uni.showModal({
  167. title: '信息提示',
  168. content: err,
  169. showCancel: false
  170. });
  171. _this.isRotate = false;
  172. });
  173. },
  174. getMore: function() {
  175. _this.$req.ajax({
  176. path: "article/listcomment",
  177. data: {
  178. ppage: _this.ppage,
  179. psize: _this.psize,
  180. articleid: _this.articleid,
  181. userid: _this.userinfo.id || 0
  182. }
  183. }).then((data) => {
  184. _this.count = data.count;
  185. _this.pstatus = data.pstatus;
  186. _this.plist = _this.plist.concat(data.plist);
  187. _this.ppage += 1;
  188. uni.stopPullDownRefresh();
  189. }).catch((err) => {
  190. uni.showModal({
  191. title: '信息提示',
  192. content: err,
  193. showCancel: false
  194. });
  195. });
  196. },
  197. }
  198. }
  199. </script>
  200. <style>
  201. </style>