小程序端工程代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

487 lines
11 KiB

  1. <template>
  2. <view class="container">
  3. <view class="tui-bg__box">
  4. <image :src="`${$VUE_APP_RESOURCES_URL}/images/bg_seckill.png`" class="tui-bg__img" mode="widthFix" :style="{ opacity: opacity }"></image>
  5. </view>
  6. <view class="tui-header__bg">
  7. <image :src="`${$VUE_APP_RESOURCES_URL}/images/bg_seckill.png`" class="tui-bg__img" mode="widthFix"></image>
  8. <scroll-view class="tui-time-slot" scroll-x>
  9. <view class="tui-time__list" :class="{ 'tui-flex__between': timeList.length < 6 }">
  10. <view class="tui-time__item" :class="[timeList.length < 6 ? 'tui-flex__1' : 'tui-width__min', index == active ? 'tui-time__active' : '']" v-for="(item, index) in timeList" :key="index" @tap="setTime(index)">
  11. <view class="tui-time">{{ item.time }}</view>
  12. <view class="tui-status">{{ item.state }}</view>
  13. </view>
  14. </view>
  15. </scroll-view>
  16. </view>
  17. <view class="tui-body">
  18. <block v-for="(item, index) in timeList" :key="index">
  19. <view class="tui-status__box" v-if="active == index">
  20. <view class="tui-full__width" v-if="item.status == 0">
  21. <tui-divider gradual width="80%" backgroundColor="#fff" :height="34">
  22. <view class="tui-divider__status">
  23. <image :src="`${$VUE_APP_RESOURCES_URL}/images/img_seckill.png`" mode="widthFix"></image>
  24. <text class="tui-color__red">{{ item.time }}</text>
  25. <text>{{ item.state }}</text>
  26. </view>
  27. </tui-divider>
  28. </view>
  29. <view class="tui-full__width" v-if="item.status == 2">
  30. <tui-divider gradual width="80%" backgroundColor="#fff" :height="34">
  31. <view class="tui-divider__status">
  32. <image :src="`${$VUE_APP_RESOURCES_URL}/images/img_seckill.png`" mode="widthFix"></image>
  33. <text class="tui-color__red">{{ item.time }}</text>
  34. <text>{{ item.state }}</text>
  35. </view>
  36. </tui-divider>
  37. </view>
  38. <view class="tui-countdown__box" v-if="item.status == 1 || item.status == 2">
  39. <text>距离{{ item.status == 1 ? '结束还剩' : '开始还有' }}</text>
  40. <CountDown :isDay="true" :tipText="'倒计时 '" :dayText="' 天 '" :hourText="' 时 '" :minuteText="' 分 '" :secondText="' 秒'" :datatime="item.stop"></CountDown>
  41. </view>
  42. </view>
  43. </block>
  44. <view class="tui-list__goods">
  45. <view class="tui-goods__left">
  46. <block v-for="(item, index) in seckillList" :key="index">
  47. <t-goods-item v-if="index % 2 == 0" :item="item" :timeList="timeList" :active="active" :isList="false" @goDetail="goDetail"></t-goods-item>
  48. </block>
  49. </view>
  50. <view class="tui-goods__right">
  51. <block v-for="(item, index) in seckillList" :key="index">
  52. <t-goods-item v-if="index % 2 !== 0" :item="item" :timeList="timeList" :active="active" :isList="false" @goDetail="goDetail"></t-goods-item>
  53. </block>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import { getSeckillConfig, getSeckillList } from '@/api/activity'
  61. import CountDown from '@/components/CountDown'
  62. // import { Tab, Tabs } from "vant-weapp";
  63. import Loading from '@/components/Loading'
  64. export default {
  65. name: 'GoodsSeckill',
  66. components: {
  67. CountDown,
  68. },
  69. props: {},
  70. data: function() {
  71. return {
  72. headerImg: '',
  73. timeList: [],
  74. sticky: false,
  75. loading: false,
  76. datatime: 0,
  77. active: 0,
  78. seckillList: [],
  79. status: false, //砍价列表是否获取完成 false 未完成 true 完成
  80. loadingList: false, //当前接口是否请求完成 false 完成 true 未完成
  81. page: 1, //页码
  82. limit: 5, //数量
  83. title: [],
  84. opacity: 1,
  85. }
  86. },
  87. mounted: function() {
  88. this.mountedStart()
  89. },
  90. onReachBottom() {
  91. !this.loadingList && this.getSeckillList()
  92. },
  93. filters: {
  94. getStatusText(status) {
  95. let text = ['活动已结束', '正在疯抢', '即将开抢'][status - 1]
  96. return text
  97. },
  98. },
  99. methods: {
  100. changeTime: function(index) {
  101. this.active = index
  102. this.getSeckillList()
  103. },
  104. mountedStart: function() {
  105. var that = this
  106. uni.showLoading()
  107. getSeckillConfig().then(res => {
  108. that.$set(that, 'headerImg', res.data.lovely)
  109. that.$set(that, 'timeList', res.data.seckillTime)
  110. that.$set(that, 'active', res.data.seckillTimeIndex)
  111. let title = []
  112. title = res.data.seckillTime.map((item, index) => {
  113. return {
  114. name: 'div',
  115. attrs: {
  116. class: 'timeItem',
  117. },
  118. children: [
  119. {
  120. name: 'div',
  121. attrs: {
  122. class: 'time',
  123. },
  124. children: [
  125. {
  126. type: 'text',
  127. text: item.time,
  128. },
  129. ],
  130. },
  131. {
  132. name: 'div',
  133. attrs: {
  134. class: 'state',
  135. },
  136. children: [
  137. {
  138. type: 'text',
  139. text: item.state,
  140. },
  141. ],
  142. },
  143. ],
  144. }
  145. })
  146. that.$set(that, 'title', title)
  147. that.datatime = that.timeList[that.active].stop
  148. that.getSeckillList()
  149. that.$nextTick(function() {
  150. that.sticky = true
  151. uni.hideLoading()
  152. })
  153. })
  154. },
  155. setTime: function(index) {
  156. var that = this
  157. that.page = 1
  158. that.loadingList = false
  159. that.status = false
  160. that.active = index
  161. that.datatime = that.timeList[that.active].stop
  162. console.log(new Date(that.datatime))
  163. this.seckillList = []
  164. that.getSeckillList()
  165. },
  166. getSeckillList: function() {
  167. var that = this
  168. if (that.loadingList) return
  169. if (that.status) return
  170. var time = that.timeList[that.active].id
  171. getSeckillList(time, {
  172. page: that.page,
  173. limit: that.limit,
  174. }).then(res => {
  175. that.status = res.data.length < that.limit
  176. that.seckillList.push.apply(that.seckillList, res.data)
  177. that.page++
  178. uni.hideLoading()
  179. })
  180. },
  181. goDetail: function(item) {
  182. var that = this
  183. var time = that.timeList[that.active].stop
  184. this.$yrouter.push({
  185. path: '/pages/activity/SeckillDetails/index',
  186. query: {
  187. id: item.id,
  188. time,
  189. status: that.timeList[that.active].status,
  190. },
  191. })
  192. },
  193. onPageScroll(e) {
  194. let scrollTop = e.scrollTop
  195. if (scrollTop <= 2) {
  196. this.opacity = 1
  197. } else {
  198. if (this.opacity <= 0) return
  199. this.opacity = 1 - scrollTop / 40
  200. }
  201. },
  202. },
  203. }
  204. </script>
  205. <style scoped lang="less">
  206. .tui-bg__box {
  207. width: 100%;
  208. height: 210rpx;
  209. position: fixed;
  210. left: 0;
  211. top: 0;
  212. /* #ifdef H5 */
  213. top: 80rpx;
  214. /* #endif */
  215. z-index: 1;
  216. }
  217. .tui-header__bg {
  218. width: 100%;
  219. height: 120rpx;
  220. position: fixed;
  221. left: 0;
  222. top: 0;
  223. /* #ifdef H5 */
  224. top: 80rpx;
  225. /* #endif */
  226. z-index: 3;
  227. overflow: hidden;
  228. }
  229. .tui-bg__img {
  230. width: 100%;
  231. height: 210rpx;
  232. display: block;
  233. transition: opacity 0.1s linear;
  234. }
  235. .tui-body {
  236. width: 100%;
  237. position: relative;
  238. margin-top: 120rpx;
  239. z-index: 2;
  240. padding: 0 25rpx;
  241. box-sizing: border-box;
  242. }
  243. .tui-time-slot {
  244. width: 100%;
  245. height: 120rpx;
  246. position: absolute;
  247. left: 0;
  248. top: 0;
  249. }
  250. .tui-time__list {
  251. min-width: 100%;
  252. height: 120rpx;
  253. display: flex;
  254. align-items: center;
  255. }
  256. .tui-flex__between {
  257. justify-content: space-between;
  258. }
  259. .tui-time__item {
  260. flex-shrink: 0;
  261. display: flex;
  262. align-items: center;
  263. flex-direction: column;
  264. justify-content: center;
  265. color: #ffb2b2;
  266. }
  267. .tui-flex__1 {
  268. flex: 1 !important;
  269. }
  270. .tui-width__min {
  271. min-width: 150rpx;
  272. }
  273. .tui-time {
  274. font-size: 32rpx;
  275. line-height: 32rpx;
  276. font-weight: bold;
  277. }
  278. .tui-status {
  279. font-size: 24rpx;
  280. line-height: 24rpx;
  281. font-weight: 500;
  282. padding-top: 16rpx;
  283. }
  284. .tui-time__active .tui-time {
  285. color: #fff;
  286. font-size: 36rpx;
  287. line-height: 36rpx;
  288. }
  289. .tui-time__active .tui-status {
  290. color: #fff;
  291. font-size: 28rpx;
  292. line-height: 28rpx;
  293. font-weight: bold;
  294. }
  295. .tui-status__box {
  296. width: 100%;
  297. height: 146rpx;
  298. background: #fff;
  299. border-radius: 20rpx;
  300. box-shadow: 0 3rpx 20rpx rgba(183, 183, 183, 0.1);
  301. display: flex;
  302. align-items: center;
  303. justify-content: center;
  304. flex-direction: column;
  305. }
  306. .tui-full__width {
  307. width: 100%;
  308. }
  309. .tui-divider__status {
  310. display: flex;
  311. align-items: center;
  312. font-size: 28rpx;
  313. color: #333;
  314. font-weight: bold;
  315. }
  316. .tui-divider__status image {
  317. width: 30rpx;
  318. height: 30rpx;
  319. margin-right: 10rpx;
  320. flex-shrink: 0;
  321. }
  322. .tui-color__red {
  323. color: #eb0909;
  324. padding-right: 6rpx;
  325. font-size: 32rpx;
  326. font-weight: 500;
  327. }
  328. .tui-countdown__box {
  329. display: flex;
  330. align-items: center;
  331. justify-content: center;
  332. color: #333;
  333. font-size: 24rpx;
  334. font-weight: 400;
  335. margin-top: 16rpx;
  336. }
  337. .tui-countdown__box text {
  338. padding-right: 12rpx;
  339. }
  340. /*======商品列表 start=======*/
  341. .tui-list__goods {
  342. width: 100%;
  343. display: flex;
  344. justify-content: space-between;
  345. flex-wrap: wrap;
  346. margin-top: 20rpx;
  347. padding-bottom: 30rpx;
  348. }
  349. .tui-goods__left,
  350. .tui-goods__right {
  351. width: 49%;
  352. }
  353. .tui-full__width {
  354. width: 100% !important;
  355. }
  356. /*======商品列表 end=======*/
  357. .tui-goods__item {
  358. width: 100%;
  359. padding: 20rpx 20rpx 36rpx;
  360. box-sizing: border-box;
  361. border-radius: 12rpx;
  362. background-color: #fff;
  363. margin-bottom: 4%;
  364. position: relative;
  365. }
  366. .tui-full__item {
  367. display: flex;
  368. margin-bottom: 20rpx !important;
  369. padding: 20rpx !important;
  370. }
  371. .tui-img__newguest {
  372. position: absolute;
  373. width: 96rpx;
  374. height: 32rpx;
  375. left: 0;
  376. top: 8rpx;
  377. }
  378. .tui-image__box {
  379. width: 100%;
  380. height: 300rpx;
  381. }
  382. .tui-full__imgbox {
  383. width: 240rpx !important;
  384. height: 240rpx !important;
  385. margin-right: 20rpx;
  386. }
  387. .tui-goods__img {
  388. max-width: 100%;
  389. max-height: 300rpx;
  390. display: block;
  391. border-radius: 8rpx;
  392. }
  393. .tui-full__img {
  394. max-height: 240rpx !important;
  395. }
  396. .tui-goods__content {
  397. width: 100%;
  398. padding-top: 16rpx;
  399. }
  400. .tui-full__content {
  401. height: 240rpx;
  402. display: flex;
  403. flex-direction: column;
  404. justify-content: space-between;
  405. padding-top: 0 !important;
  406. }
  407. .tui-goods__title {
  408. font-size: 26rpx;
  409. font-weight: 400;
  410. color: #333;
  411. word-break: break-all;
  412. overflow: hidden;
  413. text-overflow: ellipsis;
  414. display: -webkit-box;
  415. -webkit-box-orient: vertical;
  416. -webkit-line-clamp: 2;
  417. margin-bottom: 20rpx;
  418. }
  419. .tui-tag__box {
  420. display: flex;
  421. padding-top: 25rpx;
  422. padding-bottom: 25rpx;
  423. }
  424. .tui-box__bottom {
  425. width: 100%;
  426. display: flex;
  427. align-items: center;
  428. justify-content: space-between;
  429. }
  430. .tui-price__box {
  431. display: flex;
  432. flex-direction: column;
  433. align-items: center;
  434. justify-content: center;
  435. }
  436. .tui-price {
  437. display: flex;
  438. align-items: flex-end;
  439. color: #eb0909;
  440. }
  441. .tui-price__small {
  442. font-size: 24rpx;
  443. line-height: 24rpx;
  444. }
  445. .tui-price__large {
  446. font-size: 34rpx;
  447. line-height: 32rpx;
  448. font-weight: 600;
  449. }
  450. .tui-price__original {
  451. font-size: 24rpx;
  452. line-height: 24rpx;
  453. text-decoration: line-through;
  454. color: #999;
  455. padding-top: 10rpx;
  456. }
  457. </style>