jiuyiUniapp/jiuyi2/pages/index/orchard.vue

274 lines
5.3 KiB
Vue
Raw Normal View History

2024-12-18 15:46:27 +08:00
<script setup>
/**
* 榴莲果园
*/
import {
onMounted,
ref,
reactive,
getCurrentInstance,
watch,
computed,
defineExpose,
} from 'vue';
import {
onLoad,
onReady,
onHide,
} from '@dcloudio/uni-app'
// 顶部
import apex from '@/components/header/apex.vue'
// 请求地址
import api from '@/api/index.js'
//
import util from "@/common/js/util.js"
import {
useStore,
} from 'vuex'
// 榴莲果api
2024-12-18 15:46:27 +08:00
import durianlApi from '@/api/durian.js';
const {
proxy
} = getCurrentInstance()
2024-12-31 17:07:01 +08:00
const store = useStore()
// 榴莲果树列表
2024-12-18 15:46:27 +08:00
const viewData = ref([])
// 当前选择的榴莲果树对象
const selectItem = ref({})
// 规则文章
const rule = reactive({})
const userinfo = computed(() => {
let result = store.state.userinfo
return result
})
2025-01-04 20:33:45 +08:00
// 我的钱包
const purse = computed(() => {
return store.state.purse || {}
})
2024-12-18 15:46:27 +08:00
onLoad(() => {
// 获取可以兑换的榴莲果树
buyDurianList()
2025-01-04 20:33:45 +08:00
// 获取钱包
util.getPurse()
// 获取榴莲果规则
getArticle()
2024-12-18 15:46:27 +08:00
})
onReady(() => {
// proxy.$refs.ruleRef.open()
})
2024-12-31 14:46:56 +08:00
// 获取可以兑换的榴莲果树
2024-12-18 15:46:27 +08:00
function buyDurianList() {
2025-01-04 20:33:45 +08:00
durianlApi.durianList({}).then(rs => {
if (rs.code == 200) {
viewData.value = rs.data
return
}
util.alert({
content: rs.msg,
showCancel: false,
})
2024-12-18 15:46:27 +08:00
})
}
/**
* 兑换榴莲果树
2024-12-31 14:46:56 +08:00
* @param {Object} type 1榴莲果兑换 2种子兑换
2024-12-18 15:46:27 +08:00
*/
function exchange(type) {
2024-12-31 17:07:01 +08:00
const config = {
'1': {
price: selectItem.value.fruitNeed,
name: '榴莲果',
},
'2': {
price: selectItem.value.seedNeed,
name: '种子',
},
} [type]
2024-12-18 15:46:27 +08:00
util.alert({
2024-12-31 17:07:01 +08:00
content: `确认消耗${config.price}${config.name}购买榴莲果`,
2024-12-18 15:46:27 +08:00
}).then(rs => {
if (!rs.confirm) return
durianlApi.exchange({
2024-12-31 14:46:56 +08:00
data: {
2024-12-31 17:07:01 +08:00
// userId: userinfo.value.userId,
2025-01-01 00:04:32 +08:00
durianConfigId: selectItem.value.durianConfigInfoId,
2024-12-18 15:46:27 +08:00
type: type
},
}).then(rs => {
if (rs.code === 200) {
util.alert('置换成功')
proxy.$refs.typeRef.close()
2025-01-04 20:33:45 +08:00
// 获取钱包
util.getPurse()
2024-12-18 15:46:27 +08:00
return
}
2024-12-31 17:07:01 +08:00
2024-12-18 15:46:27 +08:00
util.alert({
content: rs.msg,
2024-12-31 17:07:01 +08:00
showCancel: false,
2024-12-18 15:46:27 +08:00
})
})
})
}
// 获取榴莲果规则
function getArticle() {
api.getArticle({
query: {
agreementId: 5,
2024-12-18 15:46:27 +08:00
}
}).then(rs => {
if (rs.code == 200) {
// 合并
Object.assign(rule, rs.data)
return
}
util.alert({
content: rs.msg,
value: false,
})
})
}
function openExchange(item) {
selectItem.value = item
proxy.$refs.typeRef.open()
}
function openChange() {
proxy.$refs.ruleRef.open()
}
</script>
<template>
<view class="appbw">
<!-- -->
<apex title="榴莲果园">
<template #right>
<view class="rule fmid mr10 wh80 cfff f20 cir" @click="openChange">规则</view>
</template>
</apex>
<!-- 拥有的 -->
<view class="has navs mtb40 plr50 c333 f28">
<view class="item df">
<image class="wh150" src="/static/sapling.png" mode="aspectFit" />
2025-01-04 20:33:45 +08:00
<text>×{{purse.seed}}</text>
2024-12-18 15:46:27 +08:00
</view>
<view class="item df">
<image class="wh150" src="/static/fruit.png" mode="aspectFit" />
2025-01-04 20:33:45 +08:00
<text>×{{purse.fruit}}</text>
2024-12-18 15:46:27 +08:00
</view>
</view>
<!-- 列表 -->
<view class="list">
<view class="item rows mtb30 mlr25 br15" v-for="(item,index) in viewData" :key="index">
<image class="wh180" src="@/static/tree.png" mode="aspectFit" />
<view class="content f1 mlr30 c333 f28">
2024-12-31 14:46:56 +08:00
<text>需要{{item.seedNeed}}种子或{{item.fruitNeed}}榴莲果</text>
<text>置换1颗{{item.durianName}}</text>
2024-12-18 15:46:27 +08:00
</view>
2024-12-31 17:07:01 +08:00
<view class="button fmid mlr40 wh110 c333 f24 bfff cir" @click="openExchange(item)">置换</view>
2024-12-18 15:46:27 +08:00
</view>
</view>
<!-- 填充 -->
<view class="fill" style="height: 60rpx;"></view>
</view>
<!-- 请选择对换方式 -->
<uni-popup ref="typeRef" type="center">
<view class="typeAlt popMid ver bfff">
<image class="wh350" src="/static/tree.png" mode="aspectFit" />
<view class="title c333 f48">请选择置换方式</view>
<view class="btns fmid mtb40">
2024-12-31 17:07:01 +08:00
<!-- 1榴莲果兑换 2种子兑换 -->
2024-12-31 14:46:56 +08:00
<view class="btn lg black w200" @click="exchange('2')">种子置换</view>
<view class="btn lg black w200" @click="exchange('1')">榴莲果置换</view>
2024-12-18 15:46:27 +08:00
</view>
</view>
</uni-popup>
<!-- 规则说明 -->
<uni-popup ref="ruleRef" type="center">
<view class="ruleAlt popMid bfff">
<view class="title tac ptb15 c333 f36 b">规则说明</view>
<view class="content mtb20 mlr25">
<scroll-view scroll-y="true" class="scroll">
<rich-text :nodes="rule.content"></rich-text>
2024-12-18 15:46:27 +08:00
</scroll-view>
</view>
</view>
</uni-popup>
</template>
<style lang="scss">
// 规则
.rule {
background-color: #1f1f1f;
}
// 拥有
.has {
.item {
align-items: flex-end;
}
}
// 列表
.list {
.item:nth-child(9n-8) {
background-color: #F2F2F2;
}
.item:nth-child(9n-7) {
2025-01-01 00:04:32 +08:00
background-color: #FFF0B1;
2024-12-18 15:46:27 +08:00
}
.item:nth-child(9n-6) {
2025-01-01 00:04:32 +08:00
background-color: #CAF0F3;
2024-12-18 15:46:27 +08:00
}
.item:nth-child(9n-5) {
2025-01-01 00:04:32 +08:00
background-color: #FBC5C5;
2024-12-18 15:46:27 +08:00
}
.item:nth-child(9n-4) {
background-color: #C3EBBD;
}
.item:nth-child(9n-3) {
background-color: #F2EDE3;
}
.item:nth-child(9n-2) {
background-color: #EBEBFF;
}
.item:nth-child(9n-1) {
background-color: #9EDEFF;
}
.item:nth-child(9n) {
background-color: #E8E7EE;
}
}
// 规则弹窗
.ruleAlt {
.scroll {
height: 50vh;
}
}
</style>