|
@@ -63,43 +63,8 @@ export default {
|
|
|
return {
|
|
|
dialogVisible: false,
|
|
|
selectedIndex: -1,
|
|
|
- items: [
|
|
|
- {
|
|
|
- icon: '/static/island/items/item_wood1.png',
|
|
|
- count: 999,
|
|
|
- name: '木材',
|
|
|
- description: '这是一个木材,可以用来制作各种物品',
|
|
|
- price: 100
|
|
|
- },
|
|
|
- {
|
|
|
- icon: '/static/island/items/item_wood2.png',
|
|
|
- count: 999,
|
|
|
- name: '高级木材',
|
|
|
- description: '这是一个高级木材,可以用来制作高级物品',
|
|
|
- price: 200
|
|
|
- },
|
|
|
- {
|
|
|
- icon: '/static/island/items/item_mine1.png',
|
|
|
- count: 999,
|
|
|
- name: '矿石',
|
|
|
- description: '这是一个矿石,可以用来制作金属物品',
|
|
|
- price: 150
|
|
|
- },
|
|
|
- {
|
|
|
- icon: '/static/island/items/item_mine2.png',
|
|
|
- count: 999,
|
|
|
- name: '高级矿石',
|
|
|
- description: '这是一个高级矿石,可以用来制作高级金属物品',
|
|
|
- price: 300
|
|
|
- },
|
|
|
- {
|
|
|
- icon: '/static/island/items/item_axe1.png',
|
|
|
- count: 999,
|
|
|
- name: '斧头',
|
|
|
- description: '这是一个斧头,可以用来砍伐树木',
|
|
|
- price: 500
|
|
|
- }
|
|
|
- ]
|
|
|
+ items: [],
|
|
|
+ loading: false
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
@@ -113,8 +78,7 @@ export default {
|
|
|
visible(val) {
|
|
|
this.dialogVisible = val
|
|
|
if(val) {
|
|
|
- // 默认选中第一个有道具的格子
|
|
|
- this.selectedIndex = this.items.length > 0 ? 0 : -1
|
|
|
+ this.fetchBagList()
|
|
|
}
|
|
|
},
|
|
|
dialogVisible(val) {
|
|
@@ -122,6 +86,51 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
+ fetchBagList() {
|
|
|
+ this.loading = true
|
|
|
+ uni.request({
|
|
|
+ url: this.$apiHost + '/Game/get_bag_list',
|
|
|
+ method: 'GET',
|
|
|
+ data: {
|
|
|
+ uuid: getApp().globalData.uuid,
|
|
|
+ },
|
|
|
+ header: {
|
|
|
+ 'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
+ 'sign': getApp().globalData.headerSign,
|
|
|
+ },
|
|
|
+ success: (res) => {
|
|
|
+ if (res.data.code === 0) {
|
|
|
+ this.items = res.data.data.bagList.map(item => ({
|
|
|
+ id: item.id,
|
|
|
+ tid: item.tid,
|
|
|
+ type: item.type,
|
|
|
+ count: item.num,
|
|
|
+ name: item.name,
|
|
|
+ icon: item.image,
|
|
|
+ description: `这是一个${item.name},数量:${item.num}`,
|
|
|
+ price: item.price // 这里可以根据实际需求设置价格
|
|
|
+ }))
|
|
|
+ // 默认选中第一个有道具的格子
|
|
|
+ this.selectedIndex = this.items.length > 0 ? 0 : -1
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: res.data.msg || '获取背包数据失败',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.error('获取背包数据失败:', err)
|
|
|
+ uni.showToast({
|
|
|
+ title: '获取背包数据失败',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ },
|
|
|
+ complete: () => {
|
|
|
+ this.loading = false
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
onClose() {
|
|
|
this.dialogVisible = false
|
|
|
},
|
|
@@ -144,8 +153,42 @@ export default {
|
|
|
cancelText: '取消',
|
|
|
success: (res) => {
|
|
|
if(res.confirm) {
|
|
|
- // TODO: 处理出售逻辑
|
|
|
- this.$emit('sell', item)
|
|
|
+ uni.request({
|
|
|
+ url: this.$apiHost + '/Game/sell_bag_item',
|
|
|
+ method: 'POST',
|
|
|
+ data: {
|
|
|
+ uuid: getApp().globalData.uuid,
|
|
|
+ bag_id: item.id
|
|
|
+ },
|
|
|
+ header: {
|
|
|
+ 'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
+ 'sign': getApp().globalData.headerSign,
|
|
|
+ },
|
|
|
+ success: (res) => {
|
|
|
+ if (res.data.code === 0) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '出售成功',
|
|
|
+ icon: 'success'
|
|
|
+ })
|
|
|
+ // 刷新背包列表
|
|
|
+ this.fetchBagList()
|
|
|
+ // 通知父组件更新铃钱
|
|
|
+ this.$emit('money-change', res.data.data.money)
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: res.data.msg || '出售失败',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.error('出售失败:', err)
|
|
|
+ uni.showToast({
|
|
|
+ title: '出售失败',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
})
|