index.vue 6.4 KB

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