index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. methods: {
  62. // 监听用户是否登录
  63. watchlogin() {
  64. const that = this;
  65. uni.getStorage({
  66. key: 'token',
  67. success: function(res) {
  68. let user = that.$jwt(res.data);
  69. if (user) {
  70. that.$set(that, `user`, user)
  71. that.search();
  72. }
  73. }
  74. })
  75. },
  76. async search() {
  77. const that = this;
  78. let config = that.$config;
  79. let info = {
  80. skip: that.skip,
  81. limit: that.limit,
  82. customer: that.user && that.user._id,
  83. }
  84. let res;
  85. res = await that.$api(`/room`, `GET`, {
  86. ...info,
  87. ...that.searchInfo
  88. }, 'chat');
  89. if (res.errcode == '0') {
  90. let list = [...that.list, ...res.data];
  91. for (let val of list) {
  92. if (val.last_chat) {
  93. val.last_time = val.last_chat.time
  94. let chat = val.last_chat.content.indexOf(config.stompUrl) != -1;
  95. if (chat) val.last_chat = `[图片]`
  96. else val.last_chat = val.last_chat.content
  97. }
  98. }
  99. that.$set(that, `list`, list);
  100. that.$set(that, `total`, res.total)
  101. } else {
  102. uni.showToast({
  103. title: res.errmsg,
  104. icon: 'none'
  105. })
  106. }
  107. },
  108. // 输入框
  109. toInput(e) {
  110. const that = this;
  111. if (that.searchInfo.goods) that.$set(that.searchInfo, `goods`, e.detail.value)
  112. else that.$set(that, `searchInfo`, {})
  113. that.clearPage();
  114. that.search();
  115. },
  116. // 详情
  117. toInfo(e) {
  118. uni.navigateTo({
  119. url: `/pagesMessage/message/info?id=${e._id}`
  120. })
  121. },
  122. // 分页
  123. toPage(e) {
  124. const that = this;
  125. let list = that.marketList;
  126. let limit = that.limit;
  127. if (that.total > list.length) {
  128. uni.showLoading({
  129. title: '加载中',
  130. mask: true
  131. })
  132. let page = that.page + 1;
  133. that.$set(that, `page`, page)
  134. let skip = page * limit;
  135. that.$set(that, `skip`, skip)
  136. that.searchMarket();
  137. uni.hideLoading();
  138. }
  139. },
  140. clearPage() {
  141. const that = this;
  142. that.$set(that, `list`, [])
  143. that.$set(that, `skip`, 0)
  144. that.$set(that, `limit`, 10)
  145. that.$set(that, `page`, 0)
  146. },
  147. // 菜单跳转
  148. toPath(e) {
  149. let url = `/${e.route}`;
  150. if (e.type == '0') uni.redirectTo({
  151. url
  152. })
  153. else {
  154. uni.navigateTo({
  155. url
  156. })
  157. }
  158. },
  159. }
  160. }
  161. </script>
  162. <style lang="scss">
  163. .main {
  164. display: flex;
  165. flex-direction: column;
  166. width: 96vw;
  167. padding: 2vw;
  168. background-color: var(--f1Color);
  169. .one {
  170. input {
  171. padding: 2vw;
  172. background-color: #ffffff;
  173. font-size: var(--font14Size);
  174. border-radius: 10px;
  175. }
  176. }
  177. .two {
  178. margin: 1vw 0 0 0;
  179. .list {
  180. display: flex;
  181. padding: 2vw;
  182. margin: 1vw 0 0 0;
  183. background-color: #ffffff;
  184. border-radius: 10px;
  185. .image {
  186. width: 15vw;
  187. height: 15vw;
  188. border-radius: 15vw;
  189. border: 1px solid #C0C0C0;
  190. }
  191. .content {
  192. width: 40vw;
  193. padding: 2vw;
  194. .name {
  195. font-size: 16px;
  196. padding: 1vw 0;
  197. }
  198. .news {
  199. font-size: 12px;
  200. color: #C0C0C0;
  201. }
  202. }
  203. .time {
  204. width: 32vw;
  205. text-align: right;
  206. padding: 2vw 0;
  207. font-size: 12px;
  208. color: #C0C0C0;
  209. .time_1 {
  210. margin: 0 0 1vw 0;
  211. }
  212. }
  213. }
  214. }
  215. }
  216. .scroll-view {
  217. position: absolute;
  218. top: 0;
  219. left: 0;
  220. right: 0;
  221. bottom: 0;
  222. .list-scroll-view {
  223. display: flex;
  224. flex-direction: column;
  225. }
  226. }
  227. </style>