gaoluyang
3 天以前 e449a5408265e4bd1f6c66f5be28a42efac444ee
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!--
  业务参数设置(对齐管理端 views/projectManagement/config/index.vue)
 
  目前只有一个参数「合同原件约定回传提前提醒天数」,用于销售台账里
  「合同原件约定回传日期」的临期预警:days = 回传日期 - 今天,days <= N 报警。
  后端 GET /projectManagement/config 返回 { id, contractReturnReminderDays },
  PUT 同地址整体覆盖,所以 id 必须原样带回去。
-->
<template>
  <view class="project-config">
    <PageHeader title="业务参数设置"
                @back="goBack" />
 
    <view class="form-container">
      <up-form ref="formRef"
               :model="form"
               :rules="rules"
               label-width="200"
               input-align="right"
               error-message-align="right">
        <u-cell-group class="form-section">
          <up-form-item label="合同原件约定回传提前提醒天数"
                        prop="contractReturnReminderDays"
                        required>
            <up-input v-model="form.contractReturnReminderDays"
                      type="number"
                      placeholder="请输入天数" />
          </up-form-item>
        </u-cell-group>
      </up-form>
 
      <view class="tip-text">
        <text>示例:填 3 表示「合同原件约定回传日期」距今不足 3 天时提示预警。</text>
      </view>
    </view>
 
    <FooterButtons :loading="loading"
                   confirm-text="保存设置"
                   @cancel="goBack"
                   @confirm="handleSubmit" />
  </view>
</template>
 
<script setup>
  import { ref } from "vue";
  import { onLoad } from "@dcloudio/uni-app";
  import PageHeader from "@/components/PageHeader.vue";
  import FooterButtons from "@/components/FooterButtons.vue";
  import {
    getProjectConfig,
    updateProjectConfig,
  } from "@/api/projectManagement/config";
 
  const MIN_DAYS = 1;
  const MAX_DAYS = 365;
  const DEFAULT_DAYS = 3;
 
  const formRef = ref();
  const loading = ref(false);
  const form = ref({
    id: undefined,
    contractReturnReminderDays: DEFAULT_DAYS,
  });
 
  const validateDays = (rule, value, callback) => {
    const days = Number(value);
    if (value === "" || value === null || value === undefined) {
      callback(new Error("提前提醒天数不能为空"));
      return;
    }
    if (!Number.isInteger(days) || days < MIN_DAYS || days > MAX_DAYS) {
      callback(new Error(`天数需为 ${MIN_DAYS}~${MAX_DAYS} 的整数`));
      return;
    }
    callback();
  };
 
  const rules = {
    contractReturnReminderDays: [
      { required: true, validator: validateDays, trigger: "blur" },
    ],
  };
 
  const goBack = () => uni.navigateBack();
 
  const loadConfig = async () => {
    try {
      const res = await getProjectConfig();
      const data = res?.data?.data ?? res?.data ?? res;
      if (!data) return;
      form.value.id = data.id;
      form.value.contractReturnReminderDays =
        Number(data.contractReturnReminderDays) || DEFAULT_DAYS;
    } catch (error) {
      uni.showToast({ title: "获取配置失败", icon: "none" });
    }
  };
 
  const handleSubmit = async () => {
    const valid = await formRef.value.validate().catch(() => false);
    if (!valid) return;
 
    loading.value = true;
    updateProjectConfig({
      id: form.value.id,
      contractReturnReminderDays: Number(form.value.contractReturnReminderDays),
    })
      .then(() => {
        uni.showToast({ title: "配置更新成功", icon: "success" });
        setTimeout(() => uni.navigateBack(), 300);
      })
      .catch(() => {
        uni.showToast({ title: "配置更新失败", icon: "none" });
      })
      .finally(() => {
        loading.value = false;
      });
  };
 
  onLoad(() => {
    loadConfig();
  });
</script>
 
<style scoped lang="scss">
  @import "@/static/scss/form-common.scss";
 
  .project-config {
    min-height: 100vh;
    background: #f8f9fa;
    padding-bottom: 100px;
  }
 
  .form-container {
    padding: 12px 12px 0;
  }
 
  .form-section {
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(15, 35, 95, 0.05);
  }
 
  .tip-text {
    padding: 12px 4px;
    font-size: 13px;
    line-height: 1.6;
    color: #909399;
  }
</style>