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