detail.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <div id="detail">
  3. <el-row>
  4. <el-col :span="24" class="main">
  5. <el-col :span="24" class="top">
  6. <top topType="2" @upBack="upBack"></top>
  7. </el-col>
  8. <el-col :span="24" class="info" :style="{ height: clientHeight + 'px' }">
  9. <el-col :span="24" class="one">
  10. <info :detailInfo="detailInfo"></info>
  11. </el-col>
  12. <el-col :span="24" class="two">
  13. <el-tabs v-model="active">
  14. <el-tab-pane label="用户评论" name="first">
  15. <comment :list="commentList"></comment>
  16. </el-tab-pane>
  17. </el-tabs>
  18. </el-col>
  19. </el-col>
  20. <el-col :span="24" class="foot">
  21. <el-col :span="12" class="button" @click.native="chatBtn"><i class="el-icon-chat-line-round"></i>评论</el-col>
  22. <el-col :span="12" class="button zan" @click.native="zanBtn"><img :src="detailInfo.thumbs ? zan2 : zan" /><span>点赞</span></el-col>
  23. </el-col>
  24. </el-col>
  25. </el-row>
  26. <van-dialog class="dialog" v-model="dialog" title="填写评论" :close-on-click-overlay="true" :show-confirm-button="false">
  27. <van-form @submit="onSubmit">
  28. <van-field v-model="form.content" rows="4" autosize label="评论内容" type="textarea" maxlength="100" placeholder="请输入内容" show-word-limit />
  29. <div style="margin: 16px;">
  30. <van-button round block type="info" native-type="submit">发送</van-button>
  31. </div>
  32. </van-form>
  33. </van-dialog>
  34. </div>
  35. </template>
  36. <script>
  37. import info from './parts/info.vue';
  38. import comment from './parts/comment.vue';
  39. import top from '@/layout/common/top.vue';
  40. import { mapState, createNamespacedHelpers } from 'vuex';
  41. const { mapActions: mapTopic } = createNamespacedHelpers('topic');
  42. const { mapActions: mapThumbs } = createNamespacedHelpers('thumbs');
  43. const { mapActions: reply } = createNamespacedHelpers('reply');
  44. const moment = require('moment');
  45. export default {
  46. name: 'detail',
  47. props: {},
  48. components: {
  49. info,
  50. comment,
  51. top,
  52. },
  53. data: function() {
  54. return {
  55. clientHeight: '',
  56. // 话题正文
  57. detailInfo: {},
  58. // 评论
  59. active: 'first',
  60. // 用户评论列表
  61. commentList: [],
  62. // 点赞
  63. zan: require('@a/zan.png'),
  64. zan2: require('@a/zan2.png'),
  65. // 评论
  66. dialog: false,
  67. form: {},
  68. };
  69. },
  70. async created() {
  71. await this.search();
  72. },
  73. mounted() {
  74. let clientHeight = (document.documentElement.clientHeight || document.body.clientHeight) - 80;
  75. this.$set(this, `clientHeight`, clientHeight);
  76. },
  77. methods: {
  78. ...mapTopic(['fetch']),
  79. ...mapThumbs(['create']),
  80. ...reply({ replyQuery: 'query', replyCreate: 'create' }),
  81. async search() {
  82. if (this.id) {
  83. let res = await this.fetch(this.id);
  84. if (this.$checkRes(res)) {
  85. this.$set(this, `detailInfo`, res.data);
  86. }
  87. res = await this.replyQuery({ article_id: this.id });
  88. if (this.$checkRes(res)) {
  89. this.$set(this, `commentList`, res.data);
  90. }
  91. }
  92. },
  93. // 返回上一页
  94. upBack() {
  95. this.$router.push({ path: '/community/index' });
  96. },
  97. // 点赞
  98. async zanBtn() {
  99. let data = {
  100. openid: this.user.openid,
  101. type: '1',
  102. article_id: this.detailInfo.id,
  103. };
  104. let res = await this.create(data);
  105. if (this.$checkRes(res)) {
  106. this.$set(this.detailInfo, `thumbs`, res.data);
  107. this.$toast({ type: 'success', message: this.detailInfo.thumbs ? '取消点赞' : '点赞成功' });
  108. }
  109. },
  110. // 打开评论
  111. chatBtn() {
  112. this.dialog = true;
  113. },
  114. // 发送评论
  115. async onSubmit() {
  116. let data = this.form;
  117. data.name = this.user.name;
  118. data.icon = this.user.icon;
  119. data.openid = this.user.openid;
  120. data.reply_time = moment().format('YYYY-MM-DD HH:mm:ss');
  121. data.article_id = this.id;
  122. let res = await this.replyCreate(data);
  123. if (this.$checkRes(res)) {
  124. this.$toast({ type: 'success', message: '评论成功' });
  125. this.dialogClose();
  126. this.search();
  127. }
  128. },
  129. // 关闭弹框
  130. dialogClose() {
  131. this.form = {};
  132. this.dialog = false;
  133. },
  134. },
  135. computed: {
  136. ...mapState(['user']),
  137. id() {
  138. return this.$route.query.id;
  139. },
  140. },
  141. metaInfo() {
  142. return { title: this.$route.meta.title };
  143. },
  144. watch: {},
  145. };
  146. </script>
  147. <style lang="less" scoped>
  148. .main {
  149. .top {
  150. height: 40px;
  151. overflow: hidden;
  152. border-bottom: 1px solid #f1f1f1;
  153. }
  154. .info {
  155. overflow-x: hidden;
  156. overflow-y: auto;
  157. background-color: #f1f1f1;
  158. .one {
  159. background-color: #ffffff;
  160. margin: 6px 0;
  161. }
  162. .two {
  163. padding: 0 10px;
  164. min-height: 50px;
  165. background-color: #ffffff;
  166. /deep/.el-tabs__header {
  167. margin: 0;
  168. }
  169. }
  170. }
  171. .foot {
  172. height: 40px;
  173. overflow: hidden;
  174. background-color: #ffffff;
  175. border-top: 1px solid #f1f1f1;
  176. padding: 10px 0;
  177. .button {
  178. text-align: center;
  179. height: 20px;
  180. border-right: 1px solid #ccc;
  181. line-height: 20px;
  182. font-size: 14px;
  183. }
  184. .button:last-child {
  185. border-right: none;
  186. }
  187. // 点赞
  188. .zan {
  189. img {
  190. width: 15px;
  191. height: 15px;
  192. position: relative;
  193. top: 2px;
  194. }
  195. }
  196. }
  197. }
  198. </style>