add-dialog.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <simple-form-modal :title="title" :items="formItems" ref="editRef" label-width="110px"
  3. :submit-handler="handleSubmit" @success="handleSuccess">
  4. <template #isbn="{ model }">
  5. <el-input v-model="model.isbn" placeholder="请输入" @blur="() => checkIsbn(model)" />
  6. </template>
  7. </simple-form-modal>
  8. </template>
  9. <script setup>
  10. import { ref, computed } from 'vue';
  11. import { ElMessage } from 'element-plus';
  12. import SimpleFormModal from '@/components/CommonPage/SimpleFormModal.vue';
  13. import request from '@/utils/request';
  14. const emit = defineEmits(['success']);
  15. const editRef = ref(null);
  16. const title = ref('添加图书');
  17. const currentId = ref(null);
  18. const formItems = computed(() => [
  19. {
  20. type: 'isbn', // Custom slot
  21. label: 'ISBN:',
  22. prop: 'isbn',
  23. required: true
  24. },
  25. {
  26. type: 'checkbox',
  27. label: '易投诉平台:',
  28. prop: 'platformList',
  29. required: true,
  30. options: [
  31. { label: '拼多多', value: '拼多多' },
  32. { label: '淘宝', value: '淘宝' },
  33. { label: '小程序', value: '小程序' },
  34. { label: '孔网', value: '孔网' }
  35. ]
  36. },
  37. {
  38. type: 'checkbox',
  39. label: '易投诉原因:',
  40. prop: 'reasonList',
  41. required: true,
  42. options: [
  43. { label: '出版社投诉', value: '出版社投诉' },
  44. { label: '价格投诉', value: '价格投诉' },
  45. { label: '质量投诉', value: '质量投诉' }
  46. ]
  47. }
  48. ]);
  49. const checkIsbn = (model) => {
  50. // Mock check removed or implement real check if needed
  51. };
  52. const handleOpen = (row) => {
  53. if (row) {
  54. title.value = '编辑图书';
  55. currentId.value = row.id;
  56. // Fetch details if needed or use row data
  57. // API doc says /shop/complaintBook/getInfo/{id} for details, but row might have enough info.
  58. // Let's implement getInfo as per requirement.
  59. request.get(`/shop/complaintBook/getInfo/${row.id}`).then(res => {
  60. const data = res.data;
  61. editRef.value?.handleOpen({
  62. id: data.id,
  63. isbn: data.isbn,
  64. platformList: data.platformList || [],
  65. reasonList: data.reasonList || []
  66. });
  67. });
  68. } else {
  69. title.value = '添加图书';
  70. currentId.value = null;
  71. editRef.value?.handleOpen({
  72. isbn: '',
  73. platformList: [],
  74. reasonList: []
  75. });
  76. }
  77. };
  78. const handleSubmit = (model) => {
  79. return request.post('/shop/complaintBook/setComplaintBook', {
  80. id: currentId.value,
  81. isbn: model.isbn,
  82. platformList: model.platformList,
  83. reasonList: model.reasonList
  84. });
  85. };
  86. const handleSuccess = () => {
  87. emit('success');
  88. };
  89. defineExpose({
  90. handleOpen
  91. });
  92. </script>