update console
This commit is contained in:
1 parent
29fd2dd801
commit
18ec9d181c
34 files changed
+1713
-112
No files matched your search
@@ -0,0 +1,95 @@
|
||||
<template>
|
||||
<el-row class="panel">
|
||||
<el-col :span="24">
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<h2 class="title">{{ $t('common.title.buyMore') }}</h2>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="12" :offset="6">
|
||||
<el-skeleton v-if="loading" />
|
||||
<create-order v-else-if="application" :application="application" />
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { applicationOperator, IApplication, IApplicationDetailResponse } from '@/operators';
|
||||
import CreateOrder from '@/components/order/Create.vue';
|
||||
import { ElRow, ElCol, ElCard, ElSkeleton } from 'element-plus';
|
||||
|
||||
interface IData {
|
||||
application: IApplication | undefined;
|
||||
loading: boolean;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ConsoleApplicationBuy',
|
||||
components: {
|
||||
CreateOrder,
|
||||
ElSkeleton,
|
||||
ElRow,
|
||||
ElCol
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
application: undefined,
|
||||
loading: false
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
id() {
|
||||
return this.$route.params?.id?.toString();
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.onFetchData();
|
||||
},
|
||||
methods: {
|
||||
onFetchData() {
|
||||
this.loading = true;
|
||||
applicationOperator
|
||||
.get(this.id)
|
||||
.then(({ data: data }: { data: IApplicationDetailResponse }) => {
|
||||
this.application = data;
|
||||
this.loading = false;
|
||||
})
|
||||
.catch(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.title {
|
||||
font-size: 26px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.el-card {
|
||||
min-height: 500px;
|
||||
padding-top: 50px;
|
||||
}
|
||||
|
||||
.panel {
|
||||
padding: 30px;
|
||||
width: calc(100% - 250px);
|
||||
.credential {
|
||||
.copy {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.pagination {
|
||||
float: right;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,241 @@
|
||||
<template>
|
||||
<el-row class="panel">
|
||||
<el-col :span="24">
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<h2 class="title">{{ $t('common.title.allApplications') }}</h2>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<el-table v-loading="loading" :data="applications" stripe table-layout="fixed">
|
||||
<el-table-column prop="id" :label="$t('application.field.id')" width="300px" class-name="text-center">
|
||||
<template #default="scope">
|
||||
<span>{{ scope.row.id }}</span>
|
||||
<span class="copy">
|
||||
<copy-to-clipboard :content="scope?.row?.id" />
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('application.field.name')" width="220px">
|
||||
<template #default="scope">
|
||||
<span v-if="scope.row.type === applicationType.API">{{ scope.row?.api?.title }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="remaining_amount"
|
||||
:label="$t('application.field.remainingAmount')"
|
||||
width="120px"
|
||||
class-name="text-center"
|
||||
>
|
||||
<template #default="scope">
|
||||
<span>{{ getRemainingAmount(scope.row) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="used_amount"
|
||||
:label="$t('application.field.usedAmount')"
|
||||
width="120px"
|
||||
class-name="text-center"
|
||||
>
|
||||
<template #default="scope">
|
||||
<span>{{ getUsedAmount(scope.row) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column fixed="right" width="100px">
|
||||
<template #default="scope">
|
||||
<div class="float-right">
|
||||
<el-button type="primary" @click="onBuyMore(scope?.row)">
|
||||
{{ $t('application.button.buyMore') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="10" :offset="14">
|
||||
<div class="pagination m-v-lg">
|
||||
<pagination :current-page="page" :page-size="limit" :total="total" @change="onPageChange"> </pagination>
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import {
|
||||
applicationOperator,
|
||||
IApplication,
|
||||
IApplicationListResponse,
|
||||
IApplicationType,
|
||||
ICredentialType
|
||||
} from '@/operators';
|
||||
import Pagination from '@/components/common/Pagination.vue';
|
||||
import CopyToClipboard from '@/components/common/CopyToClipboard.vue';
|
||||
import { ElTable, ElRow, ElCol, ElTableColumn, ElButton } from 'element-plus';
|
||||
import { ROUTE_CONSOLE_APPLICATION_BUY } from '@/router/constants';
|
||||
|
||||
interface IData {
|
||||
applications: IApplication[];
|
||||
loading: boolean;
|
||||
total: number | undefined;
|
||||
limit: number;
|
||||
buying: boolean;
|
||||
form: {
|
||||
amount: number | undefined;
|
||||
};
|
||||
active: {
|
||||
application: IApplication | undefined;
|
||||
};
|
||||
applicationType: typeof IApplicationType;
|
||||
credentialType: typeof ICredentialType;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ConsoleApplicationList',
|
||||
components: {
|
||||
Pagination,
|
||||
CopyToClipboard,
|
||||
ElTable,
|
||||
ElRow,
|
||||
ElCol,
|
||||
ElTableColumn,
|
||||
ElButton
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
credentialType: ICredentialType,
|
||||
applicationType: IApplicationType,
|
||||
applications: [],
|
||||
loading: false,
|
||||
total: undefined,
|
||||
buying: false,
|
||||
// dynamic calculate the limit according to window height
|
||||
limit: Math.floor((window.innerHeight - 200) / 50),
|
||||
form: {
|
||||
amount: 1
|
||||
},
|
||||
active: {
|
||||
application: undefined
|
||||
}
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
redirect() {
|
||||
return this.$route.query?.redirect;
|
||||
},
|
||||
page() {
|
||||
return parseInt(this.$route.query.page?.toString() || '1');
|
||||
},
|
||||
type() {
|
||||
return (this.$route.query.type?.toString() || IApplicationType.API) as IApplicationType;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
page: {
|
||||
handler() {
|
||||
this.onFetchData();
|
||||
}
|
||||
},
|
||||
type: {
|
||||
handler() {
|
||||
this.onFetchData();
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.onFetchData();
|
||||
},
|
||||
methods: {
|
||||
onFilterType(type: string) {
|
||||
if (type === this.type) {
|
||||
return;
|
||||
}
|
||||
this.$router.push({
|
||||
...this.$route,
|
||||
query: {
|
||||
...this.$route.query,
|
||||
page: 1,
|
||||
type
|
||||
}
|
||||
});
|
||||
},
|
||||
onBuyMore(application: IApplication) {
|
||||
this.$router.push({
|
||||
name: ROUTE_CONSOLE_APPLICATION_BUY,
|
||||
params: {
|
||||
id: application.id
|
||||
}
|
||||
});
|
||||
},
|
||||
onPageChange(page: number) {
|
||||
this.$router.push({
|
||||
name: this.$route.name?.toString(),
|
||||
query: {
|
||||
...this.$route.query,
|
||||
page: page
|
||||
}
|
||||
});
|
||||
},
|
||||
onFetchData() {
|
||||
this.loading = true;
|
||||
applicationOperator
|
||||
.getAll({
|
||||
limit: this.limit,
|
||||
offset: (this.page - 1) * this.limit,
|
||||
user_id: this.$store.getters.user.id,
|
||||
type: this.type,
|
||||
ordering: '-created_at'
|
||||
})
|
||||
.then(({ data: data }: { data: IApplicationListResponse }) => {
|
||||
this.applications = data.items;
|
||||
this.loading = false;
|
||||
this.total = data.count;
|
||||
})
|
||||
.catch(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
getRemainingAmount(application: IApplication) {
|
||||
if (application.type === IApplicationType.API) {
|
||||
const unit = this.$t(`api.unit.${application?.api?.unit}`);
|
||||
return `${application.remaining_amount}${unit}`;
|
||||
}
|
||||
},
|
||||
getUsedAmount(application: IApplication) {
|
||||
if (application.type === IApplicationType.API) {
|
||||
const unit = this.$t(`api.unit.${application?.api?.unit}`);
|
||||
return `${application.used_amount}${unit}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.panel {
|
||||
padding: 30px;
|
||||
width: calc(100% - 250px);
|
||||
.title {
|
||||
font-size: 26px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
}
|
||||
.el-table {
|
||||
min-height: calc(100vh - 350px);
|
||||
margin-bottom: 50px;
|
||||
.el-button {
|
||||
border-radius: 20px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.pagination {
|
||||
float: right;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,325 @@
|
||||
<template>
|
||||
<el-row class="panel">
|
||||
<el-col :span="24">
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<h2 class="title">{{ $t('order.title.info') }}</h2>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="12" :offset="6">
|
||||
<div v-if="loading" class="pt-5">
|
||||
<el-skeleton animated />
|
||||
</div>
|
||||
<div v-else class="order">
|
||||
<el-descriptions :column="1">
|
||||
<el-descriptions-item :label="$t('order.field.id')">{{ order?.id }}</el-descriptions-item>
|
||||
<el-descriptions-item :label="$t('order.field.description')">
|
||||
{{ order?.description }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item
|
||||
v-if="order?.application?.type === applicationType.API"
|
||||
:label="$t('order.field.api')"
|
||||
>
|
||||
{{ order?.application?.api?.title }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item :label="$t('order.field.amount')">
|
||||
<span v-if="order?.application?.type === applicationType.API">
|
||||
{{ order?.amount }}{{ $t(`api.unit.${order?.application?.api?.unit}`) }}
|
||||
</span>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item :label="$t('order.field.createdAt')">
|
||||
{{ $dayjs.format(order?.created_at) }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item :label="$t('order.field.price')">
|
||||
<span v-if="order?.price && order?.price > 0" class="price unfree">
|
||||
¥{{ order?.price?.toFixed(2) }}
|
||||
</span>
|
||||
<span v-else class="price free"> {{ $t('order.message.free') }} </span>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item v-if="order?.pay_way" :label="$t('order.field.payWay')">
|
||||
<span v-if="order?.pay_way === PayWay.WechatPay">
|
||||
{{ $t('order.title.wechatPay') }}
|
||||
</span>
|
||||
<span v-if="order?.pay_way === PayWay.AliPay">
|
||||
{{ $t('order.title.aliPay') }}
|
||||
</span>
|
||||
<span v-if="order?.pay_way === PayWay.Stripe">
|
||||
{{ $t('order.title.stripe') }}
|
||||
</span>
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row v-if="order?.state === OrderState.PAID" class="mb-5">
|
||||
<el-col :span="12" :offset="6">
|
||||
<el-divider border-style="dashed" />
|
||||
<el-alert :title="$t('order.message.paidSuccessfully')" type="success" show-icon :closable="false" />
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row v-if="order?.state === OrderState.PENDING || order?.state === OrderState.FAILED">
|
||||
<el-col :span="12" :offset="6">
|
||||
<el-divider border-style="dashed" />
|
||||
<div v-if="order.price && order.price > 0 && !order.pay_way" class="payways mb-4">
|
||||
<div
|
||||
:class="{
|
||||
payway: true,
|
||||
wechatpay: true,
|
||||
active: payWay === PayWay.WechatPay
|
||||
}"
|
||||
@click="payWay = PayWay.WechatPay"
|
||||
>
|
||||
<span class="payicon wechatpay"></span>
|
||||
{{ $t('order.title.wechatPay') }}
|
||||
</div>
|
||||
<div
|
||||
v-if="false"
|
||||
:class="{
|
||||
payway: true,
|
||||
alipay: true,
|
||||
active: payWay === PayWay.AliPay
|
||||
}"
|
||||
@click="payWay = PayWay.AliPay"
|
||||
>
|
||||
<span class="payicon alipay"></span>
|
||||
{{ $t('order.title.aliPay') }}
|
||||
</div>
|
||||
<div
|
||||
v-if="false"
|
||||
:class="{
|
||||
payway: true,
|
||||
stripe: true,
|
||||
active: payWay === PayWay.Stripe
|
||||
}"
|
||||
@click="payWay = PayWay.Stripe"
|
||||
>
|
||||
<span class="payicon stripe"></span>
|
||||
{{ $t('order.title.stripe') }}
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!order?.pay_way">
|
||||
<el-button :loading="prepaying" type="primary" size="large" class="btn-pay" @click="onPay">{{
|
||||
$t('common.button.pay')
|
||||
}}</el-button>
|
||||
</div>
|
||||
<div v-else>
|
||||
<el-button type="primary" size="large" class="btn-repay" @click="onRepay">{{
|
||||
$t('common.button.repay')
|
||||
}}</el-button>
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<wechat-pay-order
|
||||
v-if="order && payWay === PayWay.WechatPay"
|
||||
v-model="order"
|
||||
:visible="paying"
|
||||
@hide="paying = false"
|
||||
/>
|
||||
<stripe-pay-order v-if="order && payWay === PayWay.Stripe" v-model="order" :visible="paying" @hide="paying = false" />
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { IOrder, IOrderDetailResponse, orderOperator, OrderState } from '@/operators/order';
|
||||
import {
|
||||
ElRow,
|
||||
ElCol,
|
||||
ElSkeleton,
|
||||
ElDivider,
|
||||
ElAlert,
|
||||
ElDescriptions,
|
||||
ElDescriptionsItem,
|
||||
ElButton
|
||||
} from 'element-plus';
|
||||
import WechatPayOrder from '@/components/order/WechatPay.vue';
|
||||
import StripePayOrder from '@/components/order/StripePay.vue';
|
||||
import { IApplicationType } from '@/operators';
|
||||
|
||||
enum PayWay {
|
||||
WechatPay = 'WechatPay',
|
||||
Stripe = 'Stripe',
|
||||
AliPay = 'AliPay'
|
||||
}
|
||||
|
||||
interface IData {
|
||||
PayWay: typeof PayWay;
|
||||
OrderState: typeof OrderState;
|
||||
payWay: PayWay | undefined;
|
||||
order: IOrder | undefined;
|
||||
loading: boolean;
|
||||
paying: boolean;
|
||||
prepaying: boolean;
|
||||
applicationType: typeof IApplicationType;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ConsoleOrderDetail',
|
||||
components: {
|
||||
ElButton,
|
||||
ElRow,
|
||||
ElCol,
|
||||
ElSkeleton,
|
||||
ElDivider,
|
||||
ElAlert,
|
||||
ElDescriptions,
|
||||
ElDescriptionsItem,
|
||||
WechatPayOrder,
|
||||
StripePayOrder
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
PayWay: PayWay,
|
||||
payWay: PayWay.WechatPay,
|
||||
OrderState: OrderState,
|
||||
order: undefined,
|
||||
loading: false,
|
||||
paying: false,
|
||||
prepaying: false,
|
||||
applicationType: IApplicationType
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
id() {
|
||||
return this.$route.params?.id?.toString();
|
||||
},
|
||||
redirect() {
|
||||
return this.$route.query?.redirect;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
order: {
|
||||
handler(val) {
|
||||
if (val?.state === OrderState.PAID) {
|
||||
setTimeout(() => {
|
||||
if (this.redirect) {
|
||||
window.location.replace(this.redirect?.toString());
|
||||
}
|
||||
}, 2000);
|
||||
return;
|
||||
}
|
||||
},
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.onFetchData();
|
||||
},
|
||||
methods: {
|
||||
onFetchData() {
|
||||
this.loading = true;
|
||||
orderOperator
|
||||
.refresh(this.id)
|
||||
.then(({ data: data }: { data: IOrderDetailResponse }) => {
|
||||
this.order = data;
|
||||
if (data.pay_way) {
|
||||
// @ts-ignore
|
||||
this.payWay = data.pay_way;
|
||||
}
|
||||
this.loading = false;
|
||||
})
|
||||
.catch(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
onRepay() {
|
||||
this.paying = true;
|
||||
},
|
||||
onPay() {
|
||||
this.prepaying = true;
|
||||
orderOperator
|
||||
.pay(this.id, {
|
||||
pay_way: this.payWay
|
||||
})
|
||||
.then(({ data: data }: { data: IOrderDetailResponse }) => {
|
||||
this.prepaying = false;
|
||||
this.order = data;
|
||||
if (this.order.price && this.order.price > 0) {
|
||||
this.paying = true;
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
this.prepaying = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.panel {
|
||||
padding: 30px;
|
||||
width: calc(100% - 250px);
|
||||
|
||||
.title {
|
||||
font-size: 26px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
}
|
||||
}
|
||||
|
||||
.order {
|
||||
padding-top: 50px;
|
||||
.price {
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
&.unfree {
|
||||
color: #ff5441;
|
||||
}
|
||||
&.free {
|
||||
color: #29c287;
|
||||
}
|
||||
}
|
||||
}
|
||||
.payways {
|
||||
overflow: hidden;
|
||||
.payway {
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
float: left;
|
||||
width: 120px;
|
||||
line-height: 40px;
|
||||
text-align: center;
|
||||
height: 40px;
|
||||
border: 1px solid #eee;
|
||||
&.active {
|
||||
border: 1px solid #3879d1;
|
||||
}
|
||||
}
|
||||
|
||||
.payicon {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
margin-top: 2px;
|
||||
display: inline-block;
|
||||
&.wechatpay {
|
||||
position: relative;
|
||||
top: 3px;
|
||||
width: 22px;
|
||||
height: 19px;
|
||||
background-image: url(//midas.gtimg.cn/enterprise/images/ep_new_sprites@2x.png);
|
||||
background-repeat: no-repeat;
|
||||
background-size: 60px 250px;
|
||||
background-position: 0 -50px;
|
||||
}
|
||||
&.stripe {
|
||||
position: relative;
|
||||
top: 3px;
|
||||
width: 22px;
|
||||
height: 18px;
|
||||
background-image: url(https://zhishuyun-1256437459.cos.ap-beijing.myqcloud.com/2023-08-27-164440.png);
|
||||
background-size: contain;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.btn-pay,
|
||||
.btn-repay {
|
||||
width: 150px;
|
||||
border-radius: 20px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,207 @@
|
||||
<template>
|
||||
<el-row class="panel">
|
||||
<el-col :span="24">
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<h2 class="title">{{ $t('common.title.allOrders') }}</h2>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<el-table v-loading="loading" :data="orders" stripe>
|
||||
<el-table-column prop="id" :label="$t('order.field.id')" class-name="text-center" width="350px">
|
||||
<template #default="scope">
|
||||
<span class="key">{{ scope.row.id }}</span>
|
||||
<span class="copy">
|
||||
<copy-to-clipboard :content="scope.row.id" />
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('order.field.price')" width="100px">
|
||||
<template #default="scope">
|
||||
<span class="price">¥{{ scope.row?.price?.toFixed(2) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('order.field.createdAt')" width="180px">
|
||||
<template #default="scope">
|
||||
<span class="created-at">{{ $dayjs.format(scope.row.created_at) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('order.field.description')" width="300px">
|
||||
<template #default="scope">
|
||||
<span class="description">{{ scope.row.description }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="state" :label="$t('order.field.state')" class-name="text-center">
|
||||
<template #default="scope">
|
||||
<span v-if="scope.row.state === OrderState?.PENDING">
|
||||
<el-tag type="info" class="mx-1" effect="dark">{{ $t('order.state.pending') }}</el-tag>
|
||||
</span>
|
||||
<span v-else-if="scope.row.state === OrderState?.PAID" class="state state-paid">
|
||||
<el-tag type="success" class="mx-1" effect="dark">{{ $t('order.state.paid') }}</el-tag>
|
||||
</span>
|
||||
<span v-else-if="scope.row.state === OrderState?.EXPIRED" class="state state-expired">
|
||||
<el-tag type="warning" class="mx-1" effect="dark">{{ $t('order.state.expired') }}</el-tag>
|
||||
</span>
|
||||
<span v-else-if="scope.row.state === OrderState?.FAILED" class="state state-failed">
|
||||
<el-tag type="danger" class="mx-1" effect="dark"> {{ $t('order.state.failed') }}</el-tag>
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column min-width="120px">
|
||||
<template #default="scope">
|
||||
<div class="float-right">
|
||||
<el-button
|
||||
v-if="scope.row.state !== OrderState.PAID"
|
||||
type="primary"
|
||||
@click="
|
||||
$router.push({
|
||||
name: 'console-order-detail',
|
||||
params: {
|
||||
id: scope.row.id
|
||||
}
|
||||
})
|
||||
"
|
||||
>
|
||||
{{ $t('order.button.continuePay') }}
|
||||
</el-button>
|
||||
<el-button
|
||||
v-else
|
||||
@click="
|
||||
$router.push({
|
||||
name: 'console-order-detail',
|
||||
params: {
|
||||
id: scope.row.id
|
||||
}
|
||||
})
|
||||
"
|
||||
>
|
||||
{{ $t('order.button.checkDetail') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="10" :offset="14">
|
||||
<div class="pagination m-v-lg">
|
||||
<pagination :current-page="page" :page-size="limit" :total="total" @change="onPageChange"> </pagination>
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { IOrder, IOrderListResponse, orderOperator, OrderState } from '@/operators/order';
|
||||
import Pagination from '@/components/common/Pagination.vue';
|
||||
import CopyToClipboard from '@/components/common/CopyToClipboard.vue';
|
||||
import { ElRow, ElCol, ElTable, ElTableColumn, ElButton, ElTag, ElCard } from 'element-plus';
|
||||
|
||||
interface IData {
|
||||
orders: IOrder[];
|
||||
loading: boolean;
|
||||
total: number | undefined;
|
||||
limit: number;
|
||||
OrderState: typeof OrderState;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ConsoleOrderList',
|
||||
components: {
|
||||
Pagination,
|
||||
CopyToClipboard,
|
||||
ElRow,
|
||||
ElCol,
|
||||
ElTable,
|
||||
ElTableColumn,
|
||||
ElButton,
|
||||
ElTag,
|
||||
ElCard
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
OrderState: OrderState,
|
||||
orders: [],
|
||||
loading: false,
|
||||
total: undefined,
|
||||
// dynamic calculate the limit according to window height
|
||||
limit: Math.floor((window.innerHeight - 200) / 50)
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
redirect() {
|
||||
return this.$route.query.redirect;
|
||||
},
|
||||
page() {
|
||||
return parseInt(this.$route.query.page?.toString() || '1');
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
page: {
|
||||
handler() {
|
||||
this.onFetchData();
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.onFetchData();
|
||||
},
|
||||
methods: {
|
||||
onPageChange(page: number) {
|
||||
this.$router.push({
|
||||
name: this.$route.name?.toString(),
|
||||
query: {
|
||||
page: page
|
||||
}
|
||||
});
|
||||
},
|
||||
onFetchData() {
|
||||
this.loading = true;
|
||||
orderOperator
|
||||
.getAll({
|
||||
ordering: '-created_at',
|
||||
limit: this.limit,
|
||||
offset: (this.page - 1) * this.limit,
|
||||
user_id: this.$store.getters.user.id
|
||||
})
|
||||
.then(({ data: data }: { data: IOrderListResponse }) => {
|
||||
this.orders = data.items;
|
||||
this.loading = false;
|
||||
this.total = data.count;
|
||||
})
|
||||
.catch(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.panel {
|
||||
padding: 30px;
|
||||
width: calc(100% - 250px);
|
||||
.title {
|
||||
font-size: 26px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
}
|
||||
.el-table {
|
||||
min-height: calc(100vh - 300px);
|
||||
margin-bottom: 50px;
|
||||
.el-button {
|
||||
border-radius: 20px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.pagination {
|
||||
float: right;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user