hsy
4 小时以前 2d3530a7c11557a40807ad7c0b9e302ce6ce3a9f
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
104
105
106
107
108
109
<template>
  <div class="app-container">
    <el-card class="box-card" shadow="never">
      <template #header>
        <div class="card-header">
          <span>业务参数设置</span>
        </div>
      </template>
      <el-form 
        ref="configFormRef" 
        :model="form" 
        :rules="rules" 
        label-width="240px" 
        style="max-width: 600px; margin-top: 20px;"
      >
        <el-form-item label="合同原件约定回传提前提醒天数" prop="contractReturnReminderDays">
          <el-input-number 
            v-model="form.contractReturnReminderDays" 
            :min="1" 
            :max="365" 
            :step="1" 
            placeholder="请输入天数" 
            style="width: 200px"
          />
          <span style="margin-left: 10px; color: #999;">天</span>
        </el-form-item>
        
        <el-form-item>
          <el-button type="primary" :loading="submitLoading" @click="handleSubmit">保存设置</el-button>
          <el-button @click="handleReset">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
 
<script setup name="ProjectConfig">
import { ref, reactive, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { getConfig, updateConfig } from '@/api/projectManagement/config'
 
const configFormRef = ref(null)
const submitLoading = ref(false)
const originalData = ref({})
 
const form = reactive({
  id: undefined,
  contractReturnReminderDays: 3
})
 
const rules = {
  contractReturnReminderDays: [
    { required: true, message: '提前提醒天数不能为空', trigger: 'blur' }
  ]
}
 
const loadData = async () => {
  try {
    const res = await getConfig()
    if (res.code === 200 && res.data) {
      Object.assign(form, res.data)
      originalData.value = JSON.parse(JSON.stringify(res.data))
    }
  } catch (error) {
    console.error('获取配置失败:', error)
  }
}
 
const handleSubmit = async () => {
  if (!configFormRef.value) return
  await configFormRef.value.validate(async (valid) => {
    if (valid) {
      submitLoading.value = true
      try {
        const res = await updateConfig(form)
        if (res.code === 200) {
          ElMessage.success('配置更新成功')
          loadData()
        }
      } catch (error) {
        console.error('更新配置失败:', error)
      } finally {
        submitLoading.value = false
      }
    }
  })
}
 
const handleReset = () => {
  if (originalData.value.id) {
    Object.assign(form, originalData.value)
  } else {
    form.contractReturnReminderDays = 3
  }
}
 
onMounted(() => {
  loadData()
})
</script>
 
<style scoped>
.app-container {
  padding: 20px;
}
.box-card {
  min-height: calc(100vh - 124px);
}
</style>