cost.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <BasicModal
  3. @ok="handleSubmit"
  4. :destroyOnClose="true"
  5. :maskClosable="false"
  6. v-bind="$attrs"
  7. @register="registerModal"
  8. :title="getTitle"
  9. :width="1002"
  10. showFooter
  11. >
  12. <BasicForm @register="registerForm" />
  13. </BasicModal>
  14. </template>
  15. <script setup lang="ts">
  16. import { ref, computed, unref, reactive } from 'vue';
  17. import { BasicModal, useModalInner } from '/@/components/Modal';
  18. import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
  19. import {
  20. getClassTimeStatisticsSetLastInfo,
  21. postClasstimeClassTimeStatisticsSet,
  22. putClasstimeClassTimeStatisticsSet,
  23. } from '/@/services/apis/ClassTimeStatisticsSetController';
  24. const isUpdate = ref(true);
  25. const category = ref(2);
  26. const modelRef = ref<Recordable>({});
  27. const emit = defineEmits(['success', 'register']);
  28. const formConfig = reactive<Recordable[]>([
  29. { label: '早自习课时单价:正式聘用', field: 'cost1', addonAfter: '元', value: '' },
  30. { label: '非正式聘用', field: 'cost2', addonAfter: '元', value: '' },
  31. { label: '正课课时单价:正式聘用', field: 'cost3', addonAfter: '元', value: '' },
  32. { label: '非正式聘用', field: 'cost4', addonAfter: '元', value: '' },
  33. { label: '晚自习课时单价:正式聘用', field: 'cost5', addonAfter: '元', value: '' },
  34. { label: '非正式聘用', field: 'cost6', addonAfter: '元', value: '' },
  35. { label: ' 超出课时单价:正式聘用', field: 'cost7', addonAfter: '元', value: '' },
  36. { label: '非正式聘用', field: 'cost8', addonAfter: '元', value: '' },
  37. { label: '超出课时标准(每周):正式聘用', field: 'cost9', addonAfter: '课时', value: '' },
  38. { label: '非正式聘用', field: 'cost10', addonAfter: '课时', value: '' },
  39. { label: '顶课课时单价:正式聘用', field: 'cost11', addonAfter: '元', value: '' },
  40. { label: '非正式聘用', field: 'cost12', addonAfter: '元', value: '' },
  41. ]);
  42. const [registerForm, { validate, resetFields, resetSchema, setFieldsValue }] = useForm({
  43. labelWidth: 240,
  44. schemas: [],
  45. showActionButtonGroup: false,
  46. });
  47. const [registerModal, { closeModal, setModalProps }] = useModalInner(async () => {
  48. resetFields();
  49. setModalProps({ confirmLoading: false });
  50. isUpdate.value = false;
  51. const formWeightSchema: FormSchema[] = [];
  52. formConfig.forEach((item) => {
  53. formWeightSchema.push({
  54. label: item.label,
  55. field: item.field,
  56. component: 'InputNumber',
  57. colProps: { span: 12 },
  58. required: true,
  59. componentProps: {
  60. addonAfter: item.addonAfter,
  61. style: { width: '100%' },
  62. },
  63. });
  64. });
  65. resetSchema(formWeightSchema);
  66. const resData = await getClassTimeStatisticsSetLastInfo({ category: category.value });
  67. if (resData) {
  68. modelRef.value = { ...resData };
  69. const jsonContent = JSON.parse(resData.jsonContent);
  70. const values: Recordable = {};
  71. jsonContent.forEach((item) => {
  72. values[item.field] = item.value;
  73. });
  74. setFieldsValue(values);
  75. isUpdate.value = true;
  76. }
  77. });
  78. const getTitle = computed(() => (!unref(isUpdate) ? '费用设置' : '费用设置'));
  79. const handleSubmit = async () => {
  80. try {
  81. const values = await validate();
  82. const jsonContent: Recordable[] = [];
  83. setModalProps({ confirmLoading: true });
  84. formConfig.forEach((item) => {
  85. jsonContent.push({ label: item.label, field: item.field, value: values[item.field] });
  86. });
  87. const postParams: Recordable = {
  88. category: category.value,
  89. jsonContent: JSON.stringify(jsonContent),
  90. id: unref(modelRef)?.id,
  91. };
  92. if (unref(isUpdate)) {
  93. await putClasstimeClassTimeStatisticsSet(postParams as API.UpdateClassTimeStatisticsSetDto);
  94. } else {
  95. await postClasstimeClassTimeStatisticsSet(postParams as API.AddClassTimeStatisticsSetDto);
  96. }
  97. closeModal();
  98. emit('success');
  99. } finally {
  100. setModalProps({ confirmLoading: false });
  101. }
  102. };
  103. </script>
  104. <style scoped lang="less"></style>