reply-on-my.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <template>
  2. <div class="wrap">
  3. <div class="wrap-title">
  4. <TitleControl title="回复我的" @handleChange="handleSearch">
  5. <div slot="control" class="control-btn">
  6. <div
  7. class="is-read"
  8. v-if="!manageType"
  9. @click="
  10. (_) => {
  11. $message.success('已将所有信息标为已读');
  12. handleRead(list, 1);
  13. }
  14. "
  15. >
  16. <img src="@/assets/icon/read.png" alt="" />
  17. <span>全部已读</span>
  18. </div>
  19. <div class="manage" @click="manageType = true" v-if="!manageType">
  20. 管理
  21. </div>
  22. <div class="manage cancel" @click="manageType = false" v-else>
  23. 取消
  24. </div>
  25. </div>
  26. <div slot="bottom" class="switch-box">
  27. <div class="btn" :class="{ select: !type }" @click="changeType(0)">
  28. 问题
  29. <div class="mark" v-if="!!forumMarkNum.reply_forum">
  30. {{
  31. forumMarkNum.reply_forum > 99 ? "99+" : forumMarkNum.reply_forum
  32. }}
  33. </div>
  34. </div>
  35. <div class="btn" :class="{ select: !!type }" @click="changeType(1)">
  36. 回答
  37. <div class="mark" v-if="!!forumMarkNum.reply_answer">
  38. {{
  39. forumMarkNum.reply_answer > 99
  40. ? "99+"
  41. : forumMarkNum.reply_answer
  42. }}
  43. </div>
  44. </div>
  45. </div>
  46. </TitleControl>
  47. </div>
  48. <div class="wrap-content">
  49. <div class="read-box" v-if="manageType">
  50. <div class="radio">
  51. <el-checkbox
  52. v-model="allChecked"
  53. @change="changeAllChecked"
  54. ></el-checkbox>
  55. </div>
  56. <div
  57. class="btn is-read"
  58. @click="
  59. handleRead(
  60. list.filter((item) => item.checked),
  61. 1
  62. )
  63. "
  64. >
  65. 已读
  66. </div>
  67. <div
  68. class="btn un-read"
  69. @click="
  70. handleDelete(
  71. list
  72. .filter((item) => item.checked)
  73. .map((item) => item.id)
  74. .join(','),
  75. 0
  76. )
  77. "
  78. >
  79. 删除
  80. </div>
  81. </div>
  82. <div class="list">
  83. <div class="list-item" v-for="item in list" :key="item.id">
  84. <div class="radio" v-if="manageType">
  85. <el-checkbox v-model="item.checked"></el-checkbox>
  86. </div>
  87. <div
  88. class="card"
  89. :ref="'card-' + item.id"
  90. :style="manageType ? { width: 'calc(100% - 60px)' } : ''"
  91. @click="handleRead([item], 1)"
  92. >
  93. <ReplyMyCard
  94. :info="item"
  95. :manageType="manageType"
  96. :cardType="type ? 'answer' : 'question'"
  97. @reply="showReply(item)"
  98. @handleDelete="handleDelete(item.id)"
  99. @handleRead="handleRead([item], 1 - item.is_read)"
  100. @handleToDetail="
  101. (type) =>
  102. handleToDetail(item, type, {
  103. forum_id: 'forum_id',
  104. reply_id: 'reply_id',
  105. })
  106. "
  107. />
  108. </div>
  109. </div>
  110. <el-empty v-if="finished" description="没有更多数据"></el-empty>
  111. </div>
  112. </div>
  113. <Reply v-model="replyVisible" :info="info" @handleReply="handleReply" />
  114. <ToNext @toNext="toNext" v-if="!manageType" />
  115. </div>
  116. </template>
  117. <script>
  118. import { ForumService } from "@/common/service";
  119. import { mapState } from "vuex";
  120. import ReplyMyCard from "@/components/card/forum/reply-my-card.vue";
  121. import TitleControl from "@/components/module/title-control.vue";
  122. import Reply from "@/components/module/reply.vue";
  123. import ToNext from "@/components/module/to-next.vue";
  124. export default {
  125. components: { ReplyMyCard, TitleControl, Reply, ToNext },
  126. data() {
  127. return {
  128. list: [],
  129. params: {
  130. page: 1,
  131. page_num: 20,
  132. sort_type: 1,
  133. },
  134. // 是否无数据
  135. finished: false,
  136. // 是否点击管理按钮
  137. manageType: false,
  138. // 是否选中所有
  139. allChecked: false,
  140. // 回复框显示状态
  141. replyVisible: false,
  142. // 回复详情
  143. info: {},
  144. // 当前选中类型
  145. type: 0,
  146. // 搜索
  147. list_copy: "",
  148. };
  149. },
  150. computed: {
  151. ...mapState({
  152. forumMarkNum: (state) => state.mark_num.forumMarkNum,
  153. }),
  154. },
  155. watch: {
  156. manageType(val) {
  157. !val ? (this.allChecked = false) : "";
  158. this.list.forEach((item) => (item.checked = false));
  159. },
  160. },
  161. mounted() {
  162. this.getList();
  163. },
  164. methods: {
  165. // 触底
  166. TouchBottom() {
  167. if (!this.finished) {
  168. this.getList();
  169. }
  170. },
  171. // 选择全部
  172. changeAllChecked(type) {
  173. this.list.map((item) => (item.checked = type));
  174. },
  175. // 切换数据类型
  176. changeType(type) {
  177. this.type = type;
  178. this.finished = false;
  179. this.list = [];
  180. this.params.page = 1;
  181. this.manageType = false;
  182. this.getList();
  183. },
  184. // 获取数据
  185. getList() {
  186. ForumService.getReplyComment({
  187. type: this.type ? 2 : 1,
  188. ...this.params,
  189. }).then(({ data }) => {
  190. const list = data.list.map((item) => {
  191. return { checked: false, ...item };
  192. });
  193. this.list = this.params.page === 1 ? list : [...this.list, ...list];
  194. if (list.length < this.params.page_num) {
  195. this.finished = true;
  196. } else {
  197. this.params.page++;
  198. }
  199. });
  200. },
  201. // 删除记录
  202. handleDelete(val) {
  203. let that = this;
  204. this.showConfirmPopup("确定要删除该信息?")
  205. .then(() => {
  206. ForumService.batchesDel({ id: val, type: 3 }).then(({ data }) => {
  207. that.list.splice(
  208. that.list.findIndex((item) => item.id == val.id),
  209. 1
  210. );
  211. this.$message.success("删除成功!");
  212. });
  213. })
  214. .catch((_) => {});
  215. },
  216. // 更改阅读状态
  217. handleRead(arr, is_read) {
  218. let params = {
  219. id: "",
  220. type: 2,
  221. is_read,
  222. };
  223. params.id = arr.map((item) => item.id).join(",");
  224. if (!params.id) return;
  225. ForumService.unreadChange(params).then((res) => {
  226. this.list.forEach((item) => {
  227. params.id.split(",").includes(item.id + "")
  228. ? (item.is_read = params.is_read)
  229. : "";
  230. });
  231. this.manageType = false;
  232. this.$store.dispatch("getMarkNum", "forum");
  233. });
  234. },
  235. // 跳转详情
  236. handleToDetail(
  237. item,
  238. type = "question",
  239. key = { forum_id: "forum_id", reply_id: "id" }
  240. ) {
  241. if (Object.keys(item).includes("is_normal") && !item.is_normal)
  242. return this.$message.error("该问题已失效");
  243. this.$router
  244. .push({
  245. path:
  246. type == "question"
  247. ? "/forum-question-details"
  248. : "/forum-answer-item",
  249. query: {
  250. forum_id: item[key.forum_id],
  251. reply_id: item[key.reply_id],
  252. },
  253. })
  254. .catch(() => {});
  255. },
  256. // 显示回复框
  257. showReply(item) {
  258. this.replyVisible = true;
  259. this.info = item;
  260. },
  261. // 回复
  262. handleReply(val) {
  263. this.replyVisible = false;
  264. ForumService.forumSecondComment({ id: this.info.id, content: val }).then(
  265. ({ data }) => {
  266. this.$message.success("回复成功");
  267. }
  268. );
  269. },
  270. // 筛选
  271. handleSearch(val) {
  272. if (!this.list_copy) this.list_copy = this.list;
  273. if (val) {
  274. this.list = this.list_copy.filter((item) => {
  275. return item.content.includes(val);
  276. });
  277. } else {
  278. this.list = this.list_copy;
  279. this.list_copy = "";
  280. }
  281. },
  282. },
  283. };
  284. </script>
  285. <style lang="scss" scoped>
  286. .wrap {
  287. width: 100%;
  288. display: flex;
  289. flex-direction: column;
  290. align-items: center;
  291. .wrap-title {
  292. width: 80%;
  293. }
  294. .wrap-content {
  295. width: 80%;
  296. margin-top: 20px;
  297. .read-box {
  298. display: flex;
  299. align-items: center;
  300. margin: 0px 0 20px;
  301. .radio {
  302. width: 45px;
  303. display: flex;
  304. justify-content: center;
  305. margin-right: 20px;
  306. }
  307. .btn {
  308. width: 80px;
  309. height: 30px;
  310. border-radius: 17px;
  311. color: #ffffff;
  312. font-size: 16px;
  313. font-weight: 400;
  314. text-align: center;
  315. line-height: 30px;
  316. cursor: pointer;
  317. }
  318. .is-read {
  319. background: #0054f7;
  320. }
  321. .un-read {
  322. background: #ff9f18;
  323. margin-left: 10px;
  324. }
  325. }
  326. .list {
  327. .list-item {
  328. margin-bottom: 20px;
  329. display: flex;
  330. align-items: center;
  331. justify-content: flex-end;
  332. position: relative;
  333. .radio {
  334. width: 45px;
  335. background-color: white;
  336. display: flex;
  337. align-items: center;
  338. justify-content: center;
  339. position: absolute;
  340. top: 0;
  341. bottom: 0;
  342. left: 0;
  343. border-radius: 10px;
  344. }
  345. .card {
  346. width: 100%;
  347. }
  348. }
  349. }
  350. }
  351. }
  352. .control-btn {
  353. display: flex;
  354. align-items: center;
  355. justify-content: flex-end;
  356. user-select: none;
  357. .is-read {
  358. width: 100px;
  359. height: 30px;
  360. display: flex;
  361. align-items: center;
  362. justify-content: center;
  363. background: #f4f4f4;
  364. border-radius: 17px;
  365. font-size: 13px;
  366. font-weight: 400;
  367. color: #1677ff;
  368. img {
  369. width: 15px;
  370. height: 15px;
  371. margin-right: 5px;
  372. }
  373. }
  374. .manage {
  375. width: 70px;
  376. height: 30px;
  377. background: #2a63f3;
  378. border-radius: 17px;
  379. font-size: 13px;
  380. font-weight: 400;
  381. text-align: center;
  382. line-height: 30px;
  383. color: #ffffff;
  384. margin-left: 10px;
  385. }
  386. .cancel {
  387. background: transparent;
  388. color: #1677ff;
  389. }
  390. }
  391. .switch-box {
  392. display: flex;
  393. align-items: center;
  394. margin-top: 15px;
  395. .btn {
  396. width: 100px;
  397. height: 35px;
  398. text-align: center;
  399. line-height: 35px;
  400. font-size: 14px;
  401. font-weight: 400;
  402. color: #666666;
  403. background: #f4f4f4;
  404. border-radius: 22px;
  405. margin-right: 10px;
  406. position: relative;
  407. cursor: pointer;
  408. .mark {
  409. width: 36px;
  410. height: 20px;
  411. text-align: center;
  412. line-height: 20px;
  413. transform: scale(0.7);
  414. font-size: 10px;
  415. font-weight: 400;
  416. color: #ffffff;
  417. background: #ff5143;
  418. border-radius: 8px;
  419. position: absolute;
  420. top: -10px;
  421. right: -10px;
  422. }
  423. }
  424. .select {
  425. background: #2a63f3;
  426. color: #ffffff;
  427. }
  428. }
  429. </style>