DsionStep1.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <div class="dsion-step1">
  3. <div style="padding: 24px" class="flex">
  4. <div class="ml-4">
  5. <div class="flex mt-8">
  6. <Checkbox.Group v-model:value="state.checkboxItem" :options="state.checkedOptions" />
  7. </div>
  8. <div class="flex mt-2">
  9. <Radio.Group v-model:value="state.radioItem" :options="state.radioOptions" />
  10. </div>
  11. </div>
  12. </div>
  13. </div>
  14. </template>
  15. <script setup lang="ts">
  16. import { Checkbox, Radio, CheckboxOptionType } from 'ant-design-vue';
  17. import { CheckboxValueType } from 'ant-design-vue/lib/checkbox/interface';
  18. import { onMounted, reactive, watch } from 'vue';
  19. import {
  20. getBandingTaskRuleList,
  21. postBandingTaskSetRule,
  22. } from '/@/services/apis/BandingTaskController';
  23. const props = defineProps({
  24. taskId: { type: String, default: '' },
  25. });
  26. const state = reactive<{
  27. gradeId: String;
  28. enrollType: String;
  29. checkboxItem: CheckboxValueType[];
  30. radioItem: CheckboxValueType;
  31. checkedOptions: CheckboxOptionType[];
  32. radioOptions: CheckboxOptionType[];
  33. }>({
  34. gradeId: '',
  35. enrollType: '',
  36. checkboxItem: [],
  37. radioItem: '',
  38. checkedOptions: [],
  39. radioOptions: [],
  40. });
  41. watch(
  42. () => props.taskId,
  43. async (newVal) => {
  44. if (newVal) {
  45. await getRule(newVal);
  46. }
  47. },
  48. );
  49. const getRule = async (taskId) => {
  50. const data = await getBandingTaskRuleList({ id: taskId });
  51. const checkboxItem: CheckboxValueType[] = [];
  52. let radioItem = '';
  53. state.checkedOptions = data
  54. .filter((item: any) => item.chooseType === 'multi')
  55. .map((item: any) => {
  56. if (item.isSelected === 1) {
  57. checkboxItem.push(item.id);
  58. }
  59. return { value: item.id, label: item.name };
  60. });
  61. state.radioOptions = data
  62. .filter((item: any) => item.chooseType === 'radio')
  63. .map((item: any) => {
  64. if (item.isSelected === 1) {
  65. radioItem = item.id;
  66. }
  67. return { value: item.id, label: item.name };
  68. });
  69. state.checkboxItem = checkboxItem;
  70. state.radioItem = radioItem;
  71. };
  72. const validateStep = async () => {
  73. try {
  74. const bandingRuleIds = [...state.checkboxItem];
  75. if (state.radioItem) {
  76. bandingRuleIds.push(state.radioItem);
  77. }
  78. await postBandingTaskSetRule({ bandingRuleIds: bandingRuleIds, bandingTaskId: props.taskId });
  79. return true;
  80. } catch {
  81. return false;
  82. }
  83. };
  84. onMounted(async () => {});
  85. defineExpose({ validateStep });
  86. </script>
  87. <style lang="less" scoped>
  88. .dsion-step1 {
  89. margin: 24px auto;
  90. background-color: @component-background;
  91. border-radius: 16px;
  92. width: 1000px;
  93. }
  94. :deep(.ant-checkbox-wrapper) {
  95. display: flex !important;
  96. margin-bottom: 4px;
  97. }
  98. :deep(.ant-radio-wrapper) {
  99. display: flex !important;
  100. margin-bottom: 4px;
  101. }
  102. </style>