prize.vue 13 KB

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