index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <div class="p-8px bg-white">
  3. <div class="px-4">
  4. <BasicForm @register="registerForm">
  5. <template #title1>
  6. <div class="flex">
  7. <TypographyTitle :level="4">开放时间</TypographyTitle>
  8. <a-button type="link" @click="handleClick" v-if="getIsMerchant"> 查看教学日与非教学日日历 </a-button>
  9. </div>
  10. <Divider></Divider>
  11. </template>
  12. <template #title2>
  13. <TypographyTitle :level="4">封面、配套保险、使用须知</TypographyTitle>
  14. <Divider></Divider>
  15. </template>
  16. <template #title3 v-if="siteId">
  17. <TypographyTitle :level="4">场地二维码</TypographyTitle>
  18. <Divider></Divider>
  19. <div class="p-20px flex">
  20. <div>
  21. <QRCode :value="`https://api.qlapp.cn/schoolOrder/?placeId=${siteId}`" ref="qrcodeCanvasRef" />
  22. <a-button type="link" block class="mt20px" @click="downloadImage">下载图片</a-button>
  23. </div>
  24. </div>
  25. </template>
  26. <template #tenant="{ model, field }">
  27. <ApiSelect
  28. :api="Business"
  29. labelField="name"
  30. valueField="tenantId"
  31. :params="{
  32. orgCode: userInfo?.orgCode,
  33. type: 0,
  34. }"
  35. v-model:value="model[field]"
  36. @change="handleOption"
  37. ></ApiSelect>
  38. </template>
  39. <template #ZtCustomTable1="{ model, field }">
  40. <ZtCustomTable :tableColumn="ScheduleArrangementColums" :showAction="getIsMerchant" v-model:value="model[field]" :count="3"></ZtCustomTable>
  41. </template>
  42. <template #ZtCustomTable2="{ model, field }">
  43. <ZtCustomTable :tableColumn="ScheduleArrangementColums" :showAction="getIsMerchant" v-model:value="model[field]" :count="1"></ZtCustomTable>
  44. </template>
  45. <template #formFooter>
  46. <div style="margin: 0 auto" v-if="getIsMerchant">
  47. <a-button type="primary" @click="save" class="mr-2" :loading="isSubmit"> 保存</a-button>
  48. <a-button type="error" @click="back" class="mr-2"> 关闭</a-button>
  49. </div>
  50. </template>
  51. </BasicForm>
  52. <div class="h-20px"></div>
  53. </div>
  54. </div>
  55. </template>
  56. <script lang="ts" setup name="business-management-schoolOpen">
  57. import { TypographyTitle, Divider, QRCode, message } from 'ant-design-vue';
  58. import { BasicForm, useForm, ApiSelect } from '/@/components/Form/index';
  59. import ZtCustomTable from '/@/components/ZtCustomTable/index.vue';
  60. import { Business } from '../gymnasiumBag/gymnasiumBag.api';
  61. import { useUserStore } from '/@/store/modules/user';
  62. import { formSchema, ScheduleArrangementColums } from './schoolOpen.data';
  63. import { getDetails, saveOrUpdate } from './schoolOpen.api';
  64. import { ref, unref } from 'vue';
  65. import { useRouter } from 'vue-router';
  66. import { storeToRefs } from 'pinia';
  67. import { areAllItemsAllFieldsFilled } from '@/utils';
  68. const { userInfo, getIsMerchant } = storeToRefs(useUserStore());
  69. const router = useRouter();
  70. const [registerForm, { setProps, resetFields, setFieldsValue, updateSchema, validate, clearValidate, getFieldsValue }] = useForm({
  71. schemas: formSchema,
  72. showActionButtonGroup: false,
  73. });
  74. const isSubmit = ref(false);
  75. function back() {
  76. router.back();
  77. }
  78. async function save() {
  79. await validate();
  80. isSubmit.value = true;
  81. const form = await getFieldsValue();
  82. console.log(form.noTeachingDay, 'form', form.teachingDay);
  83. const newNoTeachingDay = form.noTeachingDay.map((it) => {
  84. return {
  85. ticketNum: it.editValueRefs.ticketNum ? unref(it.editValueRefs.ticketNum) : null,
  86. startTime: it.editValueRefs.time ? unref(it.editValueRefs.time)[0] : null,
  87. endTime: it.editValueRefs.time ? unref(it.editValueRefs.time)[1] : null,
  88. };
  89. });
  90. const newTeachingDay = form.teachingDay.map((it) => {
  91. return {
  92. ticketNum: it.editValueRefs.ticketNum ? unref(it.editValueRefs.ticketNum) : null,
  93. startTime: it.editValueRefs.time ? unref(it.editValueRefs.time)[0] : null,
  94. endTime: it.editValueRefs.time ? unref(it.editValueRefs.time)[1] : null,
  95. };
  96. });
  97. if (!areAllItemsAllFieldsFilled(newTeachingDay)) {
  98. isSubmit.value = false;
  99. return message.error('请填写完整的教学日信息');
  100. }
  101. if (!areAllItemsAllFieldsFilled(newNoTeachingDay)) {
  102. isSubmit.value = false;
  103. return message.error('请填写完整的非教学日信息');
  104. }
  105. const newObj = {
  106. ...form,
  107. noTeachingDay: JSON.stringify({
  108. data: newNoTeachingDay,
  109. }),
  110. teachingDay: JSON.stringify({
  111. data: newTeachingDay,
  112. }),
  113. };
  114. console.log(newObj, 'newObj');
  115. try {
  116. await saveOrUpdate(newObj);
  117. isSubmit.value = false;
  118. getData();
  119. } catch (error) {
  120. console.log(error);
  121. isSubmit.value = false;
  122. }
  123. console.log(newObj);
  124. }
  125. const qrcodeCanvasRef = ref();
  126. async function downloadImage() {
  127. const url = await qrcodeCanvasRef.value.toDataURL();
  128. const a = document.createElement('a');
  129. a.download = 'competition.png';
  130. a.href = url;
  131. document.body.appendChild(a);
  132. a.click();
  133. document.body.removeChild(a);
  134. }
  135. async function getData() {
  136. const res = await getDetails({ orgCode: useUserStore().userInfo?.orgCode });
  137. if (!res.teachingDay) return;
  138. handleCommonSet(res);
  139. console.log(JSON.parse(res.noTeachingDay));
  140. }
  141. getData();
  142. function handleClick() {
  143. router.push({ path: '/informationManagement/teachorNoteach' });
  144. }
  145. async function handleOption(options) {
  146. const res = await Business({ orgCode: useUserStore().userInfo?.orgCode, type: 0 });
  147. const orgCode = res.find((it) => it.tenantId == options).orgCode;
  148. if (orgCode) {
  149. const res = await getDetails({ orgCode: orgCode });
  150. if (!res.noTeachingDay) return;
  151. handleCommonSet(res);
  152. }
  153. }
  154. const siteId = ref();
  155. function handleCommonSet(res) {
  156. // console.log( res,'获取数据')
  157. siteId.value = res.siteId;
  158. console.log(`https://api.qlapp.cn/school/?placeId=${siteId.value}`, '获取到的siteid');
  159. setFieldsValue({
  160. ...res,
  161. insureIds: res.insureIds ? res.insureIds.split(',') : '',
  162. noTeachingDay: res.noTeachingDay
  163. ? JSON.parse(res.noTeachingDay).data.map((it) => {
  164. return { ...it, time: [it.startTime, it.endTime] };
  165. })
  166. : [],
  167. teachingDay: JSON.parse(res.teachingDay).data.map((it) => {
  168. return { ...it, time: [it.startTime, it.endTime] };
  169. }),
  170. });
  171. }
  172. </script>