BackpackDialog.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <custom-dialog
  3. :visible.sync="dialogVisible"
  4. title=""
  5. content-width="720rpx"
  6. closeImg="/static/island/UI/btn_close.png"
  7. closeImgTop="120rpx"
  8. background-color="transparent"
  9. @close="onClose"
  10. >
  11. <view class="backpack-content">
  12. <view class="backpack-name">背包</view>
  13. <view class="backpack-items">
  14. <view
  15. class="backpack-grid"
  16. v-for="index in 80"
  17. :key="index"
  18. @click="onGridClick(index-1)"
  19. >
  20. <view
  21. class="item-grid"
  22. :class="{'selected': selectedIndex === index-1 && items[index-1]}"
  23. >
  24. <template v-if="items[index-1]">
  25. <text class="count-text">{{items[index-1].count}}</text>
  26. <image class="item-icon" :src="items[index-1].icon" mode="aspectFit"></image>
  27. <text class="item-name">{{items[index-1].name}}</text>
  28. </template>
  29. </view>
  30. </view>
  31. </view>
  32. <view class="backpack-bottom">
  33. <view class="bottom-info">
  34. <text>{{selectedItem ? selectedItem.description : '请选择道具查看详情'}}</text>
  35. </view>
  36. <view class="bottom-actions">
  37. <view class="coin-info">
  38. <image class="currency-icon" src="/static/island/UI/wd_icon_xingyuan.png" mode="aspectFit"></image>
  39. <text>{{selectedItem ? selectedItem.price : 0}}</text>
  40. </view>
  41. <view class="sell-btn" :class="{'disabled': !selectedItem}" @click="onSellClick">售卖</view>
  42. </view>
  43. </view>
  44. </view>
  45. </custom-dialog>
  46. </template>
  47. <script>
  48. import CustomDialog from '../CustomDialog/CustomDialog.vue'
  49. export default {
  50. name: 'BackpackDialog',
  51. components: {
  52. CustomDialog
  53. },
  54. props: {
  55. visible: {
  56. type: Boolean,
  57. default: false
  58. }
  59. },
  60. data() {
  61. return {
  62. dialogVisible: false,
  63. selectedIndex: -1,
  64. items: [
  65. {
  66. icon: '/static/island/items/item_wood1.png',
  67. count: 999,
  68. name: '木材',
  69. description: '这是一个木材,可以用来制作各种物品',
  70. price: 100
  71. },
  72. {
  73. icon: '/static/island/items/item_wood2.png',
  74. count: 999,
  75. name: '高级木材',
  76. description: '这是一个高级木材,可以用来制作高级物品',
  77. price: 200
  78. },
  79. {
  80. icon: '/static/island/items/item_mine1.png',
  81. count: 999,
  82. name: '矿石',
  83. description: '这是一个矿石,可以用来制作金属物品',
  84. price: 150
  85. },
  86. {
  87. icon: '/static/island/items/item_mine2.png',
  88. count: 999,
  89. name: '高级矿石',
  90. description: '这是一个高级矿石,可以用来制作高级金属物品',
  91. price: 300
  92. },
  93. {
  94. icon: '/static/island/items/item_axe1.png',
  95. count: 999,
  96. name: '斧头',
  97. description: '这是一个斧头,可以用来砍伐树木',
  98. price: 500
  99. }
  100. ]
  101. }
  102. },
  103. computed: {
  104. selectedItem() {
  105. return this.selectedIndex >= 0 && this.selectedIndex < this.items.length
  106. ? this.items[this.selectedIndex]
  107. : null
  108. }
  109. },
  110. watch: {
  111. visible(val) {
  112. this.dialogVisible = val
  113. if(val) {
  114. // 默认选中第一个有道具的格子
  115. this.selectedIndex = this.items.length > 0 ? 0 : -1
  116. }
  117. },
  118. dialogVisible(val) {
  119. this.$emit('update:visible', val)
  120. }
  121. },
  122. methods: {
  123. onClose() {
  124. this.dialogVisible = false
  125. },
  126. onGridClick(index) {
  127. if(this.items[index]) {
  128. this.selectedIndex = index
  129. this.$emit('select', this.items[index])
  130. }
  131. },
  132. onSellClick() {
  133. if(!this.selectedItem) return
  134. const item = this.selectedItem
  135. const totalPrice = item.count * item.price
  136. uni.showModal({
  137. title: '确认出售',
  138. content: `出售${item.count}个${item.name},会获得铃钱:${totalPrice},\n确定出售吗?`,
  139. confirmText: '确定',
  140. cancelText: '取消',
  141. success: (res) => {
  142. if(res.confirm) {
  143. // TODO: 处理出售逻辑
  144. this.$emit('sell', item)
  145. }
  146. }
  147. })
  148. }
  149. }
  150. }
  151. </script>
  152. <style lang="scss" scoped>
  153. @import './BackpackDialog.scss';
  154. </style>