index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 textOver">{{ 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">{{ 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. toPage(e) {
  116. const that = this;
  117. let list = that.list;
  118. let limit = that.limit;
  119. if (that.total > list.length) {
  120. uni.showLoading({
  121. title: '加载中',
  122. mask: true
  123. })
  124. let page = that.page + 1;
  125. that.$set(that, `page`, page)
  126. let skip = page * limit;
  127. that.$set(that, `skip`, skip)
  128. that.searchComment();
  129. uni.hideLoading();
  130. } else that.$set(that, `is_bottom`, true)
  131. },
  132. // 触底
  133. toScroll(e) {
  134. const that = this;
  135. let up = that.scrollTop;
  136. that.$set(that, `scrollTop`, e.detail.scrollTop);
  137. let num = Math.sign(up - e.detail.scrollTop);
  138. if (num == 1) that.$set(that, `is_bottom`, false);
  139. },
  140. // 清空列表
  141. clearPage() {
  142. const that = this;
  143. that.$set(that, `list`, [])
  144. that.$set(that, `skip`, 0)
  145. that.$set(that, `limit`, 10)
  146. that.$set(that, `page`, 0)
  147. },
  148. }
  149. }
  150. </script>
  151. <style lang="scss" scoped>
  152. .main {
  153. display: flex;
  154. flex-direction: column;
  155. width: 100vw;
  156. height: 100vh;
  157. .one {
  158. display: flex;
  159. justify-content: center;
  160. align-items: center;
  161. padding: 2vw;
  162. input {
  163. width: 100%;
  164. padding: 2vw;
  165. background-color: var(--f1Color);
  166. font-size: var(--font14Size);
  167. border-radius: 5px;
  168. }
  169. }
  170. .two {
  171. position: relative;
  172. flex-grow: 1;
  173. background-color: var(--f9Color);
  174. margin: 2vw 0 0 0;
  175. .list {
  176. display: flex;
  177. background-color: var(--mainColor);
  178. border: 1px solid var(--f5Color);
  179. padding: 2vw;
  180. margin: 2vw 2vw 0 2vw;
  181. border-radius: 5px;
  182. .image {
  183. width: 25vw;
  184. height: 25vw;
  185. border-radius: 5px;
  186. }
  187. .list_1 {
  188. width: 63vw;
  189. padding: 0 0 0 2vw;
  190. .name {
  191. font-size: var(--font14Size);
  192. font-weight: bold;
  193. padding: 0 0 1vw 0;
  194. }
  195. .other {
  196. font-size: var(--font12Size);
  197. padding: 0 0 2px 0;
  198. text {
  199. color: #000;
  200. }
  201. }
  202. .other_1 {
  203. color: red;
  204. }
  205. .other_2 {
  206. color: var(--f85Color);
  207. overflow: hidden;
  208. white-space: nowrap;
  209. text-overflow: ellipsis;
  210. -o-text-overflow: ellipsis;
  211. }
  212. }
  213. }
  214. }
  215. }
  216. .scroll-view {
  217. position: absolute;
  218. top: 0;
  219. left: 0;
  220. right: 0;
  221. bottom: 0;
  222. .list-scroll-view {
  223. display: flex;
  224. flex-direction: column;
  225. }
  226. }
  227. .is_bottom {
  228. width: 100%;
  229. text-align: center;
  230. text {
  231. padding: 2vw 0;
  232. display: inline-block;
  233. color: var(--f85Color);
  234. font-size: var(--font14Size);
  235. }
  236. }
  237. </style>