msgView.vue 14 KB

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