接入官方商城的相关接口
This commit is contained in:
parent
1507d390ed
commit
ce17cb4060
@ -61,6 +61,9 @@ import { UserModule } from '@/store/modules/user'
|
|||||||
import ChainManager from '@/chain/ChainManager'
|
import ChainManager from '@/chain/ChainManager'
|
||||||
import { EventBus, PRESALE_BEGIN, PRESALE_ERROR, PRESALE_ORDER_GET } from '@/utils/event-bus'
|
import { EventBus, PRESALE_BEGIN, PRESALE_ERROR, PRESALE_ORDER_GET } from '@/utils/event-bus'
|
||||||
import { buyBox } from '@/api/Mall'
|
import { buyBox } from '@/api/Mall'
|
||||||
|
import { buyShopBox } from '@/api/Market'
|
||||||
|
|
||||||
|
export const TMP_SHOP_ORDER_ID = 'tmp_presale_order_id'
|
||||||
|
|
||||||
export interface IBoxData{
|
export interface IBoxData{
|
||||||
level: string
|
level: string
|
||||||
@ -79,6 +82,8 @@ export interface IBoxData{
|
|||||||
})
|
})
|
||||||
export default class OneBox extends Vue {
|
export default class OneBox extends Vue {
|
||||||
@Prop() private boxData: IBoxData
|
@Prop() private boxData: IBoxData
|
||||||
|
@Prop() private preSale: boolean
|
||||||
|
|
||||||
chainManger = new ChainManager()
|
chainManger = new ChainManager()
|
||||||
|
|
||||||
formatPriceShow(price: number|string, decimals?: number, fixed = 2) {
|
formatPriceShow(price: number|string, decimals?: number, fixed = 2) {
|
||||||
@ -134,9 +139,14 @@ export default class OneBox extends Vue {
|
|||||||
signature
|
signature
|
||||||
}
|
}
|
||||||
await this.chainManger.bc.increaseAllowance(priceData.contract_address, price)
|
await this.chainManger.bc.increaseAllowance(priceData.contract_address, price)
|
||||||
const res: any = await buyBox(buyData)
|
let res: any
|
||||||
|
if (this.preSale) {
|
||||||
|
res = await buyBox(buyData)
|
||||||
|
} else {
|
||||||
|
res = await buyShopBox(buyData)
|
||||||
|
}
|
||||||
const orderId = res.order_id
|
const orderId = res.order_id
|
||||||
localStorage.setItem('tmp_presale_order_id', orderId)
|
localStorage.setItem(TMP_SHOP_ORDER_ID, orderId)
|
||||||
EventBus.$emit(PRESALE_ORDER_GET, orderId)
|
EventBus.$emit(PRESALE_ORDER_GET, orderId)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('buy error: ', err)
|
console.log('buy error: ', err)
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="box-list">
|
<div class="box-list">
|
||||||
<one-box v-for="data in boxDatas" :key="data.id" :box-data="data"></one-box>
|
<one-box v-for="data in boxDatas" :key="data.id" :pre-sale="false" :box-data="data"></one-box>
|
||||||
</div>
|
</div>
|
||||||
<pagination
|
<pagination
|
||||||
v-if="totalPage>1"
|
v-if="totalPage>1"
|
||||||
@ -49,16 +49,16 @@
|
|||||||
import { Component, Vue, Watch } from 'vue-property-decorator'
|
import { Component, Vue, Watch } from 'vue-property-decorator'
|
||||||
import TopMenu from '@/components/market/TopMenu.vue'
|
import TopMenu from '@/components/market/TopMenu.vue'
|
||||||
import BaseFooter from '@/components/layout/BaseFooter.vue'
|
import BaseFooter from '@/components/layout/BaseFooter.vue'
|
||||||
import OneBox, { IBoxData } from '@/components/market/mall/OneBox.vue'
|
import OneBox, { IBoxData, TMP_SHOP_ORDER_ID } from '@/components/market/mall/OneBox.vue'
|
||||||
import { UserModule } from '@/store/modules/user'
|
import { UserModule } from '@/store/modules/user'
|
||||||
import { AppModule } from '@/store/modules/app'
|
import { AppModule } from '@/store/modules/app'
|
||||||
import ChainManager from '@/chain/ChainManager'
|
import ChainManager from '@/chain/ChainManager'
|
||||||
import { EventBus, PRESALE_BEGIN, PRESALE_ERROR, PRESALE_ORDER_GET, PRESALE_SUCCESS } from '@/utils/event-bus'
|
import { EventBus, PRESALE_BEGIN, PRESALE_ERROR, PRESALE_ORDER_GET, PRESALE_SUCCESS } from '@/utils/event-bus'
|
||||||
import { secs2str } from '@/utils/time.util'
|
import { secs2str } from '@/utils/time.util'
|
||||||
import { queryOrder, queryPresaleStatus, searchBox } from '@/api/Mall'
|
|
||||||
import { ElLoadingComponent } from 'element-ui/types/loading'
|
import { ElLoadingComponent } from 'element-ui/types/loading'
|
||||||
import TimeLoader from '@/components/main/TimeLoader.vue'
|
import TimeLoader from '@/components/main/TimeLoader.vue'
|
||||||
import Pagination from '@/components/market/Pagination.vue'
|
import Pagination from '@/components/market/Pagination.vue'
|
||||||
|
import { queryShopList, queryShopOrder } from '@/api/Market'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
components: {
|
components: {
|
||||||
@ -105,7 +105,6 @@ export default class Official extends Vue {
|
|||||||
@Watch('isLogin')
|
@Watch('isLogin')
|
||||||
private accountChange() {
|
private accountChange() {
|
||||||
if (this.accountId) {
|
if (this.accountId) {
|
||||||
this.getPresaleInfo()
|
|
||||||
this.checkOrderHistory()
|
this.checkOrderHistory()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,11 +132,10 @@ export default class Official extends Vue {
|
|||||||
|
|
||||||
async fetchData() {
|
async fetchData() {
|
||||||
await this.queryPresaleList()
|
await this.queryPresaleList()
|
||||||
await this.getPresaleInfo()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
checkOrderHistory() {
|
checkOrderHistory() {
|
||||||
const historyOrderId = localStorage.getItem('tmp_presale_order_id')
|
const historyOrderId = localStorage.getItem(TMP_SHOP_ORDER_ID)
|
||||||
if (historyOrderId && this.accountId) {
|
if (historyOrderId && this.accountId) {
|
||||||
this.beginTraceOrderStatus(historyOrderId)
|
this.beginTraceOrderStatus(historyOrderId)
|
||||||
}
|
}
|
||||||
@ -180,7 +178,6 @@ export default class Official extends Vue {
|
|||||||
this.resetTmpOrderId()
|
this.resetTmpOrderId()
|
||||||
this.showOrderStatus = false
|
this.showOrderStatus = false
|
||||||
this.$alert('Congratulations', 'Buy Success', { type: 'success', confirmButtonText: 'OK' })
|
this.$alert('Congratulations', 'Buy Success', { type: 'success', confirmButtonText: 'OK' })
|
||||||
await this.getPresaleInfo()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
beginTraceOrderStatus(orderId: string) {
|
beginTraceOrderStatus(orderId: string) {
|
||||||
@ -196,13 +193,13 @@ export default class Official extends Vue {
|
|||||||
clearInterval(this.orderTimer)
|
clearInterval(this.orderTimer)
|
||||||
this.orderTimer = null
|
this.orderTimer = null
|
||||||
}
|
}
|
||||||
localStorage.removeItem('tmp_presale_order_id')
|
localStorage.removeItem(TMP_SHOP_ORDER_ID)
|
||||||
this.loadingInstance?.close()
|
this.loadingInstance?.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOrderStatus(orderId: string) {
|
async getOrderStatus(orderId: string) {
|
||||||
try {
|
try {
|
||||||
const res: any = await queryOrder({ account: this.accountId, order_id: orderId })
|
const res: any = await queryShopOrder({ account: this.accountId, order_id: orderId })
|
||||||
if (res.state === 1) {
|
if (res.state === 1) {
|
||||||
EventBus.$emit(PRESALE_SUCCESS, {})
|
EventBus.$emit(PRESALE_SUCCESS, {})
|
||||||
} else if (res.state === 3) {
|
} else if (res.state === 3) {
|
||||||
@ -233,58 +230,13 @@ export default class Official extends Vue {
|
|||||||
this.timer = null
|
this.timer = null
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPresaleInfo() {
|
|
||||||
const reqData = {
|
|
||||||
account: this.accountId
|
|
||||||
}
|
|
||||||
const res: any = await queryPresaleStatus(reqData)
|
|
||||||
if (res.presale_info) {
|
|
||||||
this.numberTotal = res.presale_info.total_num || 0
|
|
||||||
this.numberRest = this.numberTotal - (res.presale_info.sold_num || 0)
|
|
||||||
this.numberRest = this.numberRest < 0 ? 0 : this.numberRest
|
|
||||||
this.hint = res.presale_info.hint.replace(/\\n/g, '<br/>')
|
|
||||||
// this.buyed = !!res.presale_info.buyed
|
|
||||||
this.presaleStatus = res.presale_info.state || 0
|
|
||||||
this.presaleTitle = res.presale_info.title
|
|
||||||
this.countdown = res.presale_info.countdown
|
|
||||||
if (this.presaleStatus === 1 && this.countdown > 0) {
|
|
||||||
this.beginCountdown()
|
|
||||||
}
|
|
||||||
AppModule.updatePresaleStat(this.presaleStatus)
|
|
||||||
|
|
||||||
const buySet: Set<string> = new Set()
|
|
||||||
if (res.presale_info.buyable_list) {
|
|
||||||
for (const sub of res.presale_info.buyable_list) {
|
|
||||||
buySet.add(sub.box_id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AppModule.updateCanBuy(this.presaleStatus === 2 &&
|
|
||||||
this.numberRest > 0 && buySet.size > 0
|
|
||||||
)
|
|
||||||
for (let i = 0, l = this.boxDatas.length; i < l; i++) {
|
|
||||||
const data = this.boxDatas[i]
|
|
||||||
if (!buySet.has(data.id)) {
|
|
||||||
data.open = 0
|
|
||||||
data.title = 'UNAVAILABLE'
|
|
||||||
data.desc = 'ALREADY BOUGHT'
|
|
||||||
} else {
|
|
||||||
data.open = 1
|
|
||||||
}
|
|
||||||
Vue.set(this.boxDatas, i, data)
|
|
||||||
}
|
|
||||||
// for (const data of this.boxDatas) {
|
|
||||||
// Vue.set(data, 'open', buySet.has(data.id) ? 0 : 1)
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async queryPresaleList(pageNo = 0) {
|
async queryPresaleList(pageNo = 0) {
|
||||||
const reqData = {
|
const reqData = {
|
||||||
account: '',
|
account: this.accountId,
|
||||||
page: pageNo
|
page: pageNo
|
||||||
}
|
}
|
||||||
this.boxDatas.length = 0
|
this.boxDatas.length = 0
|
||||||
const res: any = await searchBox(reqData)
|
const res: any = await queryShopList(reqData)
|
||||||
if (res.page) {
|
if (res.page) {
|
||||||
this.currentPage = (parseInt(res.page.current_page || 0)) + 1
|
this.currentPage = (parseInt(res.page.current_page || 0)) + 1
|
||||||
this.totalPage = res.page.total_pages || 1
|
this.totalPage = res.page.total_pages || 1
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="box-list">
|
<div class="box-list">
|
||||||
<one-box v-for="data in boxDatas" :key="data.id" :box-data="data"></one-box>
|
<one-box v-for="data in boxDatas" :key="data.id" :pre-sale="true" :box-data="data"></one-box>
|
||||||
</div>
|
</div>
|
||||||
<pagination
|
<pagination
|
||||||
v-if="totalPage>1"
|
v-if="totalPage>1"
|
||||||
@ -49,7 +49,7 @@
|
|||||||
import { Component, Vue, Watch } from 'vue-property-decorator'
|
import { Component, Vue, Watch } from 'vue-property-decorator'
|
||||||
import TopMenu from '@/components/market/TopMenu.vue'
|
import TopMenu from '@/components/market/TopMenu.vue'
|
||||||
import BaseFooter from '@/components/layout/BaseFooter.vue'
|
import BaseFooter from '@/components/layout/BaseFooter.vue'
|
||||||
import OneBox, { IBoxData } from '@/components/market/mall/OneBox.vue'
|
import OneBox, { IBoxData, TMP_SHOP_ORDER_ID } from '@/components/market/mall/OneBox.vue'
|
||||||
import { UserModule } from '@/store/modules/user'
|
import { UserModule } from '@/store/modules/user'
|
||||||
import { AppModule } from '@/store/modules/app'
|
import { AppModule } from '@/store/modules/app'
|
||||||
import ChainManager from '@/chain/ChainManager'
|
import ChainManager from '@/chain/ChainManager'
|
||||||
@ -137,7 +137,7 @@ export default class Presale extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkOrderHistory() {
|
checkOrderHistory() {
|
||||||
const historyOrderId = localStorage.getItem('tmp_presale_order_id')
|
const historyOrderId = localStorage.getItem(TMP_SHOP_ORDER_ID)
|
||||||
if (historyOrderId && this.accountId) {
|
if (historyOrderId && this.accountId) {
|
||||||
this.beginTraceOrderStatus(historyOrderId)
|
this.beginTraceOrderStatus(historyOrderId)
|
||||||
}
|
}
|
||||||
@ -196,7 +196,7 @@ export default class Presale extends Vue {
|
|||||||
clearInterval(this.orderTimer)
|
clearInterval(this.orderTimer)
|
||||||
this.orderTimer = null
|
this.orderTimer = null
|
||||||
}
|
}
|
||||||
localStorage.removeItem('tmp_presale_order_id')
|
localStorage.removeItem(TMP_SHOP_ORDER_ID)
|
||||||
this.loadingInstance?.close()
|
this.loadingInstance?.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user