fix:套餐界面按钮隐藏
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
v-model:columns="columnChecks"
|
||||
:loading="loading"
|
||||
:show-delete="false"
|
||||
:not-show-add="true"
|
||||
:show-add="false"
|
||||
@refresh="getData"
|
||||
/>
|
||||
</div>
|
||||
@@ -75,14 +75,15 @@
|
||||
</div>
|
||||
</AFormItem>
|
||||
|
||||
<AFormItem label="价格" name="price">
|
||||
<AFormItem label="价格" name="price" :rules="[{ required: true, message: '请输入价格' }]">
|
||||
<AInputNumber
|
||||
v-model:value="formState.price"
|
||||
placeholder="请输入价格"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
addon-after="元"
|
||||
style="width: 100%"
|
||||
:formatter="value => `¥ ${value}`"
|
||||
:parser="value => (value || '').replace(/[¥\s,]/g, '')"
|
||||
/>
|
||||
</AFormItem>
|
||||
|
||||
@@ -242,12 +243,7 @@ const { columns, columnChecks, data, loading, getData, mobilePagination } = useT
|
||||
dataIndex: 'price',
|
||||
title: '价格',
|
||||
align: 'center',
|
||||
customRender: ({ text }) => {
|
||||
if (typeof text === 'number') {
|
||||
return `¥${text.toFixed(2)}`;
|
||||
}
|
||||
return text || '-';
|
||||
}
|
||||
customRender: ({ text }) => `${Number(text).toFixed(2)}`
|
||||
},
|
||||
{
|
||||
key: 'traffic',
|
||||
@@ -332,18 +328,30 @@ const { columns, columnChecks, data, loading, getData, mobilePagination } = useT
|
||||
const showModal = ref(false);
|
||||
const formRef = ref();
|
||||
|
||||
interface PackageForm extends Omit<Api.Auth.PackageAdd, 'traffic' | 'duration'> {
|
||||
interface PackageForm {
|
||||
id?: string;
|
||||
packageName: string;
|
||||
periodNum: number;
|
||||
periodType: number;
|
||||
price: string;
|
||||
trafficEnable: boolean;
|
||||
traffic: number;
|
||||
trafficUnit: StorageUnit;
|
||||
rateLimitEnable: boolean;
|
||||
rateLimitId?: number;
|
||||
durationEnable: boolean;
|
||||
duration: number;
|
||||
durationUnit: TimeUnit;
|
||||
clientNumEnable: boolean;
|
||||
clientNum: number;
|
||||
packageEnable: boolean;
|
||||
}
|
||||
|
||||
const formState = ref<PackageForm>({
|
||||
packageName: '',
|
||||
periodNum: 1,
|
||||
periodType: 2,
|
||||
price: 0,
|
||||
price: '0',
|
||||
trafficEnable: false,
|
||||
traffic: 0,
|
||||
trafficUnit: 'GB',
|
||||
@@ -456,7 +464,7 @@ const handleCancel = () => {
|
||||
packageName: '',
|
||||
periodNum: 1,
|
||||
periodType: 2,
|
||||
price: 0,
|
||||
price: '0',
|
||||
trafficEnable: false,
|
||||
traffic: 0,
|
||||
trafficUnit: 'GB',
|
||||
@@ -474,16 +482,30 @@ const handleCancel = () => {
|
||||
const handleOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
const submitData = {
|
||||
...formState.value,
|
||||
traffic: formState.value.trafficEnable
|
||||
? Math.round(convertStorage(formState.value.traffic, formState.value.trafficUnit, 'B'))
|
||||
: 0,
|
||||
duration: formState.value.durationEnable
|
||||
? Math.round(convertTime(formState.value.duration, formState.value.durationUnit, '秒'))
|
||||
: 0
|
||||
// 准备基础数据
|
||||
const baseData = {
|
||||
packageName: formState.value.packageName,
|
||||
periodNum: formState.value.periodNum,
|
||||
periodType: formState.value.periodType,
|
||||
price: formState.value.price,
|
||||
trafficEnable: formState.value.trafficEnable,
|
||||
rateLimitEnable: formState.value.rateLimitEnable,
|
||||
rateLimitId: formState.value.rateLimitId,
|
||||
durationEnable: formState.value.durationEnable,
|
||||
clientNumEnable: formState.value.clientNumEnable,
|
||||
clientNum: formState.value.clientNum,
|
||||
packageEnable: formState.value.packageEnable
|
||||
};
|
||||
|
||||
// 计算流量和时长
|
||||
const traffic = formState.value.trafficEnable
|
||||
? Math.round(convertStorage(formState.value.traffic, formState.value.trafficUnit, 'B'))
|
||||
: 0;
|
||||
|
||||
const duration = formState.value.durationEnable
|
||||
? Math.round(convertTime(formState.value.duration, formState.value.durationUnit, '秒'))
|
||||
: 0;
|
||||
|
||||
if (isEdit.value) {
|
||||
if (!editId.value) {
|
||||
message.error('编辑ID不能为空');
|
||||
@@ -491,13 +513,19 @@ const handleOk = async () => {
|
||||
}
|
||||
// 编辑模式
|
||||
await updatePackage({
|
||||
...submitData,
|
||||
id: editId.value
|
||||
...baseData,
|
||||
id: editId.value,
|
||||
traffic,
|
||||
duration
|
||||
});
|
||||
message.success('修改成功');
|
||||
} else {
|
||||
// 新增模式
|
||||
await addPackage(submitData);
|
||||
await addPackage({
|
||||
...baseData,
|
||||
traffic,
|
||||
duration
|
||||
});
|
||||
message.success('添加成功');
|
||||
}
|
||||
handleCancel();
|
||||
|
||||
Reference in New Issue
Block a user