123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465 |
- <template>
- <div>
- <div class="nav-bar">
- <div class="back-btn" @click="$router.back()">
- <i class="arrow-left"></i>
- </div>
- <div class="title">积分商城</div>
- </div>
- <div class="jifen-container">
-
- <!-- 头部积分显示 -->
- <div class="header-section">
- <div class="points-display">
- <h2>兑换国家物资</h2>
- <div class="current-points">{{ userPoints }}</div>
- <div class="points-label">我的积分</div>
- </div>
- </div>
- <!-- 商品网格 -->
- <div class="products-grid">
- <div
- v-for="product in products"
- :key="product.id"
- class="product-card"
- :class="{ 'large-card': product.isLarge }"
- >
- <div class="product-image">
- <img :src="product.image" :alt="product.name" />
- </div>
- <div class="product-info">
- <div class="product-info-content">
- <div class="product-points">{{ product.probability }}积分</div>
- <div class="product-name">{{ product.name }}</div>
- </div>
- <button
- class="exchange-btn"
- @click="handleExchange(product)"
- >
- 立即兑换
- </button>
- </div>
- </div>
- </div>
- <!-- 兑换确认弹窗 -->
- <div v-if="showConfirmDialog" class="confirm-overlay">
- <div class="confirm-dialog">
- <div class="confirm-content">
- <h3>确认兑换</h3>
- <div class="confirm-product">
- <img :src="selectedProduct.image" :alt="selectedProduct.name" />
- <div class="confirm-info">
- <div class="confirm-name">{{ selectedProduct.name }}</div>
- <div class="confirm-points">需要 {{ selectedProduct.probability }} 积分</div>
- </div>
- </div>
- <p>确认要兑换此商品吗?</p>
- <div class="confirm-buttons">
- <button class="btn-cancel" @click="cancelExchange">取消</button>
- <button class="btn-confirm" @click="confirmExchange">确认兑换</button>
- </div>
- </div>
- </div>
- </div>
- <!-- Toast 提示 -->
- <Toast ref="toast" />
- </div>
-
- </div>
- </template>
- <script>
- import Toast from '@/components/Toast.vue';
- import { getLotteryPrize, exchangePrize } from '@/api/profile';
- export default {
- name: 'JifenPage',
- components: {
- Toast
- },
- data() {
- return {
- showConfirmDialog: false,
- selectedProduct: null,
- products: []
- }
- },
- mounted() {
- this.loadProducts();
- },
- methods: {
-
- // 加载商品列表
- async loadProducts() {
- try {
- const res = await getLotteryPrize();
- this.products = res.data;
- // 当前使用模拟数据,实际开发时替换为API调用
- console.log('商品列表加载完成');
- } catch (error) {
- console.error('加载商品列表失败:', error);
- this.$refs.toast.show('加载商品失败', 'error');
- }
- },
- // 处理兑换点击
- handleExchange(product) {
- this.selectedProduct = product;
- this.showConfirmDialog = true;
- },
- // 取消兑换
- cancelExchange() {
- this.showConfirmDialog = false;
- this.selectedProduct = null;
- },
- // 确认兑换
- async confirmExchange() {
- try {
- const res = await exchangePrize({
- prize_id: this.selectedProduct.id,
- });
- console.log(res);
- if(res.code == 1){
- this.$refs.toast.show('兑换成功!', 'success');
- this.userPoints -= this.selectedProduct.points;
- this.showConfirmDialog = false;
- this.selectedProduct = null;
- }else{
- this.$refs.toast.show('兑换失败,请重试', 'error');
- }
-
- this.showConfirmDialog = false;
- this.selectedProduct = null;
-
-
- } catch (error) {
- console.error('兑换失败:', error);
- this.$refs.toast.show('兑换失败,请重试', 'error');
- }
- }
- }
- }
- </script>
- <style scoped>
- .jifen-container {
- min-height: 100vh;
- background: linear-gradient(135deg, #c94545 0%, #b43a39 100%);
- padding: 20px;
- padding-bottom: 100px;
- }
- /* 头部积分显示 */
- .header-section {
- text-align: center;
- margin-bottom: 30px;
- }
- .points-display h2 {
- color: white;
- font-size: 20px;
- font-weight: 600;
- margin-bottom: 10px;
- }
- .current-points {
- color: white;
- font-size: 48px;
- font-weight: bold;
- margin-bottom: 5px;
- text-shadow: 0 2px 4px rgba(0,0,0,0.3);
- }
- .points-label {
- color: white;
- font-size: 16px;
- opacity: 0.9;
- }
- /* 商品网格 */
- .products-grid {
- display: grid;
- grid-template-columns: 1fr 1fr;
- gap: 15px;
- margin-bottom: 20px;
- }
- .product-card {
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- background: white;
- border-radius: 12px;
- padding: 15px;
- box-shadow: 0 4px 12px rgba(0,0,0,0.1);
- transition: transform 0.2s ease;
- }
- .product-card:active {
- transform: scale(0.98);
- }
- .product-card.large-card {
- grid-column: span 2;
- }
- .product-image {
- width: 100%;
- height: 140px;
- background: #f5f5f5;
- border-radius: 8px;
- display: flex;
- align-items: center;
- justify-content: center;
- margin-bottom: 12px;
- overflow: hidden;
- }
- .large-card .product-image {
- height: 120px;
- }
- .product-image img {
- width: 80%;
- height: 80%;
- object-fit: contain;
- }
- .product-info {
- text-align: center;
- }
- .product-info-content {
- display: flex;
- justify-content: space-between;
- align-items: center;
- }
- .product-points {
- font-size: 14px;
- color: #000;
- font-weight: 500;
- }
- .product-name {
- font-size: 14px;
- color: #000;
- font-weight: 500;
- }
- .exchange-btn {
- margin-top: 10px;
- width: 100%;
- background: #c94545;
- color: white;
- border: none;
- border-radius: 20px;
- padding: 8px 0;
- font-size: 14px;
- font-weight: 500;
- cursor: pointer;
- transition: all 0.3s ease;
- }
- .exchange-btn:hover {
- background: #b43a39;
- }
- .exchange-btn:disabled {
- background: #ccc;
- cursor: not-allowed;
- }
- .exchange-btn:active {
- transform: scale(0.95);
- }
- /* 确认弹窗 */
- .confirm-overlay {
- position: fixed;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- background: rgba(0,0,0,0.6);
- display: flex;
- align-items: center;
- justify-content: center;
- z-index: 1000;
- }
- .confirm-dialog {
- background: white;
- border-radius: 12px;
- width: 90%;
- max-width: 400px;
- overflow: hidden;
- }
- .confirm-content {
- padding: 25px 20px;
- text-align: center;
- }
- .confirm-content h3 {
- margin: 0 0 20px 0;
- font-size: 18px;
- color: #333;
- }
- .confirm-product {
- display: flex;
- align-items: center;
- background: #f8f8f8;
- border-radius: 8px;
- padding: 15px;
- margin-bottom: 20px;
- }
- .confirm-product img {
- width: 60px;
- height: 60px;
- object-fit: contain;
- margin-right: 15px;
- background: white;
- border-radius: 6px;
- }
- .confirm-info {
- flex: 1;
- text-align: left;
- }
- .confirm-name {
- font-size: 16px;
- font-weight: 500;
- color: #333;
- margin-bottom: 5px;
- }
- .confirm-points {
- font-size: 14px;
- color: #c94545;
- font-weight: 500;
- }
- .confirm-content p {
- margin: 0 0 25px 0;
- color: #666;
- font-size: 15px;
- }
- .confirm-buttons {
- display: flex;
- gap: 12px;
- }
- .btn-cancel,
- .btn-confirm {
- flex: 1;
- padding: 12px 0;
- border: none;
- border-radius: 8px;
- font-size: 16px;
- font-weight: 500;
- cursor: pointer;
- transition: all 0.3s ease;
- }
- .btn-cancel {
- background: #f5f5f5;
- color: #666;
- }
- .btn-cancel:hover {
- background: #e8e8e8;
- }
- .btn-confirm {
- background: #c94545;
- color: white;
- }
- .btn-confirm:hover {
- background: #b43a39;
- }
- .btn-cancel:active,
- .btn-confirm:active {
- transform: scale(0.98);
- }
- /* 响应式优化 */
- @media screen and (max-width: 375px) {
- .jifen-container {
- padding: 15px;
- }
-
- .products-grid {
- gap: 12px;
- }
-
- .product-card {
- padding: 12px;
- }
-
- .current-points {
- font-size: 42px;
- }
-
- .points-display h2 {
- font-size: 18px;
- }
- }
- @media screen and (max-width: 320px) {
- .current-points {
- font-size: 36px;
- }
-
- .product-image {
- height: 80px;
- }
-
- .large-card .product-image {
- height: 100px;
- }
- }
- .nav-bar {
- height: 44px;
- background-color: #fff;
- color: #000;
- display: flex;
- align-items: center;
- position: relative;
- padding: 0 15px;
- font-weight: bold;
- }
- .back-btn {
- width: 24px;
- height: 44px;
- display: flex;
- align-items: center;
- cursor: pointer;
- }
- .arrow-left {
- width: 12px;
- height: 12px;
- border-left: 2px solid #000;
- border-bottom: 2px solid #000;
- transform: rotate(45deg);
- }
- .title {
- position: absolute;
- left: 50%;
- transform: translateX(-50%);
- font-size: 16px;
- }
- </style>
|