group.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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="p-12-24 box-border-box class-b">
  8. <view class="display-flex p-24 box-border-box nav-list bgc-f b-rad-16 mb-12">
  9. <view class="text-align-center nav-item" v-for="(item,i) in navList" :key="i"
  10. @click="selectType(item.id)">
  11. <image class="nav-img" :src="item.img" mode="scaleToFill"></image>
  12. <view class="fs-24 w-96" :class="navId == item.id?'fw-600 fc-41ABF5':'fw-400'">{{item.name}}
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. <view class="p-12-24 box-border-box sift-box align-items-center" :class="siftType?'bgc-f':''">
  18. <view class="mr-20 sift-item align-items-center flex-justify-center"
  19. :class="[{'bgc-F5F5F6':siftType},{'bgc-f':!siftType},{'siftClass':siftClassID === 1}]"
  20. @click="siftClick(1)">
  21. <view class="" :class="[{'fc-41ABF5':siftClassID === 1}]">
  22. {{siftDistance}}
  23. </view>
  24. </view>
  25. <view class="mr-12 sift-item align-items-center flex-justify-center"
  26. :class="[{'bgc-F5F5F6':siftType},{'bgc-f':!siftType},{'siftClass':siftClassID === 2}]"
  27. @click="siftClick(2)">
  28. <view class="" :class="[{'fc-41ABF5':siftClassID === 2}]">
  29. {{siftSort}}
  30. </view>
  31. </view>
  32. <view v-show="pop_type" class="pop-box" :style="[{'top': pop_top + 'px'}]">
  33. <view class="pop-content" :class="pop_type?'pop-box-true':'pop-box-false'">
  34. </view>
  35. <view class="pop-mask" @click="pop_type = !pop_type"></view>
  36. </view>
  37. </view>
  38. <view class="p-12-24 box-border-box">
  39. <view class="h-200" v-for="(item,index) in 10">
  40. </view>
  41. </view>
  42. </view>
  43. </scroll-view>
  44. </view>
  45. </template>
  46. <script>
  47. import {
  48. groupList
  49. } from '@/api/groupOrder.js';
  50. import tools from "@/service/tools";
  51. import EnBlank from "@/components/en-utils/en-blank/en-blank";
  52. import {
  53. getGroup
  54. } from "@/api/category.js"
  55. export default {
  56. components: {
  57. EnBlank
  58. },
  59. data() {
  60. return {
  61. navId: 0,
  62. navList: [{
  63. name: "全部",
  64. id: 0,
  65. img: require('@/static/img/buy/t-all.png')
  66. }],
  67. siftType: false, // 粘性状态
  68. siftClassID: 0, // 粘性样式Id
  69. scrollTopNum: 0, //当前滚动条高度
  70. scroll_top: 0, //滚动条高度
  71. pop_top: 0, // pop距头部距离
  72. pop_type: false,
  73. navListHeight: '', //头部模块高度
  74. siftDistance: '附近', //距离筛选
  75. siftSort: '距离优先', //排序筛选
  76. page: 1,
  77. total: 0,
  78. list: []
  79. }
  80. },
  81. onReachBottom() {
  82. if (this.list.length < this.total) {
  83. this.page += 1;
  84. this.getList();
  85. }
  86. },
  87. onShow() {
  88. this.getGroup()
  89. this.page = 1;
  90. this.list = [];
  91. this.getList();
  92. },
  93. onLoad() {},
  94. mounted() {
  95. this.getHeight()
  96. },
  97. methods: {
  98. siftClick(num) {
  99. this.scroll_top = this.scrollTopNum
  100. this.$nextTick(function() {
  101. this.scroll_top = this.navListHeight
  102. });
  103. setTimeout(() => {
  104. this.siftClassID = num
  105. this.pop_type = true
  106. }, 400)
  107. },
  108. scroll(e) {
  109. this.scrollTopNum = e.detail.scrollTop
  110. if (e.detail.scrollTop > (this.navListHeight - 1)) {
  111. this.siftType = true
  112. } else {
  113. this.siftType = false
  114. }
  115. },
  116. getHeight() {
  117. const query = uni.createSelectorQuery().in(this);
  118. query.select('.class-b').boundingClientRect(data => {
  119. if (data) {
  120. // data.height 就是元素的高度
  121. this.navListHeight = data.height
  122. }
  123. }).exec()
  124. let Hone = 0
  125. uni.getSystemInfo({
  126. success: (e) => {
  127. let statusBarH = e.statusBarHeight + 10
  128. let custom = 0;
  129. custom = wx.getMenuButtonBoundingClientRect()
  130. let customBarH = custom.height;
  131. Hone = statusBarH + customBarH;
  132. }
  133. })
  134. let HTwo = 0
  135. const navT = uni.createSelectorQuery().in(this);
  136. navT.select('.sift-box').boundingClientRect(data => {
  137. if (data) {
  138. // data.height 就是元素的高度
  139. HTwo = data.height
  140. console.log(HTwo, '222222222');
  141. }
  142. }).exec();
  143. setTimeout(() => {
  144. this.pop_top = Number(Hone) + Number(HTwo)
  145. console.log(this.pop_top, '-----------');
  146. }, 500)
  147. },
  148. scrolltolower(e) {
  149. console.log(e);
  150. },
  151. getGroup() {
  152. let operate_id = uni.getStorageSync('operate_id');
  153. let school_id = uni.getStorageSync('school_id');
  154. getGroup({
  155. operate_id: operate_id,
  156. school_id: school_id
  157. }).then((res) => {
  158. if (res.code === 1) {
  159. this.navList = [...this.navList, ...res.data]
  160. }
  161. })
  162. },
  163. getList() {
  164. let school_id = uni.getStorageSync('school_id');
  165. groupList({
  166. school_id: school_id,
  167. page: this.page
  168. }).then((res) => {
  169. if (res.code === 1) {
  170. this.list = [...this.list, ...res.data.items];
  171. this.total = res.data.total;
  172. }
  173. })
  174. },
  175. todet(item) {
  176. uni.navigateTo({
  177. url: '/pages-buy/group-det?id=' + item.id
  178. })
  179. }
  180. },
  181. }
  182. </script>
  183. <style scoped lang="scss">
  184. .pop-box {
  185. width: 100%;
  186. height: 100vh;
  187. position: fixed;
  188. left: 0;
  189. top: 0;
  190. overflow: hidden;
  191. transition: all .3s linear;
  192. }
  193. .pop-box-true {
  194. height: 500rpx;
  195. transition: all .3s linear;
  196. /* 定义过渡效果 */
  197. // transform: translateY(-200px);
  198. }
  199. .pop-box-false {
  200. height: 0;
  201. transition: all .3s linear;
  202. /* 定义过渡效果 */
  203. // transform: translateY(0);
  204. }
  205. .pop-content {
  206. width: 100%;
  207. // height: 0;
  208. background: #fff;
  209. border-radius: 0 0 20rpx 20rpx;
  210. position: relative;
  211. left: 0;
  212. // top: var(--pop_top)px;
  213. z-index: 10;
  214. transition: all .3s linear;
  215. /* 定义过渡效果 */
  216. // transform: translateY(0);
  217. /* 初始平移状态 */
  218. }
  219. .pop-mask {
  220. width: 100%;
  221. height: 100%;
  222. background: rgba(0, 0, 0, .5);
  223. position: absolute;
  224. left: 0;
  225. top: 0;
  226. }
  227. .siftClass {
  228. color: #41ABF5;
  229. border: 1rpx solid #41ABF5;
  230. background: #deeffb;
  231. box-sizing: border-box;
  232. }
  233. .h-200 {
  234. width: 100%;
  235. height: 200px;
  236. margin-bottom: 20px;
  237. background: rebeccapurple;
  238. }
  239. .scroll-view-box {
  240. overflow: auto;
  241. }
  242. .sift-box {
  243. position: sticky;
  244. top: 0;
  245. left: 0;
  246. z-index: 200;
  247. overflow-x: scroll;
  248. }
  249. .sift-content-box {
  250. width: 100%;
  251. height: 300rpx;
  252. position: absolute;
  253. top: 74rpx;
  254. left: 0;
  255. }
  256. .sift-item {
  257. min-width: 150rpx;
  258. max-width: 280rpx;
  259. height: 60rpx;
  260. line-height: 60rpx;
  261. border-radius: 8rpx;
  262. transition: all .5s ease;
  263. }
  264. .group-box {}
  265. .nav-list {
  266. overflow-x: scroll;
  267. }
  268. .nav-item {
  269. width: 96rpx;
  270. height: 126rpx;
  271. margin-right: 48rpx;
  272. }
  273. .nav-img {
  274. width: 80rpx;
  275. height: 80rpx;
  276. border-radius: 5px;
  277. margin: 0 auto 12rpx auto;
  278. }
  279. .w-96 {
  280. // width: 96rpx;
  281. }
  282. </style>