index.vue 5.9 KB

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