index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <template>
  2. <view class="index-main">
  3. <network-error />
  4. <view class="first"
  5. :style="{height: `${firstHeight}rpx`}">
  6. <view class="index-header">
  7. <view class="index-banner"
  8. v-if="bannerList.length"
  9. v-show="!isSticky"
  10. :style="{
  11. Top: `${navHeight}rpx`
  12. }">
  13. <view class="index-logo">
  14. <image src="../static/common/logo_bt.png" />
  15. </view>
  16. <u-swiper mode="dot"
  17. img-mode="scaleToFill"
  18. :list="bannerList | bannerListFilter | imgListFilter(1)"
  19. name="url"
  20. height="176"
  21. border-radius="20"
  22. @click="bannerClick">
  23. </u-swiper>
  24. </view>
  25. </view>
  26. <view class="activity-flow"
  27. v-show="!isSticky"
  28. :style="{
  29. paddingTop: '20rpx'
  30. }">
  31. <activity-flow></activity-flow>
  32. </view>
  33. </view>
  34. <view class="index-body u-m-t-36">
  35. <u-sticky :enable="enable"
  36. offset-top="0"
  37. h5-nav-height="0"
  38. @fixed="stickyFixed"
  39. @unfixed="unStickyFixed">
  40. <!-- 只能有一个根元素 -->
  41. <view class="sticky">
  42. <view class="nav-title u-font-32 bold line-44 u-text-center"
  43. :style="{
  44. paddingTop: `${navTitleStyle.paddingTop}rpx`,
  45. paddingBottom: `${navTitleStyle.paddingBottom}rpx`,
  46. lineHeight: `${navTitleStyle.lineHeight}rpx`,
  47. fontSize: `${navTitleStyle.fontSize}rpx`
  48. }">
  49. 首页
  50. </view>
  51. <view class="index-tabs u-flex u-col-bottom u-row-between">
  52. <u-tabs :is-scroll="false"
  53. :list="tabList"
  54. :current="currentTab"
  55. height="44"
  56. font-size="34"
  57. active-color="#111111"
  58. inactive-color="#111111"
  59. :gutter="0"
  60. :bar-style="{
  61. bottom: '-10rpx',
  62. marginLeft: '-34rpx',
  63. width: '104rpx',
  64. height: '10rpx',
  65. borderRadius: 0,
  66. backgroundColor: '#FD6D4E',
  67. boxShadow: '0px 1px 1px 0px rgba(255, 102, 50, 0.3)'
  68. }"
  69. @change="tabsChange">
  70. </u-tabs>
  71. <view class="u-font-22 u-content-color">单平台门店每天只能报名1次</view>
  72. </view>
  73. </view>
  74. </u-sticky>
  75. <block v-if="isLocation">
  76. <view class="activity-list"
  77. :style="{paddingTop: `${activityListPT}rpx`}">
  78. <block v-if="activityList.length !== 0">
  79. <view class="activity-card u-border-bottom"
  80. v-for="(item, index) in activityList"
  81. :key="index">
  82. <activity-card :value="item"
  83. @clickCard="toActivityDetail"
  84. @signUp="toActivityDetail"
  85. @clickYBM="toActivityDetail"
  86. @clickYQG="toActivityDetail">
  87. </activity-card>
  88. </view>
  89. <view class="touch-bottom u-font-22 line-32 u-text-center">{{isLoadMore ? '加载中...' : '到底了~'}}</view>
  90. </block>
  91. <block v-else>
  92. <view class="def-content">
  93. <def-content type="1"></def-content>
  94. </view>
  95. </block>
  96. </view>
  97. </block>
  98. <block v-else>
  99. <view class="no-location def-content">
  100. <def-content type="2"></def-content>
  101. </view>
  102. </block>
  103. </view>
  104. </view>
  105. </template>
  106. <script>
  107. import defContent from '@/components/defContent'
  108. import activityFlow from '@/components/activityFlow'
  109. import activityCard from '@/components/activityCard'
  110. import { getActivityBannerList, getActivityList } from '@/api/activityApi'
  111. export default {
  112. components: { defContent, activityFlow, activityCard },
  113. data () {
  114. return {
  115. isLocation: false,
  116. enable: true,
  117. isSticky: false,
  118. firstHeight: 568,
  119. navTitleStyle: {
  120. paddingTop: 0,
  121. paddingBottom: 0,
  122. lineHeight: 0,
  123. fontSize: 0
  124. },
  125. activityListPT: 0,
  126. bannerList: [],
  127. isLoadMore: false,
  128. tabList: [{ name: '免费吃' }, { name: '返利餐' }],
  129. searchForm: {
  130. page_no: 1,
  131. page_size: 10,
  132. activity_type: 1
  133. },
  134. total: -1,
  135. currentTab: 0,
  136. activityList: []
  137. }
  138. },
  139. computed: {
  140. navHeight () {
  141. return (uni.getSystemInfoSync().statusBarHeight * 2) + 16
  142. }
  143. },
  144. onShow () {
  145. this.getLocation()
  146. this.getBannerData()
  147. this.isLoadMore = false
  148. this.searchForm.page_no = 1
  149. this.total = -1
  150. this.activityList = []
  151. this.getActivityData()
  152. this.enable = true
  153. },
  154. onHide () {
  155. this.enable = true
  156. },
  157. onPullDownRefresh () {
  158. this.getBannerData()
  159. this.searchForm.page_no = 1
  160. this.total = -1
  161. this.activityList = []
  162. this.getActivityData()
  163. },
  164. onReachBottom () {
  165. if (this.isLoadMore) {
  166. this.searchForm.page_no += 1
  167. this.getActivityData()
  168. }
  169. },
  170. methods: {
  171. // 获取用户经纬度
  172. getLocation () {
  173. return new Promise((resolve, reject) => {
  174. uni.getLocation({
  175. type: 'gcj02',
  176. success: (res) => {
  177. this.isLocation = true
  178. resolve(res)
  179. },
  180. fail: () => {
  181. this.isLocation = false
  182. resolve(false)
  183. }
  184. })
  185. })
  186. },
  187. // 获取banner列表
  188. async getBannerData () {
  189. const { code, data } = await getActivityBannerList()
  190. if (code === 200) {
  191. this.bannerList = data
  192. }
  193. },
  194. // 获取活动列表
  195. async getActivityData () {
  196. const location = await this.getLocation()
  197. if (!location) { return }
  198. const params = {
  199. lng: location.longitude,
  200. lat: location.latitude,
  201. page_no: this.searchForm.page_no,
  202. page_size: this.searchForm.page_size,
  203. activity_type: this.searchForm.activity_type
  204. }
  205. const { code, data } = await getActivityList(params)
  206. if (code === 200) {
  207. this.total = data.total_count
  208. this.activityList = this.activityList.concat(data.rows)
  209. this.isLoadMore = this.total !== this.activityList.length
  210. }
  211. uni.stopPullDownRefresh()
  212. },
  213. // 活动类型切换
  214. tabsChange (index) {
  215. this.currentTab = index
  216. this.searchForm.activity_type = index + 1
  217. this.searchForm.page_no = 1
  218. this.total = -1
  219. this.activityList = []
  220. this.getActivityData()
  221. },
  222. stickyFixed () {
  223. this.isSticky = true
  224. this.firstHeight = 0
  225. this.navTitleStyle = {
  226. paddingTop: this.navHeight,
  227. paddingBottom: 30,
  228. lineHeight: 44,
  229. fontSize: 32
  230. }
  231. this.activityListPT = this.navHeight + 82
  232. },
  233. unStickyFixed () {
  234. this.isSticky = false
  235. this.firstHeight = 568
  236. this.navTitleStyle = {
  237. paddingTop: 0,
  238. paddingBottom: 0,
  239. lineHeight: 0,
  240. fontSize: 0
  241. }
  242. this.activityListPT = 0
  243. },
  244. toActivityDetail (e) {
  245. uni.navigateTo({
  246. url: `../pagesSub/activity/activityDetail?id=${e.id}`
  247. })
  248. },
  249. // 点击banner事件
  250. bannerClick (index) {
  251. const banner = this.bannerList[index]
  252. console.log(banner)
  253. switch (banner.jump_type * 1) {
  254. case 1:
  255. uni.navigateTo({
  256. url: `/pagesSub/other/webView?url=${banner.jump_content}`
  257. })
  258. break
  259. case 2:
  260. this.$store.dispatch('toOtherApplte', banner.jump_content)
  261. break
  262. case 3:
  263. uni.navigateTo({
  264. url: `/pagesSub/activity/activityDetail?id=${banner.jump_content}`
  265. })
  266. break
  267. case 4:
  268. console.log('jump_content', banner.jump_content)
  269. this.$store.commit('changeCateId', banner.jump_content)
  270. uni.switchTab({
  271. url: '/pages/classification'
  272. })
  273. break
  274. case 5:
  275. this.$store.commit('changeCateId', banner.jump_content)
  276. uni.navigateTo({
  277. url: '/pagesSub/other/noviceStrategy'
  278. })
  279. break
  280. default:
  281. }
  282. }
  283. },
  284. filters: {
  285. bannerListFilter (e) {
  286. return e.map(item => {
  287. item.url = item.imgs
  288. return item
  289. })
  290. }
  291. }
  292. }
  293. </script>
  294. <style lang="scss" scoped>
  295. .index-main {
  296. .first {
  297. height: 540px;
  298. opacity: 1;
  299. transition: all 1s;
  300. }
  301. .hidden-first {
  302. height: 0;
  303. opacity: 0;
  304. }
  305. .index-header {
  306. height: 314px;
  307. background: url('~@/static/common/bg_sy.png') no-repeat center top;
  308. background-size: cover;
  309. transition: height 2s;
  310. .index-banner {
  311. position: relative;
  312. margin: 0 auto;
  313. width: 694px;
  314. transition: width 2s;
  315. .index-logo {
  316. margin-bottom: 36px;
  317. text-align: center;
  318. image {
  319. width: 88px;
  320. height: 44px;
  321. background: url('~@/static/common/logo_bt.png') no-repeat top top;
  322. background-size: cover;
  323. }
  324. }
  325. }
  326. }
  327. .activity-flow {
  328. background-color: #fff;
  329. }
  330. .index-tabs {
  331. padding: 24px 28px 16px;
  332. }
  333. .index-body {
  334. background-color: #fff;
  335. .sticky {
  336. background-color: #fff;
  337. .nav-title {
  338. box-sizing: border-box;
  339. padding-bottom: 30px;
  340. transition: padding 1s;
  341. }
  342. }
  343. .no-location,
  344. .activity-list {
  345. padding: 0 28px;
  346. min-height: 100vh;
  347. background-color: #fff;
  348. .activity-card {
  349. padding: 32px 0;
  350. }
  351. }
  352. .touch-bottom {
  353. padding: 30px 0;
  354. color: #babbbc;
  355. }
  356. }
  357. .def-content {
  358. margin-top: 212px;
  359. }
  360. }
  361. </style>
  362. <style >
  363. .index-tabs >>> .u-tab-item {
  364. z-index: 10;
  365. font-weight: bold !important;
  366. }
  367. .index-tabs >>> .u-tab-item + .u-tab-item {
  368. margin-left: 42px;
  369. }
  370. </style>