index.vue 6.7 KB

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