index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <ContentWrap>
  3. <el-form
  4. ref="formRef"
  5. :model="formData"
  6. :rules="formRules"
  7. label-width="160px"
  8. v-loading="formLoading"
  9. >
  10. <el-card shadow="never">
  11. <!-- 操作 -->
  12. <template #header>
  13. <div class="flex items-center justify-between">
  14. <CardTitle title="合同配置设置" />
  15. <el-button type="primary" @click="onSubmit" v-hasPermi="['crm:contract-config:update']">
  16. 保存
  17. </el-button>
  18. </div>
  19. </template>
  20. <!-- 表单 -->
  21. <el-form-item label="提前提醒设置" prop="notifyEnabled">
  22. <el-radio-group
  23. v-model="formData.notifyEnabled"
  24. @change="changeNotifyEnable"
  25. class="ml-4"
  26. >
  27. <el-radio :label="false" size="large">不提醒</el-radio>
  28. <el-radio :label="true" size="large">提醒</el-radio>
  29. </el-radio-group>
  30. </el-form-item>
  31. <div v-if="formData.notifyEnabled">
  32. <el-form-item>
  33. 提前 <el-input-number class="mx-2" v-model="formData.notifyDays" /> 天提醒
  34. </el-form-item>
  35. </div>
  36. </el-card>
  37. </el-form>
  38. </ContentWrap>
  39. </template>
  40. <script setup lang="ts">
  41. import * as ContractConfigApi from '@/api/crm/contract/config'
  42. import { CardTitle } from '@/components/Card'
  43. defineOptions({ name: 'CrmContractConfig' })
  44. const message = useMessage() // 消息弹窗
  45. const { t } = useI18n() // 国际化
  46. const formLoading = ref(false)
  47. const formData = ref({
  48. notifyEnabled: false,
  49. notifyDays: undefined
  50. })
  51. const formRules = reactive({})
  52. const formRef = ref() // 表单 Ref
  53. /** 获取配置 */
  54. const getConfig = async () => {
  55. try {
  56. formLoading.value = true
  57. const data = await ContractConfigApi.getContractConfig()
  58. if (data === null) {
  59. return
  60. }
  61. formData.value = data
  62. } finally {
  63. formLoading.value = false
  64. }
  65. }
  66. /** 提交配置 */
  67. const onSubmit = async () => {
  68. // 校验表单
  69. if (!formRef) return
  70. const valid = await formRef.value.validate()
  71. if (!valid) return
  72. // 提交请求
  73. formLoading.value = true
  74. try {
  75. const data = formData.value as ContractConfigApi.ContractConfigVO
  76. await ContractConfigApi.saveContractConfig(data)
  77. message.success(t('common.updateSuccess'))
  78. await getConfig()
  79. formLoading.value = false
  80. } finally {
  81. formLoading.value = false
  82. }
  83. }
  84. /** 更改提前提醒设置 */
  85. const changeNotifyEnable = () => {
  86. if (!formData.value.notifyEnabled) {
  87. formData.value.notifyDays = undefined
  88. }
  89. }
  90. onMounted(() => {
  91. getConfig()
  92. })
  93. </script>