wish.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. <template>
  2. <view class="blessingsPage">
  3. <scroll-view
  4. class="p-scroll-wrapper"
  5. :style="{ top: top + 'px' }"
  6. scroll-y
  7. refresher-enabled
  8. refresher-default-style="white"
  9. @refresherrefresh="pullRefresh"
  10. :refresher-triggered="refreshing"
  11. >
  12. <view>
  13. <view class="blessingsTitle">
  14. <image
  15. :src="ossurl.welfare.blessings.blessingsTitle"
  16. class="blessingsTitleImage"
  17. mode="aspectFit"
  18. />
  19. </view>
  20. <view class="relative swiperBox">
  21. <swiper
  22. class="cardSwiper"
  23. :indicator-dots="false"
  24. @change="changeSwiper"
  25. :current="active"
  26. >
  27. <swiper-item
  28. v-for="(item, index) in tableData"
  29. :key="item.id"
  30. :class="[active == index ? 'cur' : '']"
  31. >
  32. <view class="swiper-item" @click="showGoodsDetail(item.spu)">
  33. <view
  34. class="imgBox"
  35. :style="
  36. 'background-image:url(' +
  37. ossurl.welfare.blessings.cardBg +
  38. ')'
  39. "
  40. >
  41. <image
  42. :src="item.spu.cover"
  43. class="spu-image"
  44. mode="aspectFit"
  45. />
  46. </view>
  47. <view class="numBox">
  48. 仅剩
  49. <span class="num">
  50. {{ item.quantity - item.completeQuantity }}
  51. </span>
  52. </view>
  53. </view>
  54. </swiper-item>
  55. </swiper>
  56. <view class="prev" @click="active -= 1" v-if="active > 0">
  57. <image
  58. :src="ossurl.welfare.blessings.prev"
  59. class="image"
  60. mode="aspectFit"
  61. />
  62. </view>
  63. <view class="next" @click="active += 1" v-if="active < tableData.length - 1">
  64. <image
  65. :src="ossurl.welfare.blessings.next"
  66. class="image"
  67. mode="aspectFit"
  68. />
  69. </view>
  70. <view class="rule-btn" @click="$refs.rule.show()">
  71. <image
  72. :src="ossurl.welfare.blessings.rule"
  73. class="image"
  74. mode="aspectFit"
  75. />
  76. </view>
  77. </view>
  78. <view class="goods-wrapper">
  79. <view class="">
  80. <view class="blessingsPrograss">
  81. <image
  82. :src="ossurl.welfare.blessings.blessingsPrograss"
  83. class="blessingsPrograssImg"
  84. mode="aspectFit"
  85. />
  86. </view>
  87. </view>
  88. <view class="progress">
  89. <view class="progressNum" :style="{ left: progress + '%' }">
  90. {{ progress > 0 ? progress.toFixed(1) : progress }}%
  91. </view>
  92. <view class="bar" :style="{ width: progress + '%' }"></view>
  93. </view>
  94. <view class="processBox">
  95. <view class="addItem" @click="showStoreChoose">
  96. <image :src="ossurl.welfare.blessings.add" class="add" />
  97. </view>
  98. <view class="goodListBox">
  99. <view v-for="(item, index) in goodsList" :key="item.id" class="item">
  100. <image
  101. :src="item.spu.cover"
  102. class="goods radius6"
  103. mode="aspectFit"
  104. />
  105. <span class="cuIcon-close close" @click="minus(item)"></span>
  106. </view>
  107. </view>
  108. </view>
  109. </view>
  110. <view style="height: 130rpx"></view>
  111. </view>
  112. <empty v-if="isEmpty" :top="180" />
  113. </scroll-view>
  114. <view class="bottom paddingB20 paddingT5 flex-align-center">
  115. <view class="collect bottomBtn" v-if="!progress || progress < 100" @click="toAward">
  116. 还差一点点,去收集
  117. </view>
  118. <view class="submit bottomBtn" v-else @click="submit">点亮心愿</view>
  119. </view>
  120. <goods-detail ref="goodsDetailRef" @close="goodsDetailColse" />
  121. <rule ref="rule" />
  122. </view>
  123. </template>
  124. <script>
  125. import ossurl from '@/utils/ossurl'
  126. import empty from '@/components/empty.vue'
  127. import store from '@/store'
  128. import { throttle } from '@/utils'
  129. import goodsDetail from './../store/goods_detail'
  130. import rule from './wish_rule.vue'
  131. export default {
  132. components: { empty, goodsDetail, rule },
  133. props: {
  134. statusBarHeight: Number
  135. },
  136. data() {
  137. return {
  138. ossurl,
  139. refreshing: false,
  140. requesting: false,
  141. active: 0,
  142. tableData: [],
  143. goodsList: [],
  144. goodsMap: {},
  145. progress: 0
  146. }
  147. },
  148. computed: {
  149. top() {
  150. return this.statusBarHeight + uni.upx2px(72) + 45
  151. },
  152. left() {
  153. return (store.state.systemInfo.screenWidth - uni.upx2px(466)) / 2
  154. }
  155. },
  156. mounted() {
  157. this.loadData()
  158. this.$event.on(this.$event.key.STORE_CHOOSE, (map) => {
  159. this.goodsMap = map
  160. this.goodsList = Object.values(map)
  161. this.wishPreview()
  162. })
  163. },
  164. destroyed() {
  165. this.$event.off(this.$event.key.STORE_CHOOSE)
  166. },
  167. methods: {
  168. pullRefresh() {
  169. this.refreshing = true
  170. this.loadData()
  171. },
  172. async loadData() {
  173. this.requesting = true
  174. const res = await this.$service.weal.wishList()
  175. if (res && res.length > 0) {
  176. this.tableData = res
  177. }
  178. setTimeout(() => {
  179. this.refreshing = false
  180. this.requesting = false
  181. }, 1000)
  182. return res
  183. },
  184. changeSwiper(e) {
  185. this.changeActive(e.detail.current)
  186. this.wishPreview()
  187. },
  188. changeActive(index) {
  189. this.active = index
  190. },
  191. showStoreChoose() {
  192. if (!this.$common.checkLogin()) return
  193. this.$cache.set(this.$cache.key.STORE_CHOOSE, this.goodsMap)
  194. this.$router.push('store-choose', { type: 1 })
  195. },
  196. minus(item) {
  197. delete this.goodsMap[item.id]
  198. this.goodsList = Object.values(this.goodsMap)
  199. this.wishPreview()
  200. },
  201. async wishPreview() {
  202. if (!this.goodsList || this.goodsList.length === 0) {
  203. this.progress = 0
  204. return
  205. }
  206. let inventoryIds = this.goodsList.map((item) => item.id)
  207. let id = this.tableData[this.active].id
  208. const res = await this.$service.weal.wishPreview(id, inventoryIds)
  209. if (res) {
  210. let progressNum = res.progress * 100
  211. let progressStr = progressNum.toFixed(4)
  212. let array = progressStr.split('.')
  213. let str = array[0] + '.' + array[1].substr(0, 2)
  214. this.progress = Number(str)<100?Number(str):100
  215. }
  216. },
  217. async submit() {
  218. throttle.call(this.realSubmit)
  219. },
  220. realSubmit() {
  221. if (!this.goodsList || this.goodsList.length === 0 || this.progress < 100) {
  222. return
  223. }
  224. let inventoryIds = this.goodsList.map((item) => item.id)
  225. let id = this.tableData[this.active].id
  226. this.$message.confirm('确定点亮吗?', async () => {
  227. const res = await this.$service.weal.wishSubmit(id, inventoryIds)
  228. if (res) {
  229. this.goodsList = []
  230. this.goodsMap = {}
  231. this.progress = 0
  232. this.$message.success('置换成功')
  233. }
  234. })
  235. },
  236. toAward() {
  237. this.$router.switchTab('award')
  238. },
  239. showGoodsDetail(spu) {
  240. this.$parent.$parent.lock = true
  241. this.$refs.goodsDetailRef.show(spu)
  242. },
  243. goodsDetailColse() {
  244. this.$parent.$parent.lock = false
  245. }
  246. }
  247. }
  248. </script>
  249. <style lang="scss" scoped>
  250. .blessingsPage {
  251. padding-top: 160rpx;
  252. }
  253. .cardSwiper {
  254. height: 630rpx;
  255. position: relative;
  256. .swiper-item {
  257. padding: 0;
  258. position: relative;
  259. .imgBox {
  260. height: 630rpx;
  261. background-size: 474rpx 626rpx;
  262. background-position: center;
  263. background-repeat: no-repeat;
  264. text-align: center;
  265. display: flex;
  266. align-items: center;
  267. justify-content: center;
  268. padding-top: 40rpx;
  269. }
  270. .spu-image {
  271. width: 400rpx;
  272. height: 550rpx;
  273. }
  274. .numBox {
  275. position: absolute;
  276. left: 118rpx;
  277. z-index: 100;
  278. bottom: 50rpx;
  279. background: #000000;
  280. color: #f0cd49;
  281. font-size: 20rpx;
  282. border-radius: 0 28rpx 28rpx 0;
  283. line-height: 38rpx;
  284. padding: 4rpx;
  285. display: flex;
  286. align-items: center;
  287. .num {
  288. display: inline-block;
  289. text-align: center;
  290. margin-left: 8rpx;
  291. width: 30rpx;
  292. height: 30rpx;
  293. background: #f0cd49;
  294. color: #000;
  295. border-radius: 50%;
  296. line-height: 30rpx;
  297. font-size: 24rpx;
  298. }
  299. }
  300. }
  301. }
  302. .swiperBox {
  303. position: relative;
  304. height: 41vh;
  305. .prev,
  306. .next {
  307. position: absolute;
  308. z-index: 100;
  309. .image {
  310. width: 72rpx;
  311. height: 72rpx;
  312. }
  313. }
  314. .prev {
  315. left: 20rpx;
  316. top: 45%;
  317. }
  318. .next {
  319. right: 20rpx;
  320. top: 45%;
  321. }
  322. }
  323. .goods-wrapper {
  324. height: 20vh;
  325. margin: 0 28rpx;
  326. margin-top: 2.5vh;
  327. padding: 32rpx 30rpx;
  328. border-radius: 20rpx;
  329. min-height: 200rpx;
  330. .progress {
  331. margin-top: 20rpx;
  332. margin-bottom: 16rpx;
  333. height: 36rpx;
  334. width: 100%;
  335. border-radius: 18rpx;
  336. background: #c20009;
  337. border: 8rpx solid rgb(231, 86, 88);
  338. position: relative;
  339. .bar {
  340. height: 100%;
  341. border-radius: 10rpx;
  342. background: linear-gradient(90deg, #000000 0%, #460008 100%);
  343. width: 0%;
  344. position: absolute;
  345. left: 0;
  346. height: 18rpx;
  347. bottom: 0;
  348. }
  349. .progressNum {
  350. position: absolute;
  351. width: 84rpx;
  352. height: 38rpx;
  353. border: 4rpx solid #fde3ac;
  354. text-align: center;
  355. line-height: 30rpx;
  356. font-size: 24rpx;
  357. font-family: Source Han Sans, Source Han Sans;
  358. font-weight: 400;
  359. color: #fde3ac;
  360. border-radius: 20rpx;
  361. z-index: 10;
  362. background: #000000;
  363. bottom: -8rpx;
  364. margin-left: -42rpx;
  365. }
  366. }
  367. .item {
  368. position: relative;
  369. margin: 14rpx 16rpx;
  370. width: 72rpx;
  371. height: 94rpx;
  372. background: #930007;
  373. border-radius: 8px;
  374. display: flex;
  375. align-items: center;
  376. justify-content: center;
  377. .goods {
  378. width: 60rpx;
  379. height: 80rpx;
  380. }
  381. .add {
  382. width: 116rpx;
  383. height: 116rpx;
  384. }
  385. .close {
  386. position: absolute;
  387. right: -10rpx;
  388. top: -10rpx;
  389. width: 32rpx;
  390. height: 32rpx;
  391. background-color: #000;
  392. color: #fde3ac;
  393. border: 3rpx solid #fde3ac;
  394. border-radius: 50%;
  395. font-size: 20rpx;
  396. text-align: center;
  397. line-height: 28rpx;
  398. }
  399. }
  400. }
  401. .bottom {
  402. position: fixed;
  403. left: 0;
  404. right: 0;
  405. bottom: 0;
  406. }
  407. .rule-btn {
  408. position: absolute;
  409. right: 0rpx;
  410. top: -100rpx;
  411. .image {
  412. width: 42rpx;
  413. height: 74rpx;
  414. }
  415. }
  416. .blessingsTitle {
  417. text-align: center;
  418. height: 10vh;
  419. line-height: 10vh;
  420. .blessingsTitleImage {
  421. height: 130rpx;
  422. width: 474rpx;
  423. }
  424. }
  425. .blessingsPrograss {
  426. text-align: center;
  427. .blessingsPrograssImg {
  428. width: 204rpx;
  429. height: 48rpx;
  430. }
  431. }
  432. .bottomBtn {
  433. border-radius: 40rpx;
  434. background: #f0cd49;
  435. border: 8rpx solid rgb(213, 87, 69);
  436. line-height: 60rpx;
  437. padding: 0 80rpx;
  438. }
  439. .processBox {
  440. padding: 16rpx 6rpx;
  441. border-radius: 10rpx;
  442. background: rgba(105, 0, 0, 0.23);
  443. display: flex;
  444. .goodListBox {
  445. overflow: auto;
  446. flex: 1;
  447. width: 0;
  448. word-break: keep-all;
  449. white-space: nowrap;
  450. .item {
  451. display: inline-block;
  452. padding: 12rpx 14rpx;
  453. }
  454. }
  455. .addItem {
  456. position: relative;
  457. padding-right: 15rpx;
  458. &::after {
  459. position: absolute;
  460. right: 0rpx;
  461. width: 4rpx;
  462. height: 100%;
  463. background: linear-gradient(
  464. 180deg,
  465. rgba(253, 227, 172, 0) 0%,
  466. #fde3ac 54%,
  467. rgba(253, 227, 172, 0) 100%
  468. );
  469. content: '';
  470. display: inline-block;
  471. }
  472. .add {
  473. width: 112rpx;
  474. height: 112rpx;
  475. }
  476. }
  477. }
  478. </style>