20260803173356
This commit is contained in:
1 parent
5f67172892
commit
efd5a2bc93
21 files changed
+14314
No files matched your search
@@ -0,0 +1,220 @@
|
||||
<script setup>
|
||||
import g3Group from "@/components/g3Group.vue";
|
||||
|
||||
import { ref, onMounted, computed } from "vue";
|
||||
import axios from "@/utils/axios";
|
||||
import { useUserStore } from "@/store/user";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { useRoute } from "vue-router";
|
||||
import { getSFId } from "@/utils/common";
|
||||
import { getMainTable } from "@/utils/dodata";
|
||||
import {
|
||||
getDefaultValue,
|
||||
checkMustField,
|
||||
checkAllowRepeat,
|
||||
initReserveData,
|
||||
handleDisabledState,
|
||||
} from "@/utils/g3Funlib";
|
||||
import { diffData } from "@/utils/dataDiffUtils";
|
||||
import { morePermission } from "@/utils/auth";
|
||||
|
||||
const userStore = useUserStore();
|
||||
|
||||
const route = useRoute();
|
||||
const viewtable = "v_cw_account";
|
||||
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const error = ref("");
|
||||
const maintable = ref({});
|
||||
const maintableorg = ref({});
|
||||
|
||||
const id = ref(route.query.id ?? "");
|
||||
const op = ref(String(route.query.op ?? ""));
|
||||
|
||||
const { approved } = handleDisabledState(() => maintable.value?.b_state);
|
||||
|
||||
async function handleNew() {
|
||||
const reserveData = await initReserveData(maintable.value, viewtable);
|
||||
resetAll();
|
||||
op.value = "new";
|
||||
await initNew();
|
||||
Object.assign(maintable.value, reserveData);
|
||||
}
|
||||
function resetAll() {
|
||||
maintable.value = {};
|
||||
maintableorg.value = {};
|
||||
maintable.value.b_state = "草拟";
|
||||
}
|
||||
async function initNew() {
|
||||
await getDefaultValue(maintable, viewtable);
|
||||
maintable.value.b_id = await getSFId();
|
||||
id.value = "";
|
||||
}
|
||||
|
||||
async function handleCopy() {
|
||||
clearOriginalData();
|
||||
resetBusinessStatus();
|
||||
await regenerateBusinessNo();
|
||||
op.value = "new";
|
||||
ElMessage.success("复制成功");
|
||||
}
|
||||
function clearOriginalData() {
|
||||
maintable.value.b_account = "";
|
||||
maintableorg.value = {};
|
||||
}
|
||||
function resetBusinessStatus() {
|
||||
maintable.value.b_state = "草拟";
|
||||
}
|
||||
async function regenerateBusinessNo() {
|
||||
maintable.value.b_id = await getSFId();
|
||||
}
|
||||
|
||||
async function beforeSave() {
|
||||
error.value = "";
|
||||
|
||||
const ok = await checkMustField(maintable.value, viewtable);
|
||||
if (!ok) return false;
|
||||
|
||||
const isValid = await checkAllowRepeat(maintable.value, viewtable);
|
||||
|
||||
if (!isValid) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
function buildSaveData() {
|
||||
const mainChanges = diffData(maintable.value, maintableorg.value, "b_id", {
|
||||
isSingle: true,
|
||||
});
|
||||
|
||||
// 无变更检测
|
||||
if (!mainChanges.hasChanges) {
|
||||
return null;
|
||||
}
|
||||
return [
|
||||
{
|
||||
tableName: "cw_account",
|
||||
keyField: "b_id",
|
||||
inserts: mainChanges.insertdata,
|
||||
updates: mainChanges.updatedata,
|
||||
deletes: [],
|
||||
},
|
||||
];
|
||||
}
|
||||
const handleSave = async () => {
|
||||
try {
|
||||
saving.value = true;
|
||||
error.value = "";
|
||||
|
||||
if (!(await beforeSave())) return;
|
||||
|
||||
const requestData = buildSaveData();
|
||||
if (!requestData) {
|
||||
ElMessage.info("没有数据变更");
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await axios.post("/saveobjectV2", requestData, {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
if (response.data?.success) {
|
||||
ElMessage.success("保存成功");
|
||||
|
||||
afterSave();
|
||||
} else {
|
||||
throw new Error(response.data?.message || "保存失败");
|
||||
}
|
||||
} catch (err) {
|
||||
error.value = `保存失败: ${err.message}`;
|
||||
console.error("保存错误:", err);
|
||||
ElMessage.error("保存失败");
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
};
|
||||
function afterSave() {
|
||||
maintableorg.value = JSON.parse(JSON.stringify(maintable.value));
|
||||
|
||||
op.value = "mod";
|
||||
}
|
||||
|
||||
// 初始化加载数据
|
||||
onMounted(async () => {
|
||||
if (op.value === "mod") {
|
||||
await getMainTable("v_cw_account", maintable, maintableorg, id.value);
|
||||
} else if (op.value === "new") {
|
||||
await getDefaultValue(maintable, "v_cw_account");
|
||||
maintable.value.b_state = "草拟";
|
||||
maintable.value.b_id = await getSFId();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="g3pagecontainer">
|
||||
<div class="g3toolbar">
|
||||
<el-button
|
||||
:disabled="approved || morePermission(3)"
|
||||
type="success"
|
||||
:loading="saving"
|
||||
@click="handleSave"
|
||||
>
|
||||
保存
|
||||
</el-button>
|
||||
<el-button :disabled="morePermission(5)" type="primary"> 报表 </el-button>
|
||||
<el-button :disabled="morePermission(1)" type="primary" @click="handleNew"> 新建 </el-button>
|
||||
<el-button :disabled="morePermission(2)" type="primary" @click="handleCopy"> 复制 </el-button>
|
||||
</div>
|
||||
<div class="g3main">
|
||||
<g3Group v-model="maintable" viewtable="v_cw_account" />
|
||||
|
||||
<!-- 错误提示 -->
|
||||
<el-alert
|
||||
v-if="error"
|
||||
class="g3-error-message"
|
||||
:title="error"
|
||||
type="error"
|
||||
show-icon
|
||||
closable
|
||||
@close="error = ''"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.g3pagecontainer {
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
background-color: #f2f3f5;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
flex-direction: column;
|
||||
|
||||
.g3toolbar {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
height: 50px;
|
||||
margin-bottom: 4px;
|
||||
border-bottom: 1px solid #e4e7ed;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.g3main {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
overflow-y: auto;
|
||||
background-color: #fff;
|
||||
border-bottom: 1px solid #e4e7ed;
|
||||
min-height: 0;
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.g3panel) {
|
||||
grid-template-columns: repeat(1, 1fr);
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user