科室级别,增加新增执行诊室的功能
parent
ab2c0f8252
commit
2113317f2f
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\API\Admin\YeWu;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Services\Admin\YeWu\DeptDeviceService;
|
||||||
|
|
||||||
|
class DeptDeviceController extends Controller
|
||||||
|
{
|
||||||
|
//获取当前科室下的设备列表
|
||||||
|
public function GetList(Request $request)
|
||||||
|
{
|
||||||
|
$searchInfo = request('searchInfo');
|
||||||
|
$page = request('page');
|
||||||
|
$pageSize = request('pageSize');
|
||||||
|
$userid = $request->get('userid');
|
||||||
|
$service = new DeptDeviceService();
|
||||||
|
return $service->GetList($searchInfo, $page, $pageSize, $userid);
|
||||||
|
}
|
||||||
|
|
||||||
|
//保存设备
|
||||||
|
public function Save(Request $request)
|
||||||
|
{
|
||||||
|
$data = request('Info');
|
||||||
|
$userid = $request->get('userid');
|
||||||
|
$service = new DeptDeviceService();
|
||||||
|
return $service->Save($data, $userid);
|
||||||
|
}
|
||||||
|
|
||||||
|
//删除设备
|
||||||
|
public function Del()
|
||||||
|
{
|
||||||
|
$id = request('id');
|
||||||
|
$service = new DeptDeviceService();
|
||||||
|
return $service->Del($id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Services\Admin\YeWu;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class DeptDeviceService
|
||||||
|
{
|
||||||
|
//获取当前科室下的设备列表(分页,支持搜索)
|
||||||
|
public function GetList($searchInfo, $page, $pageSize, $userid)
|
||||||
|
{
|
||||||
|
$user = DB::table('users')->where('id', $userid)->first();
|
||||||
|
if (!$user || !$user->department_id) {
|
||||||
|
return \Yz::Return(true, '查询成功', ['list' => [], 'count' => 0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$list = DB::table('s_devices')
|
||||||
|
->join('s_department_resources_device', 's_devices.id', '=', 's_department_resources_device.device_id')
|
||||||
|
->where('s_department_resources_device.department_id', $user->department_id)
|
||||||
|
->where('s_devices.is_del', 0);
|
||||||
|
|
||||||
|
if (!empty($searchInfo['name'])) {
|
||||||
|
$list->where('s_devices.device_name', 'like', '%' . $searchInfo['name'] . '%');
|
||||||
|
}
|
||||||
|
if (isset($searchInfo['status']) && $searchInfo['status'] !== '') {
|
||||||
|
$list->where('s_devices.status', $searchInfo['status']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$count = $list->count();
|
||||||
|
$items = $list->select('s_devices.*')
|
||||||
|
->orderBy('s_devices.id', 'desc')
|
||||||
|
->skip(($page - 1) * $pageSize)
|
||||||
|
->take($pageSize)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
return \Yz::Return(true, '查询成功', ['list' => $items, 'count' => $count]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//保存设备(新建时同时关联到当前科室)
|
||||||
|
public function Save($data, $userid)
|
||||||
|
{
|
||||||
|
$user = DB::table('users')->where('id', $userid)->first();
|
||||||
|
if (!$user || !$user->department_id) {
|
||||||
|
return \Yz::Return(false, '用户科室信息不存在');
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
try {
|
||||||
|
if (empty($data['id'])) {
|
||||||
|
//新建设备
|
||||||
|
$deviceId = DB::table('s_devices')->insertGetId([
|
||||||
|
'device_name' => $data['device_name'],
|
||||||
|
'status' => $data['status'] ?? 1,
|
||||||
|
'is_del' => 0,
|
||||||
|
]);
|
||||||
|
//关联到当前科室
|
||||||
|
DB::table('s_department_resources_device')->insert([
|
||||||
|
'department_id' => $user->department_id,
|
||||||
|
'device_id' => $deviceId,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
//更新设备
|
||||||
|
DB::table('s_devices')->where('id', $data['id'])->update([
|
||||||
|
'device_name' => $data['device_name'],
|
||||||
|
'status' => $data['status'] ?? 1,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
DB::commit();
|
||||||
|
return \Yz::Return(true, '保存成功');
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
return \Yz::Return(false, '保存失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//删除设备(软删除 + 解除关联)
|
||||||
|
public function Del($id)
|
||||||
|
{
|
||||||
|
DB::beginTransaction();
|
||||||
|
try {
|
||||||
|
DB::table('s_devices')->where('id', $id)->update(['is_del' => 1]);
|
||||||
|
DB::table('s_department_resources_device')->where('device_id', $id)->delete();
|
||||||
|
DB::commit();
|
||||||
|
return \Yz::Return(true, '删除成功');
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
return \Yz::Return(false, '删除失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,176 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<div class="head">
|
||||||
|
<el-row>
|
||||||
|
<el-form-item>
|
||||||
|
<el-select :filterable="true" clearable v-model="searchInfo.status" placeholder="所有状态"
|
||||||
|
style="margin-left: 10px;">
|
||||||
|
<el-option label="正常" :value="1" />
|
||||||
|
<el-option label="不可用" :value="0" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-input v-model="searchInfo.name" placeholder="请输入排班名称" style="margin-left: 10px;" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-button @click="GetList()" style="margin-left: 10px;">查询</el-button>
|
||||||
|
<el-button type="primary" @click="Add()" style="margin-left: 10px;">添加排班</el-button>
|
||||||
|
</el-row>
|
||||||
|
</div>
|
||||||
|
<el-table :data="tableData" style="width: 100%;" row-key="id" v-loading="loading">
|
||||||
|
<el-table-column prop="id" label="Id" width="100" />
|
||||||
|
<el-table-column prop="device_name" label="排班名称" />
|
||||||
|
<el-table-column prop="status" label="状态" width="100">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-tag v-if="scope.row.status==1" class="ml-2" type="success">正常</el-tag>
|
||||||
|
<el-tag v-if="scope.row.status==0" class="ml-2" type="danger">不可用</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column prop="" label="操作" width="180">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-button type="primary" @click="Edit(scope.row)" size="small">修改</el-button>
|
||||||
|
<el-button type="danger" @click="Del(scope.row.id)" size="small">删除</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
<div class="page">
|
||||||
|
<el-pagination v-model:current-page="currentPage" v-model:page-size="pageSize"
|
||||||
|
:page-sizes="[15, 50, 100, 200]" layout="total,sizes, prev, pager, next" :total="total"
|
||||||
|
@size-change="PageSizeChange" @current-change="PageCurrentChange" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<el-dialog v-model="dialogVisible" title="排班信息" width="30%">
|
||||||
|
<el-form :model="DeviceInfo" label-width="100px" v-loading="loading" style="padding-right: 40px;">
|
||||||
|
<el-form-item label="排班名称:">
|
||||||
|
<el-input v-model="DeviceInfo.device_name" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="状态:">
|
||||||
|
<el-switch v-model="DeviceInfo.status" size="large" active-text="正常" inactive-text="关闭"
|
||||||
|
:active-value="1" :inactive-value="0" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<span class="dialog-footer">
|
||||||
|
<el-button @click="dialogVisible = false">取消</el-button>
|
||||||
|
<el-button type="primary" @click="Save">
|
||||||
|
确定
|
||||||
|
</el-button>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import {
|
||||||
|
ref,
|
||||||
|
onMounted
|
||||||
|
} from 'vue'
|
||||||
|
import {
|
||||||
|
GetDeptDeviceListPage,
|
||||||
|
SaveDeptDevice,
|
||||||
|
DelDeptDevice
|
||||||
|
} from '@/api/api.js'
|
||||||
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
|
|
||||||
|
let loading = ref(false);
|
||||||
|
let searchInfo = ref({
|
||||||
|
status: null,
|
||||||
|
name: ''
|
||||||
|
})
|
||||||
|
let DeviceInfo = ref({
|
||||||
|
id: null,
|
||||||
|
device_name: '',
|
||||||
|
status: 1
|
||||||
|
})
|
||||||
|
|
||||||
|
let dialogVisible = ref(false);
|
||||||
|
|
||||||
|
//获取设备列表
|
||||||
|
let tableData = ref([])
|
||||||
|
let currentPage = ref(1)
|
||||||
|
let pageSize = ref(15)
|
||||||
|
let total = 0
|
||||||
|
const GetList = () => {
|
||||||
|
loading.value = true
|
||||||
|
GetDeptDeviceListPage({
|
||||||
|
searchInfo: searchInfo.value,
|
||||||
|
page: currentPage.value,
|
||||||
|
pageSize: pageSize.value
|
||||||
|
}).then(res => {
|
||||||
|
loading.value = false
|
||||||
|
if (res.status) {
|
||||||
|
tableData.value = res.data.list
|
||||||
|
total = res.data.count
|
||||||
|
} else {
|
||||||
|
ElMessage.error(res.msg)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const PageSizeChange = (e) => {
|
||||||
|
pageSize.value = e
|
||||||
|
GetList()
|
||||||
|
}
|
||||||
|
const PageCurrentChange = (e) => {
|
||||||
|
currentPage.value = e
|
||||||
|
GetList()
|
||||||
|
}
|
||||||
|
const Add = () => {
|
||||||
|
dialogVisible.value = true
|
||||||
|
DeviceInfo.value = {
|
||||||
|
id: null,
|
||||||
|
device_name: '',
|
||||||
|
status: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const Edit = (row) => {
|
||||||
|
DeviceInfo.value = {
|
||||||
|
id: row.id,
|
||||||
|
device_name: row.device_name,
|
||||||
|
status: row.status
|
||||||
|
}
|
||||||
|
dialogVisible.value = true
|
||||||
|
}
|
||||||
|
const Del = (id) => {
|
||||||
|
ElMessageBox.confirm(
|
||||||
|
'确定删除吗?',
|
||||||
|
'提示', {
|
||||||
|
confirmButtonText: '确定',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.then(() => {
|
||||||
|
DelDeptDevice({ id: id }).then(res => {
|
||||||
|
loading.value = false
|
||||||
|
if (res.status) {
|
||||||
|
GetList()
|
||||||
|
} else {
|
||||||
|
ElMessage.error(res.msg)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const Save = () => {
|
||||||
|
loading.value = true
|
||||||
|
SaveDeptDevice({ Info: DeviceInfo.value }).then(res => {
|
||||||
|
loading.value = false
|
||||||
|
if (res.status) {
|
||||||
|
dialogVisible.value = false
|
||||||
|
GetList()
|
||||||
|
} else {
|
||||||
|
ElMessage.error(res.msg)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
onMounted(() => {
|
||||||
|
GetList()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.page {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Loading…
Reference in New Issue