index.vue 6.5 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_1"><text>人均消费:</text>¥{{ item.money ||'暂无'}}</view> -->
  20. <view class="other other_2"><text>营业时间:</text>{{ item.open_time||'暂无' }}</view>
  21. <view class="other other_2"><text>联系电话:</text>{{ item.phone||'暂无' }}</view>
  22. <view class="other other_2 textOne">{{ item.address ||'暂无'}}</view>
  23. </view>
  24. </view>
  25. <view class="is_bottom" v-if="is_bottom">
  26. <text>{{config.bottom_title||'到底了!'}}</text>
  27. </view>
  28. </view>
  29. </scroll-view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import moment from 'moment';
  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. type: that.type
  97. }
  98. if (that.user._id) info.user = that.user._id
  99. const res = await that.$api(`/location/location`, 'GET', {
  100. ...info,
  101. ...that.searchInfo
  102. })
  103. if (res.errcode == '0') {
  104. let list = [...that.list, ...res.data];
  105. that.$set(that, `list`, list)
  106. that.$set(that, `total`, res.total)
  107. } else {
  108. uni.showToast({
  109. title: res.errmsg,
  110. });
  111. }
  112. },
  113. // 输入框
  114. toInput(e) {
  115. const that = this;
  116. if (that.searchInfo.name) that.$set(that.searchInfo, `name`, e.detail.value)
  117. else that.$set(that, `searchInfo`, {})
  118. that.clearPage();
  119. that.search();
  120. },
  121. // 详情
  122. toInfo(e) {
  123. uni.navigateTo({
  124. url: `/pagesHome/type/info?id=${e.id||e._id}`
  125. })
  126. },
  127. // 收藏
  128. async onClick(item) {
  129. const that = this;
  130. let res;
  131. if (item.is_collect == false) {
  132. const form = {
  133. user: that.user._id,
  134. source: item._id,
  135. source_type: "location",
  136. type: '1',
  137. create_time: moment().format('YYYY-MM-DD HH:mm:ss'),
  138. }
  139. res = await that.$api(`/like`, 'POST', form);
  140. } else res = await that.$api(`/like/${item.like}`, 'DELETE', {})
  141. if (res.errcode == '0') {
  142. that.clearPage();
  143. that.search()
  144. }
  145. },
  146. // 分页
  147. toPage(e) {
  148. const that = this;
  149. let list = that.list;
  150. let limit = that.limit;
  151. if (that.total > list.length) {
  152. uni.showLoading({
  153. title: '加载中',
  154. mask: true
  155. })
  156. let page = that.page + 1;
  157. that.$set(that, `page`, page)
  158. let skip = page * limit;
  159. that.$set(that, `skip`, skip)
  160. that.searchComment();
  161. uni.hideLoading();
  162. } else that.$set(that, `is_bottom`, true)
  163. },
  164. // 触底
  165. toScroll(e) {
  166. const that = this;
  167. let up = that.scrollTop;
  168. that.$set(that, `scrollTop`, e.detail.scrollTop);
  169. let num = Math.sign(up - e.detail.scrollTop);
  170. if (num == 1) that.$set(that, `is_bottom`, false);
  171. },
  172. // 清空列表
  173. clearPage() {
  174. const that = this;
  175. that.$set(that, `list`, [])
  176. that.$set(that, `skip`, 0)
  177. that.$set(that, `limit`, 10)
  178. that.$set(that, `page`, 0)
  179. },
  180. }
  181. }
  182. </script>
  183. <style lang="scss" scoped>
  184. .main {
  185. display: flex;
  186. flex-direction: column;
  187. width: 100vw;
  188. height: 100vh;
  189. .one {
  190. display: flex;
  191. justify-content: center;
  192. align-items: center;
  193. padding: 2vw;
  194. input {
  195. width: 100%;
  196. padding: 2vw;
  197. background-color: var(--f1Color);
  198. font-size: var(--font14Size);
  199. border-radius: 5px;
  200. }
  201. }
  202. .two {
  203. position: relative;
  204. flex-grow: 1;
  205. background-color: var(--f9Color);
  206. margin: 2vw 0 0 0;
  207. .list {
  208. display: flex;
  209. background-color: var(--mainColor);
  210. border: 1px solid var(--f5Color);
  211. padding: 2vw;
  212. margin: 2vw 2vw 0 2vw;
  213. border-radius: 5px;
  214. .image {
  215. width: 22vw;
  216. height: 22vw;
  217. border-radius: 5px;
  218. }
  219. .list_1 {
  220. width: 67vw;
  221. padding: 0 0 0 2vw;
  222. .top {
  223. display: flex;
  224. justify-content: space-between;
  225. align-items: center;
  226. .name {
  227. width: 50vw;
  228. font-size: var(--font14Size);
  229. font-weight: bold;
  230. padding: 0 0 1vw 0;
  231. }
  232. }
  233. .other {
  234. font-size: var(--font12Size);
  235. padding: 0 0 2px 0;
  236. text {
  237. color: #000;
  238. }
  239. }
  240. .other_1 {
  241. color: red;
  242. }
  243. .other_2 {
  244. color: var(--f85Color);
  245. }
  246. }
  247. }
  248. }
  249. }
  250. .scroll-view {
  251. position: absolute;
  252. top: 0;
  253. left: 0;
  254. right: 0;
  255. bottom: 0;
  256. .list-scroll-view {
  257. display: flex;
  258. flex-direction: column;
  259. }
  260. }
  261. .is_bottom {
  262. width: 100%;
  263. text-align: center;
  264. text {
  265. padding: 2vw 0;
  266. display: inline-block;
  267. color: var(--f85Color);
  268. font-size: var(--font14Size);
  269. }
  270. }
  271. </style>