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

View File

@ -3,7 +3,23 @@ import { useI18n } from '@/hooks/web/useI18n'
import { required } from '@/utils/formRules' import { required } from '@/utils/formRules'
import { DICT_TYPE } from '@/utils/dict' import { DICT_TYPE } from '@/utils/dict'
import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas' import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas'
import { getTenantPackageList, TenantPackageVO } from '@/api/system/tenantPackage'
import { ComponentOptions } from '@/types/components'
const { t } = useI18n() // 国际化 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({ export const rules = reactive({
@ -30,7 +46,18 @@ const crudSchemas = reactive<VxeCrudSchema>({
}, },
{ {
title: '租户套餐', title: '租户套餐',
field: 'packageId' field: 'packageId',
table: {
slots: {
default: 'packageId_default'
}
},
form: {
component: 'Select',
componentProps: {
options: tenantPackageOption
}
}
}, },
{ {
title: '联系人', title: '联系人',
@ -60,6 +87,11 @@ const crudSchemas = reactive<VxeCrudSchema>({
{ {
title: '账号额度', title: '账号额度',
field: 'accountCount', field: 'accountCount',
table: {
slots: {
default: 'accountCount_default'
}
},
form: { form: {
component: 'InputNumber' component: 'InputNumber'
} }