Message.vue 11 KB

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