<!--
|
业务参数设置(对齐管理端 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>
|