index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <div>
  3. <div class="flex justify-between mb-4">
  4. <div>
  5. <a-button type="primary" size="large" class="btn-add" @click="handleCreate">查房</a-button>
  6. </div>
  7. <div>
  8. <XTForm :form-data="formData" @change="callForm" />
  9. </div>
  10. </div>
  11. <BasicTable @register="registerTable">
  12. <template #bodyCell="{ column, record }">
  13. <template v-if="column.key === 'updatorName'">
  14. <img :src="record.updateAvatar" class="table-avatar" />
  15. {{ record.updatorName }}
  16. </template>
  17. <template v-if="column.key === 'action'">
  18. <TableAction
  19. :actions="[
  20. {
  21. auth: 'archives:patrolWard:edit',
  22. icon: 'icon-xt-details_edit_default|iconfont',
  23. tooltip: '编辑',
  24. onClick: handleEdit.bind(null, record),
  25. },
  26. {
  27. auth: 'archives:patrolWard:remove',
  28. icon: 'icon-xt-details_delete_default|iconfont',
  29. tooltip: '删除',
  30. popConfirm: {
  31. title: '是否取消删除',
  32. placement: 'left',
  33. confirm: handleDelete.bind(null, record, column),
  34. },
  35. },
  36. ]"
  37. />
  38. </template>
  39. </template>
  40. </BasicTable>
  41. <FormModal @register="registerModal" @success="callSuccess" />
  42. </div>
  43. </template>
  44. <script lang="ts" setup>
  45. import { reactive, ref } from 'vue';
  46. import { XTForm } from '/@/components/XTForm/index';
  47. import { BasicTable, useTable, TableAction } from '/@/components/Table';
  48. // import { useModal } from '/@/components/Modal';
  49. import { useMessage } from '/@/hooks/web/useMessage';
  50. import FormModal from './FormModal.vue';
  51. // import ViewDrawer from './viewDrawer.vue';
  52. import { columns } from './data';
  53. import {
  54. archivesPatrolWardQueryPage,
  55. archivesPatrolWardRemove,
  56. } from '/@/api/biz/archives/patrolWardApi';
  57. import { useModal } from '/@/components/Modal';
  58. import dayjs from 'dayjs';
  59. const props = defineProps({
  60. info: {
  61. type: Object,
  62. default: () => {},
  63. },
  64. });
  65. const { createConfirm, createMessage } = useMessage();
  66. const [registerModal, { openModal }] = useModal();
  67. const tableSort = ref([
  68. {
  69. field: 'create_time',
  70. direction: 'DESC',
  71. },
  72. ]) as any;
  73. // formdata
  74. const formData = [
  75. {
  76. name: 'patrolTime',
  77. label: '查房时间',
  78. componentType: 'RangePicker',
  79. placeholder: '请输入',
  80. format: 'YYYY-MM-DD',
  81. valueFormat: 'YYYY-MM-DD',
  82. defaultValue: [
  83. dayjs().subtract(3, 'month').format('YYYY-MM-DD'),
  84. dayjs().format('YYYY-MM-DD'),
  85. ],
  86. },
  87. {
  88. name: 'content',
  89. componentType: 'Input',
  90. placeholder: '请输入',
  91. prefix: 'icon-xt-search',
  92. width: 280,
  93. },
  94. ];
  95. const formValue = reactive({
  96. patrolTime: [
  97. dayjs().subtract(3, 'month').format('YYYY-MM-DD'),
  98. dayjs().add(1, 'day').format('YYYY-MM-DD'),
  99. ],
  100. content: '',
  101. });
  102. const [registerTable, { reload, getSelectRowKeys }] = useTable({
  103. api: archivesPatrolWardQueryPage,
  104. rowKey: 'id',
  105. columns,
  106. showIndexColumn: false,
  107. bordered: true,
  108. striped: false,
  109. actionColumn: {
  110. width: 200,
  111. title: '操作',
  112. dataIndex: 'action',
  113. },
  114. beforeFetch: handleBeforeFetch,
  115. sortFn: handleSortFn,
  116. });
  117. // 新增按钮事件
  118. function handleCreate() {
  119. openModal(true, {
  120. isUpdate: false,
  121. record: { patientBasicId: props.info.id },
  122. });
  123. }
  124. // 编辑按钮事件
  125. function handleEdit(record: Recordable) {
  126. openModal(true, {
  127. record: { patientBasicId: props.info.id, ...record },
  128. isUpdate: true,
  129. });
  130. }
  131. // 删除按钮事件
  132. async function handleDelete(record: Recordable) {
  133. if (record) {
  134. await archivesPatrolWardRemove([record.id]);
  135. createMessage.success('删除成功!');
  136. await reload();
  137. } else {
  138. createConfirm({
  139. content: '你确定要删除?',
  140. iconType: 'warning',
  141. onOk: async () => {
  142. const keys = getSelectRowKeys();
  143. await archivesPatrolWardRemove(keys);
  144. createMessage.success('删除成功!');
  145. await reload();
  146. },
  147. });
  148. }
  149. }
  150. // 表格点击字段排序
  151. function handleSortFn(sortInfo) {
  152. if (sortInfo?.order && sortInfo?.columnKey) {
  153. // 默认单列排序
  154. tableSort.value = [
  155. {
  156. field: sortInfo.columnKey,
  157. direction: sortInfo.order.replace(/(\w+)(end)/g, '$1').toUpperCase(),
  158. },
  159. ];
  160. }
  161. }
  162. // 表格请求之前,对参数进行处理, 添加默认 排序
  163. function handleBeforeFetch(params) {
  164. console.log({ ...params, orders: tableSort.value, patientBasicId: props.info?.id });
  165. return {
  166. ...params,
  167. orders: tableSort.value,
  168. patientBasicId: props.info?.id,
  169. patrolTime: [
  170. formValue.patrolTime[0],
  171. dayjs(formValue.patrolTime[1]).add(1, 'day').format('YYYY-MM-DD'),
  172. ],
  173. content: formValue.content,
  174. };
  175. }
  176. // 弹窗回调事件
  177. async function callSuccess() {
  178. await reload();
  179. }
  180. // 查询回调
  181. async function callForm(data) {
  182. formValue.content = data.content || '';
  183. formValue.patrolTime = data.patrolTime || '';
  184. await reload();
  185. }
  186. </script>
  187. <style lang="less" scoped>
  188. ::v-deep(.ant-btn-link) {
  189. color: rgb(61 65 85 / 100%);
  190. }
  191. ::v-deep(.ant-input) {
  192. border-color: #c2ccd4;
  193. border-radius: 4px;
  194. }
  195. ::v-deep(.ant-input-affix-wrapper) {
  196. border-color: #c2ccd4;
  197. border-radius: 4px;
  198. }
  199. ::v-deep(.ant-picker) {
  200. border-color: #c2ccd4;
  201. border-radius: 4px;
  202. }
  203. ::v-deep(.ant-table-tbody > tr > td) {
  204. border-right: 0 !important;
  205. border-left: 0 !important;
  206. border-bottom: 1px solid #f0f0f0;
  207. }
  208. ::v-deep(.ant-table-wrapper table) {
  209. border: 0;
  210. }
  211. ::v-deep(.ant-table-cell-fix-right-first::after, .ant-table-cell-fix-right-last::after) {
  212. content: '';
  213. top: auto;
  214. width: 0;
  215. }
  216. .btn-add {
  217. width: 120px;
  218. border-radius: 4px;
  219. }
  220. </style>