FormDrawer.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <BasicDrawer
  3. v-bind="$attrs"
  4. destroyOnClose
  5. @register="registerDrawer"
  6. :title="getTitle"
  7. :width="width"
  8. @ok="handleSubmit"
  9. :showFooter="true"
  10. >
  11. <BasicForm
  12. @register="registerForm"
  13. layout="vertical"
  14. class="!px-6 !pt-4"
  15. @field-value-change="callFormFieldChange"
  16. >
  17. <template #suppliesTemplate>
  18. <div>
  19. <a-button type="primary" shape="round" @click="handleAdd">
  20. <template #icon>
  21. <PlusOutlined />
  22. </template>
  23. 添加
  24. </a-button>
  25. <div class="w-full mt-2">
  26. <BasicTable @register="registerTable">
  27. <template #bodyCell="{ column, record }">
  28. <template v-if="column.key === 'action'">
  29. <TableAction
  30. :actions="[
  31. {
  32. auth: 'archives:diagnosisHistory:edit',
  33. icon: 'icon-xt-details_delete_default|iconfont',
  34. tooltip: '删除',
  35. popConfirm: {
  36. title: '是否取消删除',
  37. placement: 'left',
  38. confirm: handleDel.bind(null, record, column),
  39. },
  40. },
  41. ]"
  42. />
  43. </template>
  44. </template>
  45. </BasicTable>
  46. </div>
  47. </div>
  48. </template>
  49. </BasicForm>
  50. <FormDrawerHistory @register="registerDrawerHistory" />
  51. </BasicDrawer>
  52. </template>
  53. <script lang="ts" setup>
  54. import { ref, reactive, unref, nextTick } from 'vue';
  55. import { BasicDrawer, useDrawer, useDrawerInner } from '/@/components/Drawer';
  56. import { BasicForm, useForm } from '/@/components/Form';
  57. import { useMessage } from '/@/hooks/web/useMessage';
  58. import { columnsDrawer, dataFormSchema } from './data';
  59. import { listDictModel } from '/@/api/common';
  60. import { PlusOutlined } from '@ant-design/icons-vue';
  61. import { BasicTable, useTable, TableAction } from '@/components/Table';
  62. import { nanoid } from 'nanoid';
  63. import {
  64. archivesFormulaTemplateAdd,
  65. archivesFormulaTemplateDetail,
  66. archivesFormulaTemplateEdit,
  67. } from '@/api/biz/archives/formulaTemplateApi';
  68. import FormDrawerHistory from './FormDrawerHistory.vue';
  69. import dayjs from 'dayjs';
  70. const emit = defineEmits(['success', 'register']);
  71. const getTitle = ref('透析处方');
  72. const width = '70%';
  73. const isUpdate = ref(false);
  74. const rowId = ref();
  75. const patientBasicId = ref();
  76. const bizDictOptions = reactive({
  77. accessType: [],
  78. });
  79. // 表格数据
  80. const tableData = ref([]);
  81. const { createMessage } = useMessage();
  82. const [registerDrawerHistory, { openDrawer }] = useDrawer();
  83. const [registerForm, { setFieldsValue, resetFields, validate, updateSchema }] = useForm({
  84. schemas: dataFormSchema,
  85. showActionButtonGroup: false,
  86. baseColProps: {
  87. span: 6,
  88. },
  89. });
  90. const [registerTable, { setTableData, getDataSource }] = useTable({
  91. rowKey: 'id',
  92. showIndexColumn: false,
  93. bordered: true,
  94. striped: false,
  95. pagination: false,
  96. maxHeight: 200,
  97. actionColumn: {
  98. width: 80,
  99. title: '操作',
  100. dataIndex: 'action',
  101. },
  102. dataSource: tableData.value,
  103. columns: columnsDrawer,
  104. });
  105. const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async data => {
  106. console.log('🚀 ~ file: FormDrawer.vue:49 ~ data:', data);
  107. await resetFields();
  108. setDrawerProps({ confirmLoading: false });
  109. isUpdate.value = data.isUpdate;
  110. getTitle.value = `${isUpdate.value ? '编辑透析处方模板' : '新建透析处方模板'} ( ${
  111. data.record.name
  112. } | ${data.record.gender} | ${data.record.age}岁 )`;
  113. bizDictOptions.accessType = await listDictModel({ dictCode: 'va_type' });
  114. patientBasicId.value = data.record.patientBasicId;
  115. rowId.value = data.record?.id;
  116. console.log('unref(isUpdate)', unref(isUpdate));
  117. if (unref(isUpdate)) {
  118. const resData = await archivesFormulaTemplateDetail(rowId.value);
  119. if (resData.suppliesTemplate) {
  120. tableData.value = resData.suppliesTemplate.map(ele => {
  121. return {
  122. name: ele.name,
  123. typeName: ele.typeName,
  124. count: ele.count,
  125. };
  126. });
  127. await nextTick();
  128. await setTableData(tableData.value);
  129. }
  130. await setFieldsValue({
  131. ...resData,
  132. });
  133. if (resData.dialysisType) {
  134. updateSchema({
  135. // label: '透析模式',
  136. field: 'dialysisType',
  137. // required: true,
  138. // component: 'ApiSelect',
  139. componentProps: {
  140. disabled: true,
  141. // api: listDictModel,
  142. // params: {
  143. // dictCode: 'dt',
  144. // },
  145. },
  146. });
  147. }
  148. } else {
  149. await setFieldsValue({
  150. enactedTime: dayjs().format('YYYY-MM-DD'),
  151. });
  152. }
  153. });
  154. // 提交按钮事件
  155. async function handleSubmit() {
  156. try {
  157. const values = await validate();
  158. setDrawerProps({ confirmLoading: true });
  159. values.patientBasicId = patientBasicId.value;
  160. !unref(isUpdate)
  161. ? await archivesFormulaTemplateAdd({ ...values })
  162. : await archivesFormulaTemplateEdit({ ...values, id: rowId.value });
  163. !unref(isUpdate) ? createMessage.success('新增成功!') : createMessage.success('编辑成功!');
  164. closeDrawer();
  165. emit('success', {
  166. isUpdate: unref(isUpdate),
  167. values: { ...values, id: rowId.value },
  168. });
  169. } finally {
  170. setDrawerProps({ confirmLoading: false });
  171. }
  172. }
  173. async function handleAdd() {
  174. console.log('添加');
  175. tableData.value.push({
  176. typeId: '',
  177. name: '',
  178. nanoid: nanoid(5),
  179. });
  180. console.log(
  181. '🚀 ~ file: FormModal.vue:135 ~ handleAdd ~ tableDataAllergic.value:',
  182. tableData.value,
  183. );
  184. await nextTick();
  185. await setTableData(tableData.value);
  186. }
  187. function handleDel(record) {
  188. console.log('删除');
  189. const data = getDataSource();
  190. const index = data.findIndex(item => item.id === record.id);
  191. tableData.value.splice(index, 1);
  192. setTableData(tableData.value);
  193. }
  194. function callFormFieldChange(key) {
  195. console.log('🚀 ~ file: FormDrawer.vue:169 ~ callFormFieldChange ~ key:', key);
  196. if (key == 'vitals') {
  197. console.log('打开体征历史数据');
  198. openDrawer(true, {
  199. record: {
  200. patientBasicId: patientBasicId.value,
  201. },
  202. });
  203. }
  204. }
  205. </script>
  206. <style lang="less" scoped>
  207. ::v-deep(.ant-table-body) {
  208. height: 200px !important;
  209. }
  210. ::v-deep(label[for='form_item_suppliesTemplate']) {
  211. display: none;
  212. }
  213. ::v-deep(.ant-btn-link) {
  214. color: rgb(61 65 85 / 100%);
  215. }
  216. </style>