chat.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <view class="content">
  3. <view class="list" id="list">
  4. <block v-for="(item,index) in pageList" :key="index">
  5. <view class="hflex acenter jend item" v-if="item.user.id == userId">
  6. <view class="message">{{item.content}}</view>
  7. <image :src="item.user.headimg" class="headimg"></image>
  8. </view>
  9. <view class="hflex acenter item" v-else>
  10. <image :src="item.user.headimg" class="headimg"></image>
  11. <view class="message message_left">{{item.content}}</view>
  12. </view>
  13. </block>
  14. </view>
  15. <view class="bottom hflex jbetween">
  16. <view class="bottom_left">
  17. <u-input v-model="message" shape="circle" placeholder="请输入信息..." border="none"></u-input>
  18. </view>
  19. <view class="bottom_btn hflex acenter jcenter" @click="send">立即回复</view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import $api from '@/static/js/api.js'
  25. var that = ''
  26. export default {
  27. data() {
  28. return {
  29. offer: {},
  30. message: '',
  31. pageList: [],
  32. type: '',
  33. id: '',
  34. tab: '',
  35. offer_id: '',
  36. userId: ''
  37. }
  38. },
  39. onLoad(options) {
  40. that = this
  41. that.id = options.id
  42. that.tab = options.tab
  43. that.userId = uni.getStorageSync('id')
  44. that.getList()
  45. },
  46. methods: {
  47. getList() {
  48. $api.req({
  49. url: '/data/api.auth.Purchase/msg_get',
  50. data: {
  51. id: that.id,
  52. tab: that.tab
  53. }
  54. }, function(res) {
  55. if(res.code == 1) {
  56. that.pageList = res.data
  57. setTimeout(() => {
  58. that.scrollToBottom()
  59. },300)
  60. }
  61. })
  62. },
  63. send() {
  64. if(that.message == "") {
  65. $api.info('不能发送空的内容')
  66. } else {
  67. $api.req({
  68. url: '/data/api.auth.Purchase/msg_send',
  69. method: 'POST',
  70. data: {
  71. id: that.id,
  72. tab: that.tab,
  73. content: that.message
  74. }
  75. }, function(res) {
  76. if(res.code == 1) {
  77. that.message = ""
  78. that.getList()
  79. }
  80. })
  81. }
  82. },
  83. scrollToBottom() {
  84. uni.createSelectorQuery().select('#list').boundingClientRect(function(rect){
  85. // 使页面滚动到底部
  86. console.log("页面的高度",rect)
  87. uni.pageScrollTo({
  88. scrollTop: rect.bottom
  89. })
  90. }).exec()
  91. }
  92. },
  93. }
  94. </script>
  95. <style lang="scss" scoped>
  96. .content::v-deep {
  97. background: #F4F4F4;
  98. .top {
  99. width: 100%;
  100. // height: 300px;
  101. background: #FFFFFF;
  102. box-shadow: 0px 4rpx 32rpx 0px rgba(0,0,0,0.04);
  103. border-radius: 0px 0px 28rpx 28rpx;
  104. box-sizing: border-box;
  105. padding: 24rpx 30rpx 0;
  106. .top_title {
  107. font-size: 28rpx;
  108. font-weight: 500;
  109. color: #222222;
  110. line-height: 40rpx;
  111. padding-bottom: 24rpx;
  112. }
  113. .top_item {
  114. width: 100%;
  115. height: 76rpx;
  116. background: #F4F4F4;
  117. border-radius: 16rpx;
  118. margin-bottom: 20rpx;
  119. box-sizing: border-box;
  120. padding: 0 20rpx;
  121. .item_label {
  122. font-size: 24rpx;
  123. font-weight: 500;
  124. color: #777777;
  125. line-height: 34rpx;
  126. padding-right: 28rpx;
  127. }
  128. .text_red {
  129. font-size: 28rpx;
  130. font-weight: 400;
  131. color: #FF3636;
  132. line-height: 34rpx;
  133. }
  134. }
  135. .img {
  136. width: 220rpx;
  137. height: 220rpx;
  138. border-radius: 16rpx;
  139. margin: 0 16rpx 24rpx 0;
  140. }
  141. .img:nth-child(3n+3) {
  142. margin: 0 0 24rpx;
  143. }
  144. }
  145. .list {
  146. width: 100%;
  147. margin-bottom: 186rpx;
  148. box-sizing: border-box;
  149. padding: 0 30rpx;
  150. .item {
  151. margin-top: 32rpx;
  152. .message {
  153. max-width: 480rpx;
  154. background: #FFFFFF;
  155. border-radius: 24rpx 4rpx 24rpx 24rpx;
  156. box-sizing: border-box;
  157. padding: 18rpx 20rpx;
  158. font-size: 26rpx;
  159. font-weight: 400;
  160. color: #444444;
  161. line-height: 36rpx;
  162. margin: 0 20rpx 0 0;
  163. }
  164. .message_left {
  165. margin: 0 0 0 20rpx;
  166. border-radius: 4rpx 24rpx 24rpx 24rpx;
  167. }
  168. .headimg {
  169. width: 68rpx;
  170. height: 68rpx;
  171. border-radius: 50%;
  172. }
  173. }
  174. }
  175. .bottom {
  176. width: 100%;
  177. height: 166rpx;
  178. position: fixed;
  179. bottom: 0;
  180. z-index: 999;
  181. box-sizing: border-box;
  182. padding: 16rpx 30rpx 0;
  183. background: #FFFFFF;
  184. .bottom_left {
  185. width: 490rpx;
  186. height: 72rpx;
  187. .u-input {
  188. height: 100%;
  189. background: #F4F4F4;
  190. padding: 0 32rpx !important;
  191. }
  192. }
  193. .bottom_btn {
  194. width: 180rpx;
  195. height: 72rpx;
  196. background: #506DFF;
  197. border-radius: 36rpx;
  198. font-size: 28rpx;
  199. font-weight: 500;
  200. color: #FFFFFF;
  201. }
  202. }
  203. }
  204. </style>