index.vue 5.6 KB

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