comment.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <view class="wanl-comment">
  3. <!-- 评论主体-start -->
  4. <scroll-view @scrolltolower="loadMore" v-if="commentList.length != 0" class="margin-bottom-bj"
  5. :style="{ height: `${mainHeight}px` }" scroll-y>
  6. <view class="flex flex-direction margin-bottom-sm" v-for="(item, index) in commentList" :key="index">
  7. <image class="comment-avatar round margin-right-bj" :src="static_photo + item.user_info.face"></image>
  8. <view class="flex-sub">
  9. <!-- 父评论体-start -->
  10. <view class="flex flex-direction justify-between align-center">
  11. <view class="flex flex-direction align-center">
  12. <view>
  13. <text class="text-30 text-white-6">{{ item.user_info.nickname }}</text>
  14. </view>
  15. </view>
  16. </view>
  17. <view class="margin-tb-s">
  18. <text class="text-sm text-white-9">{{ item.content }}</text>
  19. </view>
  20. <view class="flex flex-direction align-center margin-bottom-sm">
  21. <view class="margin-right-sm">
  22. <text class="text-sm text-white-5">{{ timestampFormat(item.createtime) }}</text>
  23. </view>
  24. <!-- <view class="margin-right-sm" @click="
  25. handleReply(item.user_info.nickname, item.share_id)
  26. ">
  27. <text class="text-sm text-blue">回复</text>
  28. </view> -->
  29. </view>
  30. <!-- 父评论体-end -->
  31. <!-- 子评论列表-start -->
  32. <view v-if="item.children.length > 0" class="
  33. comment-chil-dlist
  34. padding-lr-sm padding-top-sm
  35. margin-bottom-sm
  36. radius-bock
  37. ">
  38. <view class="flex flex-direction" v-for="(each, keys) in item.childlist" :key="keys">
  39. <image class="comment-avatar round margin-right-bj"
  40. :src="static_photo + each.user_info.face">
  41. </image>
  42. <view class="flex-sub">
  43. <view class="flex flex-direction justify-between align-center">
  44. <view class="nick-name">
  45. <text class="text-30 text-white-6">{{ each.user_info.nickname }}</text>
  46. </view>
  47. </view>
  48. <view class="margin-tb-s">
  49. <text class="text-sm text-white-9">{{ each.content }}</text>
  50. </view>
  51. <view class="
  52. comment-main-foot
  53. flex flex-direction
  54. align-center
  55. margin-bottom
  56. ">
  57. <view class="margin-right-sm">
  58. <text class="text-sm text-white-5">{{ timestampFormat(each.createtime) }}</text>
  59. </view>
  60. <!-- <view class="margin-right-sm" @click="
  61. handleReply(
  62. item.user.nickname,
  63. item.share_id
  64. )
  65. ">
  66. <text class="text-sm text-blue">回复</text>
  67. </view> -->
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. <!-- 子评论列表-end -->
  73. </view>
  74. </view>
  75. </scroll-view>
  76. <!-- 评论不存在 -->
  77. <view class="flex align-center justify-center" :style="{ height: `${mainHeight}px` }" v-else>
  78. <view class="nomore">
  79. <view class="flex-direction text-center justify-center margin-top-bj">
  80. <text class="text-gray-dark text-sm">还没有任何评论,</text>
  81. <text class="text-orange text-sm" @click="commentInput">抢沙发!</text>
  82. </view>
  83. </view>
  84. </view>
  85. <!-- 底部评论条 -->
  86. <view class="flex flex-direction justify-between align-center"
  87. :style="{ height: `${tabbarHeight}px`, paddingBottom: `${tabbarTop}px` }">
  88. <input class="comment-input flex-sub padding-lr-sm" v-model="commentReq.content" placeholder="留下你的精彩评论吧"
  89. placeholder-style="fontSize: 14px; color: #999999;" :maxlength="100" :focus="focus"
  90. @blur="handleBlur" />
  91. <view class="flex comment-button margin-left-bj justify-center align-center" @click="handleAdd">
  92. <text class="icon text-sm">&#xe640;</text>
  93. </view>
  94. </view>
  95. </view>
  96. </template>
  97. <script>
  98. import uniIcons from "@/components/uni-icons/uni-icons.vue";
  99. import _data from "@/common/_data";
  100. import _get from "@/common/_get";
  101. import _mixins from '@/common/_mixins';
  102. import _action from "@/common/_action";
  103. export default {
  104. props: {
  105. findId: {
  106. type: Number,
  107. default: 0,
  108. },
  109. commenCount: {
  110. type: Number,
  111. default: 0,
  112. },
  113. commentList: {
  114. type: Array,
  115. default () {
  116. return [];
  117. },
  118. },
  119. deleteTip: {
  120. type: String,
  121. default: "删除后不可找回,子评论将一并删除",
  122. },
  123. },
  124. components: {
  125. uniIcons,
  126. },
  127. mounted() {
  128. console.log("this.findId", this.findId);
  129. },
  130. data() {
  131. return {
  132. mainHeight: 0,
  133. tabbarTop: 0,
  134. tabbarHeight: 0,
  135. commentReq: {
  136. pid: null, // 评论父id
  137. content: null, // 评论内容
  138. },
  139. pUser: null, // 标签-回复人
  140. focus: false, // 输入框自动聚焦
  141. static_photo: _data.staticPhoto(),
  142. my_data: {}, //本人
  143. page: 2
  144. };
  145. },
  146. async mounted() {
  147. let sys = uni.getSystemInfoSync();
  148. this.mainHeight = sys.windowHeight / 1.8;
  149. this.tabbarTop = sys.safeAreaInsets.bottom;
  150. this.tabbarHeight = sys.safeAreaInsets.bottom + uni.upx2px(70);
  151. let _this = this;
  152. _get.getUserInfo({});
  153. uni.$on('data_user_info', function(data) {
  154. data.photo = data.photo + '?_=' + +Math.random()
  155. data.photo = data.photo.replace(/(\?_=)[\d\.]+$/, '$1' + Math.random());
  156. _this.my_data = data;
  157. _data.data('user_info', data)
  158. });
  159. },
  160. methods: {
  161. loadMore() {
  162. _mixins.methods.$httpSend({
  163. path: "/im/video.Share/getComment",
  164. data: {
  165. id: this.findId,
  166. type: "1",
  167. page: this.page,
  168. },
  169. success: (res) => {
  170. if (this.page <= res.last_page) {
  171. this.page++;
  172. this.commentList.push(...res.data);
  173. }
  174. },
  175. });
  176. },
  177. timestampFormat(time) {
  178. return _action.timestampFormat(time);
  179. },
  180. // 回复评论
  181. handleReply(pUser, pId) {
  182. this.commentReq.pid = pId;
  183. if (pUser) {
  184. this.commentReq.content = "@" + pUser + " ";
  185. } else {
  186. this.commentReq.content = "";
  187. }
  188. this.commentInput();
  189. },
  190. // 新增评论
  191. async handleAdd() {
  192. if (
  193. this.commentReq.content == null) {
  194. uni.showToast({
  195. title: "请输入评论内容",
  196. duration: 2000,
  197. icon: "none",
  198. });
  199. return;
  200. }
  201. this.commentReq.find_id = this.findId;
  202. let data = {
  203. share_id: this.findId,
  204. comment_id: this.commentReq.pid || 0,
  205. content: this.commentReq.content,
  206. }
  207. console.log("评论参数", data);
  208. _mixins.methods.$httpSend({
  209. path: "/im/video.Share/comment",
  210. data: {
  211. share_id: this.findId,
  212. comment_id: this.commentReq.pid || 0,
  213. content: this.commentReq.content,
  214. },
  215. success: (data) => {
  216. console.log("data", data);
  217. if (data.code == 0) {
  218. uni.showToast({
  219. title: "评论成功",
  220. icon: "none",
  221. });
  222. this.commentList.unshift({
  223. user_info: this.my_data,
  224. content: this.commentReq.content,
  225. share_id: this.findId,
  226. comment_id: this.commentReq.pid || 0,
  227. createtime: new Date().getTime(),
  228. children: []
  229. })
  230. this.commentReq.content = "";
  231. console.log("this.commentList", this.commentList);
  232. // this.tagClose();
  233. this.$emit("complete", {
  234. type: "add",
  235. id: this.findId
  236. });
  237. }
  238. },
  239. });
  240. },
  241. // 标签关闭
  242. tagClose() {
  243. this.pUser = null;
  244. this.commentReq.pid = null;
  245. this.commentReq.content = null;
  246. },
  247. // 输入框失去焦点
  248. handleBlur() {
  249. this.focus = false;
  250. },
  251. // 输入评论
  252. commentInput() {
  253. this.focus = true;
  254. // TODO 调起键盘方法
  255. },
  256. },
  257. };
  258. </script>
  259. <style scoped>
  260. @import "@/static/css/common.css";
  261. .nomore {
  262. height: 200rpx;
  263. }
  264. .comment-avatar {
  265. width: 70rpx;
  266. height: 70rpx;
  267. background-color: rgba(255, 255, 255, 0);
  268. }
  269. .comment-tag {
  270. padding: 0 10rpx;
  271. border-radius: 10rpx;
  272. height: 32rpx;
  273. overflow: hidden;
  274. }
  275. .comment-none-image {
  276. height: 360rpx;
  277. width: 360rpx;
  278. }
  279. .comment-input {
  280. background-color: #ececec;
  281. height: 70rpx;
  282. border-radius: 10rpx;
  283. font-size: 14px;
  284. color: #333333;
  285. }
  286. .comment-button {
  287. background-color: #02dc6b;
  288. border-radius: 5000rpx;
  289. height: 70rpx;
  290. width: 70rpx;
  291. }
  292. .comment-chil-dlist {
  293. background-color: rgba(100, 100, 100, 0.05);
  294. }
  295. .comment-fabulous {
  296. height: 40rpx;
  297. }
  298. </style>