ShopDialog.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. <view class="item-card">
  18. <view class="new-tag" v-if="item.isNew">新品</view>
  19. <view class="item-left">
  20. <image class="item-icon" :src="item.icon" mode="aspectFit"></image>
  21. <text class="owned-text">已持有: {{item.owned}}</text>
  22. </view>
  23. <view class="item-info">
  24. <text class="item-name">{{item.name}}</text>
  25. <view class="item-details">
  26. <text class="detail-text">收获期: {{item.harvestTime}}</text>
  27. <text class="detail-text">成长期: {{item.growthTime}}</text>
  28. <text class="detail-text">产量: {{item.yield}}</text>
  29. </view>
  30. <view class="item-bottom">
  31. <view class="item-price">
  32. <image class="currency-icon" src="/static/currency/coin.png" mode="aspectFit"></image>
  33. <text>{{item.price}}</text>
  34. </view>
  35. <button class="buy-btn">购买</button>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </custom-dialog>
  43. </template>
  44. <script>
  45. import CustomDialog from '../CustomDialog/CustomDialog.vue'
  46. import './ShopDialog.scss'
  47. export default {
  48. name: 'ShopDialog',
  49. components: {
  50. CustomDialog
  51. },
  52. props: {
  53. visible: {
  54. type: Boolean,
  55. default: false
  56. }
  57. },
  58. data() {
  59. return {
  60. dialogVisible: false,
  61. currentTab: 0,
  62. tabs: ['种子', '道具', '钻石'],
  63. items: {
  64. 0: [
  65. {
  66. icon: '/static/items/seed1.png',
  67. name: '草莓种子',
  68. harvestTime: '160时',
  69. growthTime: '60时',
  70. yield: '10',
  71. price: 100,
  72. owned: 3,
  73. isNew: true
  74. },
  75. {
  76. icon: '/static/items/seed1.png',
  77. name: '草莓种子',
  78. harvestTime: '160时',
  79. growthTime: '60时',
  80. yield: '10',
  81. price: 100,
  82. owned: 3,
  83. isNew: true
  84. },
  85. {
  86. icon: '/static/items/seed1.png',
  87. name: '草莓种子',
  88. harvestTime: '160时',
  89. growthTime: '60时',
  90. yield: '10',
  91. price: 100,
  92. owned: 3,
  93. isNew: true
  94. }
  95. ],
  96. 1: [],
  97. 2: []
  98. }
  99. }
  100. },
  101. computed: {
  102. currentItems() {
  103. return this.items[this.currentTab]
  104. }
  105. },
  106. watch: {
  107. visible(val) {
  108. this.dialogVisible = val
  109. },
  110. dialogVisible(val) {
  111. this.$emit('update:visible', val)
  112. }
  113. },
  114. methods: {
  115. onClose() {
  116. this.dialogVisible = false
  117. },
  118. onItemClick(item) {
  119. this.$emit('buy', item)
  120. }
  121. }
  122. }
  123. </script>
  124. <style lang="scss" scoped>
  125. @import './ShopDialog.scss';
  126. </style>