|
|
@@ -134,7 +134,7 @@
|
|
|
</van-cell>
|
|
|
</van-cell-group> -->
|
|
|
|
|
|
- <div class="vip-box">
|
|
|
+ <div class="vip-box" v-if="(userVip && userVip.autoTradeEnabled) || typeList.length > 0">
|
|
|
<img v-if="isVip" src="@/assets/png-huiyuan-bg.png" alt="" class="bg" />
|
|
|
<img v-else src="@/assets/png-huiyuan-bg-not.png" alt="" class="bg" />
|
|
|
<div class="vip-content">
|
|
|
@@ -145,7 +145,7 @@
|
|
|
<div class="text1">{{ vipTitle }}</div>
|
|
|
<div class="text2">{{ vipTime }}</div>
|
|
|
</div>
|
|
|
- <div class="btn" @click="showRechargeModal = true">
|
|
|
+ <div class="btn" @click="onVipPurchase">
|
|
|
<img v-if="isVip" src="@/assets/icon-anniu.png" alt="" />
|
|
|
<img v-else src="@/assets/icon-anniu-not.png" alt="" />
|
|
|
<span>{{ isVip ? $t('vip.btn') : $t('balance.recharge') }}</span>
|
|
|
@@ -159,9 +159,17 @@
|
|
|
</div>
|
|
|
<div class="tips">
|
|
|
{{ $t('vip.auto') }}
|
|
|
- <span>({{ checked ? $t('vip.isOpen') : $t('vip.isClose') }})</span>
|
|
|
+ <span
|
|
|
+ >({{
|
|
|
+ userVip && userVip.autoTradeEnabled ? $t('vip.isOpen') : $t('vip.isClose')
|
|
|
+ }})</span
|
|
|
+ >
|
|
|
</div>
|
|
|
- <van-switch @click="changeAuto" :disabled="!isVip" v-model="checked" />
|
|
|
+ <van-switch
|
|
|
+ @click="changeAuto"
|
|
|
+ :disabled="!isVip"
|
|
|
+ :model-value="userVip && userVip.autoTradeEnabled"
|
|
|
+ />
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -219,10 +227,10 @@
|
|
|
<ion-modal
|
|
|
id="modal-recharge"
|
|
|
class="modal"
|
|
|
- :is-open="showRechargeModal"
|
|
|
+ :is-open="showVipPurchaseModal"
|
|
|
:initial-breakpoint="breakpoint"
|
|
|
:breakpoints="[0, breakpoint]"
|
|
|
- @didDismiss="showRechargeModal = false"
|
|
|
+ @didDismiss="showVipPurchaseModal = false"
|
|
|
>
|
|
|
<ion-content class="modal-content" :style="{ height: `${breakpoint * 100}%` }">
|
|
|
<div class="modal-box">
|
|
|
@@ -233,13 +241,13 @@
|
|
|
<div class="text1">{{ $t('vip.recharge') }}</div>
|
|
|
<div class="text2">{{ $t('vip.tips') }}</div>
|
|
|
</div>
|
|
|
- <div class="close" @click="showRechargeModal = false">
|
|
|
+ <div class="close" @click="showVipPurchaseModal = false">
|
|
|
<img src="@/assets/icon_close2.png" alt="" />
|
|
|
</div>
|
|
|
</div>
|
|
|
- <van-tabs v-model:active="chooseType" @change="getTypeVip">
|
|
|
+ <van-tabs v-model:active="chooseType" @change="getVipConfig">
|
|
|
<van-tab
|
|
|
- :title="item.typeName"
|
|
|
+ :title="item.name"
|
|
|
:name="item.id"
|
|
|
v-for="(item, index) in typeList"
|
|
|
:key="index"
|
|
|
@@ -290,9 +298,9 @@
|
|
|
<img src="@/assets/icon_close2.png" alt="" />
|
|
|
</div>
|
|
|
<div class="fileds">
|
|
|
- <van-field v-model="upInterval" type="digit" :placeholder="$t('vip.pla')" />
|
|
|
+ <van-field v-model="maxPrice" type="digit" :placeholder="$t('vip.pla')" />
|
|
|
<span class="fileds-text"> {{ $t('vip.to') }} </span>
|
|
|
- <van-field v-model="downInterval" type="digit" :placeholder="$t('vip.pla')" />
|
|
|
+ <van-field v-model="minPrice" type="digit" :placeholder="$t('vip.pla')" />
|
|
|
</div>
|
|
|
<div class="footer">
|
|
|
<van-button type="primary" block @click="confirmInterval">{{
|
|
|
@@ -307,11 +315,10 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { computed } from 'vue'
|
|
|
+import { computed, ref, watch, inject } from 'vue'
|
|
|
import { useUserStore } from '@/stores/user'
|
|
|
import { useIonRouter } from '@ionic/vue'
|
|
|
import defaultAvatar from '@/assets/png_moren.png'
|
|
|
-import { ref, watch } from 'vue'
|
|
|
import { http } from '@/plugins/http'
|
|
|
import { onIonViewWillEnter } from '@ionic/vue'
|
|
|
import intoIcon from '@/assets/svgs/icon_inter.svg'
|
|
|
@@ -320,11 +327,10 @@ import { useI18n } from 'vue-i18n'
|
|
|
import { differenceInDays, format } from 'date-fns'
|
|
|
import Toast from '@/utils/toast'
|
|
|
import { showConfirmDialog } from 'vant'
|
|
|
+import { storeToRefs } from 'pinia'
|
|
|
|
|
|
-const userStore = useUserStore()
|
|
|
-const user = computed(() => {
|
|
|
- return userStore.user
|
|
|
-})
|
|
|
+const promptLogin = inject('promptLogin')
|
|
|
+const { user } = storeToRefs(useUserStore())
|
|
|
|
|
|
const router = useIonRouter()
|
|
|
const goLogin = () => {
|
|
|
@@ -344,14 +350,14 @@ function getBalance() {
|
|
|
watch(user, val => {
|
|
|
if (val) {
|
|
|
getBalance()
|
|
|
- getVip()
|
|
|
+ getVipType()
|
|
|
} else {
|
|
|
balance.value = {}
|
|
|
}
|
|
|
})
|
|
|
onIonViewWillEnter(() => {
|
|
|
getBalance()
|
|
|
- getVip()
|
|
|
+ getVipType()
|
|
|
})
|
|
|
const balanceText = computed(() => {
|
|
|
if (balance.value && balance.value.balance != undefined) {
|
|
|
@@ -360,7 +366,7 @@ const balanceText = computed(() => {
|
|
|
return '-'
|
|
|
})
|
|
|
|
|
|
-const showRechargeModal = ref(false)
|
|
|
+const showVipPurchaseModal = ref(false)
|
|
|
const { height: windowHeight } = useWindowSize()
|
|
|
const breakpoint = computed(() => {
|
|
|
return Number((530 / windowHeight.value).toFixed(2))
|
|
|
@@ -368,48 +374,48 @@ const breakpoint = computed(() => {
|
|
|
|
|
|
const vipList = ref([])
|
|
|
const typeList = ref([])
|
|
|
-const chooseType = ref(0)
|
|
|
-const chooseVip = ref(0)
|
|
|
+const chooseType = ref(null)
|
|
|
+const chooseVip = ref(null)
|
|
|
|
|
|
-const checked = ref(false)
|
|
|
-const vipUserInfo = ref(null)
|
|
|
-function getVip() {
|
|
|
- if (user.value == null) return
|
|
|
- http.post('/vip/typeList').then(res => {
|
|
|
+const userVip = ref(null)
|
|
|
+function getVipType() {
|
|
|
+ http.post('/vip/type/all', { query: { enabled: true } }, { body: 'json' }).then(res => {
|
|
|
typeList.value = res
|
|
|
if (res.length > 0) {
|
|
|
chooseType.value = res[0].id
|
|
|
}
|
|
|
- getTypeVip()
|
|
|
+ getVipConfig()
|
|
|
})
|
|
|
getMineVip()
|
|
|
}
|
|
|
|
|
|
-function getTypeVip() {
|
|
|
- http.get('/vip/vipList/' + chooseType.value).then(res => {
|
|
|
+function getVipConfig() {
|
|
|
+ if (!chooseType.value) return
|
|
|
+ http.post('/vip/config/all', { query: { typeId: chooseType.value } }, { body: 'json' }).then(res => {
|
|
|
vipList.value = res
|
|
|
if (res.length > 0) {
|
|
|
chooseVip.value = res[0].id
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
-
|
|
|
+function onVipPurchase() {
|
|
|
+ if (!user.value) {
|
|
|
+ promptLogin()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ showVipPurchaseModal.value = true
|
|
|
+}
|
|
|
function getMineVip() {
|
|
|
- http.get('/vip/getUserVipInfo/' + user.value.id)
|
|
|
- .then(res => {
|
|
|
- vipUserInfo.value = res
|
|
|
- checked.value = res.isAuto
|
|
|
- upInterval.value = res.upInterval
|
|
|
- downInterval.value = res.downInterval
|
|
|
- if (res.vipId) {
|
|
|
- return http.get('/vip/get/' + res.vipId)
|
|
|
- } else {
|
|
|
- return Promise.reject()
|
|
|
- }
|
|
|
- })
|
|
|
- .then(res => {
|
|
|
- maxNumber.value = res.validityPeriod
|
|
|
- })
|
|
|
+ if (!user.value) {
|
|
|
+ userVip.value = null
|
|
|
+ return
|
|
|
+ }
|
|
|
+ http.get('/vip/mine').then(res => {
|
|
|
+ userVip.value = res
|
|
|
+ maxPrice.value = res.maxPrice
|
|
|
+ minPrice.value = res.minPrice
|
|
|
+ maxNumber.value = res.dailyFrequency
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
function recharge() {
|
|
|
@@ -417,19 +423,16 @@ function recharge() {
|
|
|
message: t('common.loading') + '...',
|
|
|
forbidClick: true
|
|
|
})
|
|
|
- http.post('/vip/createOrder', {
|
|
|
- vipId: chooseVip.value
|
|
|
+ http.post('/vip/purchaseVip', {
|
|
|
+ typeId: chooseType.value,
|
|
|
+ configId: chooseVip.value,
|
|
|
+ num: 1
|
|
|
})
|
|
|
- .then(res => {
|
|
|
- return http.post('/vip/balancePay', {
|
|
|
- vipOrderId: res.id
|
|
|
- })
|
|
|
- })
|
|
|
.then(res => {
|
|
|
Toast.clear()
|
|
|
- showRechargeModal.value = false
|
|
|
+ showVipPurchaseModal.value = false
|
|
|
getBalance()
|
|
|
- getVip()
|
|
|
+ getVipType()
|
|
|
Toast.success(t('blf.sucess'))
|
|
|
})
|
|
|
.catch(e => {
|
|
|
@@ -440,14 +443,14 @@ function recharge() {
|
|
|
}
|
|
|
|
|
|
const isVip = computed(() => {
|
|
|
- return vipUserInfo.value && vipUserInfo.value.status === 'EFFECTIVE'
|
|
|
+ return userVip.value && userVip.value.expired === false
|
|
|
})
|
|
|
const { t } = useI18n()
|
|
|
const vipTitle = computed(() => {
|
|
|
if (isVip.value) {
|
|
|
return t('vip.title')
|
|
|
} else {
|
|
|
- if (vipUserInfo.value) {
|
|
|
+ if (userVip.value) {
|
|
|
return t('vip.expired')
|
|
|
} else {
|
|
|
return t('vip.noVip')
|
|
|
@@ -456,10 +459,10 @@ const vipTitle = computed(() => {
|
|
|
})
|
|
|
const vipTime = computed(() => {
|
|
|
if (isVip.value) {
|
|
|
- return t('vip.time') + ' ' + format(new Date(vipUserInfo.value.endTime), 'yyyy-mm-dd', new Date())
|
|
|
+ return t('vip.time') + ' ' + format(new Date(userVip.value.expireAt), 'yyyy-MM-dd', new Date())
|
|
|
} else {
|
|
|
- if (vipUserInfo.value) {
|
|
|
- let day = differenceInDays(new Date(), new Date(vipUserInfo.value.endTime))
|
|
|
+ if (userVip.value) {
|
|
|
+ let day = differenceInDays(new Date(), new Date(userVip.value.expireAt))
|
|
|
return t('vip.lost', { day: day })
|
|
|
} else {
|
|
|
return t('vip.TopUp')
|
|
|
@@ -469,12 +472,11 @@ const vipTime = computed(() => {
|
|
|
|
|
|
const showSetModal = ref(false)
|
|
|
const maxNumber = ref(0)
|
|
|
-const upInterval = ref(0)
|
|
|
-const downInterval = ref(0)
|
|
|
+const maxPrice = ref(0)
|
|
|
+const minPrice = ref(0)
|
|
|
|
|
|
function changeAuto() {
|
|
|
- checked.value = vipUserInfo.value.isAuto
|
|
|
- if (vipUserInfo.value.isAuto) {
|
|
|
+ if (userVip.value.autoTradeEnabled) {
|
|
|
showConfirmDialog({
|
|
|
title: t('common.alert'),
|
|
|
message: t('vip.sureClose'),
|
|
|
@@ -485,10 +487,10 @@ function changeAuto() {
|
|
|
message: t('common.loading') + '...',
|
|
|
forbidClick: true
|
|
|
})
|
|
|
- return http.get('/vip/modifyAuto/' + user.value.id)
|
|
|
+ return http.post('/vip/disableAutoTrade')
|
|
|
})
|
|
|
.then(() => {
|
|
|
- Toast.success(t('vip.closeSu'))
|
|
|
+ Toast.success(t('vip.closed'))
|
|
|
getMineVip()
|
|
|
})
|
|
|
.catch(e => {
|
|
|
@@ -503,7 +505,7 @@ function changeAuto() {
|
|
|
}
|
|
|
|
|
|
function confirmInterval() {
|
|
|
- if (Number(downInterval.value) <= Number(upInterval.value)) {
|
|
|
+ if (Number(minPrice.value) <= Number(maxPrice.value)) {
|
|
|
Toast('请输入正确区间')
|
|
|
return
|
|
|
}
|
|
|
@@ -511,17 +513,14 @@ function confirmInterval() {
|
|
|
message: t('common.loading') + '...',
|
|
|
forbidClick: true
|
|
|
})
|
|
|
- http.post('/vip/modifyInterval', {
|
|
|
+ http.post('/vip/enableAutoTrade', {
|
|
|
userId: user.value.id,
|
|
|
- upInterval: upInterval.value,
|
|
|
- downInterval: downInterval.value
|
|
|
+ maxPrice: maxPrice.value,
|
|
|
+ minPrice: minPrice.value
|
|
|
})
|
|
|
- .then(res => {
|
|
|
- return http.get('/vip/modifyAuto/' + user.value.id)
|
|
|
- })
|
|
|
.then(() => {
|
|
|
showSetModal.value = false
|
|
|
- Toast.success('开启成功')
|
|
|
+ Toast.success(t('vip.opened'))
|
|
|
getMineVip()
|
|
|
})
|
|
|
.catch(e => {
|
|
|
@@ -908,10 +907,10 @@ ion-content {
|
|
|
--van-switch-height: 20px;
|
|
|
--van-switch-node-size: 26px;
|
|
|
border: 1px solid #ffffff;
|
|
|
- /deep/&.van-switch--on {
|
|
|
+ :deep(&.van-switch--on) {
|
|
|
border-color: #0044b4;
|
|
|
}
|
|
|
- /deep/.van-switch__node {
|
|
|
+ :deep(.van-switch__node) {
|
|
|
height: 16px;
|
|
|
border-radius: 16px;
|
|
|
}
|