index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <view :data-theme="theme">
  3. <view class='cart_nav'>
  4. <view v-if="styleValue=='1'">
  5. <nav-bar ref="navBarRef" @getNavH='getNavH' iconColor='#fff' :navTitle="pageScrollStatus ? '限时秒杀' : ''"
  6. :backgroundColor="pageScrollStatus?'#e93323':''" :isBackgroundColor="false" :isHeight="false">
  7. </nav-bar>
  8. </view>
  9. <view v-else>
  10. <!-- #ifdef MP || APP-PLUS-->
  11. <nav-bar @getNavH='getNavH' iconColor='#fff' :isBackgroundColor="false" ref="navBarRef"
  12. :isHeight="false">
  13. <view slot='default' class="">
  14. <image class="seckill_title" src="../static/images/seckill_title.png" mode=""></image>
  15. </view>
  16. </nav-bar>
  17. <!-- #endif -->
  18. </view>
  19. </view>
  20. <view @touchstart="touchStart">
  21. <ListStyle v-if="styleValue=='1'" :pageScrollStatus="pageScrollStatus" :seckillList="seckillList"
  22. :timeLine="timeLine" :loading="loading" :active="active" @getCheckSeckill="getCheckSeckill"></ListStyle>
  23. <PageStyle v-if="styleValue=='2'" :tabLeft="tabLeft" :mainWidth="mainWidth" :datatime="datatime"
  24. :isWidth="isWidth" :desc="desc" :marTop="marTop" :seckillList="seckillList" :timeLine="timeLine"
  25. :loading="loading" :active="active" @getCheckSeckill="getCheckSeckill"></PageStyle>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import {
  31. getSeckillHeaderApi,
  32. getSeckillListApi,
  33. seckillStyleApi
  34. } from '@/api/activity.js';
  35. import {
  36. silenceBindingSpread,
  37. getUserSpread
  38. } from '@/utils/index.js';
  39. import ListStyle from "../components/listStyle.vue";
  40. import PageStyle from "../components/pageStyle.vue";
  41. import navBar from '@/components/navBar';
  42. import {
  43. mapGetters
  44. } from "vuex";
  45. import onShare from "../../../mixins/onShare";
  46. let app = getApp();
  47. let sysHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
  48. export default {
  49. mixins: [onShare],
  50. components: {
  51. navBar,
  52. ListStyle,
  53. PageStyle
  54. },
  55. computed: mapGetters(['isLogin', 'uid', 'globalData']),
  56. created() {
  57. var that = this
  58. // 获取设备宽度
  59. uni.getSystemInfo({
  60. success(e) {
  61. that.mainWidth = e.windowWidth
  62. that.isWidth = (e.windowWidth - 65) / 4
  63. }
  64. })
  65. },
  66. onPageScroll(object) {
  67. if (object.scrollTop > 200) {
  68. this.pageScrollStatus = true;
  69. } else if (object.scrollTop < 200) {
  70. this.pageScrollStatus = false;
  71. }
  72. uni.$emit('scroll');
  73. },
  74. data() {
  75. return {
  76. seckillList: [],
  77. timeList: [],
  78. active: 0,
  79. page: 1,
  80. limit: 5,
  81. loading: true,
  82. loadend: false,
  83. timeLine: [],
  84. showSkeleton: true, //骨架屏显示隐藏
  85. isNodes: 0, //控制什么时候开始抓取元素节点,只要数值改变就重新抓取
  86. circular: true,
  87. autoplay: true,
  88. interval: 500,
  89. topImage: '',
  90. scrollLeft: 0,
  91. status: 1,
  92. returnShow: true,
  93. navH: '',
  94. theme: this.$Cache.get("theme"),
  95. isLeft: 0,
  96. mainWidth: 0,
  97. tabLeft: 0,
  98. isWidth: 0,
  99. info: {},
  100. desc: '',
  101. datatime: 0,
  102. marTop: 0,
  103. activeTime: {},
  104. loadTitle: '',
  105. sysHeight: sysHeight,
  106. pageScrollStatus: false,
  107. styleValue: '1', //样式值
  108. title: '秒杀列表'
  109. }
  110. },
  111. onLoad(options) {
  112. this.getSeckillStyle();
  113. //分销码
  114. getUserSpread(options);
  115. setTimeout(() => {
  116. this.isNodes++;
  117. }, 500);
  118. var pages = getCurrentPages();
  119. this.returnShow = pages.length === 1 ? false : true;
  120. // #ifdef H5
  121. this.navH = app.globalData.navHeight - 18;
  122. // #endif
  123. this.getSeckillConfig();
  124. },
  125. onShow() {
  126. //分销绑定
  127. silenceBindingSpread(this.isLogin, this.globalData.spread);
  128. },
  129. methods: {
  130. //滚动
  131. touchStart() {
  132. this.$refs.navBarRef.currentPage = false;
  133. },
  134. //获取秒杀样式
  135. async getSeckillStyle() {
  136. let {
  137. code,
  138. data
  139. } = await seckillStyleApi();
  140. if (code === 200) this.styleValue = data;
  141. },
  142. getNavH(marTop) {
  143. this.marTop = marTop;
  144. },
  145. //点击时间段
  146. getCheckSeckill(index, item) {
  147. this.active = index;
  148. this.isLeft = -(index * this.isWidth) //设置下划线位置
  149. this.tabLeft = (index - 2) * this.isWidth //设置下划线位置
  150. this.status = item.status;
  151. if (item.status == 1) {
  152. this.desc = '距本场结束';
  153. this.datatime = item.endTimeStamp / 1000;
  154. } else if (item.status == 2 || item.status == 3) {
  155. this.desc = '距本场开始';
  156. this.datatime = item.startTimeStamp / 1000;
  157. } else if (item.status == 0) {
  158. this.desc = '已结束';
  159. }
  160. this.loading = false;
  161. this.loadend = false;
  162. this.page = 1;
  163. this.activeTime = item;
  164. this.getSeckillList(item);
  165. },
  166. getSeckillConfig: function() {
  167. getSeckillHeaderApi().then(res => {
  168. this.timeLine = res.data;
  169. //找出第一个进行中的下标
  170. this.active = this.timeLine.length ? res.data.findIndex(item => item.status === 1 || item
  171. .status === 2) : 0;
  172. this.$nextTick(() => {
  173. this.tabLeft = (this.active - 2) * this.isWidth //选中的位置放在第一位
  174. })
  175. if (res.data[this.active].status == 1) {
  176. this.desc = '距本场结束';
  177. this.datatime = res.data[this.active].endTimeStamp / 1000;
  178. this.status = 1;
  179. } else if (res.data[this.active].status == 2) {
  180. this.desc = '距本场开始';
  181. this.status = 2;
  182. this.datatime = res.data[this.active].startTimeStamp / 1000;
  183. } else if (res.data[this.active].status == 0) {
  184. this.desc = '已结束';
  185. this.status = 0;
  186. }
  187. this.loading = false;
  188. this.loadend = false;
  189. this.page = 1;
  190. //this.seckillList = [];
  191. let item = this.timeLine[this.active];
  192. this.activeTime = item;
  193. this.getSeckillList(this.activeTime);
  194. });
  195. },
  196. async getSeckillList(item) {
  197. try {
  198. const data = {
  199. page: this.page,
  200. limit: this.limit,
  201. date: item.date,
  202. startTime: item.startTime,
  203. endTime: item.endTime
  204. };
  205. if (this.loadend) return;
  206. if (this.loading) return;
  207. this.loadTitle = '';
  208. this.loading = true
  209. // 获取数据的逻辑
  210. const res = await getSeckillListApi(data);
  211. this.loadend = this.page > res.data.totalPage;
  212. if (this.page == 1) {
  213. this.seckillList = [];
  214. }
  215. this.loadTitle = this.loadend ? '已全部加载' : '加载更多';
  216. this.seckillList = this.seckillList.concat(res.data.list || []);
  217. this.$set(this, 'page', this.page + 1);
  218. // 在数据更新后恢复滚动位置
  219. this.$nextTick(() => {
  220. this.$set(this, 'seckillList', this.seckillList);
  221. });
  222. this.loading = false;
  223. // #ifdef H5
  224. this.setShare();
  225. // #endif
  226. this.showSkeleton = false
  227. } catch (error) {
  228. this.loading = false
  229. }
  230. },
  231. goBack: function() {
  232. uni.navigateBack();
  233. },
  234. setShare: function() {
  235. this.$wechat.isWeixin() &&
  236. this.$wechat.wechatEvevt([
  237. "updateAppMessageShareData",
  238. "updateTimelineShareData",
  239. "onMenuShareAppMessage",
  240. "onMenuShareTimeline"
  241. ], {
  242. desc: this.seckillList[0].title,
  243. title: this.seckillList[0].title,
  244. link: location.href,
  245. imgUrl: this.seckillList[0].image
  246. }).then(res => {}).catch(err => {
  247. console.log(err);
  248. });
  249. },
  250. },
  251. /**
  252. * 页面上拉触底事件的处理函数
  253. */
  254. onReachBottom: function() {
  255. this.getSeckillList(this.activeTime);
  256. }
  257. }
  258. </script>
  259. <style scoped lang="scss">
  260. .seckill_title {
  261. width: 144rpx;
  262. height: 36rpx;
  263. }
  264. </style>