fix: tenant package select

This commit is contained in:
xingyu 2022-11-24 13:08:36 +08:00
parent 0a6d93fefa
commit e187e7a016
2 changed files with 42 additions and 38 deletions

View File

@ -19,10 +19,10 @@
@click="handleExport()"
/>
</template>
<template #accountCount="{ row }">
<template #accountCount_default="{ row }">
<el-tag> {{ row.accountCount }} </el-tag>
</template>
<template #packageId="{ row }">
<template #packageId_default="{ row }">
<el-tag v-if="row.packageId === 0" type="danger">系统租户</el-tag>
<el-tag v-else type="success"> {{ getPackageName(row.packageId) }} </el-tag>
</template>
@ -58,18 +58,7 @@
:schema="allSchemas.formSchema"
:rules="rules"
ref="formRef"
>
<template #packageId>
<el-select v-model="tenantPackageId">
<el-option
v-for="item in tenantPackageOptions"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</template>
</Form>
/>
<!-- 对话框(详情) -->
<Descriptions
v-if="actionType === 'detail'"
@ -97,16 +86,15 @@
</XModal>
</template>
<script setup lang="ts" name="Tenant">
import { ref, unref, onMounted } from 'vue'
import { ref, unref } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { useVxeGrid } from '@/hooks/web/useVxeGrid'
import { VxeGridInstance } from 'vxe-table'
import { ElTag, ElSelect, ElOption } from 'element-plus'
import { ElTag } from 'element-plus'
import { FormExpose } from '@/components/Form'
import * as TenantApi from '@/api/system/tenant'
import { rules, allSchemas } from './tenant.data'
import { getTenantPackageList, TenantPackageVO } from '@/api/system/tenantPackage'
import { rules, allSchemas, tenantPackageOption } from './tenant.data'
const { t } = useI18n() //
const message = useMessage() //
@ -125,17 +113,10 @@ const dialogVisible = ref(false) // 是否显示弹出层
const dialogTitle = ref('edit') //
const formRef = ref<FormExpose>() // Ref
const detailRef = ref() // Ref
const tenantPackageId = ref() //
const tenantPackageOptions = ref<TenantPackageVO[]>([]) //
const getTenantPackageOptions = async () => {
const res = await getTenantPackageList()
tenantPackageOptions.value.push(...res)
}
const getPackageName = (packageId: number) => {
for (let item of tenantPackageOptions.value) {
if (item.id === packageId) {
return item.name
for (let item of tenantPackageOption) {
if (item.value === packageId) {
return item.label
}
}
return '未知套餐'
@ -151,7 +132,6 @@ const setDialogTile = (type: string) => {
//
const handleCreate = () => {
//
tenantPackageId.value = ''
setDialogTile('create')
}
@ -160,7 +140,6 @@ const handleUpdate = async (rowId: number) => {
setDialogTile('update')
//
const res = await TenantApi.getTenantApi(rowId)
tenantPackageId.value = res.packageId
unref(formRef)?.setValues(res)
}
@ -168,7 +147,6 @@ const handleUpdate = async (rowId: number) => {
const handleDetail = async (rowId: number) => {
//
const res = await TenantApi.getTenantApi(rowId)
tenantPackageId.value = res.packageId
detailRef.value = res
setDialogTile('detail')
}
@ -193,7 +171,6 @@ const submitForm = async () => {
//
try {
const data = unref(formRef)?.formModel as TenantApi.TenantVO
data.packageId = tenantPackageId.value
if (actionType.value === 'create') {
await TenantApi.createTenantApi(data)
message.success(t('common.createSuccess'))
@ -211,9 +188,4 @@ const submitForm = async () => {
}
})
}
// ========== ==========
onMounted(async () => {
await getTenantPackageOptions()
})
</script>

View File

@ -3,7 +3,23 @@ import { useI18n } from '@/hooks/web/useI18n'
import { required } from '@/utils/formRules'
import { DICT_TYPE } from '@/utils/dict'
import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas'
import { getTenantPackageList, TenantPackageVO } from '@/api/system/tenantPackage'
import { ComponentOptions } from '@/types/components'
const { t } = useI18n() // 国际化
export const tenantPackageOption: ComponentOptions[] = []
const getTenantPackageOptions = async () => {
const res = await getTenantPackageList()
res.forEach((tenantPackage: TenantPackageVO) => {
tenantPackageOption.push({
key: tenantPackage.id,
value: tenantPackage.id,
label: tenantPackage.name
})
})
return tenantPackageOption
}
getTenantPackageOptions()
// 表单校验
export const rules = reactive({
@ -30,7 +46,18 @@ const crudSchemas = reactive<VxeCrudSchema>({
},
{
title: '租户套餐',
field: 'packageId'
field: 'packageId',
table: {
slots: {
default: 'packageId_default'
}
},
form: {
component: 'Select',
componentProps: {
options: tenantPackageOption
}
}
},
{
title: '联系人',
@ -60,6 +87,11 @@ const crudSchemas = reactive<VxeCrudSchema>({
{
title: '账号额度',
field: 'accountCount',
table: {
slots: {
default: 'accountCount_default'
}
},
form: {
component: 'InputNumber'
}