FollowUpRecordForm.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <Dialog v-model="dialogVisible" :title="dialogTitle" width="50%">
  3. <el-form
  4. ref="formRef"
  5. v-loading="formLoading"
  6. :model="formData"
  7. :rules="formRules"
  8. label-width="120px"
  9. >
  10. <el-row>
  11. <el-col :span="12">
  12. <el-form-item label="跟进类型" prop="type">
  13. <el-select v-model="formData.type" placeholder="请选择跟进类型">
  14. <el-option
  15. v-for="dict in getIntDictOptions(DICT_TYPE.CRM_FOLLOW_UP_TYPE)"
  16. :key="dict.value"
  17. :label="dict.label"
  18. :value="dict.value"
  19. />
  20. </el-select>
  21. </el-form-item>
  22. </el-col>
  23. <el-col :span="12">
  24. <el-form-item label="下次联系时间" prop="nextTime">
  25. <el-date-picker
  26. v-model="formData.nextTime"
  27. placeholder="选择下次联系时间"
  28. type="date"
  29. value-format="x"
  30. />
  31. </el-form-item>
  32. </el-col>
  33. <el-col :span="24">
  34. <el-form-item label="跟进内容" prop="content">
  35. <Editor v-model="formData.content" height="300px" />
  36. </el-form-item>
  37. </el-col>
  38. <el-col :span="24">
  39. <el-form-item label="关联联系人" prop="contactIds">
  40. <el-button @click="submitForm">
  41. <Icon class="mr-5px" icon="ep:plus" />
  42. 选择添加联系人
  43. </el-button>
  44. <contact-list v-model:contactIds="formData.contactIds" />
  45. </el-form-item>
  46. </el-col>
  47. <el-col :span="24">
  48. <el-form-item label="关联商机" prop="businessIds">
  49. <el-button @click="submitForm">
  50. <Icon class="mr-5px" icon="ep:plus" />
  51. 选择添加商机
  52. </el-button>
  53. <business-list v-model:businessIds="formData.businessIds" />
  54. </el-form-item>
  55. </el-col>
  56. </el-row>
  57. </el-form>
  58. <template #footer>
  59. <el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
  60. <el-button @click="dialogVisible = false">取 消</el-button>
  61. </template>
  62. </Dialog>
  63. </template>
  64. <script lang="ts" setup>
  65. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  66. import { FollowUpRecordApi, FollowUpRecordVO } from '@/api/crm/followup'
  67. import { BusinessList, ContactList } from './components'
  68. /** 跟进记录 表单 */
  69. defineOptions({ name: 'FollowUpRecordForm' })
  70. const { t } = useI18n() // 国际化
  71. const message = useMessage() // 消息弹窗
  72. const dialogVisible = ref(false) // 弹窗的是否展示
  73. const dialogTitle = ref('') // 弹窗的标题
  74. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  75. const formType = ref('') // 表单的类型:create - 新增;update - 修改
  76. const formData = ref<FollowUpRecordVO>({} as FollowUpRecordVO)
  77. const formRules = reactive({
  78. type: [{ required: true, message: '跟进类型不能为空', trigger: 'change' }],
  79. content: [{ required: true, message: '跟进内容不能为空', trigger: 'blur' }],
  80. nextTime: [{ required: true, message: '下次联系时间不能为空', trigger: 'blur' }]
  81. })
  82. const formRef = ref() // 表单 Ref
  83. /** 打开弹窗 */
  84. const open = async (bizType: number, bizId: number, type: string, id?: number) => {
  85. dialogVisible.value = true
  86. dialogTitle.value = t('action.' + type)
  87. formType.value = type
  88. resetForm()
  89. formData.value.bizType = bizType
  90. formData.value.bizId = bizId
  91. // 修改时,设置数据
  92. if (id) {
  93. formLoading.value = true
  94. try {
  95. formData.value = await FollowUpRecordApi.getFollowUpRecord(id)
  96. } finally {
  97. formLoading.value = false
  98. }
  99. }
  100. }
  101. defineExpose({ open }) // 提供 open 方法,用于打开弹窗
  102. /** 提交表单 */
  103. const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
  104. const submitForm = async () => {
  105. // 校验表单
  106. await formRef.value.validate()
  107. // 提交请求
  108. formLoading.value = true
  109. try {
  110. const data = formData.value as unknown as FollowUpRecordVO
  111. if (formType.value === 'create') {
  112. await FollowUpRecordApi.createFollowUpRecord(data)
  113. message.success(t('common.createSuccess'))
  114. } else {
  115. await FollowUpRecordApi.updateFollowUpRecord(data)
  116. message.success(t('common.updateSuccess'))
  117. }
  118. dialogVisible.value = false
  119. // 发送操作成功的事件
  120. emit('success')
  121. } finally {
  122. formLoading.value = false
  123. }
  124. }
  125. /** 重置表单 */
  126. const resetForm = () => {
  127. formRef.value?.resetFields()
  128. formData.value = {} as FollowUpRecordVO
  129. }
  130. </script>