增加销售同时增加用户
This commit is contained in:
37
src/api/tenant.js
Normal file
37
src/api/tenant.js
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import request from '@/utils/request'
|
||||||
|
|
||||||
|
// 分页查询租户列表
|
||||||
|
export function getTenantList(params) {
|
||||||
|
return request({
|
||||||
|
url: '/tenant/list',
|
||||||
|
method: 'post',
|
||||||
|
data: params
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增租户
|
||||||
|
export function addTenant(data) {
|
||||||
|
return request({
|
||||||
|
url: '/tenant/add',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新租户
|
||||||
|
export function updateTenant(data) {
|
||||||
|
return request({
|
||||||
|
url: '/tenant/update',
|
||||||
|
method: 'put',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取所有租户列表(不分页)
|
||||||
|
export function getAllTenantList() {
|
||||||
|
return request({
|
||||||
|
url: '/tenant/listAll',
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
@@ -50,6 +50,7 @@
|
|||||||
|
|
||||||
<!-- 操作按钮区域 -->
|
<!-- 操作按钮区域 -->
|
||||||
<el-card class="action-container" shadow="never">
|
<el-card class="action-container" shadow="never">
|
||||||
|
<el-button type="primary" icon="el-icon-plus" @click="handleAdd">添加设备</el-button>
|
||||||
<el-button type="primary" @click="handleBatchAssign">批量分配设备到机构</el-button>
|
<el-button type="primary" @click="handleBatchAssign">批量分配设备到机构</el-button>
|
||||||
</el-card>
|
</el-card>
|
||||||
|
|
||||||
@@ -120,6 +121,16 @@
|
|||||||
<el-form-item label="设备编号" prop="deviceCode">
|
<el-form-item label="设备编号" prop="deviceCode">
|
||||||
<el-input v-model="deviceForm.deviceCode" placeholder="请输入设备编号" />
|
<el-input v-model="deviceForm.deviceCode" placeholder="请输入设备编号" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<el-form-item label="租户名称" prop="tenantId">
|
||||||
|
<el-select v-model="deviceForm.tenantId" placeholder="请选择租户" style="width: 100%">
|
||||||
|
<el-option
|
||||||
|
v-for="item in tenantOptions"
|
||||||
|
:key="item.value"
|
||||||
|
:label="item.label"
|
||||||
|
:value="item.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
<el-form-item label="所属机构" prop="dealershipId">
|
<el-form-item label="所属机构" prop="dealershipId">
|
||||||
<el-select v-model="deviceForm.dealershipId" placeholder="请选择所属机构" style="width: 100%">
|
<el-select v-model="deviceForm.dealershipId" placeholder="请选择所属机构" style="width: 100%">
|
||||||
<el-option
|
<el-option
|
||||||
@@ -210,6 +221,7 @@ import {
|
|||||||
import { getDealershipList } from '@/api/dealership'
|
import { getDealershipList } from '@/api/dealership'
|
||||||
import { getProjectList } from '@/api/project'
|
import { getProjectList } from '@/api/project'
|
||||||
import { getSalesList } from '@/api/sales'
|
import { getSalesList } from '@/api/sales'
|
||||||
|
import { getAllTenantList } from '@/api/tenant'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Device',
|
name: 'Device',
|
||||||
@@ -236,8 +248,10 @@ export default {
|
|||||||
deviceForm: {
|
deviceForm: {
|
||||||
id: null,
|
id: null,
|
||||||
deviceCode: '',
|
deviceCode: '',
|
||||||
|
tenantId: '',
|
||||||
dealershipId: '',
|
dealershipId: '',
|
||||||
bindUserId: '',
|
bindUserId: '',
|
||||||
|
projectId: '',
|
||||||
bindStatus: false
|
bindStatus: false
|
||||||
},
|
},
|
||||||
// 批量分配表单
|
// 批量分配表单
|
||||||
@@ -268,7 +282,9 @@ export default {
|
|||||||
// 用户选项
|
// 用户选项
|
||||||
userOptions: [],
|
userOptions: [],
|
||||||
// 项目选项
|
// 项目选项
|
||||||
projectOptions: []
|
projectOptions: [],
|
||||||
|
// 租户选项
|
||||||
|
tenantOptions: []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
@@ -276,6 +292,7 @@ export default {
|
|||||||
this.getDealershipOptions()
|
this.getDealershipOptions()
|
||||||
this.getUserOptions()
|
this.getUserOptions()
|
||||||
this.getProjectOptions()
|
this.getProjectOptions()
|
||||||
|
this.getTenantOptions()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 获取机构选项
|
// 获取机构选项
|
||||||
@@ -345,6 +362,26 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 获取租户选项
|
||||||
|
getTenantOptions() {
|
||||||
|
getAllTenantList().then(response => {
|
||||||
|
console.log('获取租户列表响应:', response)
|
||||||
|
if (response && response.code === 20000) {
|
||||||
|
// 处理响应数据,可能是数组或包含data字段的对象
|
||||||
|
const tenantList = Array.isArray(response.data) ? response.data : (response.data?.data || [])
|
||||||
|
this.tenantOptions = tenantList.map(item => ({
|
||||||
|
value: item.id,
|
||||||
|
label: item.tenantName
|
||||||
|
}))
|
||||||
|
} else {
|
||||||
|
this.$message.error(response?.message || '获取租户列表失败')
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('获取租户列表失败:', error)
|
||||||
|
this.$message.error('获取租户列表失败,请稍后重试')
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
// 获取列表数据
|
// 获取列表数据
|
||||||
getList() {
|
getList() {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
@@ -473,11 +510,19 @@ export default {
|
|||||||
this.deviceForm = {
|
this.deviceForm = {
|
||||||
id: null,
|
id: null,
|
||||||
deviceCode: '',
|
deviceCode: '',
|
||||||
|
tenantId: '',
|
||||||
dealershipId: '',
|
dealershipId: '',
|
||||||
bindUserId: '',
|
bindUserId: '',
|
||||||
|
projectId: '',
|
||||||
bindStatus: false
|
bindStatus: false
|
||||||
}
|
}
|
||||||
this.dialogVisible = true
|
this.dialogVisible = true
|
||||||
|
// 确保表单引用已准备好并清除验证
|
||||||
|
this.$nextTick(() => {
|
||||||
|
if (this.$refs.deviceForm) {
|
||||||
|
this.$refs.deviceForm.clearValidate()
|
||||||
|
}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
// 编辑设备
|
// 编辑设备
|
||||||
|
|||||||
@@ -166,6 +166,29 @@
|
|||||||
<el-form-item label="登录账号" prop="loginAccount">
|
<el-form-item label="登录账号" prop="loginAccount">
|
||||||
<el-input v-model="salesForm.loginAccount" placeholder="请输入登录账号" />
|
<el-input v-model="salesForm.loginAccount" placeholder="请输入登录账号" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<el-form-item label="登录密码" prop="password">
|
||||||
|
<el-input
|
||||||
|
v-model="salesForm.password"
|
||||||
|
type="password"
|
||||||
|
placeholder="请输入登录密码"
|
||||||
|
show-password
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="租户" prop="tenantCode">
|
||||||
|
<el-select
|
||||||
|
v-model="salesForm.tenantCode"
|
||||||
|
placeholder="请选择租户"
|
||||||
|
style="width: 100%"
|
||||||
|
filterable
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="item in tenantOptions"
|
||||||
|
:key="item.value"
|
||||||
|
:label="item.label"
|
||||||
|
:value="item.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
<el-form-item label="所属项目" prop="projectId">
|
<el-form-item label="所属项目" prop="projectId">
|
||||||
<el-select
|
<el-select
|
||||||
v-model="salesForm.projectId"
|
v-model="salesForm.projectId"
|
||||||
@@ -224,6 +247,7 @@
|
|||||||
import { getSalesList, getSalesById, addSales, updateSales, deleteSales, batchDeleteSales } from '@/api/sales'
|
import { getSalesList, getSalesById, addSales, updateSales, deleteSales, batchDeleteSales } from '@/api/sales'
|
||||||
import { getDealershipList } from '@/api/dealership'
|
import { getDealershipList } from '@/api/dealership'
|
||||||
import { getProjectList } from '@/api/project'
|
import { getProjectList } from '@/api/project'
|
||||||
|
import { getAllTenantList } from '@/api/tenant'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Sales',
|
name: 'Sales',
|
||||||
@@ -249,6 +273,8 @@ export default {
|
|||||||
storeOptions: [],
|
storeOptions: [],
|
||||||
// 项目选项
|
// 项目选项
|
||||||
projectOptions: [],
|
projectOptions: [],
|
||||||
|
// 租户选项
|
||||||
|
tenantOptions: [],
|
||||||
// 添加/编辑对话框相关
|
// 添加/编辑对话框相关
|
||||||
dialogVisible: false,
|
dialogVisible: false,
|
||||||
dialogTitle: '',
|
dialogTitle: '',
|
||||||
@@ -257,6 +283,8 @@ export default {
|
|||||||
id: undefined,
|
id: undefined,
|
||||||
salesName: '',
|
salesName: '',
|
||||||
loginAccount: '',
|
loginAccount: '',
|
||||||
|
password: '',
|
||||||
|
tenantCode: '',
|
||||||
dealershipId: '',
|
dealershipId: '',
|
||||||
role: '',
|
role: '',
|
||||||
status: '1'
|
status: '1'
|
||||||
@@ -274,6 +302,7 @@ export default {
|
|||||||
this.getList()
|
this.getList()
|
||||||
this.getStoreOptions()
|
this.getStoreOptions()
|
||||||
this.getProjectOptions()
|
this.getProjectOptions()
|
||||||
|
this.getTenantOptions()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 获取列表数据
|
// 获取列表数据
|
||||||
@@ -385,6 +414,26 @@ export default {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 获取租户选项
|
||||||
|
getTenantOptions() {
|
||||||
|
getAllTenantList().then(response => {
|
||||||
|
console.log('获取租户列表响应:', response)
|
||||||
|
if (response && response.code === 20000) {
|
||||||
|
// 处理响应数据,可能是数组或包含data字段的对象
|
||||||
|
const tenantList = Array.isArray(response.data) ? response.data : (response.data?.data || [])
|
||||||
|
this.tenantOptions = tenantList.map(item => ({
|
||||||
|
value: item.tenantCode, // 使用租户编码作为值
|
||||||
|
label: `${item.tenantName} ${item.tenantCode}` // 显示格式:租户名称 租户编码
|
||||||
|
}))
|
||||||
|
} else {
|
||||||
|
this.$message.error(response?.message || '获取租户列表失败')
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('获取租户列表失败:', error)
|
||||||
|
this.$message.error('获取租户列表失败,请稍后重试')
|
||||||
|
})
|
||||||
|
},
|
||||||
// 查询
|
// 查询
|
||||||
handleQuery() {
|
handleQuery() {
|
||||||
this.queryParams.pageNum = 1
|
this.queryParams.pageNum = 1
|
||||||
@@ -571,6 +620,8 @@ export default {
|
|||||||
id: undefined,
|
id: undefined,
|
||||||
salesName: '',
|
salesName: '',
|
||||||
loginAccount: '',
|
loginAccount: '',
|
||||||
|
password: '',
|
||||||
|
tenantCode: '',
|
||||||
dealershipId: '',
|
dealershipId: '',
|
||||||
role: '',
|
role: '',
|
||||||
status: '1'
|
status: '1'
|
||||||
@@ -583,8 +634,16 @@ export default {
|
|||||||
console.log('提交表单:', this.salesForm)
|
console.log('提交表单:', this.salesForm)
|
||||||
this.$refs.salesForm.validate(valid => {
|
this.$refs.salesForm.validate(valid => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
|
// 构建提交数据,将租户编码赋值给租户id
|
||||||
|
const submitData = { ...this.salesForm }
|
||||||
|
if (submitData.tenantCode) {
|
||||||
|
submitData.tenantId = submitData.tenantCode // 将租户编码赋值给租户id
|
||||||
|
}
|
||||||
|
// 移除 tenantCode 字段,只传递 tenantId
|
||||||
|
delete submitData.tenantCode
|
||||||
|
|
||||||
const submitFunc = this.isEdit ? updateSales : addSales
|
const submitFunc = this.isEdit ? updateSales : addSales
|
||||||
submitFunc(this.salesForm).then(response => {
|
submitFunc(submitData).then(response => {
|
||||||
console.log('提交表单响应:', response) // 调试日志
|
console.log('提交表单响应:', response) // 调试日志
|
||||||
|
|
||||||
if (response && response.code === 20000) {
|
if (response && response.code === 20000) {
|
||||||
|
|||||||
@@ -23,11 +23,41 @@
|
|||||||
|
|
||||||
<el-form-item label="状态">
|
<el-form-item label="状态">
|
||||||
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
|
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
|
||||||
<el-option label="启用" :value="true" />
|
<el-option label="启用" :value="0" />
|
||||||
<el-option label="禁用" :value="false" />
|
<el-option label="禁用" :value="1" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="联系人">
|
||||||
|
<el-input
|
||||||
|
v-model="queryParams.contactName"
|
||||||
|
placeholder="请输入联系人姓名"
|
||||||
|
clearable
|
||||||
|
style="width: 200px"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="联系电话">
|
||||||
|
<el-input
|
||||||
|
v-model="queryParams.contactPhone"
|
||||||
|
placeholder="请输入联系电话"
|
||||||
|
clearable
|
||||||
|
style="width: 200px"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="过期时间">
|
||||||
|
<el-date-picker
|
||||||
|
v-model="queryParams.expireTimeRange"
|
||||||
|
type="datetimerange"
|
||||||
|
range-separator="至"
|
||||||
|
start-placeholder="开始时间"
|
||||||
|
end-placeholder="结束时间"
|
||||||
|
value-format="yyyy-MM-dd HH:mm:ss"
|
||||||
|
style="width: 400px"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
|
<el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
|
||||||
<el-button icon="el-icon-delete" @click="resetQuery">清空</el-button>
|
<el-button icon="el-icon-delete" @click="resetQuery">清空</el-button>
|
||||||
@@ -53,23 +83,28 @@
|
|||||||
<el-table-column label="序号" type="index" width="50" />
|
<el-table-column label="序号" type="index" width="50" />
|
||||||
<el-table-column label="租户名称" prop="tenantName" sortable min-width="150" />
|
<el-table-column label="租户名称" prop="tenantName" sortable min-width="150" />
|
||||||
<el-table-column label="租户代码" prop="tenantCode" sortable min-width="150" />
|
<el-table-column label="租户代码" prop="tenantCode" sortable min-width="150" />
|
||||||
<el-table-column label="联系人" prop="contactPerson" min-width="120" />
|
<el-table-column label="联系人" prop="contactName" min-width="120" />
|
||||||
<el-table-column label="联系电话" prop="contactPhone" min-width="150" />
|
<el-table-column label="联系电话" prop="contactPhone" min-width="150" />
|
||||||
<el-table-column label="邮箱" prop="email" min-width="200" show-overflow-tooltip />
|
|
||||||
<el-table-column label="状态" prop="status" sortable min-width="100">
|
<el-table-column label="状态" prop="status" sortable min-width="100">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-tag :type="scope.row.status ? 'success' : 'danger'">
|
<el-tag :type="scope.row.status === 0 ? 'success' : 'danger'">
|
||||||
{{ scope.row.status ? '启用' : '禁用' }}
|
{{ scope.row.status === 0 ? '启用' : '禁用' }}
|
||||||
</el-tag>
|
</el-tag>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
<el-table-column label="过期时间" prop="expireTime" sortable min-width="150">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
{{ formatDateTime(scope.row.expireTime) }}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
<el-table-column label="创建时间" prop="createTime" sortable min-width="150">
|
<el-table-column label="创建时间" prop="createTime" sortable min-width="150">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
{{ formatDateTime(scope.row.createTime) }}
|
{{ formatDateTime(scope.row.createTime) }}
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="操作" width="200" fixed="right">
|
<el-table-column label="操作" width="280" fixed="right">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
|
<el-button type="text" @click="handleAddDevice(scope.row)">添加设备</el-button>
|
||||||
<el-button type="text" @click="handleEdit(scope.row)">编辑</el-button>
|
<el-button type="text" @click="handleEdit(scope.row)">编辑</el-button>
|
||||||
<el-button type="text" style="color: #F56C6C;" @click="handleDelete(scope.row)">删除</el-button>
|
<el-button type="text" style="color: #F56C6C;" @click="handleDelete(scope.row)">删除</el-button>
|
||||||
</template>
|
</template>
|
||||||
@@ -107,28 +142,25 @@
|
|||||||
<el-form-item label="租户代码" prop="tenantCode">
|
<el-form-item label="租户代码" prop="tenantCode">
|
||||||
<el-input v-model="tenantForm.tenantCode" placeholder="请输入租户代码" />
|
<el-input v-model="tenantForm.tenantCode" placeholder="请输入租户代码" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="联系人" prop="contactPerson">
|
<el-form-item label="联系人" prop="contactName">
|
||||||
<el-input v-model="tenantForm.contactPerson" placeholder="请输入联系人" />
|
<el-input v-model="tenantForm.contactName" placeholder="请输入联系人" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="联系电话" prop="contactPhone">
|
<el-form-item label="联系电话" prop="contactPhone">
|
||||||
<el-input v-model="tenantForm.contactPhone" placeholder="请输入联系电话" />
|
<el-input v-model="tenantForm.contactPhone" placeholder="请输入联系电话" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="邮箱" prop="email">
|
|
||||||
<el-input v-model="tenantForm.email" placeholder="请输入邮箱" />
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="状态" prop="status">
|
<el-form-item label="状态" prop="status">
|
||||||
<el-switch
|
<el-select v-model="tenantForm.status" placeholder="请选择状态">
|
||||||
v-model="tenantForm.status"
|
<el-option label="启用" :value="0" />
|
||||||
active-text="启用"
|
<el-option label="禁用" :value="1" />
|
||||||
inactive-text="禁用"
|
</el-select>
|
||||||
/>
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="备注">
|
<el-form-item label="过期时间" prop="expireTime">
|
||||||
<el-input
|
<el-date-picker
|
||||||
v-model="tenantForm.remark"
|
v-model="tenantForm.expireTime"
|
||||||
type="textarea"
|
type="datetime"
|
||||||
:rows="3"
|
placeholder="请选择过期时间"
|
||||||
placeholder="请输入备注"
|
value-format="yyyy-MM-dd HH:mm:ss"
|
||||||
|
style="width: 100%"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
@@ -141,6 +173,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { addTenant, getTenantList, updateTenant } from '@/api/tenant'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Tenant',
|
name: 'Tenant',
|
||||||
data() {
|
data() {
|
||||||
@@ -158,18 +192,20 @@ export default {
|
|||||||
size: 10,
|
size: 10,
|
||||||
tenantName: '',
|
tenantName: '',
|
||||||
tenantCode: '',
|
tenantCode: '',
|
||||||
status: null
|
status: null,
|
||||||
|
contactName: '',
|
||||||
|
contactPhone: '',
|
||||||
|
expireTimeRange: null
|
||||||
},
|
},
|
||||||
// 租户表单
|
// 租户表单
|
||||||
tenantForm: {
|
tenantForm: {
|
||||||
id: null,
|
id: null,
|
||||||
tenantName: '',
|
tenantName: '',
|
||||||
tenantCode: '',
|
tenantCode: '',
|
||||||
contactPerson: '',
|
contactName: '',
|
||||||
contactPhone: '',
|
contactPhone: '',
|
||||||
email: '',
|
status: 0,
|
||||||
status: true,
|
expireTime: ''
|
||||||
remark: ''
|
|
||||||
},
|
},
|
||||||
// 表单验证规则
|
// 表单验证规则
|
||||||
formRules: {
|
formRules: {
|
||||||
@@ -179,15 +215,25 @@ export default {
|
|||||||
tenantCode: [
|
tenantCode: [
|
||||||
{ required: true, message: '请输入租户代码', trigger: 'blur' }
|
{ required: true, message: '请输入租户代码', trigger: 'blur' }
|
||||||
],
|
],
|
||||||
contactPerson: [
|
contactName: [
|
||||||
{ required: true, message: '请输入联系人', trigger: 'blur' }
|
{ required: true, message: '请输入联系人', trigger: 'blur' }
|
||||||
],
|
],
|
||||||
contactPhone: [
|
contactPhone: [
|
||||||
{ required: true, message: '请输入联系电话', trigger: 'blur' },
|
{ required: true, message: '请输入联系电话', trigger: 'blur' }
|
||||||
{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号码', trigger: 'blur' }
|
|
||||||
],
|
],
|
||||||
email: [
|
status: [
|
||||||
{ type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur' }
|
{
|
||||||
|
required: true,
|
||||||
|
message: '请选择状态',
|
||||||
|
trigger: 'change',
|
||||||
|
validator: (rule, value, callback) => {
|
||||||
|
if (value === null || value === undefined || value === '') {
|
||||||
|
callback(new Error('请选择状态'))
|
||||||
|
} else {
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -199,21 +245,55 @@ export default {
|
|||||||
// 获取租户列表
|
// 获取租户列表
|
||||||
getTenantList() {
|
getTenantList() {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
// TODO: 调用实际的API接口
|
|
||||||
// getTenantList(this.queryParams).then(response => {
|
|
||||||
// this.tenantList = response.data.records || []
|
|
||||||
// this.total = response.data.total || 0
|
|
||||||
// this.loading = false
|
|
||||||
// }).catch(() => {
|
|
||||||
// this.loading = false
|
|
||||||
// })
|
|
||||||
|
|
||||||
// 临时模拟数据
|
// 构建查询参数
|
||||||
setTimeout(() => {
|
const params = {
|
||||||
|
current: this.queryParams.current,
|
||||||
|
size: this.queryParams.size,
|
||||||
|
tenantCode: this.queryParams.tenantCode || undefined,
|
||||||
|
tenantName: this.queryParams.tenantName || undefined,
|
||||||
|
status: this.queryParams.status !== null && this.queryParams.status !== '' ? this.queryParams.status : undefined,
|
||||||
|
contactName: this.queryParams.contactName || undefined,
|
||||||
|
contactPhone: this.queryParams.contactPhone || undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理过期时间范围
|
||||||
|
if (this.queryParams.expireTimeRange && this.queryParams.expireTimeRange.length === 2) {
|
||||||
|
params.expireStartTime = this.queryParams.expireTimeRange[0]
|
||||||
|
params.expireEndTime = this.queryParams.expireTimeRange[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 移除空值
|
||||||
|
Object.keys(params).forEach(key => {
|
||||||
|
if (params[key] === undefined || params[key] === '') {
|
||||||
|
delete params[key]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log('查询租户列表参数:', params)
|
||||||
|
|
||||||
|
getTenantList(params).then(response => {
|
||||||
|
console.log('租户列表响应:', response)
|
||||||
|
|
||||||
|
if (response && response.code === 20000) {
|
||||||
|
// 响应格式:{ code: 20000, data: [...], total: 3, current: 1, pages: 1, size: 10, message: "查询成功" }
|
||||||
|
// response.data 就是租户数组
|
||||||
|
this.tenantList = Array.isArray(response.data) ? response.data : []
|
||||||
|
this.total = response.total || 0
|
||||||
|
} else if (response && response.code === 200) {
|
||||||
|
// 兼容其他响应格式
|
||||||
|
this.tenantList = Array.isArray(response.data) ? response.data : []
|
||||||
|
this.total = response.total || 0
|
||||||
|
} else {
|
||||||
this.tenantList = []
|
this.tenantList = []
|
||||||
this.total = 0
|
this.total = 0
|
||||||
|
}
|
||||||
this.loading = false
|
this.loading = false
|
||||||
}, 500)
|
}).catch(error => {
|
||||||
|
console.error('获取租户列表失败:', error)
|
||||||
|
this.$message.error('获取租户列表失败,请稍后重试')
|
||||||
|
this.loading = false
|
||||||
|
})
|
||||||
},
|
},
|
||||||
// 搜索
|
// 搜索
|
||||||
handleQuery() {
|
handleQuery() {
|
||||||
@@ -227,7 +307,10 @@ export default {
|
|||||||
size: 10,
|
size: 10,
|
||||||
tenantName: '',
|
tenantName: '',
|
||||||
tenantCode: '',
|
tenantCode: '',
|
||||||
status: null
|
status: null,
|
||||||
|
contactName: '',
|
||||||
|
contactPhone: '',
|
||||||
|
expireTimeRange: null
|
||||||
}
|
}
|
||||||
this.getTenantList()
|
this.getTenantList()
|
||||||
},
|
},
|
||||||
@@ -249,7 +332,28 @@ export default {
|
|||||||
handleAdd() {
|
handleAdd() {
|
||||||
this.dialogTitle = '添加租户'
|
this.dialogTitle = '添加租户'
|
||||||
this.isEdit = false
|
this.isEdit = false
|
||||||
|
// 重置表单
|
||||||
|
this.resetForm()
|
||||||
this.dialogVisible = true
|
this.dialogVisible = true
|
||||||
|
// 确保表单引用已准备好
|
||||||
|
this.$nextTick(() => {
|
||||||
|
if (this.$refs.tenantForm) {
|
||||||
|
this.$refs.tenantForm.clearValidate()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
// 添加设备
|
||||||
|
handleAddDevice(row) {
|
||||||
|
console.log('添加设备,租户信息:', row)
|
||||||
|
// 跳转到设备管理页面,并传递租户信息
|
||||||
|
this.$router.push({
|
||||||
|
path: '/system/device',
|
||||||
|
query: {
|
||||||
|
tenantId: row.id,
|
||||||
|
tenantName: row.tenantName,
|
||||||
|
tenantCode: row.tenantCode
|
||||||
|
}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
// 编辑
|
// 编辑
|
||||||
handleEdit(row) {
|
handleEdit(row) {
|
||||||
@@ -259,11 +363,10 @@ export default {
|
|||||||
id: row.id,
|
id: row.id,
|
||||||
tenantName: row.tenantName,
|
tenantName: row.tenantName,
|
||||||
tenantCode: row.tenantCode,
|
tenantCode: row.tenantCode,
|
||||||
contactPerson: row.contactPerson,
|
contactName: row.contactName,
|
||||||
contactPhone: row.contactPhone,
|
contactPhone: row.contactPhone,
|
||||||
email: row.email,
|
|
||||||
status: row.status,
|
status: row.status,
|
||||||
remark: row.remark || ''
|
expireTime: row.expireTime || ''
|
||||||
}
|
}
|
||||||
this.dialogVisible = true
|
this.dialogVisible = true
|
||||||
},
|
},
|
||||||
@@ -305,18 +408,68 @@ export default {
|
|||||||
},
|
},
|
||||||
// 提交表单
|
// 提交表单
|
||||||
handleSubmit() {
|
handleSubmit() {
|
||||||
|
console.log('handleSubmit 被调用')
|
||||||
|
console.log('表单ref是否存在:', !!this.$refs.tenantForm)
|
||||||
|
console.log('当前表单数据:', this.tenantForm)
|
||||||
|
console.log('isEdit:', this.isEdit)
|
||||||
|
|
||||||
|
if (!this.$refs.tenantForm) {
|
||||||
|
this.$message.error('表单引用不存在,请稍后重试')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
this.$refs.tenantForm.validate((valid) => {
|
this.$refs.tenantForm.validate((valid) => {
|
||||||
|
console.log('表单验证结果:', valid)
|
||||||
if (valid) {
|
if (valid) {
|
||||||
// TODO: 调用添加/更新API
|
if (this.isEdit) {
|
||||||
// const submitFunc = this.isEdit ? updateTenant : addTenant
|
// 更新租户
|
||||||
// submitFunc(this.tenantForm).then(() => {
|
const formData = {
|
||||||
// this.$message.success(this.isEdit ? '更新成功' : '添加成功')
|
id: this.tenantForm.id,
|
||||||
// this.dialogVisible = false
|
tenantCode: this.tenantForm.tenantCode,
|
||||||
// this.getTenantList()
|
tenantName: this.tenantForm.tenantName,
|
||||||
// })
|
status: this.tenantForm.status,
|
||||||
this.$message.success(this.isEdit ? '更新成功' : '添加成功')
|
contactName: this.tenantForm.contactName,
|
||||||
|
contactPhone: this.tenantForm.contactPhone,
|
||||||
|
expireTime: this.tenantForm.expireTime || ''
|
||||||
|
}
|
||||||
|
console.log('准备更新的数据:', formData)
|
||||||
|
console.log('调用 updateTenant API')
|
||||||
|
|
||||||
|
updateTenant(formData).then(response => {
|
||||||
|
console.log('updateTenant 响应:', response)
|
||||||
|
this.$message.success(response.message || response.data?.message || '租户更新成功')
|
||||||
this.dialogVisible = false
|
this.dialogVisible = false
|
||||||
this.getTenantList()
|
this.getTenantList()
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('更新租户失败:', error)
|
||||||
|
this.$message.error(error.message || '更新租户失败,请稍后重试')
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// 新增租户
|
||||||
|
const formData = {
|
||||||
|
tenantCode: this.tenantForm.tenantCode,
|
||||||
|
tenantName: this.tenantForm.tenantName,
|
||||||
|
status: this.tenantForm.status,
|
||||||
|
contactName: this.tenantForm.contactName,
|
||||||
|
contactPhone: this.tenantForm.contactPhone,
|
||||||
|
expireTime: this.tenantForm.expireTime || ''
|
||||||
|
}
|
||||||
|
console.log('准备发送的数据:', formData)
|
||||||
|
console.log('调用 addTenant API')
|
||||||
|
|
||||||
|
addTenant(formData).then(response => {
|
||||||
|
console.log('addTenant 响应:', response)
|
||||||
|
this.$message.success(response.message || response.data?.message || '租户添加成功')
|
||||||
|
this.dialogVisible = false
|
||||||
|
this.getTenantList()
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('添加租户失败:', error)
|
||||||
|
this.$message.error(error.message || '添加租户失败,请稍后重试')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('表单验证失败')
|
||||||
|
this.$message.warning('请填写完整的表单信息')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -327,11 +480,10 @@ export default {
|
|||||||
id: null,
|
id: null,
|
||||||
tenantName: '',
|
tenantName: '',
|
||||||
tenantCode: '',
|
tenantCode: '',
|
||||||
contactPerson: '',
|
contactName: '',
|
||||||
contactPhone: '',
|
contactPhone: '',
|
||||||
email: '',
|
status: 0,
|
||||||
status: true,
|
expireTime: ''
|
||||||
remark: ''
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 格式化日期时间
|
// 格式化日期时间
|
||||||
|
|||||||
Reference in New Issue
Block a user