ShopDialog.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. export default {
  47. name: 'ShopDialog',
  48. components: {
  49. CustomDialog
  50. },
  51. props: {
  52. visible: {
  53. type: Boolean,
  54. default: false
  55. }
  56. },
  57. data() {
  58. return {
  59. dialogVisible: false,
  60. currentTab: 0,
  61. tabs: ['种子', '道具', '钻石'],
  62. items: {
  63. 0: [
  64. {
  65. icon: '/static/items/seed1.png',
  66. name: '草莓种子',
  67. harvestTime: '160时',
  68. growthTime: '60时',
  69. yield: '10',
  70. price: 100,
  71. owned: 3,
  72. isNew: true
  73. },
  74. {
  75. icon: '/static/items/seed1.png',
  76. name: '草莓种子',
  77. harvestTime: '160时',
  78. growthTime: '60时',
  79. yield: '10',
  80. price: 100,
  81. owned: 3,
  82. isNew: true
  83. },
  84. {
  85. icon: '/static/items/seed1.png',
  86. name: '草莓种子',
  87. harvestTime: '160时',
  88. growthTime: '60时',
  89. yield: '10',
  90. price: 100,
  91. owned: 3,
  92. isNew: true
  93. }
  94. ],
  95. 1: [],
  96. 2: []
  97. }
  98. }
  99. },
  100. computed: {
  101. currentItems() {
  102. return this.items[this.currentTab]
  103. }
  104. },
  105. watch: {
  106. visible(val) {
  107. this.dialogVisible = val
  108. },
  109. dialogVisible(val) {
  110. this.$emit('update:visible', val)
  111. }
  112. },
  113. methods: {
  114. onClose() {
  115. this.dialogVisible = false
  116. },
  117. onItemClick(item) {
  118. this.$emit('buy', item)
  119. }
  120. }
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. @import './ShopDialog.scss';
  125. </style>