msgView.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. <template>
  2. <!-- #ifdef H5 -->
  3. <view class="message_view_page">
  4. <!-- 横幅 -->
  5. <view class="gonggao">
  6. <view>防骗手册,为您保驾护航</view>
  7. <text class="iconfont icon-jinru"></text>
  8. </view>
  9. <!-- 商品信息 -->
  10. <view class="goods_info">
  11. <!-- 商品图片 -->
  12. <view class="goods_img">
  13. <image style="width: 100%; height: 100%;" mode="aspectFill" :src="goodsDetail.goodsPicUrl"></image>
  14. </view>
  15. <!-- 商品描述 -->
  16. <view class="goods_text">
  17. <view class="goods_name">{{goodsDetail.title}}</view>
  18. <view class="goods_pon">
  19. <view>
  20. <view class="goods_jiag">{{goodsDetail.amount?"¥"+goodsDetail.amount:"面议"}}</view>
  21. <view class="goods_fuwu">卖家包运费</view>
  22. </view>
  23. <view class="go_goods_btn">立即购买</view>
  24. </view>
  25. </view>
  26. </view>
  27. <!-- 聊天内容 -->
  28. <view class="message_view">
  29. <scroll-view class="message_view_scroll" :scroll-y="true" :scroll-top="scrollTop" :enhanced="true"
  30. :bounces="false" :show-scrollbar="false" @scrolltoupper="upper" @scrolltolower="lower" @scroll="scroll">
  31. <view style="box-sizing: border-box;padding: 10rpx 0;" ref="scrollviewDiv" class="scrollviewDiv">
  32. <view v-for="(item,index) in list" :key="index">
  33. <!-- 右消息 -->
  34. <view class="msg_view" v-if="userId===item.userId">
  35. <!-- 占位 -->
  36. <view class="msg_user_img_kong">
  37. </view>
  38. <view class="msg_view_info msg_view_info_right">
  39. <view class="msg_view_conent">
  40. {{item.message}}
  41. </view>
  42. <view class="msg_view_time">{{item.createTime}}</view>
  43. </view>
  44. <!-- 头像 -->
  45. <view class="msg_user_img">
  46. <image style="width: 100%; height: 100%;" mode="aspectFill" :src="item.userPic"></image>
  47. </view>
  48. </view>
  49. <!-- 左消息 -->
  50. <view class="msg_view" v-else>
  51. <!-- 头像 -->
  52. <view class="msg_user_img">
  53. <image style="width: 100%; height: 100%;" mode="aspectFill" :src="item.userPic"></image>
  54. </view>
  55. <view class="msg_view_info msg_view_info_left">
  56. <view class="msg_view_conent">{{item.message}}</view>
  57. <view class="msg_view_time">{{item.createTime}}</view>
  58. </view>
  59. <!-- 占位 -->
  60. <view class="msg_user_img_kong">
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </scroll-view>
  66. </view>
  67. <!-- 输入框 -->
  68. <view>
  69. <view class="text_input_view">
  70. <view class="text_input_lay">
  71. <view class="text_input_tengh">
  72. <input class="uni-input_chat" focus placeholder="请输入" v-model="message" />
  73. </view>
  74. <!-- 更多功能 -->
  75. <!-- <view class="text_input_mount" @click="gengduo = !gengduo">
  76. +
  77. </view> -->
  78. <!-- 发送消息 -->
  79. <view class="text_input_mount" @click="send">
  80. <image style="width: 60%; height: 60%;" mode="aspectFill" src="/static/tabBar/icon_issue01.png"></image>
  81. </view>
  82. </view>
  83. </view>
  84. <view v-if="gengduo" class="gengduo_view">
  85. <view class="gengduo_view_ay">
  86. <view class="gengduo_view_icon"></view>
  87. <view class="gengduo_view_name">相册</view>
  88. </view>
  89. <view class="gengduo_view_ay">
  90. <view class="gengduo_view_icon"></view>
  91. <view class="gengduo_view_name">拍照</view>
  92. </view>
  93. <view class="gengduo_view_ay">
  94. <view class="gengduo_view_icon"></view>
  95. <view class="gengduo_view_name">位置</view>
  96. </view>
  97. <view class="gengduo_view_ay">
  98. <view class="gengduo_view_icon"></view>
  99. <view class="gengduo_view_name">举报</view>
  100. </view>
  101. </view>
  102. </view>
  103. </view>
  104. <!-- #endif -->
  105. <!-- #ifndef H5 -->
  106. <web-view :src="webViewHref('/pages/message/msgView',pam)"></web-view>
  107. <!-- #endif -->
  108. </template>
  109. <script>
  110. import api from '@/common/http/'
  111. export default {
  112. data() {
  113. return {
  114. scrollTop: 0,
  115. gengduo: false,
  116. pam: {},
  117. list: [],
  118. message: "",
  119. userId: this.$store.state.user.userId,
  120. goodsDetail: {}
  121. }
  122. },
  123. onLoad(pam) {
  124. this.pam = pam
  125. },
  126. onShow() {
  127. // #ifdef H5
  128. this.getGoods()
  129. this.getNewList()
  130. // #endif
  131. },
  132. onHide() {
  133. // #ifdef H5
  134. if (this.timeId) {
  135. clearTimeout(this.timeId)
  136. }
  137. // #endif
  138. },
  139. methods: {
  140. // #ifdef H5
  141. getGoods() {
  142. if (!this.pam.goodsId) {
  143. return
  144. }
  145. api.postJson('/goods/detail', {
  146. id: this.pam.goodsId,
  147. }).then(res => {
  148. this.goodsDetail = res.data
  149. console.log(res)
  150. })
  151. },
  152. getNewList() {
  153. if (this.timeId) {
  154. clearTimeout(this.timeId)
  155. }
  156. this.getMsgList(0, () => {
  157. this.timeId = setTimeout(this.getNewList, 3000)
  158. uni.createSelectorQuery().select('.message_view_scroll').boundingClientRect(data => {
  159. uni.createSelectorQuery().select('.scrollviewDiv').boundingClientRect(data2 => {
  160. if ((this.scrollTop + data.height + 10) >= data2.height) {
  161. this.scrollTop = data2.height
  162. }
  163. }).exec()
  164. }).exec()
  165. })
  166. },
  167. getMsgList(flag, cb) {
  168. api.postJson('/user/talk/list', {
  169. userId: this.$store.state.user.userId,
  170. flag: flag,
  171. ...(() => {
  172. if (this.pam.goodsId) {
  173. return {
  174. goodsId: this.pam.goodsId,
  175. }
  176. }
  177. return {}
  178. })(),
  179. ...(() => {
  180. if (this.pam.groupId) {
  181. return {
  182. groupId: this.pam.groupId,
  183. }
  184. }
  185. return {}
  186. })(),
  187. ...(() => {
  188. if (this.list.length) {
  189. return {
  190. id: this.list[flag ? 0 : this.list.length - 1].id
  191. }
  192. }
  193. return {}
  194. })(),
  195. }, false).then(res => {
  196. if (flag) {
  197. this.list.unshift(...res.data)
  198. } else {
  199. this.list.push(...res.data)
  200. }
  201. cb && cb()
  202. })
  203. },
  204. upper() {
  205. // console.log("顶")
  206. uni.createSelectorQuery().select('.scrollviewDiv').boundingClientRect(data => {
  207. var oldHeight = data.height
  208. this.getMsgList(1, () => {
  209. this.$nextTick(() => {
  210. uni.createSelectorQuery().select('.scrollviewDiv').boundingClientRect(data2 => {
  211. this.scrollTop = data2.height - oldHeight
  212. }).exec()
  213. })
  214. })
  215. }).exec()
  216. },
  217. lower() {
  218. // console.log("底")
  219. },
  220. scroll(e) {
  221. this.scrollTop = e.detail.scrollTop
  222. },
  223. send() {
  224. if (this.pam.goodsId && this.$store.state.user.userId) {
  225. api.postJson('/user/talk/send', {
  226. message: this.message,
  227. userId: this.$store.state.user.userId,
  228. goodsId: this.pam.goodsId,
  229. ...(() => {
  230. if (this.pam.groupId) {
  231. return {
  232. groupId: this.pam.groupId,
  233. }
  234. }
  235. return {}
  236. })(),
  237. }, false).then(res => {
  238. this.message = ""
  239. this.getNewList()
  240. })
  241. }
  242. },
  243. // #endif
  244. // #ifndef H5
  245. // #endif
  246. },
  247. }
  248. </script>
  249. <style lang="scss" scoped>
  250. page {
  251. height: 100%;
  252. overflow: hidden;
  253. }
  254. .message_view_page {
  255. overflow: hidden;
  256. width: 100%;
  257. /* #ifdef H5 */
  258. height: 100%;
  259. /* #endif */
  260. /* #ifndef H5 */
  261. height: 100vh;
  262. /* #endif */
  263. display: flex;
  264. flex-direction: column;
  265. .msg_view {
  266. width: 100%;
  267. height: auto;
  268. box-sizing: border-box;
  269. padding: 10rpx 20rpx;
  270. display: flex;
  271. .msg_view_info {
  272. flex: 1;
  273. min-height: 80rpx;
  274. .msg_view_conent {
  275. display: inline-block;
  276. max-width: 100%;
  277. height: auto;
  278. background: #fff;
  279. border-radius: 10rpx;
  280. box-sizing: border-box;
  281. padding: 18rpx;
  282. word-break: break-all;
  283. }
  284. .msg_view_time {
  285. margin-top: 8rpx;
  286. font-size: 22rpx;
  287. color: #aaa;
  288. }
  289. }
  290. .msg_view_info_left {
  291. display: flex;
  292. flex-direction: column;
  293. align-items: flex-start;
  294. box-sizing: border-box;
  295. padding-left: 30rpx;
  296. }
  297. .msg_view_info_right {
  298. display: flex;
  299. flex-direction: column;
  300. align-items: flex-end;
  301. padding-right: 30rpx;
  302. }
  303. .msg_user_img_kong {
  304. width: 80rpx;
  305. height: 80rpx;
  306. }
  307. .msg_user_img {
  308. background: #fff;
  309. width: 80rpx;
  310. height: 80rpx;
  311. border-radius: 40rpx;
  312. }
  313. }
  314. .gengduo_view {
  315. width: 100%;
  316. height: auto;
  317. box-sizing: border-box;
  318. padding: 8rpx 20rpx 18rpx 20rpx;
  319. background: #fff;
  320. display: flex;
  321. justify-content: space-around;
  322. .gengduo_view_ay {
  323. width: 110rpx;
  324. }
  325. .gengduo_view_icon {
  326. width: 110rpx;
  327. height: 110rpx;
  328. border-radius: 16rpx;
  329. background: #eee;
  330. margin-bottom: 16rpx;
  331. }
  332. .gengduo_view_name {
  333. font-size: 22rpx;
  334. text-align: center;
  335. color: #aaa;
  336. }
  337. }
  338. .text_input_view {
  339. width: 100%;
  340. height: 100rpx;
  341. box-sizing: border-box;
  342. padding: 18rpx 20rpx;
  343. background: #fff;
  344. .text_input_lay {
  345. width: 100%;
  346. height: 100%;
  347. display: flex;
  348. .text_input_tengh {
  349. flex: 1;
  350. height: 100%;
  351. box-sizing: border-box;
  352. padding-right: 18rpx;
  353. .uni-input_chat {
  354. border-radius: 34rpx;
  355. width: 100%;
  356. height: 100%;
  357. box-sizing: border-box;
  358. border: 1rpx solid #eee;
  359. padding: 0 10rpx;
  360. }
  361. }
  362. .text_input_mount {
  363. width: 64rpx;
  364. height: 64rpx;
  365. font-size: 52rpx;
  366. font-weight: bold;
  367. color: #999;
  368. display: flex;
  369. justify-content: center;
  370. align-items: center;
  371. }
  372. }
  373. }
  374. .goods_info {
  375. width: 100%;
  376. height: auto;
  377. padding: 20rpx;
  378. box-sizing: border-box;
  379. background: #fff;
  380. display: flex;
  381. .goods_img {
  382. width: 100rpx;
  383. height: 100rpx;
  384. }
  385. .goods_text {
  386. flex: 1;
  387. min-height: 100rpx;
  388. height: auto;
  389. box-sizing: border-box;
  390. padding-left: 16rpx;
  391. .goods_name {
  392. width: 100%;
  393. margin-bottom: 10rpx;
  394. font-size: 28rpx;
  395. font-weight: bold;
  396. overflow: hidden;
  397. /*超出部分隐藏*/
  398. white-space: nowrap;
  399. /*禁止换行*/
  400. text-overflow: ellipsis;
  401. /*省略号*/
  402. }
  403. .goods_jiag {
  404. font-size: 26rpx;
  405. color: red;
  406. }
  407. .goods_fuwu {
  408. font-size: 24rpx;
  409. color: #aaa;
  410. }
  411. .goods_pon {
  412. width: 100%;
  413. display: flex;
  414. justify-content: space-between;
  415. align-items: center;
  416. .go_goods_btn {
  417. width: auto;
  418. height: auto;
  419. box-sizing: border-box;
  420. padding: 14rpx 28rpx;
  421. border-radius: 10rpx;
  422. font-size: 24rpx;
  423. font-weight: bold;
  424. color: #fff;
  425. background: rgb(250, 42, 42);
  426. }
  427. }
  428. }
  429. }
  430. .message_view {
  431. width: 100%;
  432. flex: 1;
  433. position: relative;
  434. .message_view_scroll {
  435. position: absolute;
  436. top: 0;
  437. bottom: 0;
  438. left: 0;
  439. right: 0;
  440. }
  441. }
  442. .gonggao {
  443. width: 100%;
  444. height: 80rpx;
  445. background: #fff2d4;
  446. box-sizing: border-box;
  447. padding: 0 20rpx;
  448. display: flex;
  449. align-items: center;
  450. justify-content: space-between;
  451. font-size: 24rpx;
  452. color: rgb(230, 138, 19);
  453. view {
  454. color: rgb(230, 138, 19);
  455. }
  456. }
  457. }
  458. </style>