group.vue 11 KB

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