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