index.vue 5.7 KB

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