ReviewReturnDialog.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <a-modal
  3. v-bind="$attrs"
  4. title="打回"
  5. :maskClosable="false"
  6. :footer="false"
  7. :zIndex="6000"
  8. >
  9. <div ref="modalContenBox">
  10. <a-form
  11. autocomplete="off"
  12. :model="reasonOption"
  13. :labelCol="{span: 5}"
  14. @keydown.stop=""
  15. @keypress.stop=""
  16. @finish="onConfirm"
  17. >
  18. <a-form-item label="打回原因" name="reason" required>
  19. <a-select
  20. v-model:value="reasonOption.reason"
  21. placeholder="选择打回原因"
  22. :virtual="false"
  23. :getPopupContainer="() => modalContenBox!"
  24. :options="reasonOptions"
  25. >
  26. </a-select>
  27. </a-form-item>
  28. <a-form-item label="详情描述" name="desc">
  29. <a-textarea
  30. v-model:value="reasonOption.desc"
  31. placeholder="详情描述(限制50字以内)"
  32. :maxlength="50"
  33. ></a-textarea>
  34. </a-form-item>
  35. <a-form-item>
  36. <a-row justify="center">
  37. <a-col>
  38. <a-button type="primary" htmlType="submit">打回</a-button>
  39. </a-col>
  40. <a-col :offset="2">
  41. <a-button type="ghost" @click="onCancel">取消</a-button>
  42. </a-col>
  43. </a-row>
  44. </a-form-item>
  45. </a-form>
  46. </div>
  47. </a-modal>
  48. </template>
  49. <script setup lang="ts">
  50. import { reactive, useAttrs, watch, ref } from "vue";
  51. interface ReturnInfo {
  52. reason?: string;
  53. desc: string;
  54. }
  55. /** select 定位层级较低, 所以在弹窗中使用一个div容器, 将select 组件的 dorpdown 挂载在div中, 避免dropdown被modal挡住 */
  56. const modalContenBox = ref<HTMLElement>();
  57. const emit = defineEmits(["confirmReturn"]);
  58. /** 打回原因元数据 */
  59. const reasonOptions = ["给分较高", "给分较低", "判分错误", "其它"].map((v) => ({
  60. value: v,
  61. }));
  62. /** 初始化表单数据 */
  63. const getInitialFormData = (): ReturnInfo => {
  64. return {
  65. reason: undefined,
  66. desc: "",
  67. };
  68. };
  69. const reasonOption = reactive<ReturnInfo>(getInitialFormData());
  70. watch(
  71. () => modalContenBox,
  72. () => {
  73. console.log(modalContenBox);
  74. }
  75. );
  76. /** 弹窗关闭时 重置form表单数据 */
  77. const attrs = useAttrs();
  78. watch(
  79. () => attrs.visible,
  80. (v) => {
  81. if (!v) {
  82. Object.assign(reasonOption, getInitialFormData());
  83. }
  84. }
  85. );
  86. /** 确定打回 */
  87. const onConfirm = () => {
  88. emit(
  89. "confirmReturn",
  90. Object.values(reasonOption)
  91. .map((s) => s || "")
  92. .join(":")
  93. );
  94. onCancel();
  95. };
  96. /** 取消打回 */
  97. const onCancel = (e?: MouseEvent) => {
  98. (attrs["onUpdate:visible"] as (e: boolean) => void)?.(false);
  99. (attrs.onChange as (e: boolean) => void)?.(false);
  100. (attrs.onCancel as (e?: MouseEvent) => void)?.(e);
  101. };
  102. </script>
  103. <style scoped></style>