prize.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. <template>
  2. <view class="prize">
  3. <!-- 分段器 -->
  4. <view class="segmented">
  5. <view class="tab_nav">
  6. <view class="navTitle" v-for="(item,index) in items" :key="index">
  7. <view :class="{'active':isActive == index}" @click="checked(index)">
  8. {{item}}
  9. </view>
  10. </view>
  11. </view>
  12. </view>
  13. <!-- 占位 -->
  14. <view style="width: 100%;height: 112rpx;"></view>
  15. <view class="msg-null" v-if="isActive == 0 && PhysicalPrizes.length == 0 ">
  16. <image src="https://t9.9026.com/imgs/dataNull.png" style="width: 394rpx;height: 396rpx;" mode=""></image>
  17. <view class="msg-null-text">
  18. <text>暂无数据</text>
  19. </view>
  20. </view>
  21. <view class="msg-null" v-if="isActive == 1 && VirtualPrizes.length == 0 ">
  22. <image src="https://t9.9026.com/imgs/dataNull.png" style="width: 394rpx;height: 396rpx;" mode=""></image>
  23. <view class="msg-null-text">
  24. <text>暂无数据</text>
  25. </view>
  26. </view>
  27. <view class="msg-null" v-if="isActive == 2 && prizeRecord.length == 0 ">
  28. <image src="https://t9.9026.com/imgs/dataNull.png" style="width: 394rpx;height: 396rpx;" mode=""></image>
  29. <view class="msg-null-text">
  30. <text>暂无数据</text>
  31. </view>
  32. </view>
  33. <view style="margin-bottom: 60rpx;margin-top: 24rpx;">
  34. <!-- 实物奖品 -->
  35. <view class="prizeList" :style="{'--height':ListHeight+'rpx'}"
  36. v-if="isActive == 0 && PhysicalPrizes.length > 0 ">
  37. <view class="ListItem" v-for="(item,index) in PhysicalPrizes" :key="index">
  38. <view class="title"><text>{{item.name}}</text></view>
  39. <view class='data'><text>{{item.exchange_start_time}}--{{item.exchange_end_time}}</text></view>
  40. <view class="alreadyBtn" v-if="item.status == 2">
  41. <text>已兑换</text>
  42. </view>
  43. <view class="instantBtn" v-if="item.status == 1" @click="goExchangePhy(item.id)">
  44. <text>立即兑换</text>
  45. </view>
  46. <view class="alreadyBtn" v-if="item.status == 3">
  47. <text>已过期</text>
  48. </view>
  49. </view>
  50. </view>
  51. <!-- 线下奖品 -->
  52. <view class="prizeList" :style="{'--height':ListHeight+'rpx'}"
  53. v-if="isActive == 1 && VirtualPrizes.length > 0 ">
  54. <view class="ListItem" v-for="(item,index) in VirtualPrizes" :key="index">
  55. <view class="title"><text>{{item.name}}</text></view>
  56. <view class='data'><text>{{item.exchange_start_time}}--{{item.exchange_end_time}}</text></view>
  57. <view class="instantBtn" v-if="item.status == 1" @click="goExchangeVir(item.id)">
  58. <text>立即兑换</text>
  59. </view>
  60. <view class="alreadyBtn" v-if="item.status == 2">
  61. <text>已兑换</text>
  62. </view>
  63. <view class="alreadyBtn" v-if="item.status == 3">
  64. <text>已过期</text>
  65. </view>
  66. <view class="alreadyBtn" v-if="item.status == 4">
  67. <text>未开始</text>
  68. </view>
  69. </view>
  70. </view>
  71. <!-- 中奖记录 -->
  72. <view class="prizeList" :style="{'--height':ListHeight+'rpx'}"
  73. v-if="isActive == 2 && prizeRecord.length > 0 ">
  74. <view class="ListItem" v-for="(item,index) in prizeRecord" :key="index">
  75. <view style="display: flex; justify-content: space-between;">
  76. <view class="title"><text>{{item.name}}</text> </view>
  77. <view class='data' style="flex:none;"><text>{{item.created_at}}</text></view>
  78. </view>
  79. <view class="content"><text>{{item.remark||'无'}}</text></view>
  80. </view>
  81. </view>
  82. </view>
  83. <!-- 已经到底啦 -->
  84. <view class="home-bottom" style="margin-top: 88rpx;padding-bottom: 60rpx;" v-if="isActive == 0 && PhysicalPrizes.length > 0 " >
  85. <uni-load-more :status="status" color="#CCCCCC"
  86. :content-text="contentText" />
  87. </view>
  88. <view class="home-bottom" style="margin-top: 88rpx;padding-bottom: 60rpx;" v-if="isActive == 1 && VirtualPrizes.length > 0 " >
  89. <uni-load-more :status="status" color="#CCCCCC"
  90. :content-text="contentText" />
  91. </view>
  92. <view class="home-bottom" style="margin-top: 88rpx;padding-bottom: 60rpx;" v-if="isActive == 2 && prizeRecord.length > 0 " >
  93. <uni-load-more :status="status" color="#CCCCCC"
  94. :content-text="contentText" />
  95. </view>
  96. </view>
  97. </template>
  98. <script>
  99. export default {
  100. data() {
  101. return {
  102. // 分段器标题
  103. items: ['实物奖品', '虚拟奖品', '中奖记录'],
  104. isActive: 0,
  105. // 列表高度
  106. ListHeight: 800,
  107. contentText: {
  108. contentdown: '查看更多',
  109. contentrefresh: '加载中',
  110. contentnomore: '—— 已经到底啦 ——'
  111. },
  112. // 实物奖品列表
  113. PhysicalPrizes: [],
  114. // 虚拟奖品列表
  115. VirtualPrizes: [],
  116. // 中奖记录
  117. prizeRecord: [],
  118. // 分页
  119. page: 1,
  120. pagesize: 15,
  121. totalElements: '',
  122. allListItem: '',
  123. // 组件uni-load-more
  124. status: 'noMore',
  125. totalElementsPhy: '',
  126. totalElementsVir: '',
  127. }
  128. },
  129. onLoad(o) {
  130. if (o.product_type == 2) {
  131. //分段器标题切换
  132. this.checked(o.product_type - 1)
  133. } else {
  134. //实物奖品
  135. this.getPrizeList(0)
  136. }
  137. uni.$on('refreshPrizeData', () => {
  138. // 中奖记录
  139. this.getPrizeRecord()
  140. //实物奖品
  141. this.getPrizeList(0)
  142. //虚拟奖品
  143. this.getPrizeList(1)
  144. })
  145. },
  146. onUnload() {
  147. uni.$emit('refreshOrderNum')
  148. },
  149. onReachBottom() {
  150. // 触底的时候请求数据,即为上拉加载更多
  151. var allTotal = this.page * this.pagesize
  152. //this.page为加载次数,this.pagesize为每一次加载的数据条数
  153. if (this.isActive == 1) {
  154. console.log('虚拟')
  155. if (allTotal < this.totalElementsVir) {
  156. //this.totalElements为请求数据的总条数。只要现有条数小于总条数就就执行一下代码
  157. this.allListItem = false;
  158. this.page++;
  159. //加载次数递加
  160. this.status = "loading"
  161. this.$api.lottery.getDrawRecord({ //请求更多数据列表
  162. page: this.page,
  163. is_virtual: this.isActive,
  164. }).then(res => {
  165. let ret = [...this.VirtualPrizes, ...res.data.data]
  166. this.VirtualPrizes = ret
  167. console.log(ret)
  168. })
  169. } else {
  170. this.allListItem = true;
  171. console.log('已加载全部数据')
  172. this.status = "noMore"
  173. }
  174. } else if (this.isActive == 2) {
  175. if (allTotal < this.totalElements) {
  176. //this.totalElements为请求数据的总条数。只要现有条数小于总条数就就执行一下代码
  177. this.allListItem = false;
  178. this.page++;
  179. //加载次数递加
  180. this.status = "loading"
  181. this.$api.lottery.getDrawRecord({ //请求更多数据列表
  182. page: this.page,
  183. }).then(res => {
  184. let ret = [...this.prizeRecord, ...res.data.data]
  185. this.prizeRecord = ret
  186. console.log(ret)
  187. })
  188. } else {
  189. this.allListItem = true;
  190. console.log('已加载全部数据')
  191. this.status = "noMore"
  192. }
  193. }else if(this.isActive ==0) {
  194. console.log(allTotal,'实物');
  195. if (allTotal < this.totalElementsPhy) {
  196. //this.totalElements为请求数据的总条数。只要现有条数小于总条数就就执行一下代码
  197. this.allListItem = false;
  198. this.page++;
  199. //加载次数递加
  200. this.status = "loading"
  201. this.$api.lottery.getDrawRecord({ //请求更多数据列表
  202. page: this.page,
  203. is_virtual: this.isActive,
  204. }).then(res => {
  205. let ret = [...this.PhysicalPrizes, ...res.data.data]
  206. this.PhysicalPrizes = ret
  207. console.log(ret)
  208. })
  209. } else {
  210. this.allListItem = true;
  211. console.log('已加载全部数据')
  212. this.status = "noMore"
  213. }
  214. }
  215. },
  216. methods: {
  217. // 获取奖品列表
  218. getPrizeList(type) {
  219. this.$api.lottery.getDrawRecord({
  220. is_virtual: type,
  221. page: 0
  222. }).then(res => {
  223. //实物奖品
  224. if (type == 0) {
  225. this.PhysicalPrizes = res.data.data
  226. this.totalElementsPhy = res.data.total
  227. this.pagesize = res.data.per_page
  228. } else {
  229. this.VirtualPrizes = res.data.data
  230. this.totalElementsVir = res.data.total
  231. this.pagesize = res.data.per_page
  232. console.log(this.totalElementsVir,'虚拟');
  233. }
  234. })
  235. },
  236. // 获取中奖记录
  237. getPrizeRecord() {
  238. this.$api.lottery.getDrawRecord({
  239. page: 0
  240. }).then(res => {
  241. console.log(res, "中奖记录")
  242. if (res.code == 0) {
  243. this.prizeRecord = res.data.data
  244. this.totalElements = res.data.total
  245. this.pagesize = res.data.per_page
  246. }
  247. })
  248. },
  249. //分段器标题切换
  250. checked(index) {
  251. if (index <= 1) {
  252. this.page = 1
  253. this.isActive = index
  254. console.log(this.isActive,'------->this.isActive');
  255. this.getPrizeList(index)
  256. } else {
  257. this.page = 1
  258. this.isActive = index
  259. this.getPrizeRecord()
  260. }
  261. },
  262. // 实物立即兑换
  263. goExchangePhy(id) {
  264. uni.navigateTo({
  265. url: `/pages/my/prize/exchangePrize?id=${id}&isPhy=1`
  266. })
  267. },
  268. // 虚拟立即兑换
  269. goExchangeVir(id) {
  270. uni.navigateTo({
  271. url: `/pages/my/prize/exchangePrize?id=${id}&isPhy=2`
  272. })
  273. },
  274. },
  275. }
  276. </script>
  277. <style lang="scss" scoped>
  278. $pageColor:#F9F9F9;
  279. $bgColor:#FFFFFF;
  280. @mixin flexlayout {
  281. display: flex;
  282. align-items: center;
  283. justify-content: center;
  284. }
  285. .prize {
  286. height: 100%;
  287. background: $pageColor;
  288. }
  289. .msg-null {
  290. padding-top: 60rpx;
  291. display: flex;
  292. flex-direction: column;
  293. align-items: center;
  294. justify-content: center;
  295. .msg-null-text {
  296. margin-top: 40rpx;
  297. font-size: 28rpx;
  298. color: #333;
  299. }
  300. }
  301. .segmented {
  302. position: fixed;
  303. top: 0;
  304. z-index: 999;
  305. width: 750rpx;
  306. height: 112rpx;
  307. background: $bgColor;
  308. box-shadow: 0px 4rpx 8rpx 0rpx rgba(0, 0, 0, 0.04);
  309. border-radius: 0rpx 0rpx 16rpx 16rpx;
  310. margin-bottom: 24rpx;
  311. padding: 0rpx 30rpx;
  312. box-sizing: border-box;
  313. //菜单切换
  314. .tab_nav {
  315. width: 690rpx;
  316. display: flex;
  317. justify-content: space-between;
  318. align-items: center;
  319. font-family: PingFang-SC-Heavy, PingFang-SC;
  320. }
  321. .tab_nav .navTitle {
  322. margin-top: 20rpx;
  323. width: 128rpx;
  324. flex: none;
  325. height: 28rpx;
  326. font-size: 32rpx;
  327. color: #666;
  328. position: relative;
  329. }
  330. .active {
  331. color: #D9A94D;
  332. font-weight: bold;
  333. &::after {
  334. display: inline-block;
  335. content: '';
  336. width: 48rpx;
  337. height: 12rpx;
  338. background: linear-gradient(90deg, #F3D69F 0%, #D9A94D 100%);
  339. border-radius: 6px;
  340. position: absolute;
  341. bottom: -30rpx;
  342. left: 40rpx;
  343. }
  344. }
  345. }
  346. ::v-deep .segmented-control__text {
  347. font-size: 32rpx !important;
  348. font-family: PingFang-SC-Heavy, PingFang-SC;
  349. font-weight: 500 !important;
  350. }
  351. ::v-deep .segmented-control__item--text {
  352. font-size: 32rpx;
  353. font-family: PingFang-SC-Heavy, PingFang-SC;
  354. font-weight: 800 !important;
  355. padding: 10rpx 0 !important;
  356. border-radius: 4rpx !important;
  357. }
  358. .prizeList {
  359. width: 750rpx;
  360. // height: var(--height);
  361. background: $bgColor;
  362. box-shadow: 0px 4rpx 24rpx -10rpx rgba(101, 95, 90, 0.3);
  363. border-radius: 12rpx;
  364. padding: 0rpx 28rpx 0 32rpx;
  365. box-sizing: border-box;
  366. .ListItem {
  367. width: 690rpx;
  368. height: 160rpx;
  369. border-bottom: #F0F0F0 solid 0.5rpx;
  370. position: relative;
  371. padding-top: 35rpx;
  372. box-sizing: border-box;
  373. .title {
  374. margin-bottom: 5rpx;
  375. text {
  376. font-size: 32rpx;
  377. font-family: PingFang-SC-Bold, PingFang-SC;
  378. font-weight: bold;
  379. color: #333333;
  380. }
  381. }
  382. .data {
  383. text {
  384. font-size: 26rpx;
  385. font-family: PingFang-SC-Medium, PingFang-SC;
  386. font-weight: 500;
  387. color: #999999;
  388. }
  389. }
  390. .alreadyBtn {
  391. position: absolute;
  392. top: 50rpx;
  393. right: 0rpx;
  394. width: 148rpx;
  395. height: 60rpx;
  396. background: $bgColor;
  397. border-radius: 30rpx;
  398. border: 2rpx solid #D0D0D0;
  399. @include flexlayout();
  400. text {
  401. font-size: 26rpx;
  402. font-family: PingFang-SC-Medium, PingFang-SC;
  403. font-weight: 500;
  404. color: #D0D0D0;
  405. }
  406. }
  407. .instantBtn {
  408. position: absolute;
  409. top: 50rpx;
  410. right: 0rpx;
  411. width: 148rpx;
  412. height: 60rpx;
  413. background: $bgColor;
  414. border-radius: 30rpx;
  415. border: 2rpx solid #FF6200;
  416. @include flexlayout();
  417. text {
  418. font-size: 26rpx;
  419. font-family: PingFang-SC-Medium, PingFang-SC;
  420. color: #FF6200;
  421. }
  422. }
  423. .content {
  424. text {
  425. font-size: 28rpx;
  426. font-family: PingFang-SC-Medium, PingFang-SC;
  427. font-weight: 500;
  428. color: #333333;
  429. }
  430. }
  431. }
  432. .ListItem:last-child {
  433. width: 690rpx;
  434. height: 160rpx;
  435. border-bottom: #F0F0F0 solid 0rpx;
  436. position: relative;
  437. padding-top: 35rpx;
  438. box-sizing: border-box;
  439. .title {
  440. margin-bottom: 10rpx;
  441. text {
  442. font-size: 32rpx;
  443. font-family: PingFang-SC-Bold, PingFang-SC;
  444. font-weight: bold;
  445. color: #333333;
  446. }
  447. }
  448. .data {
  449. text {
  450. font-size: 26rpx;
  451. font-family: PingFang-SC-Medium, PingFang-SC;
  452. color: #999999;
  453. }
  454. }
  455. .alreadyBtn {
  456. position: absolute;
  457. top: 50rpx;
  458. right: 0rpx;
  459. width: 148rpx;
  460. height: 60rpx;
  461. background: $bgColor;
  462. border-radius: 30rpx;
  463. border: 2rpx solid #D0D0D0;
  464. @include flexlayout();
  465. text {
  466. font-size: 26rpx;
  467. font-family: PingFang-SC-Medium, PingFang-SC;
  468. font-weight: 500;
  469. color: #D0D0D0;
  470. }
  471. }
  472. .instantBtn {
  473. position: absolute;
  474. top: 50rpx;
  475. right: 0rpx;
  476. width: 148rpx;
  477. height: 60rpx;
  478. background: $bgColor;
  479. border-radius: 30rpx;
  480. border: 2rpx solid #FF6200;
  481. @include flexlayout();
  482. text {
  483. font-size: 26rpx;
  484. font-family: PingFang-SC-Medium, PingFang-SC;
  485. font-weight: 500;
  486. color: #FF6200;
  487. }
  488. }
  489. .content {
  490. text {
  491. font-size: 28rpx;
  492. font-family: PingFang-SC-Medium, PingFang-SC;
  493. font-weight: 500;
  494. color: #333333;
  495. }
  496. }
  497. }
  498. }
  499. </style>