ModifySiteCode.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <a-modal
  3. v-model:open="visible"
  4. :width="450"
  5. style="top: 10vh"
  6. :confirm-loading="loading"
  7. @ok="confirm"
  8. >
  9. <template #title> 设置扫描点代码 </template>
  10. <a-form
  11. ref="formRef"
  12. :model="formData"
  13. :rules="rules"
  14. :label-col="{ style: { width: '110px' } }"
  15. >
  16. <a-form-item name="scanSite" label="扫描点代码">
  17. <a-input
  18. v-model:value="formData.scanSite"
  19. placeholder="请输入"
  20. ></a-input>
  21. </a-form-item>
  22. </a-form>
  23. </a-modal>
  24. </template>
  25. <script setup lang="ts">
  26. import { reactive, ref, watch } from "vue";
  27. import type { UnwrapRef } from "vue";
  28. import { message } from "ant-design-vue";
  29. import { markSiteCodeSet } from "@/ap/resultExport";
  30. import useLoading from "@/hooks/useLoading";
  31. import useModal from "@/hooks/useModal";
  32. import { objAssign, objModifyAssign } from "@/utils/tool";
  33. import { MarkSiteSetParams } from "@/ap/types/resultExport";
  34. defineOptions({
  35. name: "ModifyMarkSite",
  36. });
  37. /* modal */
  38. const { visible, open, close } = useModal();
  39. defineExpose({ open, close });
  40. const defaultFormData = {
  41. examId: 0,
  42. scanSite: "",
  43. };
  44. const props = defineProps<{
  45. rowData: MarkSiteSetParams;
  46. }>();
  47. const emit = defineEmits(["modified"]);
  48. const formRef = ref();
  49. const formData: UnwrapRef<MarkSiteSetParams> = reactive({
  50. ...defaultFormData,
  51. });
  52. const rules: FormRules<keyof MarkSiteSetParams> = {
  53. scanSite: [
  54. {
  55. required: true,
  56. message: "请输入",
  57. trigger: "change",
  58. },
  59. {
  60. max: 30,
  61. message: "不能超过30字符",
  62. trigger: "change",
  63. },
  64. ],
  65. };
  66. /* confirm */
  67. const { loading, setLoading } = useLoading();
  68. async function confirm() {
  69. const valid = await formRef.value?.validate().catch(() => false);
  70. if (!valid) return;
  71. setLoading(true);
  72. const datas = objAssign(formData, {});
  73. const res = await markSiteCodeSet(datas).catch(() => false);
  74. setLoading(false);
  75. if (!res) return;
  76. message.success("保存成功!");
  77. emit("modified", datas);
  78. close();
  79. }
  80. watch(
  81. () => visible.value,
  82. (val) => {
  83. if (val) {
  84. modalOpenHandle();
  85. }
  86. },
  87. {
  88. immediate: true,
  89. }
  90. );
  91. /* init modal */
  92. function modalOpenHandle() {
  93. objModifyAssign(formData, props.rowData);
  94. }
  95. </script>