ShopDialog.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <custom-dialog :visible.sync="dialogVisible" title="商店" @close="onClose">
  3. <view class="shop-content">
  4. <view class="shop-tabs">
  5. <view
  6. v-for="(tab, index) in tabs"
  7. :key="index"
  8. class="tab-item"
  9. :class="{'active': currentTab === index}"
  10. @click="currentTab = index"
  11. >
  12. {{tab}}
  13. </view>
  14. </view>
  15. <view class="shop-items">
  16. <view class="shop-item" v-for="(item, index) in currentItems" :key="index" @click="onItemClick(item)">
  17. <image class="item-icon" :src="item.icon" mode="aspectFit"></image>
  18. <view class="item-info">
  19. <text class="item-name">{{item.name}}</text>
  20. <text class="item-desc">{{item.description}}</text>
  21. </view>
  22. <view class="item-price">
  23. <image class="currency-icon" src="/static/currency/coin.png" mode="aspectFit"></image>
  24. <text>{{item.price}}</text>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </custom-dialog>
  30. </template>
  31. <script>
  32. import CustomDialog from '../CustomDialog/CustomDialog.vue'
  33. export default {
  34. name: 'ShopDialog',
  35. components: {
  36. CustomDialog
  37. },
  38. props: {
  39. visible: {
  40. type: Boolean,
  41. default: false
  42. }
  43. },
  44. data() {
  45. return {
  46. dialogVisible: false,
  47. currentTab: 0,
  48. tabs: ['道具', '装备', '材料'],
  49. items: {
  50. 0: [
  51. { icon: '/static/items/potion1.png', name: '生命药水', description: '恢复100点生命值', price: 100 },
  52. { icon: '/static/items/potion2.png', name: '魔法药水', description: '恢复50点魔法值', price: 150 },
  53. { icon: '/static/items/potion3.png', name: '体力药水', description: '恢复50点体力值', price: 120 }
  54. ],
  55. 1: [
  56. { icon: '/static/items/weapon1.png', name: '铁剑', description: '攻击力+10', price: 500 },
  57. { icon: '/static/items/armor1.png', name: '皮甲', description: '防御力+5', price: 300 }
  58. ],
  59. 2: [
  60. { icon: '/static/items/material1.png', name: '木材', description: '基础材料', price: 50 },
  61. { icon: '/static/items/material2.png', name: '铁矿', description: '基础材料', price: 80 }
  62. ]
  63. }
  64. }
  65. },
  66. computed: {
  67. currentItems() {
  68. return this.items[this.currentTab]
  69. }
  70. },
  71. watch: {
  72. visible(val) {
  73. this.dialogVisible = val
  74. },
  75. dialogVisible(val) {
  76. this.$emit('update:visible', val)
  77. }
  78. },
  79. methods: {
  80. onClose() {
  81. this.dialogVisible = false
  82. },
  83. onItemClick(item) {
  84. // 处理购买逻辑
  85. this.$emit('buy', item)
  86. }
  87. }
  88. }
  89. </script>
  90. <style lang="scss" scoped>
  91. .shop-content {
  92. .shop-tabs {
  93. display: flex;
  94. border-bottom: 2rpx solid #eee;
  95. margin-bottom: 20rpx;
  96. .tab-item {
  97. flex: 1;
  98. text-align: center;
  99. padding: 20rpx 0;
  100. font-size: 28rpx;
  101. color: #666;
  102. position: relative;
  103. &.active {
  104. color: #007AFF;
  105. font-weight: 500;
  106. &::after {
  107. content: '';
  108. position: absolute;
  109. bottom: 0;
  110. left: 50%;
  111. transform: translateX(-50%);
  112. width: 40rpx;
  113. height: 4rpx;
  114. background: #007AFF;
  115. border-radius: 2rpx;
  116. }
  117. }
  118. }
  119. }
  120. .shop-items {
  121. .shop-item {
  122. display: flex;
  123. align-items: center;
  124. padding: 20rpx;
  125. border-bottom: 2rpx solid #f5f5f5;
  126. .item-icon {
  127. width: 80rpx;
  128. height: 80rpx;
  129. margin-right: 20rpx;
  130. }
  131. .item-info {
  132. flex: 1;
  133. .item-name {
  134. font-size: 28rpx;
  135. color: #333;
  136. margin-bottom: 4rpx;
  137. }
  138. .item-desc {
  139. font-size: 24rpx;
  140. color: #999;
  141. }
  142. }
  143. .item-price {
  144. display: flex;
  145. align-items: center;
  146. gap: 8rpx;
  147. .currency-icon {
  148. width: 32rpx;
  149. height: 32rpx;
  150. }
  151. text {
  152. font-size: 28rpx;
  153. color: #FF9500;
  154. font-weight: 500;
  155. }
  156. }
  157. }
  158. }
  159. }
  160. </style>