comment.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. <template>
  2. <view class="content">
  3. <!-- 评论组件 -->
  4. <view class="plbox">
  5. <view class="pl">{{num}}评论</view>
  6. <view class="subsection" >
  7. <view :class="curNow==0?'checksub':'nocheck'" @click="sectionChange(0)">最新</view>
  8. <view :class="curNow==1?'checksub':'nocheck'" @click="sectionChange(1)">热门</view>
  9. <!-- <u-subsection
  10. :list="subsectionlist" :current="curNow"
  11. @change="sectionChange"></u-subsection> -->
  12. </view>
  13. </view>
  14. <!-- 评论列表 -->
  15. <view class="comment" v-for="(item,index) in dataList" :key="index">
  16. <view class="photo">
  17. <u--image v-if="item.authorLogo" width="80rpx" height="80rpx" :src="item.authorLogo" ></u--image>
  18. </view>
  19. <view class="right_content">
  20. <view class="rc_1">{{item.authorName || '未知用户'}}</view>
  21. <view class="rc_2">{{item.createTime}}</view>
  22. <view class="rc_3" @click="openPopup(item)">{{item.content}}</view>
  23. <view class="rc_sub" v-for="(item2,index) in item.floorList" :key="index">
  24. <!-- index 只显示3条 -->
  25. <view v-if="index<2" @click="openPopup(item)" class="rc_sub_item">
  26. {{item2.authorName}}:{{item2.content}}
  27. </view>
  28. </view>
  29. <view class="rc_bottom">
  30. <view class="rb_1">{{item.time}}</view>
  31. <view @click="openPopup(item)" class="rb_2">
  32. <u--image width="40rpx" height="40rpx" src="/static/index/iconm_message.png" ></u--image>
  33. <view style="margin-left:8rpx">回复</view>
  34. </view>
  35. </view>
  36. <u-line margin='40rpx 0' color="#e4e7ed" />
  37. </view>
  38. </view>
  39. <view class="loadmore" @click="loadmore()" >
  40. {{jiazaitext}}
  41. </view>
  42. <!-- 对主题进行回复 -->
  43. <view class="w700 flex bfixed">
  44. <u-input class="commentInput" placeholder="点击输入评论" v-model="inputValue" :auto-height="true" type="text" />
  45. <view class="btn">
  46. <u-button shape="circle" size="medium" type="primary"
  47. @click="submit1">提交</u-button>
  48. </view>
  49. </view>
  50. <!-- 点击评论弹出层 -->
  51. <u-popup :closeable='true' :round="10" :show="popupShow" @close="close" @open="open">
  52. <view class="popupView">
  53. <view class="scrollview">
  54. <!-- 弹出层中意见详情 -->
  55. <view class="comment">
  56. <view class="photo">
  57. <u--image width="80rpx" v-if="popupData.authorLogo" height="80rpx" :src="popupData.authorLogo" ></u--image>
  58. </view>
  59. <view class="right_content">
  60. <view class="rc_1" @click="toReply(popupData,2)">{{popupData.authorName || '未知用户'}}</view>
  61. <view class="rc_2">{{popupData.createTime}}</view>
  62. <view class="rc_3" @click="toReply(popupData,2)">{{popupData.content}}</view>
  63. </view>
  64. </view>
  65. <u-line margin='30rpx 0' color="#e4e7ed" />
  66. <view class="comment" v-for="(item2,index) in popupData.floorList" :key="index">
  67. <view class="photo">
  68. <u--image width="80rpx" height="80rpx" v-if="item2.authorLogo" :src="item2.authorLogo" ></u--image>
  69. </view>
  70. <view class="right_content">
  71. <view class="rc_1" @click="toReply(item2,3)">{{item2.authorName || '未知用户'}}</view>
  72. <view class="rc_2">{{item2.createTime}}</view>
  73. <view class="rc_3" @click="toReply(item2,3)">
  74. <text v-if="item2.citeAuthorName">{{ '@'+ item2.citeAuthorName + '回复:' }}</text>
  75. {{item2.content}}
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. </view>
  81. <u-line margin='20rpx 0' color="#e4e7ed" />
  82. <view class="w700 btnflex">
  83. <u-input class="commentInput" :placeholder="popupPlaceholder" v-model="inputValue2" :auto-height="true" type="text" />
  84. <view class="btn">
  85. <u-button shape="circle" size="medium" type="primary"
  86. @click="submit2">提交</u-button>
  87. </view>
  88. </view>
  89. </u-popup>
  90. </view>
  91. </template>
  92. <script>
  93. import {topicDetail,replyPage,topicReply} from '@/http/api/common.js'
  94. import * as util from '@/pages/util/util.js'
  95. export default {
  96. options: { styleIsolation: 'shared' },
  97. props: {
  98. topicId: {
  99. type: String,
  100. default: '',
  101. },
  102. },
  103. watch:{
  104. topicId: {
  105. immediate: true,
  106. handler(val) {
  107. console.log(val);
  108. if(val!=''){
  109. //获取评论列表
  110. this.getTopicReply()
  111. }
  112. },
  113. }
  114. },
  115. data() {
  116. return {
  117. popupShow:false,
  118. show:false,
  119. inputValue:'',
  120. inputValue2:'',
  121. num:999,
  122. popupData:{
  123. name:'',
  124. userimg:'',
  125. content:'',
  126. time:'',
  127. sublist:[]
  128. },
  129. dataList:[],
  130. subsectionlist: [
  131. {
  132. name: '热门'
  133. },
  134. {
  135. name: '最新'
  136. }
  137. ],
  138. curNow:0,
  139. popupPlaceholder:'点击输入评论',
  140. pageNum:1,
  141. pageSize:2,//初始为2
  142. jiazaitext:'加载更多',
  143. replyType:2,//回复类型 1:回复主题 2:回复楼层 3:回复楼层内的评论
  144. replyId:''
  145. }
  146. },
  147. onReachBottom() {
  148. this.loadmore()
  149. },
  150. methods: {
  151. //加载更多
  152. loadmore(){
  153. console.log('下拉加载',this.jiazaitext);
  154. if (this.pageSize == 2) {
  155. this.pageSize = 10
  156. this.dataList = []
  157. this.jiazaitext="加载中..."
  158. this.getTopicReply()
  159. }else{
  160. if (this.jiazaitext=="加载更多") {
  161. this.pageNum=this.pageNum+1
  162. this.jiazaitext="加载中..."
  163. this.getTopicReply()
  164. }
  165. }
  166. },
  167. async getTopicReply(){
  168. let res = await topicDetail({
  169. pageNum:this.pageNum,
  170. pageSize:this.pageSize,
  171. sortType:this.curNow==1? '1' : '',//1=热门回答: 最新回答传空
  172. },this.topicId)
  173. if (res.data.code == 200) {
  174. let newrows = res.data.data.repliesPage.rows || []
  175. this.dataList.push(...newrows)
  176. this.num = res.data.data.repliesPage.total
  177. if(this.dataList.length!=res.data.data.repliesPage.total){
  178. this.jiazaitext="加载更多"
  179. }else{
  180. this.jiazaitext="已经到底"
  181. }
  182. }
  183. },
  184. sectionChange(index) {
  185. console.log(index);
  186. this.curNow = index;
  187. //每次切换页签初始化请求页签
  188. this.pageNum = 1
  189. this.dataList = []
  190. this.getTopicReply()
  191. },
  192. openPopup(item){
  193. // 打开弹出层
  194. console.log(item);
  195. this.popupData = item
  196. this.popupShow = true
  197. },
  198. async submit1(){
  199. //对主题回复
  200. let res = await topicReply({
  201. content:this.inputValue,
  202. replyType:1,
  203. },this.topicId)
  204. if (res.data.code == 200) {
  205. util.toastFunc('回复成功')
  206. this.inputValue = ''
  207. //初始化请求页签
  208. this.pageNum = 1
  209. this.dataList = []
  210. //获取评论列表
  211. this.getTopicReply()
  212. }
  213. },
  214. async submit2(){
  215. //对子级回复
  216. let res = await topicReply({
  217. floorId:this.popupData.id,
  218. content:this.inputValue2,
  219. replyId:this.replyId,
  220. replyType:this.replyType, //回复类型 1:回复主题 2:回复楼层 3:回复楼层内的评论
  221. },this.topicId)
  222. if (res.data.code == 200) {
  223. util.toastFunc('回复成功')
  224. this.inputValue2 = ''
  225. //初始化请求页签
  226. this.pageNum = 1
  227. this.dataList = []
  228. //获取评论列表
  229. this.getTopicReply()
  230. this.close()
  231. }
  232. },
  233. open() {
  234. // console.log('open');
  235. },
  236. close() {
  237. this.popupShow = false
  238. // console.log('close');
  239. },
  240. toReply(item,type){
  241. //获取对谁回复
  242. console.log(item);
  243. this.replyType = type
  244. if (type == 3) {
  245. this.replyId = item.id
  246. }else{
  247. this.replyId = ''
  248. }
  249. this.popupPlaceholder = `对${item.authorName}回复`
  250. }
  251. }
  252. }
  253. </script>
  254. <style lang="scss" scoped>
  255. .content{
  256. width: 750rpx;
  257. background-color: #FFFFFF;
  258. padding: 30rpx 0 30rpx 0;
  259. }
  260. .plbox{
  261. width: 700rpx;
  262. display: flex;
  263. justify-content: space-between;
  264. align-items: center;
  265. }
  266. .pl{
  267. width: 132rpx;
  268. height: 45rpx;
  269. font-size: 32rpx;
  270. font-weight: bold;
  271. color: #333333;
  272. line-height: 36rpx;
  273. }
  274. .comment{
  275. display: flex;
  276. width: 700rpx;
  277. margin-top: 40rpx;
  278. }
  279. .photo{
  280. width: 80rpx;
  281. height: 80rpx;
  282. background: #EEEEEE;
  283. opacity: 1;
  284. background-image: url('@/static/btn_mine.png');
  285. background-position: center center;
  286. background-size: contain;
  287. }
  288. .right_content{
  289. width: 598rpx;
  290. margin-left: 26rpx;
  291. }
  292. .rc_1{
  293. width: 500rpx;
  294. height: 50rpx;
  295. font-size: 28rpx;
  296. font-weight: bold;
  297. color: #333333;
  298. word-break: break-all;
  299. text-overflow: ellipsis;
  300. overflow: hidden;
  301. }
  302. .rc_2{
  303. width: 500rpx;
  304. height: 50rpx;
  305. font-size: 28rpx;
  306. font-weight: 400;
  307. color: #999999;
  308. line-height: 40rpx;
  309. }
  310. .rc_3{
  311. width: 598rpx;
  312. height: 80rpx;
  313. font-size: 28rpx;
  314. font-weight: 500;
  315. color: #333333;
  316. line-height: 40rpx;
  317. margin-bottom: 24rpx;
  318. }
  319. .rc_sub{
  320. /* width: 560rpx;
  321. min-height: 80rpx;
  322. background: #F1F1F1;
  323. border-radius: 8rpx 8rpx 8rpx 8rpx;
  324. opacity: 1;
  325. padding: 20rpx; */
  326. }
  327. .rc_sub_item{
  328. width: 550rpx;
  329. height: 80rpx;
  330. font-size: 28rpx;
  331. font-weight: 500;
  332. color: #333333;
  333. line-height: 40rpx;
  334. background: #F1F1F1;
  335. border-radius: 8rpx 8rpx 8rpx 8rpx;
  336. opacity: 1;
  337. padding: 20rpx;
  338. }
  339. .rc_bottom{
  340. display: flex;
  341. font-size: 28rpx;
  342. font-weight: 400;
  343. color: #999999;
  344. line-height: 40rpx;
  345. justify-content: space-between;
  346. margin-top: 24rpx;
  347. }
  348. .rb_1{
  349. height: 33rpx;
  350. }
  351. .rb_2{
  352. display: flex;
  353. }
  354. .btn{
  355. width: 150rpx;
  356. margin-left: 20rpx;
  357. }
  358. .popupView{
  359. height: 1000rpx;
  360. display: flex;
  361. padding-top: 100rpx;
  362. flex-direction: column;
  363. align-items: center;
  364. }
  365. .scrollview{
  366. height: 850rpx;
  367. overflow: auto;
  368. }
  369. .btnflex{
  370. display: flex;
  371. flex-direction: row;
  372. align-items: center;
  373. position: absolute;
  374. bottom: 20rpx;
  375. left: 20rpx;
  376. }
  377. .loadmore{
  378. height:200rpx;
  379. text-align: center;
  380. font-size: 28rpx;
  381. font-weight: 400;
  382. color: #999;
  383. padding-top: 24rpx;
  384. }
  385. .commentInput{
  386. background: #EEEEEE;
  387. border-radius: 40rpx 40rpx 40rpx 40rpx;
  388. }
  389. .bfixed{
  390. background-color: #fff;
  391. position: fixed;
  392. bottom: 0px;
  393. border: 20rpx solid #fff;
  394. left: 0px;
  395. }
  396. </style>