Message.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. <template>
  2. <div class="message-body">
  3. <div class="message">
  4. <div class="con">
  5. <ul class="form">
  6. <li>
  7. <span>留言人:</span>
  8. <div class="name">
  9. <sradio
  10. @click.native="select = 'nickName'"
  11. :checked="select == 'nickName'"
  12. class="radio lightradio"
  13. :name="'使用昵称'"
  14. />
  15. <sradio
  16. @click.native="select = 'realName'"
  17. :checked="select == 'realName'"
  18. class="radio lightradio"
  19. :name="'使用真实姓名'"
  20. />
  21. </div>
  22. </li>
  23. <li>
  24. <span>留言内容:</span>
  25. <div class="input">
  26. <textarea
  27. :placeholder="
  28. mseIsShow
  29. ? '请输入您的留言,您的留言将直接显示'
  30. : '请输入您的留言'
  31. "
  32. maxlength="250"
  33. v-model="msg"
  34. rows="3"
  35. cols="80"
  36. >
  37. </textarea>
  38. <span>{{ msg.length }}/250</span>
  39. <span class="loginwarn" v-if="!token" @click.stop="tologin"
  40. ><img :src="require('@/assets/images/warn.png')" alt="" />
  41. 请先登录后,再进行留言</span
  42. >
  43. </div>
  44. <div class="button dati_btn" @click="leaveMsg('', '')">
  45. <span class="active">提交</span>
  46. </div>
  47. </li>
  48. </ul>
  49. </div>
  50. <div class="leaving">
  51. <div class="title">
  52. <span
  53. >全部留言
  54. <i class="lightbtmLine"></i>
  55. </span>
  56. </div>
  57. <ul class="content">
  58. <li v-for="(item, i) in message" :key="i">
  59. <div class="info">
  60. <span class="primaryTxt">{{
  61. (item.isRealName ? item.realName : item.nickName) || "匿名用户"
  62. }}</span>
  63. <span>{{ item.createTime }}</span>
  64. </div>
  65. <div class="body">
  66. <span>{{ item.content }}</span>
  67. <div class="txtSameHovers" @click="showComment(item, i)">
  68. <img
  69. :src="require(`@/assets/images/btnlist/item_comment.png`)"
  70. alt=""
  71. />
  72. <span>评论</span>
  73. </div>
  74. </div>
  75. <ul class="response-text" v-if="item.children">
  76. <li v-for="(sub, idx) in item.children" :key="idx">
  77. <div>{{ sub.content }}</div>
  78. <div>
  79. 来自:{{
  80. sub.isRealName ? sub.realName : sub.nickName
  81. }}
  82. 的评论 {{ sub.createTime }}
  83. </div>
  84. </li>
  85. </ul>
  86. <template v-if="item.showComment">
  87. <div class="response input">
  88. <textarea
  89. v-model="item.comment"
  90. rows="3"
  91. maxlength="250"
  92. cols="80"
  93. placeholder="请写下您的评论"
  94. ></textarea>
  95. <span>{{ item.comment.length }}/250</span>
  96. </div>
  97. <div
  98. class="subbutton button primarybtn mySubbutton"
  99. @click="leaveMsg(item, i)"
  100. >
  101. 提交
  102. </div>
  103. </template>
  104. </li>
  105. </ul>
  106. </div>
  107. <div v-if="!loadAll" class="loadmore" @click="loadmore">
  108. <span class="lightborderThemeStyle">加载更多</span>
  109. </div>
  110. </div>
  111. </div>
  112. </template>
  113. <script>
  114. import { getMsg, saveMsg, webMesCheck } from "@/config/api";
  115. export default {
  116. data() {
  117. return {
  118. msg: "",
  119. message: [],
  120. select: "nickName",
  121. mtotal: 0,
  122. mpageSize: 6,
  123. mcurrentPage: 1,
  124. loadAll: false,
  125. // 是否有留言权限
  126. mseIsShow: false,
  127. };
  128. },
  129. watch: {
  130. mpageSize() {
  131. this.getMessage();
  132. },
  133. },
  134. async mounted() {
  135. this.getMessage();
  136. },
  137. methods: {
  138. tologin() {
  139. window.scrollTo(0, 0);
  140. this.$bus.$emit("showLogin", true);
  141. },
  142. loadmore() {
  143. this.mpageSize += this.mpageSize;
  144. },
  145. async leaveMsg(item = "", i = "") {
  146. let tmp = (item ? item.comment : this.msg).trim();
  147. if (!tmp) {
  148. return alert("留言不能为空");
  149. }
  150. saveMsg(
  151. "comment",
  152. {
  153. content: tmp,
  154. parentId: item.id || "",
  155. isRealName: Number(this.select == "realName"),
  156. },
  157. (res) => {
  158. if (res.code == 0) {
  159. this.msg = "";
  160. alert("留言成功");
  161. item && this.showComment(item, i);
  162. this.getMessage();
  163. }
  164. }
  165. );
  166. },
  167. showComment(item, i) {
  168. item.showComment = !item.showComment;
  169. item.comment = "";
  170. this.$set(this.message, i, item);
  171. },
  172. async getMessage() {
  173. if (this.loadAll) return;
  174. getMsg(
  175. {
  176. pageNum: this.mcurrentPage,
  177. pageSize: this.mpageSize,
  178. },
  179. (result) => {
  180. result.data.list.forEach((item) => {
  181. item.showComment = false;
  182. item.comment = "";
  183. });
  184. if (result.data.list.length == this.message.length) {
  185. this.loadAll = true;
  186. }
  187. this.message = result.data.list;
  188. this.mtotal = result.data.total;
  189. }
  190. );
  191. },
  192. },
  193. async created() {
  194. // 查看是否有留言权限
  195. let res = await webMesCheck();
  196. this.mseIsShow = res.data;
  197. },
  198. };
  199. </script>
  200. <style lang="less" scoped>
  201. .message-body {
  202. max-width: 80%;
  203. margin: 100px auto 0;
  204. position: relative;
  205. height: 80%;
  206. z-index: 99;
  207. .message {
  208. height: 100%;
  209. .con {
  210. width: 100%;
  211. .form {
  212. text-align: left;
  213. width: 100%;
  214. > li {
  215. margin-bottom: 30px;
  216. display: flex;
  217. width: 100%;
  218. align-items: flex-start;
  219. > span {
  220. display: inline-block;
  221. width: 100px;
  222. flex-shrink: 0;
  223. font-size: 20px;
  224. margin-right: 10px;
  225. text-align: right;
  226. }
  227. .name {
  228. .radio {
  229. margin-right: 50px;
  230. }
  231. }
  232. .input {
  233. flex: auto;
  234. width: 100%;
  235. position: relative;
  236. font-size: 0;
  237. > textarea {
  238. width: 100%;
  239. line-height: 2;
  240. font-size: 16px;
  241. color: #2d2d2d;
  242. }
  243. > span {
  244. display: inline-block;
  245. color: rgba(153, 153, 153, 1);
  246. position: absolute;
  247. font-size: 12px;
  248. bottom: 5px;
  249. right: 14px;
  250. }
  251. .loginwarn {
  252. left: 50%;
  253. right: auto;
  254. transform: translateX(-50%);
  255. background-color: rgba(51, 51, 51, 0.5);
  256. color: #fff;
  257. display: flex;
  258. align-items: center;
  259. bottom: 10px;
  260. padding: 4px;
  261. border-radius: 2px;
  262. > img {
  263. width: 20px;
  264. margin-right: 4px;
  265. }
  266. }
  267. }
  268. .button {
  269. flex-shrink: 0;
  270. align-self: flex-end;
  271. text-align: center;
  272. border: none;
  273. border-radius: 5px;
  274. margin-left: 20px;
  275. > span {
  276. width: 100%;
  277. padding: 0;
  278. border-radius: 5px;
  279. margin-left: 0;
  280. }
  281. }
  282. &:last-of-type {
  283. margin-bottom: 10px;
  284. }
  285. }
  286. }
  287. > div {
  288. display: flex;
  289. justify-content: center;
  290. align-items: center;
  291. .button {
  292. position: relative;
  293. width: 150px;
  294. &:first-of-type {
  295. margin-right: 50px;
  296. }
  297. > span {
  298. position: absolute;
  299. left: -220px;
  300. top: 50%;
  301. transform: translateY(-50%);
  302. color: rgba(153, 153, 153, 1);
  303. display: flex;
  304. align-items: center;
  305. > img {
  306. width: 24px;
  307. height: 24px;
  308. margin-right: 8px;
  309. }
  310. }
  311. }
  312. }
  313. }
  314. .leaving {
  315. height: 40%;
  316. .title {
  317. text-align: left;
  318. font-size: 30px;
  319. border-bottom: 1px solid #fff;
  320. padding-bottom: 10px;
  321. position: relative;
  322. margin-bottom: 20px;
  323. width: 98%;
  324. span {
  325. display: inline-block;
  326. min-width: 118px;
  327. font-size: 20px;
  328. position: relative;
  329. > i {
  330. bottom: -16px;
  331. }
  332. }
  333. }
  334. .content {
  335. color: #fff;
  336. text-align: left;
  337. padding-right: 20px;
  338. overflow-y: auto;
  339. height: 80%;
  340. > li {
  341. margin-bottom: 10px;
  342. .info {
  343. > span {
  344. display: inline-block;
  345. font-size: 20px;
  346. margin-right: 10px;
  347. &:not(:first-of-type) {
  348. font-size: 14px;
  349. }
  350. }
  351. }
  352. .body {
  353. margin: 10px 0;
  354. display: flex;
  355. justify-content: space-between;
  356. > span {
  357. width: 90%;
  358. word-break: break-all;
  359. display: inline-block;
  360. color: #fff;
  361. }
  362. .txtSameHovers {
  363. color: #fff;
  364. cursor: pointer;
  365. img {
  366. margin-right: 10px;
  367. width: 16px;
  368. position: relative;
  369. top: -1px;
  370. }
  371. }
  372. }
  373. .response {
  374. margin-top: 10px;
  375. border: 1px #fff solid;
  376. width: 100%;
  377. position: relative;
  378. font-size: 0;
  379. > textarea {
  380. line-height: 2;
  381. color: #2d2d2d;
  382. }
  383. > span {
  384. display: inline-block;
  385. color: #909399;
  386. position: absolute;
  387. font-size: 12px;
  388. bottom: 5px;
  389. right: 14px;
  390. }
  391. }
  392. .response-text {
  393. border: 1px rgba(153, 153, 153, 1) solid;
  394. background-color: #f3f3f3;
  395. padding: 10px 13px;
  396. color: rgba(153, 153, 153, 1);
  397. > li {
  398. > div {
  399. &:last-of-type {
  400. font-size: 14px;
  401. text-align: right;
  402. margin-top: 20px;
  403. }
  404. }
  405. }
  406. }
  407. .subbutton {
  408. font-size: 18px;
  409. font-weight: bold;
  410. display: inline-block;
  411. text-align: center;
  412. margin-top: 20px;
  413. }
  414. }
  415. }
  416. }
  417. .loadmore {
  418. margin-top: 70px;
  419. .lightborderThemeStyle {
  420. padding: 10px 30px;
  421. border-radius: 4px;
  422. }
  423. }
  424. }
  425. }
  426. </style>