DsionStep2.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <div class="dsion-step2">
  3. <BasicTable @register="registerTable" :searchInfo="searchInfo">
  4. <template #toolbar>
  5. <a-button type="primary" @click="handelImport" :disabled="status === 1">导入</a-button>
  6. <a-button type="primary" @click="handelAdd" :disabled="status === 1">添加</a-button>
  7. </template>
  8. <template #action="{ record }">
  9. <TableAction :actions="createActions(record)" />
  10. </template>
  11. </BasicTable>
  12. <FormImport @register="registerImportModal" @success="handleSuccess" />
  13. </div>
  14. </template>
  15. <script setup lang="ts">
  16. import { reactive, ref, watch } from 'vue';
  17. import {
  18. BasicTable,
  19. useTable,
  20. TableAction,
  21. EditRecordRow,
  22. ActionItem,
  23. } from '/@/components/Table';
  24. import { table2Columns } from '../data.config';
  25. import { useMessage } from '/@/hooks/web/useMessage';
  26. import { buildUUID } from '/@/utils/uuid';
  27. import FormImport from './import.vue';
  28. import { useModal } from '/@/components/Modal';
  29. import {
  30. deleteBandingBandingTaskClass,
  31. getBandingTaskClassList,
  32. postBandingBandingTaskClass,
  33. putBandingBandingTaskClass,
  34. } from '/@/services/apis/BandingTaskClassController';
  35. import { cloneDeep } from 'lodash-es';
  36. const [registerImportModal, { openModal: openImportModal }] = useModal();
  37. const [registerTable, { reload, insertTableDataRecord, deleteTableDataRecord, getDataSource }] =
  38. useTable({
  39. api: getBandingTaskClassList,
  40. title: '班级列表',
  41. rowKey: 'id',
  42. columns: table2Columns,
  43. useSearchForm: false,
  44. showTableSetting: true,
  45. bordered: true,
  46. immediate: false,
  47. canResize: true,
  48. pagination: false,
  49. actionColumn: {
  50. width: 120,
  51. title: '操作',
  52. dataIndex: 'action',
  53. slots: { customRender: 'action' },
  54. fixed: 'right',
  55. },
  56. });
  57. const searchInfo = reactive<Recordable>({});
  58. const props = defineProps({
  59. taskId: { type: String, default: '' },
  60. status: { type: Number, default: 0 },
  61. });
  62. watch(
  63. () => props.taskId,
  64. async (newVal) => {
  65. if (newVal) {
  66. searchInfo.bandingTaskId = newVal;
  67. }
  68. },
  69. );
  70. const currentEditKeyRef = ref('');
  71. const { createMessage } = useMessage();
  72. const handelAdd = () => {
  73. insertTableDataRecord({ id: buildUUID(), _newRow: true });
  74. };
  75. const handleEdit = async (record: EditRecordRow) => {
  76. currentEditKeyRef.value = record.id;
  77. await record.onEdit?.(true);
  78. };
  79. const handleCancel = (record: EditRecordRow) => {
  80. currentEditKeyRef.value = '';
  81. record.onEdit?.(false, false);
  82. };
  83. const handleDelete = async (record: EditRecordRow) => {
  84. if (record._newRow) {
  85. deleteTableDataRecord(record.id);
  86. } else {
  87. await deleteBandingBandingTaskClass([record.id]);
  88. }
  89. };
  90. const handleSave = async (record: EditRecordRow) => {
  91. const valid = await record.onValid?.();
  92. if (valid) {
  93. const data = cloneDeep(record.editValueRefs);
  94. data['isOrderClass'] = data['isOrderClass'] ? 1 : 0;
  95. if (record._newRow) {
  96. await postBandingBandingTaskClass({
  97. ...data,
  98. bandingTaskId: props.taskId,
  99. } as API.AddBandingTaskClassDto);
  100. } else {
  101. const _dataSource = getDataSource();
  102. const editData = _dataSource.filter((row) => row.id === record.id)[0];
  103. Object.assign(editData, data);
  104. await putBandingBandingTaskClass(editData as API.UpdateBandingTaskClassDto);
  105. }
  106. await record.onEdit?.(false, true);
  107. currentEditKeyRef.value = '';
  108. reload();
  109. } else {
  110. createMessage.error({ content: '请填写正确的数据', key: 'saving' });
  111. }
  112. };
  113. const createActions = (record: EditRecordRow): ActionItem[] => {
  114. if (!record.editable) {
  115. return [
  116. {
  117. label: '编辑',
  118. disabled: currentEditKeyRef.value ? currentEditKeyRef.value !== record.id : false,
  119. onClick: handleEdit.bind(null, record),
  120. },
  121. {
  122. label: '删除',
  123. popConfirm: {
  124. title: '是否删除',
  125. confirm: handleDelete.bind(null, record),
  126. },
  127. },
  128. ];
  129. }
  130. return [
  131. {
  132. label: '确定',
  133. onClick: handleSave.bind(null, record),
  134. },
  135. {
  136. label: '取消',
  137. popConfirm: {
  138. title: '是否取消编辑',
  139. confirm: handleCancel.bind(null, record),
  140. },
  141. },
  142. ];
  143. };
  144. const handelImport = () => {
  145. openImportModal(true, { baseData: { taskId: props.taskId } });
  146. };
  147. const handleSuccess = () => {
  148. reload();
  149. };
  150. const validateStep = () => {
  151. return true;
  152. };
  153. const reloadStep = () => {
  154. reload();
  155. };
  156. defineExpose({ validateStep, reloadStep });
  157. </script>
  158. <style lang="less" scoped>
  159. .dsion-step2 {
  160. margin: 16px 0;
  161. }
  162. </style>