discount.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <template>
  2. <view class="spikeListBox">
  3. <JHeader :dark="false" title="限时折扣专区" width="50" height="50" style="padding: 24upx 0 0;"></JHeader>
  4. <view class="discountBg">
  5. 限时折扣
  6. </view>
  7. <view v-if="shopShowType == false" class="countdown">
  8. <label v-if="discountDataListState">距活动结束剩余</label>
  9. <label v-else>即将开始</label>
  10. <view class="endDate"><span>{{ hou }}</span><i>:</i><span>{{ min }}</span><i>:</i><span>{{ sec }}</span></view>
  11. </view>
  12. <view class="shop-list-nav">
  13. <view class="nav-item-sort" @click="sortTap(1)">
  14. <text class="nav-title" :class="{ 'active': sortIndex == 1 }">综合</text>
  15. </view>
  16. <view class="nav-item-sort" @click="sortTap(2)">
  17. <text class="nav-title" :class="{ 'active': sortIndex == 2 }">价格</text>
  18. <view class="r">
  19. <view class="arrowUp" :class="{ activeUp: queryInfo.type == 1 }"></view>
  20. <view class="arrowDown" :class="{ activeDown: queryInfo.type == 2 }"></view>
  21. </view>
  22. </view>
  23. <view class="nav-item-sort" @click="sortTap(3)">
  24. <text class="nav-title" :class="{ 'active': sortIndex == 3 }">销量</text>
  25. <view class="r">
  26. <view class="arrowUp" :class="{ activeUp: queryInfo.volume == 1 }"></view>
  27. <view class="arrowDown" :class="{ activeDown: queryInfo.volume == 2 }"></view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="spikeList mar-top-20">
  32. <view v-if="discountList && discountList.length">
  33. <view v-for="(item, index) in discountList" :key="index" class="listItem">
  34. <view class="itemBox">
  35. <img :src="common.seamingImgUrl(item.image)">
  36. </view>
  37. <view class="itemInfo">
  38. <p>{{ item.productName }}</p>
  39. <view v-if="item.limitNumber" class="number">限量{{ item.limitNumber }}件 / 剩余{{ item.limitStockNumber }}件</view>
  40. <view class="originalPrice">原价: ¥{{ item.originalPrice }}</view>
  41. <view class="price">
  42. <view class="currentPrice flex-row-plus flex-items-plus font-color-FF7800">
  43. <view class="iconBox">
  44. <image src="../../../static/images/new-business/shop/discountListIcon.png"></image>
  45. </view>
  46. <view class="flex-row-plus flex-items priceInfo">
  47. <label class="fs24">¥</label>
  48. <label class="fs36">{{ item.price }}</label>
  49. </view>
  50. </view>
  51. <view
  52. v-if="discountDataListState" class="snapUpBtn"
  53. @click="gogoodsDetails(item.shopId, item.productId, item.skuId)"
  54. >
  55. <view class="btnText">去抢购</view>
  56. <view style="width: 82%;margin: 0 auto">
  57. <progress activeColor="#FFFFFF" :percent="getPercent(20, 100)" active stroke-width="5" />
  58. </view>
  59. </view>
  60. <view v-else class="snapUpBtn btnStyle1">
  61. <view class="btnText">即将开始</view>
  62. <view style="width: 82%;margin: 0 auto">
  63. <progress activeColor="#FFFFFF" :percent="getPercent(20, 100)" active stroke-width="5" />
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. <view style="padding-bottom: 45upx;">
  71. <LoadingMore
  72. :status="!isEmpty && !discountList.length
  73. ? 'loading' : !isEmpty && discountList.length && (discountList.length >= discountTotal) ? 'no-more' : ''"
  74. >
  75. </LoadingMore>
  76. <tui-no-data v-if="isEmpty" :fixed="false" style="margin-top: 60upx;">暂无数据</tui-no-data>
  77. </view>
  78. </view>
  79. </view>
  80. </template>
  81. <script>
  82. import { getIndexDiscountListApi } from '../../../api/anotherTFInterface'
  83. export default {
  84. name: 'Discount',
  85. data() {
  86. return {
  87. isEmpty: false,
  88. discountList: [],
  89. discountTotal: 0,
  90. queryInfo: {
  91. page: 1,
  92. pageSize: 20,
  93. shopId: 0,
  94. type: 0, // 价格
  95. volume: 0, // 销量
  96. shopDiscountId: ''
  97. },
  98. discountDataListState: '',
  99. days: '00',
  100. hou: '00',
  101. min: '00',
  102. sec: '00',
  103. shopShowType: false,
  104. sortIndex: 1
  105. }
  106. },
  107. onLoad(options) {
  108. if (options.shopId && options.shopDiscountId) {
  109. this.shopShowType = false
  110. this.queryInfo.shopId = options.shopId
  111. this.queryInfo.shopDiscountId = options.shopDiscountId
  112. } else {
  113. this.shopShowType = true
  114. this.queryInfo.shopId = 0
  115. this.queryInfo.shopDiscountId = 0
  116. }
  117. this.getDiscountList()
  118. },
  119. methods: {
  120. getPercent(num, total) {
  121. num = parseFloat(num)
  122. total = parseFloat(total)
  123. if (isNaN(num) || isNaN(total)) {
  124. return '-'
  125. }
  126. return total <= 0 ? '0%' : Math.round((num / total) * 10000) / 100.0
  127. },
  128. sortTap(index) {
  129. this.queryInfo.page = 1
  130. this.discountList = []
  131. this.sortIndex = index
  132. if (index == 1) {
  133. this.queryInfo.type = 0
  134. this.queryInfo.volume = 0
  135. } else if (index == 2) {
  136. this.queryInfo.volume = 0
  137. if (this.queryInfo.type === 0) {
  138. this.queryInfo.type = 1
  139. } else {
  140. this.queryInfo.type = this.queryInfo.type != 1 ? 1 : 2
  141. }
  142. } else if (index == 3) {
  143. this.queryInfo.type = 0
  144. if (this.queryInfo.volume === 0) {
  145. this.queryInfo.volume = 1
  146. } else {
  147. this.queryInfo.volume = this.queryInfo.volume != 1 ? 1 : 2
  148. }
  149. }
  150. this.getDiscountList()
  151. },
  152. gogoodsDetails(shopId, productId, skuId) {
  153. uni.navigateTo({
  154. url: '/another-tf/another-serve/goodsDetails/index?shopId=' + shopId + '&productId=' + productId + '&skuId=' + skuId
  155. })
  156. },
  157. getDiscountList(isLoadmore) {
  158. uni.showLoading()
  159. getIndexDiscountListApi(this.queryInfo).then((res) => {
  160. this.discountDataListState = res.data.state
  161. if (this.shopShowType == false) {
  162. if (res.data.state) {
  163. this.dateformat(res.data.time)
  164. } else {
  165. this.dateformat(res.data.enableTime)
  166. }
  167. this.countDown()
  168. }
  169. this.discountTotal = res.data.page.total
  170. if (isLoadmore) {
  171. this.discountList.push(...res.data.page.list)
  172. } else {
  173. this.discountList = res.data.page.list
  174. }
  175. this.isEmpty = this.discountList.length === 0
  176. uni.hideLoading()
  177. })
  178. .catch((e) => {
  179. uni.hideLoading()
  180. })
  181. },
  182. // 时分秒换算
  183. dateformat(micro_second) {
  184. // 总秒数
  185. const second = Math.floor(micro_second / 1000)
  186. // 天数
  187. const day = Math.floor(second / 3600 / 24)
  188. // 小时
  189. const hr = Math.floor(second / 3600 % 24)
  190. // 分钟
  191. const min = Math.floor(second / 60 % 60)
  192. // 秒
  193. const sec = Math.floor(second % 60)
  194. this.hou = hr + day * 24
  195. this.min = min
  196. this.sec = sec
  197. },
  198. countDown() {
  199. const timeOut = setTimeout(() => {
  200. const hou = parseInt(this.hou + this.days * 24)
  201. const min = parseInt(this.min)
  202. const sec = parseInt(this.sec)
  203. let netxSec = sec - 1
  204. let netxMin = min
  205. let netxHou = hou
  206. if (netxHou == 0 && netxMin == 0 && netxSec == -1) {
  207. clearTimeout(timeOut)
  208. this.$switchTab('/')
  209. uni.showToast({
  210. title: '活动结束',
  211. duration: 2000,
  212. icon: 'none'
  213. })
  214. } else {
  215. if (netxSec == -1) {
  216. netxSec = 59
  217. netxMin = netxMin - 1
  218. }
  219. if (netxMin == -1) {
  220. netxMin = 59
  221. netxHou = netxHou - 1
  222. }
  223. // if (netxHou == -1) {
  224. // netxHou = 23
  225. // }
  226. this.hou = this.timeFormat(netxHou),
  227. this.min = this.timeFormat(netxMin),
  228. this.sec = this.timeFormat(netxSec),
  229. this.timeOut = timeOut
  230. this.countDown()
  231. }
  232. }, 1000)
  233. },
  234. timeFormat(param) { // 小于10的格式化函数
  235. return param < 10 ? '0' + param : param
  236. }
  237. },
  238. onReachBottom() {
  239. if (this.discountList.length < this.discountTotal) {
  240. ++this.queryInfo.page
  241. this.getDiscountList(true)
  242. }
  243. }
  244. }
  245. </script>
  246. <style lang="less" scoped>
  247. .spikeListBox {
  248. min-height: 100vh;
  249. background-color: #333333;
  250. box-sizing: border-box;
  251. .discountBg {
  252. width: 100%;
  253. position: relative;
  254. margin: 40rpx 0;
  255. font-size: 40upx;
  256. font-weight: bold;
  257. text-align: center;
  258. color: #ffffff;
  259. }
  260. .countdown {
  261. display: flex;
  262. justify-content: center;
  263. height: 80upx;
  264. align-items: center;
  265. width: 100%;
  266. color: #CCCCCC;
  267. .endDate {
  268. display: flex;
  269. align-items: center;
  270. margin-left: 20upx;
  271. span {
  272. min-width: 44rpx;
  273. padding: 0 8rpx;
  274. height: 52upx;
  275. line-height: 52upx;
  276. background: #999999;
  277. display: block;
  278. font-size: 26upx;
  279. color: #FFEBC4;
  280. text-align: center;
  281. }
  282. i {
  283. font-size: 26upx;
  284. color: #999999;
  285. font-style: normal;
  286. margin: 0 8upx;
  287. }
  288. }
  289. }
  290. .spikeList {
  291. padding: 20upx 30upx 20upx 30upx;
  292. .listItem {
  293. display: flex;
  294. padding: 30rpx;
  295. margin-bottom: 30upx;
  296. background: #FFFFFF;
  297. &:last-child {
  298. border-bottom: none;
  299. }
  300. .itemBox {
  301. width: 260upx;
  302. height: 260upx;
  303. margin-right: 30upx;
  304. img {
  305. width: 100%;
  306. height: 100%;
  307. }
  308. }
  309. .itemInfo {
  310. flex: 1;
  311. .iconBox {
  312. image {
  313. width: 58rpx;
  314. height: 36rpx;
  315. }
  316. }
  317. p {
  318. font-size: 26upx;
  319. color: #333333;
  320. line-height: 40upx;
  321. margin-bottom: 20upx;
  322. text-overflow: -o-ellipsis-lastline;
  323. overflow: hidden;
  324. text-overflow: ellipsis;
  325. display: -webkit-box;
  326. -webkit-line-clamp: 2;
  327. line-clamp: 2;
  328. -webkit-box-orient: vertical;
  329. }
  330. .number {
  331. color: #C5AA7B;
  332. font-size: 26rpx;
  333. height: 40rpx;
  334. background: #FFFFFF;
  335. border: 2rpx solid #E4E5E6;
  336. font-weight: 400;
  337. display: inline;
  338. padding: 0 5rpx;
  339. }
  340. .originalPrice {
  341. font-size: 24upx;
  342. margin-top: 20upx;
  343. text-decoration: line-through;
  344. color: #CCCCCC;
  345. }
  346. .price {
  347. display: flex;
  348. justify-content: space-between;
  349. align-items: center;
  350. .priceInfo {
  351. font-size: 40rpx;
  352. color: #C83732;
  353. }
  354. .snapUpBtn {
  355. width: 160upx;
  356. height: 84upx;
  357. text-align: center;
  358. background: linear-gradient(90deg, #C83732 0%, #E25C44 100%);
  359. box-shadow: 0rpx 6rpx 12rpx rgba(233, 0, 0, 0.3);
  360. opacity: 1;
  361. border-radius: 10rpx;
  362. .btnText {
  363. color: #FFFFFF;
  364. font-weight: 400;
  365. opacity: 0.5;
  366. margin: 10rpx 0;
  367. }
  368. }
  369. .btnStyle1 {
  370. background: linear-gradient(90deg, #29C790 0%, #75D98C 100%);
  371. box-shadow: 0 6rpx 12rpx rgba(52, 203, 144, 0.3);
  372. }
  373. }
  374. }
  375. }
  376. }
  377. }
  378. .shop-list-nav {
  379. display: flex;
  380. flex-direction: row;
  381. align-items: center;
  382. height: 80rpx;
  383. line-height: 76rpx;
  384. }
  385. .active {
  386. color: #C5AA7B;
  387. }
  388. .nav-item-sort {
  389. flex: 1;
  390. font-size: 24rpx;
  391. color: #999999;
  392. display: flex;
  393. flex-direction: row;
  394. align-items: center;
  395. justify-content: center;
  396. height: 80rpx;
  397. line-height: 80rpx;
  398. }
  399. .nav-item-sort .r {
  400. display: flex;
  401. flex-direction: column;
  402. align-items: center;
  403. justify-content: center;
  404. margin-left: 5rpx;
  405. .arrowDown {
  406. width: 0;
  407. height: 0;
  408. border-width: 10rpx;
  409. border-style: solid;
  410. border-color: #CCCCCC transparent transparent transparent;
  411. margin-top: 2rpx;
  412. }
  413. .arrowUp {
  414. margin-bottom: 2rpx;
  415. width: 0;
  416. height: 0;
  417. border-width: 10rpx;
  418. border-style: solid;
  419. border-color: transparent transparent #CCCCCC transparent;
  420. }
  421. .activeDown {
  422. border-color: #C5AA7B transparent transparent transparent;
  423. }
  424. .activeUp {
  425. border-color: transparent transparent #C5AA7B transparent;
  426. }
  427. }
  428. </style>