group.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. <template>
  2. <view class="group-box iPhone-bottom box-border-box flex-common-css">
  3. <Nav class="nav-b" title='团购专区'></Nav>
  4. <scroll-view :scroll-y="true" class="scroll-view-box" @scroll='scroll' @scrolltolower="scrolltolower"
  5. :scroll-top='scroll_top' :scroll-with-animation="false">
  6. <view class="">
  7. <view class="box-border-box p-12-24 search-box">
  8. <view class="head-search align-items-center">
  9. <!-- <uni-icons class="s-icon" type="search" size="19"></uni-icons> -->
  10. <image class="wh-32" src="@/static/img/index/ss.png" mode=""></image>
  11. <input class="input" v-model="fromData.search" type="text" placeholder="搜一搜带你玩周边">
  12. <view class="head-search-buttom text-align-center fs-28 fw-500 fc-f" @click="searchFun()">搜索
  13. </view>
  14. </view>
  15. </view>
  16. <view class="p-12-24 box-border-box class-b">
  17. <view class="display-flex p-24 box-border-box nav-list bgc-f b-rad-16 mb-12">
  18. <view class="text-align-center nav-item" v-for="(item,i) in navList" :key="i"
  19. @click="selectType(item.id)">
  20. <image class="nav-img" :src="item.img" mode="scaleToFill"></image>
  21. <view class="fs-24 w-96"
  22. :class="fromData.category_id == item.id?'fw-600 fc-41ABF5':'fw-400'">{{item.name}}
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="p-12-24 box-border-box sift-box align-items-center" :class="siftType?'bgc-f':''"
  28. @touchmove.stop.prevent="stopScroll">
  29. <view class="mr-20 sift-item align-items-center flex-justify-center"
  30. :class="[{'bgc-F5F5F6':siftType},{'bgc-f':!siftType},{'siftClass':siftClassID === 1 && pop_type}]"
  31. @click="siftClick(1)">
  32. <view class=""
  33. :class="[{'fc-41ABF5':(siftClassID === 1 && pop_type) || fromData.distance != 0}]">
  34. {{siftDistance}}
  35. </view>
  36. </view>
  37. <view class="mr-12 sift-item align-items-center flex-justify-center"
  38. :class="[{'bgc-F5F5F6':siftType},{'bgc-f':!siftType},{'siftClass':siftClassID === 2 && pop_type}]"
  39. @click="siftClick(2)">
  40. <view class=""
  41. :class="[{'fc-41ABF5':(siftClassID === 2 && pop_type) || fromData.orderBy != 0}]">
  42. {{siftSort}}
  43. </view>
  44. </view>
  45. <view class="pop-content" :style="[{'top': pop_top + 'px'}]"
  46. :class="pop_type?'pop-box-true':'pop-box-false'" @click="gbPopType">
  47. <view class="pop-select-box" @click.stop="noPopType">
  48. <view class="select-box p-24 box-border-box">
  49. <view class="distance-box" v-show="siftClassID === 1">
  50. <view class="mb-16 fs-30 fc-3 fw-500">
  51. 我的附近
  52. </view>
  53. <view class="align-items-center flex-wrap-wrap">
  54. <view class="distance-label text-align-center mb-12"
  55. v-for="(item,index) in distance_label" :key="item.id"
  56. :class="fromData.distance===item.id?'siftClass':'bgc-F5F5F6'"
  57. @click="distanceClick(item)">
  58. {{item.name}}
  59. </view>
  60. </view>
  61. </view>
  62. <view class="sort-box" v-show="siftClassID === 2">
  63. <view class="sort-select-box text-align-left" v-for="(item,index) in sort_label"
  64. :key="item.id" @click="sortSelectClick(item)"
  65. :class="fromData.orderBy===item.id?'fc-41ABF5':''">
  66. {{item.name}}
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. <view v-show="pop_type" :style="[{'top': pop_top + 'px'}]" class="pop-mask" @click="gbPopType"
  74. @touchmove.stop.prevent="stopScroll"></view>
  75. <view class="p-12-24 box-border-box">
  76. <shopListVue ref="shopListRef"></shopListVue>
  77. </view>
  78. </view>
  79. </scroll-view>
  80. </view>
  81. </template>
  82. <script>
  83. import {
  84. groupList
  85. } from '@/api/groupOrder.js';
  86. import tools from "@/service/tools";
  87. import shopListVue from './group-mod/shop-list.vue';
  88. import {
  89. getGroup
  90. } from "@/api/category.js"
  91. export default {
  92. components: {
  93. shopListVue
  94. },
  95. data() {
  96. return {
  97. fromData: {
  98. operate_id: '',
  99. lat: '',
  100. lon: '',
  101. search: '',
  102. category_id: 0,
  103. distance: 0,
  104. orderBy: 0,
  105. page: 1
  106. },
  107. navList: [{
  108. name: "全部",
  109. id: 0,
  110. img: require('@/static/img/buy/t-all.png')
  111. }],
  112. siftType: false, // 粘性状态
  113. siftClassID: 0, // 粘性样式Id
  114. scrollTopNum: 0, //当前滚动条高度
  115. scroll_top: 0, //滚动条高度
  116. pop_top: 0, // pop距头部距离
  117. pop_type: false,
  118. navListHeight: '', //头部模块高度
  119. siftDistance: '附近', //距离筛选
  120. siftSort: '默认排序', //排序筛选
  121. distance_label: [{
  122. name: '附近',
  123. id: 0
  124. }, {
  125. name: '500m',
  126. id: 0.5
  127. }, {
  128. name: '1km',
  129. id: 1
  130. }, {
  131. name: '3km',
  132. id: 3
  133. }, {
  134. name: '5km',
  135. id: 5
  136. }, {
  137. name: '10km',
  138. id: 10
  139. }],
  140. sort_label: [{
  141. name: '默认排序',
  142. id: 0
  143. }, {
  144. name: '距离优先',
  145. id: 1
  146. }, {
  147. name: '销量优先',
  148. id: 2
  149. }]
  150. }
  151. },
  152. onShow() {
  153. this.getGroup()
  154. this.fromData.page = 1;
  155. this.getList();
  156. },
  157. onLoad() {},
  158. mounted() {
  159. this.getHeight()
  160. },
  161. methods: {
  162. distanceClick(item) {
  163. // 距离筛选
  164. if (this.fromData.distance === item.id) {
  165. this.gbPopType()
  166. } else {
  167. this.fromData.distance = item.id
  168. this.siftDistance = item.name
  169. this.fromData.page = 1;
  170. this.getList()
  171. this.gbPopType()
  172. }
  173. },
  174. sortSelectClick(item) {
  175. // 排序筛选
  176. if (this.fromData.orderBy === item.id) {
  177. this.gbPopType()
  178. } else {
  179. this.fromData.orderBy = item.id
  180. this.siftSort = item.name
  181. this.fromData.page = 1;
  182. this.getList()
  183. this.gbPopType()
  184. }
  185. },
  186. selectType(num) {
  187. if (this.fromData.category_id === num) {
  188. return
  189. }
  190. this.fromData.category_id = num
  191. this.fromData.page = 1;
  192. this.getList()
  193. },
  194. noPopType() {},
  195. stopScroll(event) {
  196. // 阻止默认的滑动行为
  197. event.preventDefault();
  198. },
  199. siftClick(num) {
  200. this.scroll_top = this.scrollTopNum
  201. if (this.scrollTopNum < this.navListHeight) {
  202. this.$nextTick(function() {
  203. this.scroll_top = this.navListHeight
  204. });
  205. }
  206. if (this.pop_type && this.siftClassID === num) {
  207. this.pop_type = false
  208. } else {
  209. setTimeout(() => {
  210. this.siftClassID = num
  211. this.pop_type = true
  212. }, 200)
  213. }
  214. },
  215. gbPopType() {
  216. this.pop_type = !this.pop_type
  217. },
  218. scroll(e) {
  219. this.scrollTopNum = e.detail.scrollTop
  220. if (e.detail.scrollTop > (this.navListHeight - 1)) {
  221. this.siftType = true
  222. } else {
  223. this.siftType = false
  224. }
  225. },
  226. getHeight() {
  227. this.$nextTick(() => {
  228. let HThree = 0
  229. const navH = uni.createSelectorQuery().in(this);
  230. navH.select('.search-box').boundingClientRect(data => {
  231. if (data) {
  232. // data.height 就是元素的高度
  233. HThree = data.height
  234. console.log(HThree, '333333333');
  235. }
  236. }).exec();
  237. const query = uni.createSelectorQuery().in(this);
  238. query.select('.class-b').boundingClientRect(data => {
  239. if (data) {
  240. // data.height 就是元素的高度
  241. this.navListHeight = Number(data.height) + Number(HThree)
  242. }
  243. }).exec()
  244. let Hone = 0
  245. uni.getSystemInfo({
  246. success: (e) => {
  247. let statusBarH = e.statusBarHeight + 10
  248. let custom = 0;
  249. custom = wx.getMenuButtonBoundingClientRect()
  250. let customBarH = custom.height;
  251. Hone = statusBarH + customBarH;
  252. }
  253. })
  254. let HTwo = 0
  255. const navT = uni.createSelectorQuery().in(this);
  256. navT.select('.sift-box').boundingClientRect(data => {
  257. if (data) {
  258. // data.height 就是元素的高度
  259. HTwo = data.height
  260. console.log(HTwo, '222222222');
  261. }
  262. }).exec();
  263. setTimeout(() => {
  264. this.pop_top = Number(Hone) + Number(HTwo)
  265. console.log(this.pop_top, '-----------');
  266. }, 500)
  267. })
  268. },
  269. scrolltolower(e) {
  270. ++this.fromData.page
  271. this.getList()
  272. },
  273. getGroup() {
  274. let operate_id = uni.getStorageSync('operate_id');
  275. let school_id = uni.getStorageSync('school_id');
  276. this.navList = {
  277. name: "全部",
  278. id: 0,
  279. img: require('@/static/img/buy/t-all.png')
  280. }
  281. getGroup({
  282. operate_id: operate_id,
  283. school_id: school_id
  284. }).then((res) => {
  285. if (res.code === 1) {
  286. this.navList = [this.navList, ...res.data]
  287. }
  288. })
  289. },
  290. searchFun() {
  291. if (this.fromData.search) {
  292. this.fromData.page = 1;
  293. this.getList()
  294. } else {
  295. tools.error("请输入搜索内容")
  296. }
  297. },
  298. getList() {
  299. this.fromData.operate_id = uni.getStorageSync('operate_id');
  300. this.fromData.lon = uni.getStorageSync('lon');
  301. this.fromData.lat = uni.getStorageSync('lat');
  302. console.log(this.fromData);
  303. this.$refs.shopListRef.groupShop(this.fromData)
  304. }
  305. },
  306. }
  307. </script>
  308. <style scoped lang="scss">
  309. .select-box {}
  310. .distance-box {}
  311. .sort-box {}
  312. .distance-label {
  313. width: 32%;
  314. height: 60rpx;
  315. line-height: 60rpx;
  316. border-radius: 8rpx;
  317. margin-right: 1%;
  318. }
  319. .sort-select-box {
  320. width: 100%;
  321. height: 40rpx;
  322. line-height: 40rpx;
  323. padding: 15rpx 0;
  324. }
  325. .pop-box-true {
  326. // display: block;
  327. // transition: all .3s inherit;
  328. /* 定义过渡效果 */
  329. height: 500rpx;
  330. // height: 200rpx;
  331. // min-height: 200rpx;
  332. transition: height 0.3s ease-in-out;
  333. // transform: translateY(0);
  334. }
  335. .pop-box-false {
  336. // display: none;
  337. height: 0px;
  338. transition: height 0.3s ease-in-out;
  339. // transform: translateY(-250px);
  340. }
  341. .pop-content {
  342. width: 100%;
  343. // height: 500rpx;
  344. background: transparent;
  345. position: fixed;
  346. left: 0;
  347. // top: var(--pop_top)px;
  348. z-index: 10;
  349. overflow: auto;
  350. // transition: all .3s inherit;
  351. /* 定义过渡效果 */
  352. /* 初始平移状态 */
  353. }
  354. .pop-select-box {
  355. position: relative;
  356. z-index: 15;
  357. background: #fff;
  358. border-radius: 0 0 20rpx 20rpx;
  359. }
  360. .pop-mask {
  361. width: 100%;
  362. height: 100vh;
  363. background: rgba(0, 0, 0, .5);
  364. position: fixed;
  365. left: 0;
  366. z-index: 10;
  367. // top: 0;
  368. }
  369. .siftClass {
  370. color: #41ABF5;
  371. border: 1rpx solid #41ABF5;
  372. background: #deeffb;
  373. box-sizing: border-box;
  374. }
  375. .h-200 {
  376. width: 100%;
  377. height: 200px;
  378. margin-bottom: 20px;
  379. background: rebeccapurple;
  380. }
  381. .scroll-view-box {
  382. overflow: auto;
  383. position: relative;
  384. }
  385. .sift-box {
  386. position: sticky;
  387. top: 0;
  388. left: 0;
  389. z-index: 200;
  390. overflow-x: scroll;
  391. }
  392. .sift-content-box {
  393. width: 100%;
  394. height: 300rpx;
  395. position: absolute;
  396. top: 74rpx;
  397. left: 0;
  398. }
  399. .sift-item {
  400. min-width: 150rpx;
  401. max-width: 280rpx;
  402. height: 60rpx;
  403. line-height: 60rpx;
  404. border-radius: 8rpx;
  405. transition: all .5s ease;
  406. }
  407. .group-box {}
  408. .nav-list {
  409. overflow-x: scroll;
  410. }
  411. .nav-item {
  412. width: 96rpx;
  413. height: 126rpx;
  414. margin-right: 48rpx;
  415. }
  416. .nav-img {
  417. width: 80rpx;
  418. height: 80rpx;
  419. border-radius: 5px;
  420. margin: 0 auto 12rpx auto;
  421. }
  422. .head-search {
  423. width: 100%;
  424. position: relative;
  425. }
  426. .s-icon {
  427. position: absolute;
  428. left: 24rpx;
  429. top: 20rpx;
  430. }
  431. .input {
  432. width: 100%;
  433. height: 72rpx;
  434. background: #FFFFFF;
  435. border-radius: 200rpx;
  436. box-sizing: border-box;
  437. padding: 0 130rpx 0 68rpx;
  438. font-size: 32rpx;
  439. }
  440. .head-search-buttom {
  441. width: 120rpx;
  442. height: 60rpx;
  443. background: linear-gradient(90deg, #2CE6F8 0%, #41ABF5 100%);
  444. border-radius: 200rpx;
  445. line-height: 60rpx;
  446. position: absolute;
  447. right: 6rpx;
  448. top: 6rpx;
  449. }
  450. .wh-32 {
  451. position: absolute;
  452. left: 24rpx;
  453. top: 20rpx;
  454. width: 32rpx;
  455. height: 32rpx;
  456. }
  457. </style>