index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <template>
  2. <mobile-frame :frameStyle="frameStyle" @toPath="toPath">
  3. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage">
  4. <view class="list-scroll-view">
  5. <view class="main">
  6. <!-- <view class="one">
  7. <input type="text" v-model="searchInfo.name" @input="toInput" placeholder="搜索">
  8. </view> -->
  9. <view class="two">
  10. <view class="list" v-for="(item,index) in list" :key="index" @tap="toInfo(item)">
  11. <image class="image"
  12. :src="item.shop&&item.shop.logo&&item.shop.logo.length>0?item.shop.logo[0].url:''"
  13. mode="">
  14. </image>
  15. <view class="content">
  16. <view class="name textOver">{{item.shop&&item.shop.name||'暂无'}}</view>
  17. <view class="news textOver">{{item.last_chat}}</view>
  18. </view>
  19. <view class="time">
  20. <view class="time_1">{{item.last_time}}</view>
  21. <uni-badge :text="item.not_read" size="small"></uni-badge>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </scroll-view>
  28. </mobile-frame>
  29. </template>
  30. <script>
  31. export default {
  32. data() {
  33. return {
  34. frameStyle: {
  35. useBar: true
  36. },
  37. user: {},
  38. searchInfo: {},
  39. list: [],
  40. total: 0,
  41. skip: 0,
  42. limit: 10,
  43. page: 0,
  44. };
  45. },
  46. onLoad: async function() {
  47. const that = this;
  48. await that.watchlogin();
  49. },
  50. onShow: async function() {
  51. const that = this;
  52. that.clearPage();
  53. if (that.user && that.user._id) that.search();
  54. },
  55. onPullDownRefresh: async function() {
  56. const that = this;
  57. that.clearPage();
  58. await that.watchlogin();
  59. uni.stopPullDownRefresh();
  60. },
  61. computed: {
  62. listenWebsocket() {
  63. return this.$store.state.websocketData;
  64. }
  65. },
  66. watch: {
  67. listenWebsocket: function(newstr) {
  68. if (newstr.type == 'chat') {
  69. this.clearPage()
  70. this.search();
  71. }
  72. }
  73. },
  74. methods: {
  75. // 监听用户是否登录
  76. watchlogin() {
  77. const that = this;
  78. uni.getStorage({
  79. key: 'token',
  80. success: function(res) {
  81. let user = that.$jwt(res.data);
  82. if (user) {
  83. that.$set(that, `user`, user)
  84. that.search();
  85. }
  86. }
  87. })
  88. },
  89. async search() {
  90. const that = this;
  91. let config = that.$config;
  92. let info = {
  93. skip: that.skip,
  94. limit: that.limit,
  95. customer: that.user && that.user._id,
  96. }
  97. let res;
  98. res = await that.$api(`/room`, `GET`, {
  99. ...info,
  100. ...that.searchInfo
  101. }, 'chat');
  102. if (res.errcode == '0') {
  103. let list = [...that.list, ...res.data];
  104. for (let val of list) {
  105. if (val.last_chat) {
  106. val.last_time = val.last_chat.time
  107. if (val.last_chat.msg_type == '1') val.last_chat = `[图片]`
  108. else if (val.last_chat.msg_type == '2') val.last_chat = `[商品]`
  109. else if (val.last_chat.msg_type == '3') val.last_chat = `[订单]`
  110. else val.last_chat = val.last_chat.content
  111. }
  112. }
  113. that.$set(that, `list`, list);
  114. that.$set(that, `total`, res.total)
  115. } else {
  116. uni.showToast({
  117. title: res.errmsg,
  118. icon: 'none'
  119. })
  120. }
  121. },
  122. // 输入框
  123. toInput(e) {
  124. const that = this;
  125. if (that.searchInfo.goods) that.$set(that.searchInfo, `goods`, e.detail.value)
  126. else that.$set(that, `searchInfo`, {})
  127. that.clearPage();
  128. that.search();
  129. },
  130. // 详情
  131. toInfo(e) {
  132. uni.navigateTo({
  133. url: `/pagesMessage/message/info?id=${e._id}`
  134. })
  135. },
  136. // 分页
  137. toPage(e) {
  138. const that = this;
  139. let list = that.marketList;
  140. let limit = that.limit;
  141. if (that.total > list.length) {
  142. uni.showLoading({
  143. title: '加载中',
  144. mask: true
  145. })
  146. let page = that.page + 1;
  147. that.$set(that, `page`, page)
  148. let skip = page * limit;
  149. that.$set(that, `skip`, skip)
  150. that.search();
  151. uni.hideLoading();
  152. }
  153. },
  154. clearPage() {
  155. const that = this;
  156. that.$set(that, `list`, [])
  157. that.$set(that, `skip`, 0)
  158. that.$set(that, `limit`, 10)
  159. that.$set(that, `page`, 0)
  160. },
  161. // 菜单跳转
  162. toPath(e) {
  163. let url = `/${e.route}`;
  164. if (e.type == '0') uni.redirectTo({
  165. url
  166. })
  167. else {
  168. uni.navigateTo({
  169. url
  170. })
  171. }
  172. },
  173. }
  174. }
  175. </script>
  176. <style lang="scss">
  177. .main {
  178. display: flex;
  179. flex-direction: column;
  180. width: 96vw;
  181. padding: 2vw;
  182. background-color: var(--f1Color);
  183. .one {
  184. input {
  185. padding: 2vw;
  186. background-color: #ffffff;
  187. font-size: var(--font14Size);
  188. border-radius: 10px;
  189. }
  190. }
  191. .two {
  192. margin: 1vw 0 0 0;
  193. .list {
  194. display: flex;
  195. padding: 2vw;
  196. margin: 1vw 0 0 0;
  197. background-color: #ffffff;
  198. border-radius: 10px;
  199. .image {
  200. width: 15vw;
  201. height: 15vw;
  202. border-radius: 15vw;
  203. border: 1px solid #C0C0C0;
  204. }
  205. .content {
  206. width: 40vw;
  207. padding: 2vw;
  208. .name {
  209. font-size: 16px;
  210. padding: 1vw 0;
  211. }
  212. .news {
  213. font-size: 12px;
  214. color: #C0C0C0;
  215. }
  216. }
  217. .time {
  218. width: 30vw;
  219. text-align: right;
  220. padding: 2vw 0;
  221. font-size: 12px;
  222. color: #C0C0C0;
  223. .time_1 {
  224. margin: 0 0 1vw 0;
  225. }
  226. }
  227. }
  228. }
  229. }
  230. .scroll-view {
  231. position: absolute;
  232. top: 0;
  233. left: 0;
  234. right: 0;
  235. bottom: 0;
  236. .list-scroll-view {
  237. display: flex;
  238. flex-direction: column;
  239. }
  240. }
  241. </style>