publishcourses.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <div class="p-8px bg-white">
  3. <div class="px-4">
  4. <BasicForm @register="registerForm">
  5. <template #title1>
  6. <TypographyTitle :level="4">基础信息</TypographyTitle>
  7. <Divider></Divider>
  8. </template>
  9. <template #title2>
  10. <TypographyTitle :level="4">价格、限购、正常课表</TypographyTitle>
  11. <Divider></Divider>
  12. </template>
  13. <template #ZtCustomTable1="{ model, field }">
  14. <ZtCustomTable
  15. :tableColumn="publishcoursesColums"
  16. v-model:value="model[field]"
  17. show-index
  18. :show-action="Number(route.query.type) == 0"
  19. ></ZtCustomTable>
  20. </template>
  21. <template #title3>
  22. <TypographyTitle :level="4">课程介绍</TypographyTitle>
  23. <Divider></Divider>
  24. </template>
  25. <template #VideoUpload="{ model, field }">
  26. <uploadVideo v-model:model-value="model[field]"></uploadVideo>
  27. <span class="text-gray">单个视频;时长10s ~ 5分钟以内;宽高比为5:4。单个文件不超过100M;</span>
  28. </template>
  29. <template #formFooter>
  30. <div class="w-full flex items-center justify-center my-3" v-if="Number(route.query.type) != 1">
  31. <a-button type="primary" @click="save" class="mr-2" :loading="isSubmit"> 保存 </a-button>
  32. <a-button type="error" @click="back" class="mr-2"> 关闭 </a-button>
  33. </div>
  34. </template>
  35. </BasicForm>
  36. <div class="h-20px"></div>
  37. </div>
  38. </div>
  39. </template>
  40. <script lang="ts" setup name="business-management-publishcourses">
  41. import uploadVideo from '@/components/uploadVideo/index.vue';
  42. import { TypographyTitle, Divider } from 'ant-design-vue';
  43. import { BasicForm, useForm } from '/@/components/Form/index';
  44. import ZtCustomTable from '/@/components/ZtCustomTable/index.vue';
  45. import { formSchema, publishcoursesColums } from './courses.data';
  46. import dayjs from 'dayjs';
  47. import { useTabs } from '/@/hooks/web/useTabs';
  48. import { saveOrUpdate, getDetaile } from './courses.api';
  49. import { ref } from 'vue';
  50. import { useRoute } from 'vue-router';
  51. import { nextTick } from 'vue';
  52. import { useShopInfoStore } from '/@/store/modules/shopInfo';
  53. useShopInfoStore().getCurrentDep();
  54. const { close: closeTab } = useTabs();
  55. const route = useRoute();
  56. const [registerForm, { setProps, resetFields, setFieldsValue, updateSchema, validate, clearValidate, getFieldsValue }] = useForm({
  57. schemas: formSchema,
  58. showActionButtonGroup: false,
  59. labelCol: { span: 4 },
  60. });
  61. const viewDataSport = ref<any>({});
  62. const customTableData = ref({});
  63. async function isView() {
  64. if (Number(route.query.type) != 0) {
  65. await getDataList();
  66. nextTick(async () => {
  67. setProps({
  68. disabled: Number(route.query.type) == 1,
  69. });
  70. await setFieldsValue({
  71. ...viewDataSport.value,
  72. categoryId: viewDataSport.value.categoryId.split(','),
  73. priceRulesList: customTableData.value,
  74. });
  75. });
  76. }
  77. }
  78. isView();
  79. async function getDataList() {
  80. const res = await getDetaile({ id: route.query.id });
  81. // viewDataSportList.value = res;\
  82. customTableData.value = res.priceRulesList.map((it) => {
  83. return {
  84. name: it.name,
  85. time: [it.startTime, it.endTime],
  86. id: dayjs().valueOf(),
  87. };
  88. });
  89. viewDataSport.value = res.courses;
  90. }
  91. const isSubmit = ref(false);
  92. async function back() {
  93. await closeTab();
  94. }
  95. async function save() {
  96. await validate();
  97. const form = await getFieldsValue();
  98. isSubmit.value = true;
  99. const newObj = {
  100. courses: { ...form, priceRulesList: null },
  101. priceRulesList: transformData(form.priceRulesList),
  102. };
  103. try {
  104. await saveOrUpdate(newObj, Number(route.query.type) != 0);
  105. isSubmit.value = false;
  106. back();
  107. } catch (error) {
  108. console.log(error);
  109. isSubmit.value = false;
  110. }
  111. }
  112. function transformData(data) {
  113. return data.map((it) => {
  114. return {
  115. startTime: dayjs(it.editValueRefs.time[0]).format('YYYY-MM-DD hh:mm:ss'),
  116. endTime: dayjs(it.editValueRefs.time[1]).format('YYYY-MM-DD hh:mm:ss'),
  117. name: it.editValueRefs.name.value,
  118. };
  119. });
  120. }
  121. </script>