index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <template>
  2. <div class="p-2">
  3. <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
  4. <div v-show="showSearch" class="mb-[10px]">
  5. <el-card shadow="hover">
  6. <el-form ref="queryFormRef" :model="queryParams" :inline="true">
  7. <el-form-item label="病区名称" prop="wardName">
  8. <el-input v-model="queryParams.wardName" placeholder="请输入" clearable @keyup.enter="handleQuery" />
  9. </el-form-item>
  10. <!-- <el-form-item label="科室ID" prop="deptId">
  11. <el-input v-model="queryParams.deptId" placeholder="请输入科室ID" clearable @keyup.enter="handleQuery" />
  12. </el-form-item> -->
  13. <el-form-item>
  14. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  15. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  16. </el-form-item>
  17. </el-form>
  18. </el-card>
  19. </div>
  20. </transition>
  21. <el-card shadow="never">
  22. <template #header>
  23. <el-row :gutter="10" class="mb8">
  24. <el-col :span="1.5">
  25. <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['system:ward:add']">新增病区</el-button>
  26. </el-col>
  27. <!-- <el-col :span="1.5">
  28. <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['system:ward:edit']">修改</el-button>
  29. </el-col>
  30. <el-col :span="1.5">
  31. <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['system:ward:remove']">删除</el-button>
  32. </el-col>
  33. <el-col :span="1.5">
  34. <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['system:ward:export']">导出</el-button>
  35. </el-col> -->
  36. <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
  37. </el-row>
  38. </template>
  39. <el-table v-loading="loading" border stripe :data="wardList" @selection-change="handleSelectionChange">
  40. <!-- <el-table-column type="selection" width="55" align="center" /> -->
  41. <!-- <el-table-column label="主键ID" align="center" prop="wardId" v-if="true" /> -->
  42. <el-table-column label="病区名称" align="center" prop="wardName"/>
  43. <el-table-column label="所属科室" align="center" prop="deptName" />
  44. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  45. <template #default="scope">
  46. <el-tooltip content="编辑" placement="top">
  47. <el-button link type="primary" icon="Edit" @click="handleUpdate(false,scope.row)" v-hasPermi="['system:ward:edit']">编辑</el-button>
  48. </el-tooltip>
  49. <el-tooltip content="详情" placement="详情">
  50. <el-button link type="primary" icon="View" @click="handleUpdate(true,scope.row)" v-hasPermi="['system:ward:edit']">详情</el-button>
  51. </el-tooltip>
  52. <el-tooltip content="删除" placement="top">
  53. <el-button link type="danger" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:ward:remove']">删除</el-button>
  54. </el-tooltip>
  55. </template>
  56. </el-table-column>
  57. </el-table>
  58. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  59. </el-card>
  60. <!-- 添加或修改病区管理对话框 -->
  61. <el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
  62. <el-form ref="wardFormRef" :model="form" :rules="rules" label-width="80px">
  63. <el-form-item label="病区名称" prop="wardName">
  64. <el-input v-model="form.wardName" placeholder="请输入" :disabled="dialog.disabled" />
  65. </el-form-item>
  66. <el-form-item label="科室" prop="deptIds">
  67. <el-tree-select :disabled="dialog.disabled"
  68. v-model="form.deptIds"
  69. show-checkbox
  70. multiple
  71. default-expand-all
  72. :data="enabledDeptOptions"
  73. :props="{ value: 'id', label: 'label', children: 'children' } as any"
  74. value-key="id"
  75. placeholder="请选择"
  76. />
  77. </el-form-item>
  78. </el-form>
  79. <template #footer>
  80. <div class="dialog-footer">
  81. <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  82. <el-button @click="cancel">取 消</el-button>
  83. </div>
  84. </template>
  85. </el-dialog>
  86. </div>
  87. </template>
  88. <script setup name="Ward" lang="ts">
  89. import api from '@/api/system/user';
  90. import { listWard, getWard, delWard, addWard, updateWard,listUsed} from '@/api/system/ward';
  91. import { WardVO, WardQuery, WardForm } from '@/api/system/ward/types';
  92. import { DeptTreeVO } from '@/api/system/dept/types';
  93. import { object } from 'vue-types';
  94. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  95. const enabledDeptOptions = ref<DeptTreeVO[]>([]);
  96. const wardList = ref<WardVO[]>([]);
  97. const buttonLoading = ref(false);
  98. const loading = ref(true);
  99. const showSearch = ref(true);
  100. const ids = ref<Array<string | number>>([]);
  101. const single = ref(true);
  102. const multiple = ref(true);
  103. const total = ref(0);
  104. const queryFormRef = ref<ElFormInstance>();
  105. const wardFormRef = ref<ElFormInstance>();
  106. const dialog = reactive<DialogOption>({
  107. visible: false,
  108. title: '',
  109. disabled:false
  110. });
  111. const initFormData: WardForm = {
  112. wardId: undefined,
  113. wardName: undefined,
  114. deptId: undefined,
  115. deptIds: undefined,
  116. status: undefined,
  117. }
  118. const data = reactive<PageData<WardForm, WardQuery>>({
  119. form: {...initFormData},
  120. queryParams: {
  121. pageNum: 1,
  122. pageSize: 10,
  123. wardName: undefined,
  124. deptId: undefined,
  125. status: undefined,
  126. params: {
  127. }
  128. },
  129. rules: {
  130. wardName: [
  131. { required: true, message: "病区名称不能为空", trigger: "blur" }
  132. ],
  133. }
  134. });
  135. const { queryParams, form, rules } = toRefs(data);
  136. /** 查询科室下拉树结构 */
  137. const getDeptTree = async (isshow:boolean) => {
  138. let usedDept={};
  139. if (!isshow){
  140. const response = await listUsed();
  141. usedDept=response.data;
  142. }
  143. const res = await api.deptTreeSelect();
  144. enabledDeptOptions.value = filterDisabledDept(res.data,usedDept);
  145. };
  146. /** 过滤禁用的科室 */
  147. const filterDisabledDept = (deptList: DeptTreeVO[],usedDept:any) => {
  148. return deptList.filter((dept) => {
  149. dept.disabled=usedDept[dept.id.toString()]==true;
  150. if (dept.disabled) {
  151. return false;
  152. }
  153. if (dept.children && dept.children.length) {
  154. dept.children = filterDisabledDept(dept.children,usedDept);
  155. }
  156. return true;
  157. });
  158. };
  159. /** 查询病区管理列表 */
  160. const getList = async () => {
  161. loading.value = true;
  162. const res = await listWard(queryParams.value);
  163. wardList.value = res.rows;
  164. total.value = res.total;
  165. loading.value = false;
  166. }
  167. /** 取消按钮 */
  168. const cancel = () => {
  169. reset();
  170. dialog.visible = false;
  171. }
  172. /** 表单重置 */
  173. const reset = () => {
  174. form.value = {...initFormData};
  175. wardFormRef.value?.resetFields();
  176. }
  177. /** 搜索按钮操作 */
  178. const handleQuery = () => {
  179. queryParams.value.pageNum = 1;
  180. getList();
  181. }
  182. /** 重置按钮操作 */
  183. const resetQuery = () => {
  184. queryFormRef.value?.resetFields();
  185. handleQuery();
  186. }
  187. /** 多选框选中数据 */
  188. const handleSelectionChange = (selection: WardVO[]) => {
  189. ids.value = selection.map(item => item.wardId);
  190. single.value = selection.length != 1;
  191. multiple.value = !selection.length;
  192. }
  193. /** 新增按钮操作 */
  194. const handleAdd = () => {
  195. getDeptTree(false);
  196. reset();
  197. dialog.visible = true;
  198. dialog.disabled = false;
  199. dialog.title = "添加病区管理";
  200. }
  201. /** 修改按钮操作 */
  202. const handleUpdate = async (disabled:boolean,row?: WardVO) => {
  203. await getDeptTree(true);
  204. reset();
  205. const _wardId = row?.wardId || ids.value[0]
  206. const res = await getWard(_wardId);
  207. Object.assign(form.value, res.data);
  208. if (res.data.deptId) {
  209. let deptId:string =res.data.deptId.toString();
  210. form.value.deptIds =deptId.length>0?deptId.split(","):[];
  211. }else{
  212. form.value.deptIds = [];
  213. }
  214. dialog.visible = true;
  215. dialog.disabled = disabled;
  216. dialog.title = "修改病区管理";
  217. }
  218. /** 提交按钮 */
  219. const submitForm = () => {
  220. wardFormRef.value?.validate(async (valid: boolean) => {
  221. if (valid) {
  222. buttonLoading.value = true;
  223. let params = ref<WardForm>({});
  224. Object.assign(params.value, form.value);
  225. params.value.deptId = params.value.deptIds.join(",");
  226. params.value.deptIds=undefined;
  227. if (form.value.wardId) {
  228. await updateWard(params.value).finally(() => buttonLoading.value = false);
  229. } else {
  230. await addWard(params.value).finally(() => buttonLoading.value = false);
  231. }
  232. proxy?.$modal.msgSuccess("操作成功");
  233. dialog.visible = false;
  234. await getList();
  235. }
  236. });
  237. }
  238. /** 删除按钮操作 */
  239. const handleDelete = async (row?: WardVO) => {
  240. const _wardIds = row?.wardId || ids.value;
  241. await proxy?.$modal.confirm('是否确认删除病区管理编号为"' + _wardIds + '"的数据项?').finally(() => loading.value = false);
  242. await delWard(_wardIds);
  243. proxy?.$modal.msgSuccess("删除成功");
  244. await getList();
  245. }
  246. /** 导出按钮操作 */
  247. const handleExport = () => {
  248. proxy?.download('system/ward/export', {
  249. ...queryParams.value
  250. }, `ward_${new Date().getTime()}.xlsx`)
  251. }
  252. onMounted(() => {
  253. getList();
  254. });
  255. </script>