index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <script setup lang="tsx">
  2. import { ref } from 'vue';
  3. import { NInputNumber } from 'naive-ui';
  4. import { fetchCountdown, fetchGetConfig, fetchNotice, fetchProtocol } from '@/service/api/film-manage/config';
  5. import { useForm } from '@/components/zt/Form/hooks/useForm';
  6. import type { FormSchema } from '@/components/zt/Form/types/form';
  7. type ActiveTab = 'countdown' | 'protocol' | 'notice';
  8. const activeTab = ref<ActiveTab>('countdown');
  9. const protocol = ref('');
  10. const countForm: FormSchema[] = [
  11. {
  12. label: '选票倒计时',
  13. field: 'countdownVotes',
  14. component: 'NInput',
  15. render({ model, field }) {
  16. return (
  17. <NInputNumber
  18. v-slots={{ suffix: () => '分钟' }}
  19. value={model[field]}
  20. onUpdate:value={val => (model[field] = val)}
  21. min={0}
  22. max={600000}
  23. ></NInputNumber>
  24. );
  25. }
  26. },
  27. {
  28. label: '付款倒计时',
  29. field: 'countdownPay',
  30. component: 'NInput',
  31. render({ model, field }) {
  32. return (
  33. <NInputNumber
  34. v-slots={{ suffix: () => '分钟' }}
  35. value={model[field]}
  36. onUpdate:value={val => (model[field] = val)}
  37. max={10}
  38. min={0}
  39. ></NInputNumber>
  40. );
  41. }
  42. }
  43. ];
  44. const notice = ref();
  45. const submitLoding = ref(false);
  46. const [countdownForm, { getFieldsValue, setFieldsValue }] = useForm({
  47. schemas: countForm,
  48. labelWidth: 120,
  49. layout: 'horizontal',
  50. gridProps: {
  51. cols: '1 xl:4 s:1 l:3',
  52. itemResponsive: true
  53. },
  54. collapsedRows: 1,
  55. showActionButtonGroup: false
  56. });
  57. async function handleChange(value: ActiveTab) {
  58. activeTab.value = value;
  59. }
  60. async function handleSubmit() {
  61. console.log(protocol.value, 'protocol');
  62. submitLoding.value = true;
  63. try {
  64. if (activeTab.value == 'countdown') {
  65. await fetchCountdown({ ...getFieldsValue() });
  66. }
  67. if (activeTab.value == 'protocol') {
  68. await fetchProtocol({ protocol: protocol.value });
  69. }
  70. if (activeTab.value == 'notice') {
  71. await fetchNotice({ notice: notice.value });
  72. }
  73. submitLoding.value = false;
  74. window.$message?.success('保存成功');
  75. } catch {
  76. submitLoding.value = false;
  77. }
  78. }
  79. async function getData() {
  80. const { data, error } = await fetchGetConfig();
  81. console.log(data);
  82. if (!error) {
  83. setFieldsValue({ ...data });
  84. notice.value = data.notice;
  85. protocol.value = data.protocol;
  86. }
  87. }
  88. getData();
  89. </script>
  90. <template>
  91. <div>
  92. <NCard :bordered="false" class="h-full flex-1 card-wrapper bg-white sm:flex-1-hidden dark:bg-dark" size="small">
  93. <NTabs v-model:value="activeTab" size="large" animated @update-value="handleChange">
  94. <NTabPane name="countdown" tab="倒计时" display-directive="show">
  95. <BasicForm @register-form="countdownForm"></BasicForm>
  96. </NTabPane>
  97. <NTabPane name="protocol" tab="退改签协议">
  98. <div class="flex pt50px">
  99. <div class="w120px flex-shrink-0 text-end">改签协议:</div>
  100. <Editor v-model:model-value="protocol"></Editor>
  101. </div>
  102. </NTabPane>
  103. <NTabPane name="notice" tab="购票须知">
  104. <div class="flex">
  105. <div class="w120px flex-shrink-0 text-end">购买须知:</div>
  106. <NInput v-model:value="notice" type="textarea" placeholder="请输入购票须知" />
  107. </div>
  108. </NTabPane>
  109. </NTabs>
  110. <div class="mt40px w-full flex items-center justify-center">
  111. <NButton :loading="submitLoding" type="primary" @click="handleSubmit">
  112. <template #icon>
  113. <SvgIcon icon="ant-design:save-outlined"></SvgIcon>
  114. </template>
  115. 保存
  116. </NButton>
  117. </div>
  118. </NCard>
  119. </div>
  120. </template>
  121. <style lang="scss" scoped></style>