changeTextBook.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <script setup lang="ts">
  2. import { useModalInner } from '/@/components/Modal';
  3. import { useTable } from '/@/components/Table';
  4. import BasicModal from '/@/components/Modal/src/BasicModal.vue';
  5. import { changeColumns, textbookColumns } from './data.config';
  6. import { reactive, ref } from 'vue';
  7. import BasicTable from '/@/components/Table/src/BasicTable.vue';
  8. import { Modal } from 'ant-design-vue';
  9. import { getTextbookPage } from '/@/services/apis/TextbookController';
  10. import { getDataOption } from '/@/api/system/dic';
  11. import { putWfTextbookSubscriptionAlteration } from '/@/services/apis/WfTextbookSubscriptionController';
  12. import { useMessage } from '/@/hooks/web/useMessage';
  13. const emits = defineEmits(['success', 'register']);
  14. const dataSource = ref<any>([]);
  15. const visible = ref(false);
  16. const changeType = ref(0);
  17. const changeId = ref<string>('');
  18. const rawValue = reactive({
  19. studentSubscriptionNumber: 0,
  20. teacherSubscriptionNumber: 0,
  21. });
  22. const [register, { closeModal, setModalProps }] = useModalInner((data) => {
  23. changeId.value = data.id;
  24. dataSource.value = [data];
  25. rawValue.studentSubscriptionNumber = data.studentSubscriptionNumber;
  26. rawValue.teacherSubscriptionNumber = data.teacherSubscriptionNumber;
  27. });
  28. const [selectTableRef, { getSelectRows, clearSelectedRowKeys }] = useTable({
  29. title: '可选课程信息',
  30. bordered: true,
  31. columns: textbookColumns.slice(0, -5),
  32. api: getTextbookPage,
  33. useSearchForm: true,
  34. showTableSetting: true,
  35. resizeHeightOffset: 200,
  36. rowSelection: {
  37. type: 'radio',
  38. },
  39. formConfig: {
  40. labelWidth: 120,
  41. schemas: [
  42. {
  43. field: 'textbookType',
  44. label: '教材类型',
  45. component: 'ApiSelect',
  46. componentProps: {
  47. api: getDataOption,
  48. params: {
  49. code: 'textbook_type',
  50. },
  51. },
  52. colProps: {
  53. span: 12,
  54. },
  55. },
  56. {
  57. field: 'bookName',
  58. label: '教材名称',
  59. component: 'Input',
  60. colProps: {
  61. span: 12,
  62. },
  63. },
  64. ],
  65. },
  66. beforeFetch: (params) => {
  67. return {
  68. ...params,
  69. };
  70. },
  71. });
  72. const { createMessage } = useMessage();
  73. const handleSubmit = () => {
  74. dataSource.value = getSelectRows();
  75. changeType.value = 2;
  76. handleCancel();
  77. };
  78. const handleCancel = () => {
  79. visible.value = false;
  80. clearSelectedRowKeys();
  81. };
  82. const handleEdit = async () => {
  83. if (changeType.value === 0) {
  84. return createMessage.warning('您未进行任何变更,请选择变更课程或者变更征订数量后提交');
  85. }
  86. const value = dataSource.value[0];
  87. if (changeType.value === 1) {
  88. if (
  89. rawValue.studentSubscriptionNumber === value.studentSubscriptionNumber &&
  90. rawValue.teacherSubscriptionNumber === value.teacherSubscriptionNumber
  91. ) {
  92. return createMessage.warning('您未进行任何变更,请选择变更课程或者变更征订数量后提交');
  93. }
  94. }
  95. if (changeType.value === 2) {
  96. value.courseSubjectId = value.id;
  97. }
  98. value.id = changeId.value;
  99. value.alterationType = changeType.value;
  100. try {
  101. setModalProps({
  102. confirmLoading: true,
  103. });
  104. await putWfTextbookSubscriptionAlteration(value, 'none');
  105. createMessage.success('变更成功');
  106. emits('success');
  107. changeType.value = 0;
  108. closeModal();
  109. } catch (e) {
  110. console.log(e);
  111. createMessage.error('变更失败');
  112. } finally {
  113. setModalProps({
  114. confirmLoading: false,
  115. });
  116. }
  117. };
  118. </script>
  119. <template>
  120. <BasicModal
  121. defaultFullscreen
  122. @ok="handleEdit"
  123. v-bind="$attrs"
  124. @register="register"
  125. width="1200px"
  126. title="变更"
  127. >
  128. <a-button type="primary" @click="visible = true">选择变更课程</a-button>
  129. <BasicTable
  130. :bordered="true"
  131. :pagination="false"
  132. :data-source="dataSource"
  133. :columns="changeColumns"
  134. >
  135. <template #studentSubscriptionNumber="{ record }">
  136. <a-input-number
  137. :default-value="0"
  138. @change="changeType !== 2 ? (changeType = 1) : null"
  139. :step="1"
  140. :min="0"
  141. placeholder="请输入"
  142. v-model:value="record.studentSubscriptionNumber"
  143. />
  144. </template>
  145. <template #teacherSubscriptionNumber="{ record }">
  146. <a-input-number
  147. :default-value="0"
  148. @change="changeType !== 2 ? (changeType = 1) : null"
  149. :step="1"
  150. :min="0"
  151. placeholder="请输入"
  152. v-model:value="record.teacherSubscriptionNumber"
  153. />
  154. </template>
  155. </BasicTable>
  156. </BasicModal>
  157. <Modal
  158. @cancel="handleCancel"
  159. @ok="handleSubmit"
  160. width="1000px"
  161. v-model:visible="visible"
  162. title="选择变更课程"
  163. >
  164. <BasicTable @register="selectTableRef" title="课程列表" />
  165. </Modal>
  166. </template>
  167. <style scoped lang="less"></style>