index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <view class="main">
  3. <view class="one">
  4. <input type="text" v-model="searchInfo.name" @input="toInput" placeholder="搜索名称">
  5. </view>
  6. <view class="two">
  7. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  8. <view class="list-scroll-view">
  9. <view class="list" v-for="(item, index) in list" :key="index" @tap="toInfo(item)">
  10. <image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''" mode="aspectFill">
  11. </image>
  12. <view class="list_1">
  13. <view class="name textOne">{{ item.name ||'暂无'}}</view>
  14. <view class="other other_2"><text>入离时间:</text>{{ item.start_time||'暂无' }}-{{ item.end_time||'暂无' }}</view>
  15. <view class="other other_2"><text>联系电话:</text>{{ item.phone||'暂无' }}</view>
  16. <view class="other other_2 textOne">{{ item.address ||'暂无'}}</view>
  17. </view>
  18. </view>
  19. <view class="is_bottom" v-if="is_bottom">
  20. <text>{{config.bottom_title||'到底了!'}}</text>
  21. </view>
  22. </view>
  23. </scroll-view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. data() {
  30. return {
  31. type: '',
  32. searchInfo: {},
  33. config: {},
  34. user: {},
  35. list: [],
  36. total: 0,
  37. skip: 0,
  38. limit: 10,
  39. page: 0,
  40. // 数据是否触底
  41. is_bottom: false,
  42. scrollTop: 0,
  43. }
  44. },
  45. onLoad: async function(e) {
  46. const that = this;
  47. that.$set(that, `type`, e && e.type || '');
  48. uni.setNavigationBarTitle({
  49. title: e && e.title || '分类'
  50. });
  51. that.searchConfig();
  52. that.searchToken();
  53. that.search();
  54. },
  55. methods: {
  56. searchToken() {
  57. const that = this;
  58. try {
  59. const res = uni.getStorageSync('token');
  60. if (res) that.$set(that, `user`, res);
  61. } catch (e) {
  62. uni.showToast({
  63. title: err.errmsg,
  64. icon: 'error',
  65. duration: 2000
  66. });
  67. }
  68. },
  69. searchConfig() {
  70. const that = this;
  71. try {
  72. const res = uni.getStorageSync('config');
  73. if (res) that.$set(that, `config`, res);
  74. } catch (e) {
  75. uni.showToast({
  76. title: err.errmsg,
  77. icon: 'error',
  78. duration: 2000
  79. });
  80. }
  81. },
  82. // 查询
  83. async search() {
  84. const that = this;
  85. let info = {
  86. skip: that.skip,
  87. limit: that.limit,
  88. is_use: '0',
  89. status: '1'
  90. }
  91. const res = await that.$api(`/hotel`, 'GET', {
  92. ...info,
  93. ...that.searchInfo
  94. })
  95. if (res.errcode == '0') {
  96. let list = [...that.list, ...res.data];
  97. that.$set(that, `list`, list)
  98. that.$set(that, `total`, res.total)
  99. } else {
  100. uni.showToast({
  101. title: res.errmsg,
  102. });
  103. }
  104. },
  105. // 输入框
  106. toInput(e) {
  107. const that = this;
  108. if (that.searchInfo.name) that.$set(that.searchInfo, `name`, e.detail.value)
  109. else that.$set(that, `searchInfo`, {})
  110. that.clearPage();
  111. that.search();
  112. },
  113. // 详情
  114. toInfo(e) {
  115. uni.navigateTo({
  116. url: `/pagesHome/hotel/info?id=${e.id||e._id}`
  117. })
  118. },
  119. // 分页
  120. toPage(e) {
  121. const that = this;
  122. let list = that.list;
  123. let limit = that.limit;
  124. if (that.total > list.length) {
  125. uni.showLoading({
  126. title: '加载中',
  127. mask: true
  128. })
  129. let page = that.page + 1;
  130. that.$set(that, `page`, page)
  131. let skip = page * limit;
  132. that.$set(that, `skip`, skip)
  133. that.searchComment();
  134. uni.hideLoading();
  135. } else that.$set(that, `is_bottom`, true)
  136. },
  137. // 触底
  138. toScroll(e) {
  139. const that = this;
  140. let up = that.scrollTop;
  141. that.$set(that, `scrollTop`, e.detail.scrollTop);
  142. let num = Math.sign(up - e.detail.scrollTop);
  143. if (num == 1) that.$set(that, `is_bottom`, false);
  144. },
  145. // 清空列表
  146. clearPage() {
  147. const that = this;
  148. that.$set(that, `list`, [])
  149. that.$set(that, `skip`, 0)
  150. that.$set(that, `limit`, 10)
  151. that.$set(that, `page`, 0)
  152. },
  153. }
  154. }
  155. </script>
  156. <style lang="scss" scoped>
  157. .main {
  158. display: flex;
  159. flex-direction: column;
  160. width: 100vw;
  161. height: 100vh;
  162. .one {
  163. display: flex;
  164. justify-content: center;
  165. align-items: center;
  166. padding: 2vw;
  167. input {
  168. width: 100%;
  169. padding: 2vw;
  170. background-color: var(--f1Color);
  171. font-size: var(--font14Size);
  172. border-radius: 5px;
  173. }
  174. }
  175. .two {
  176. position: relative;
  177. flex-grow: 1;
  178. background-color: var(--f9Color);
  179. margin: 2vw 0 0 0;
  180. .list {
  181. display: flex;
  182. background-color: var(--mainColor);
  183. border: 1px solid var(--f5Color);
  184. padding: 2vw;
  185. margin: 2vw 2vw 0 2vw;
  186. border-radius: 5px;
  187. .image {
  188. width: 20vw;
  189. height: 20vw;
  190. border-radius: 5px;
  191. }
  192. .list_1 {
  193. width: 68vw;
  194. padding: 0 0 0 2vw;
  195. .name {
  196. font-size: var(--font14Size);
  197. font-weight: bold;
  198. padding: 0 0 1vw 0;
  199. }
  200. .other {
  201. font-size: var(--font12Size);
  202. padding: 0 0 2px 0;
  203. text {
  204. color: #000;
  205. }
  206. }
  207. .other_1 {
  208. color: red;
  209. }
  210. .other_2 {
  211. color: var(--f85Color);
  212. }
  213. }
  214. }
  215. }
  216. }
  217. .scroll-view {
  218. position: absolute;
  219. top: 0;
  220. left: 0;
  221. right: 0;
  222. bottom: 0;
  223. .list-scroll-view {
  224. display: flex;
  225. flex-direction: column;
  226. }
  227. }
  228. .is_bottom {
  229. width: 100%;
  230. text-align: center;
  231. text {
  232. padding: 2vw 0;
  233. display: inline-block;
  234. color: var(--f85Color);
  235. font-size: var(--font14Size);
  236. }
  237. }
  238. </style>