index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <el-card :class="['reply-card', total > 0 && 'header-has-border', showInput && 'card-has-padding']" shadow="never">
  3. <template #header>
  4. <el-button type="primary" link @click="showInput = !showInput">留言
  5. <template #icon><el-icon size="16"><tjm-icon-mdi-comment-text-outline /></el-icon></template>
  6. </el-button>
  7. <div v-show="showInput" class="reply-form">
  8. <el-input v-model="messageContent" type="textarea" clearable autosize show-word-limit maxlength="140" placeholder="发布你的留言"></el-input>
  9. <el-button :loading="isSaving" type="primary" :disabled="!messageContent" @click="submit">发布</el-button>
  10. </div>
  11. </template>
  12. <template v-for="(item, index) in replyData" v-bind:key="index">
  13. <reply-tree :currentReply="item" :pageSize="replyChildrenCount" @closeDialog="reloadTree">
  14. <!-- 回复详情 -->
  15. <el-button class="text-reverse" type="primary" link @click="reply_detail(item)">共{{ item.childrenCount }}条回复
  16. <template #icon><el-icon size="22"><tjm-icon-mdi-menu-down /></el-icon></template>
  17. </el-button>
  18. </reply-tree>
  19. </template>
  20. <div class="reply-card__footer">
  21. <template v-if="total > params.size">
  22. <el-divider></el-divider>
  23. <el-button class="text-reverse" type="primary" icon="arrow-right" link @click="showAllReply">查看全部{{ replyTotal }}条留言</el-button>
  24. </template>
  25. <template v-else><el-divider v-if="total">已加载全部留言</el-divider></template>
  26. </div>
  27. </el-card>
  28. <reply-detail v-if="dialog" ref="replyDetail" @closed="reloadTree(), dialog = false"></reply-detail>
  29. </template>
  30. <script>
  31. import API from "@/api/policy/message";
  32. import replyTree from "@/components/ReplyCard/tree/index.vue";
  33. import replyDetail from "@/components/ReplyCard/detail.vue";
  34. export default {
  35. components: {
  36. replyTree,
  37. replyDetail
  38. },
  39. props: {
  40. isDetail: { type: Boolean, default: false },
  41. refId: { type: String, default: "" },
  42. refType: { type: String, default: "policy_share" },
  43. replyCount: { type: Number, default: 2 },
  44. replyChildrenCount: { type: Number, default: 2 }
  45. },
  46. data() {
  47. return {
  48. loading: false,
  49. params: {
  50. page: 1,
  51. size: this.replyCount,
  52. parentId: 0,
  53. refId: this.refId,
  54. refType: this.refType
  55. },
  56. total: 0,
  57. replyData: [],
  58. showInput: false,
  59. isSaving: false,
  60. messageContent: null,
  61. dialog: false
  62. }
  63. },
  64. computed: {
  65. replyTotal() {
  66. return (this.replyData && this.replyData.length && (this.total + this.replyData.map(r => r.childrenCount).reduce((p, v) => p + v))) || 0;
  67. }
  68. },
  69. mounted() {
  70. this.reloadTree();
  71. },
  72. methods: {
  73. reloadTree() {
  74. this.loading = true;
  75. API.get(this.params).then(res => {
  76. this.loading = false;
  77. this.replyData = res.data.records;
  78. this.total = res.data.total;
  79. this.$emit("replySuccess")
  80. }).catch(() => this.loading = false);
  81. },
  82. submit() {
  83. if (this.refId && this.refType) {
  84. const data = {
  85. parentId: 0,
  86. refId: this.refId,
  87. refType: this.refType,
  88. messageContent: this.messageContent
  89. }
  90. this.isSaving = true;
  91. API.add(data).then(() => {
  92. this.isSaving = false;
  93. ElMessage.success("留言成功");
  94. this.messageContent = null;
  95. this.reloadTree();
  96. }).catch(() => this.isSaving = false);
  97. }
  98. },
  99. reply_detail(data) {
  100. this.dialog = true;
  101. nextTick(() => this.$refs.replyDetail.open(data));
  102. },
  103. showAllReply() {
  104. if (this.isDetail) {
  105. this.params.size = this.total;
  106. this.reloadTree();
  107. } else {
  108. this.$emit("replyAll", this.total);
  109. }
  110. }
  111. }
  112. }
  113. </script>
  114. <style lang="scss" scoped>
  115. .text-reverse {
  116. display: flex;
  117. flex-direction: row-reverse;
  118. :deep([class*='el-icon'] + span) {
  119. margin-left: 0;
  120. font-size: 13px;
  121. }
  122. }
  123. .reply-card {
  124. --el-card-border-color: var(--el-border-color-lighter);
  125. max-width: 750px;
  126. margin: auto;
  127. border: none;
  128. :deep(.el-card__header) {
  129. display: flex;
  130. flex-direction: column;
  131. align-items: center;
  132. border-bottom: none;
  133. padding: calc(var(--el-card-padding) / 2) var(--el-card-padding);
  134. .reply-form {
  135. display: flex;
  136. flex-direction: column;
  137. align-items: flex-end;
  138. width: 80%;
  139. margin-top: calc(var(--el-card-padding) / 2);
  140. .el-button {
  141. margin-top: 18px;
  142. }
  143. }
  144. }
  145. > :deep(.el-card__body) {
  146. padding: 0;
  147. .el-card {
  148. border: none;
  149. border-radius: 0;
  150. .el-card__body {
  151. margin-left: 10px;
  152. padding: 0;
  153. .text-reverse {
  154. margin-bottom: 10px;
  155. padding: calc(9px / 2) 0 calc(9px / 2) 9px;
  156. border: none;
  157. border-left: 1px solid var(--el-border-color-lighter);
  158. border-radius: 0;
  159. }
  160. }
  161. }
  162. }
  163. .reply-card__footer {
  164. display: flex;
  165. flex-direction: column;
  166. justify-content: center;
  167. height: fit-content;
  168. .el-divider {
  169. margin: 10px 0;
  170. border-color: var(--el-card-border-color);
  171. :deep(.el-divider__text) {
  172. padding: 0 60px;
  173. color: var(--el-text-color-disabled);
  174. }
  175. }
  176. }
  177. }
  178. .header-has-border.reply-card > {
  179. :deep(.el-card__header) {
  180. position: relative;
  181. &::after {
  182. content: '';
  183. position: absolute;
  184. bottom: 0;
  185. width: calc(100% - 2 * var(--el-card-padding));
  186. height: 1px;
  187. background: var(--el-card-border-color);
  188. }
  189. }
  190. :deep(.el-card__body) {
  191. padding: calc(var(--el-card-padding) / 2) var(--el-card-padding);
  192. }
  193. }
  194. .card-has-padding.reply-card > :deep(.el-card__header) {
  195. padding: var(--el-card-padding);
  196. }
  197. </style>