note_detail.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <template>
  2. <view class="note_detail">
  3. <custom-nav :bgColor="bgColor">
  4. <view class="current" @click="goBack">
  5. <text class="iconfont iconzuojiantou"></text>
  6. <text>便签详情</text>
  7. </view>
  8. </custom-nav>
  9. <view class="note_title">{{ note.title }}</view>
  10. <view class="note_con"><rich-text :nodes="note.content"></rich-text></view>
  11. <view class="comment">
  12. <view class="comment_title">精选评论</view>
  13. <view v-if="showNo" class="no_com">
  14. <image src="../../static/imgs/no_comment.png"></image>
  15. <view>暂未评论,赶快做第一个评论的吧~</view>
  16. </view>
  17. <view class="eva_con" v-for="item in evaList" :key="item.id">
  18. <image :src="item.get_user.avatar"></image>
  19. <view class="eva_detail">
  20. <view style="font-weight: bold;padding:15rpx 0 30rpx;">{{ item.get_user.nickname }}</view>
  21. <view>{{ item.content }}</view>
  22. <view class="reply_count">
  23. <text>{{ item.created_at }}</text>
  24. <text style="margin:0 15rpx;" v-if="note.user_id == userInfo.user_id && !item.get_reply">·</text>
  25. <text style="color:#F44545" @click="getId(item.id, item.get_user.nickname)" v-if="note.user_id == userInfo.user_id && !item.get_reply">回复</text>
  26. </view>
  27. <view class="reply" v-if="item.get_reply">
  28. <view class="reply_photo flexS">
  29. <image :src="item.reply_user.avatar"></image>
  30. <text>{{ item.reply_user.nickname }}</text>
  31. </view>
  32. <view class="reply_con">
  33. <text>回复</text>
  34. <text style="color:#F44545;">{{ item.get_user.nickname }}</text>
  35. <text>:{{ item.get_reply.content }}</text>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="eval flexA">
  41. <input type="text" :placeholder="isReply ? '@' + replyName + '...' : '我来说两句..'" v-model="content" />
  42. <view class="flexC" @click="isReply ? replay() : comment()">{{ isReply ? '回复' : '发送' }}</view>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import { showNote, sendComment, lookComment, replyComment } from '../../api/note.js';
  49. import customNav from '../../components/custom-nav.vue';
  50. export default {
  51. data() {
  52. return {
  53. note: '', //获取便签内容
  54. content: '', //评论内容
  55. id: '', //便签id
  56. page: 1, //当前页数
  57. replyName: '', //回复给谁
  58. isReply: false, //true 回复 false 发送
  59. commentId: '', //评论的id
  60. evaList: [], //评论列表
  61. userInfo: '',
  62. showNo: false, //无评论的状态
  63. bgColor: '#fff', //导航栏背景色
  64. totalPage: '' //总页数
  65. };
  66. },
  67. components: {
  68. customNav
  69. },
  70. onLoad(options) {
  71. this.id = options.id;
  72. this.getDetail(options.id);
  73. },
  74. onShow() {
  75. this.userInfo = uni.getStorageSync('userInfo');
  76. },
  77. onReachBottom() {
  78. this.getMore();
  79. },
  80. methods: {
  81. //返回便签页
  82. goBack() {
  83. uni.navigateTo({
  84. url: '../note_pad/note_pad?curTab=' + 1
  85. });
  86. },
  87. //获取回复相关内容
  88. getId(id, nickname) {
  89. this.commentId = id;
  90. this.replyName = nickname;
  91. this.isReply = true;
  92. },
  93. /*
  94. * 获取评论列表
  95. * @params id当前便签的id
  96. * @parmas page 当前是第几页
  97. */
  98. getComment(more) {
  99. lookComment({ id: this.id, page: this.page }).then(res => {
  100. if (res.code == 200) {
  101. if (res.data.list.length == 0) {
  102. this.showNo = true;
  103. return false;
  104. }
  105. this.totalPage = Math.ceil(res.data.total / 20);
  106. if (more == 1) {
  107. this.evaList = this.evaList.concat(res.data.list);
  108. } else {
  109. this.evaList = res.data.list;
  110. }
  111. } else {
  112. uni.showModal({
  113. content: res.message || '获取评论失败',
  114. showCancel: false
  115. });
  116. }
  117. });
  118. },
  119. //加载更多评论列表
  120. getMore() {
  121. if (this.page > this.totalPage) {
  122. uni.showToast({
  123. title: '没有更多啦~',
  124. icon: 'none'
  125. });
  126. return false;
  127. }
  128. this.page++;
  129. this.getComment(1);
  130. },
  131. /*
  132. * 评论便签
  133. * desc:自己不能评论自己的便签
  134. * @params id 当前便签的id
  135. * @params content 评论的内容
  136. */
  137. comment() {
  138. if (this.note.user_id == this.userInfo.user_id) {
  139. uni.showModal({
  140. content: '您不能评论自己的便签',
  141. showCancel: false
  142. });
  143. this.content = '';
  144. return false;
  145. }
  146. if (!this.content) {
  147. uni.showModal({
  148. content: '请先输入内容...',
  149. showCancel: false
  150. });
  151. return false;
  152. }
  153. sendComment({ id: this.id, content: this.content }).then(res => {
  154. if (res.code == 200) {
  155. uni.showModal({
  156. content: '评论成功',
  157. showCancel: false
  158. });
  159. this.content = '';
  160. this.getComment();
  161. }
  162. });
  163. },
  164. /*
  165. * 回复便签
  166. * @params id 当前便签的id
  167. * @params content 回复的内容
  168. * @params comment_id 词条评论的id
  169. * desc:目前只能回复一次,不能重复回复
  170. */
  171. replay() {
  172. if (!this.content) {
  173. uni.showModal({
  174. content: '请先输入内容...',
  175. showCancel: false
  176. });
  177. return false;
  178. }
  179. replyComment({ id: this.id, content: this.content, comment_id: this.commentId }).then(res => {
  180. if (res.code == 200) {
  181. uni.showModal({
  182. content: '回复成功',
  183. showCancel: false
  184. });
  185. this.content = '';
  186. this.isReply = false;
  187. this.getComment();
  188. } else {
  189. uni.showModal({
  190. content: res.message || '回复失败',
  191. showCancel: false
  192. });
  193. }
  194. });
  195. },
  196. /*
  197. * 获取便签详情
  198. * @params id 此条便签的id 从便签列表页面带过来的
  199. */
  200. getDetail(id) {
  201. showNote({ id }).then(res => {
  202. if (res.code == 200) {
  203. this.note = res.data;
  204. this.getComment();
  205. } else {
  206. uni.showModal({
  207. content: res.message || '获取便签详情失败',
  208. showCancel: false
  209. });
  210. }
  211. });
  212. }
  213. }
  214. };
  215. </script>
  216. <style>
  217. page {
  218. width: 100%;
  219. min-height: 100%;
  220. background: #fff;
  221. }
  222. </style>
  223. <style lang="scss">
  224. .current {
  225. font-size: 36rpx;
  226. font-weight: bold;
  227. .iconfont {
  228. font-size: 40rpx;
  229. color: #333;
  230. margin-left: 15rpx;
  231. vertical-align: -2rpx;
  232. }
  233. }
  234. .note_detail {
  235. padding: 150rpx 0 130rpx;
  236. }
  237. .note_title,
  238. .comment_title {
  239. font-size: 36rpx;
  240. color: #333;
  241. font-weight: bold;
  242. width: 100%;
  243. padding: 30rpx 0;
  244. }
  245. .note_title {
  246. text-align: center;
  247. }
  248. .note_con,
  249. .comment {
  250. width: 690rpx;
  251. margin: 0 auto;
  252. }
  253. .comment {
  254. .no_com {
  255. text-align: center;
  256. image {
  257. width: 390rpx;
  258. height: 282rpx;
  259. }
  260. view {
  261. font-size: 28rpx;
  262. color: #333;
  263. margin-top: 40rpx;
  264. }
  265. }
  266. .eva_con {
  267. display: flex;
  268. justify-content: flex-start;
  269. margin-bottom: 30rpx;
  270. image {
  271. width: 68rpx;
  272. height: 68rpx;
  273. border-radius: 50%;
  274. flex-shrink: 0;
  275. margin-right: 20rpx;
  276. }
  277. .eva_detail {
  278. > view {
  279. view {
  280. font-size: 28rpx;
  281. margin-bottom: 15rpx;
  282. }
  283. text {
  284. font-size: 24rpx;
  285. color: #999;
  286. }
  287. .reply_btn {
  288. width: 116rpx;
  289. height: 54rpx;
  290. background: linear-gradient(92deg, #fc9863 0%, #f76454 100%);
  291. border-radius: 28rpx;
  292. color: #fff;
  293. font-size: 28rpx;
  294. }
  295. }
  296. .reply_count {
  297. margin: 20rpx 0 30rpx;
  298. text {
  299. font-size: 24rpx;
  300. color: #999;
  301. }
  302. }
  303. .reply {
  304. margin-top: 40rpx;
  305. .reply_photo {
  306. image {
  307. height: 50rpx;
  308. width: 50rpx;
  309. margin-right: 20rpx;
  310. }
  311. text {
  312. font-size: 28rpx;
  313. color: #999;
  314. }
  315. }
  316. .reply_con {
  317. margin-top: 15rpx;
  318. text {
  319. font-size: 28rpx;
  320. color: #333;
  321. }
  322. }
  323. }
  324. }
  325. }
  326. .eval {
  327. width: 100%;
  328. height: 98rpx;
  329. position: fixed;
  330. left: 0;
  331. bottom: 0;
  332. z-index: 9999;
  333. background-color: #fff;
  334. input {
  335. width: 418rpx;
  336. height: 68rpx;
  337. background: #f8f8f8;
  338. border-radius: 34rpx;
  339. padding-left: 20rpx;
  340. color: #333;
  341. }
  342. view {
  343. width: 192rpx;
  344. height: 68rpx;
  345. line-height: 68rpx;
  346. text-align: center;
  347. background: linear-gradient(142deg, #f97c55 0%, #f44545 100%);
  348. color: #ffffff;
  349. font-size: 28rpx;
  350. border-radius: 34rpx;
  351. }
  352. .iconfont {
  353. font-size: 42rpx;
  354. color: #999;
  355. margin: 0 20rpx;
  356. }
  357. }
  358. }
  359. </style>