<template>
|
<div v-loading="formLoading" v-if="formShow">
|
<div style="margin-bottom: 10px; border-bottom: 1px solid #f6f6f6">
|
<el-button type="primary" @click="submitForm" :disabled="subDisabled"
|
>保 存</el-button
|
>
|
<el-button type="primary" @click="close">退 出</el-button>
|
</div>
|
|
<el-form ref="form" :model="form" :rules="rules" label-width="110px">
|
<el-tabs v-model="activeName" type="card">
|
<el-tab-pane label="基本信息" name="first">
|
<el-row>
|
<el-col :span="8">
|
<el-form-item label="代码:" prop="HNumber">
|
<el-input
|
v-model="form.HNumber"
|
placeholder="请输入货币代码"
|
:disabled="isEditMode"
|
/>
|
<el-input v-model="form.HItemID" type="hidden" />
|
</el-form-item>
|
</el-col>
|
<el-col :span="8">
|
<el-form-item label="名称:" prop="HName">
|
<el-input
|
v-model="form.HName"
|
placeholder="请输入货币名称"
|
/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="8">
|
<el-form-item label="助记码:">
|
<el-input
|
v-model="form.HHelpCode"
|
placeholder="请输入助记码"
|
/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
|
<el-row>
|
<el-col :span="8">
|
<el-form-item label="小数位:">
|
<el-input
|
v-model="form.HScale"
|
type="number"
|
placeholder="请输入小数位"
|
/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="8">
|
<el-form-item label="汇率:">
|
<el-input
|
v-model="form.HExchangeRate"
|
type="number"
|
placeholder="请输入汇率"
|
/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="8">
|
<el-form-item label="禁用标志:">
|
<el-checkbox v-model="form.HStopflag" disabled>禁用</el-checkbox>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
|
<el-row>
|
<el-col :span="24">
|
<el-form-item label="备注:">
|
<el-input
|
v-model="form.HRemark"
|
type="textarea"
|
placeholder="请输入备注"
|
:rows="3"
|
/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</el-tab-pane>
|
</el-tabs>
|
</el-form>
|
</div>
|
</template>
|
|
<script>
|
import axios from "axios";
|
import dayjs from "dayjs";
|
|
export default {
|
name: "GyCurrencyEdit",
|
components: {},
|
props: {
|
OperationType: { type: Number }, // 1:新增, 3:编辑, 2:复制
|
linterid: { type: Number }, // 编辑时的ID
|
HOrgID: { type: Number }, // 组织ID
|
},
|
data() {
|
return {
|
formShow: false,
|
formLoading: true,
|
subDisabled: false,
|
isEditMode: false,
|
activeName: "first",
|
isIframe: false,
|
|
// 表单参数
|
form: {
|
HItemID: 0,
|
HNumber: "",
|
HName: "",
|
HHelpCode: "",
|
HScale: "2",
|
HExchangeRate: "1",
|
HStopflag: false,
|
HRemark: "",
|
HUserName: "",
|
},
|
|
// 表单校验
|
rules: {
|
HNumber: [{ required: true, message: "货币代码不能为空", trigger: "blur" }],
|
HName: [{ required: true, message: "货币名称不能为空", trigger: "blur" }],
|
},
|
|
baseURL: process.env.VUE_APP_BASE_API || "http://47.96.97.237/API/",
|
user: "admin",
|
};
|
},
|
created() {
|
this.reset();
|
this.fetchData();
|
this.checkIframe();
|
},
|
mounted() {
|
this.user = sessionStorage["HUserName"] || "admin";
|
},
|
methods: {
|
// 检查是否在iframe中
|
checkIframe() {
|
this.isIframe = window.self !== window.top;
|
},
|
|
fetchData() {
|
// 从URL获取参数
|
const urlParams = this.getUrlParams();
|
const hID = urlParams.HInterID ? parseInt(urlParams.HInterID) : 0;
|
const opType = urlParams.OperationType ? parseInt(urlParams.OperationType) : 1;
|
|
// 如果props没有传递,使用URL参数
|
const operationType = this.OperationType || opType;
|
const linterid = this.linterid || hID;
|
|
if (operationType !== 1 && linterid) {
|
// 编辑或复制模式
|
this.getDetailData(linterid, operationType);
|
} else {
|
// 新增模式
|
this.formShow = true;
|
this.formLoading = false;
|
this.form.HItemID = 0;
|
this.isEditMode = false;
|
}
|
},
|
|
// 从URL获取参数
|
getUrlParams() {
|
const params = {};
|
const queryString = window.location.search.substring(1);
|
const pairs = queryString.split('&');
|
|
for (let i = 0; i < pairs.length; i++) {
|
const pair = pairs[i].split('=');
|
if (pair.length === 2) {
|
params[pair[0]] = decodeURIComponent(pair[1]);
|
}
|
}
|
|
return params;
|
},
|
|
getDetailData(hID, operationType) {
|
this.formLoading = true;
|
axios
|
.get(this.$baseUrl + "/GetGy_CurrencyDetail", {
|
params: {
|
HID: hID,
|
},
|
})
|
.then((response) => {
|
let result = response.data;
|
if (result.code == 1) {
|
var data = result.data.h_v_Edit_Gy_CurrencyList[0];
|
console.log("返回的数据:", data);
|
|
this.form = {
|
HItemID: operationType == 2 ? 0 : data.HItemID, // 复制时ID设为0
|
HNumber: data.货币代码,
|
HName: data.货币名称,
|
HHelpCode: data.助记代码,
|
HScale: data.小数位 || "2",
|
HExchangeRate: data.汇率 || "1",
|
HStopflag: data.禁用标记 === "true",
|
HRemark: data.备注 || "",
|
HUserName: this.user,
|
};
|
|
this.isEditMode = operationType === 3;
|
} else {
|
this.$modal.msgError(result.msg || "获取数据失败");
|
}
|
})
|
.catch((error) => {
|
this.$modal.msgError("接口请求失败!");
|
})
|
.finally(() => {
|
this.formShow = true;
|
this.formLoading = false;
|
});
|
},
|
|
// 重置表单
|
reset() {
|
this.form = {
|
HItemID: 0,
|
HNumber: "",
|
HName: "",
|
HHelpCode: "",
|
HScale: "2",
|
HExchangeRate: "1",
|
HStopflag: false,
|
HRemark: "",
|
HUserName: this.user,
|
};
|
this.subDisabled = false;
|
},
|
|
// 退出
|
close() {
|
if (this.isIframe) {
|
// 在iframe中,通知父窗口关闭或返回
|
if (window.parent.editGyClose) {
|
window.parent.editGyClose();
|
} else {
|
// 尝试关闭iframe
|
try {
|
const index = parent.layer && parent.layer.getFrameIndex ? parent.layer.getFrameIndex(window.name) : null;
|
if (index !== null && index !== undefined) {
|
parent.layer.close(index);
|
} else {
|
// 如果没有layer,使用其他方式
|
window.parent.postMessage({ action: 'closeIframe' }, '*');
|
}
|
} catch (e) {
|
console.log("关闭iframe失败:", e);
|
this.$router.back();
|
}
|
}
|
} else {
|
// 不在iframe中,使用路由返回或跳转
|
if (this.$route) {
|
this.$router.back();
|
} else if (this.OperationType === 1) {
|
// 新增模式,返回首页
|
window.location.href = "/index.html";
|
} else {
|
window.history.back();
|
}
|
}
|
},
|
|
// 提交保存
|
// 提交保存
|
submitForm() {
|
this.$refs["form"].validate((valid) => {
|
if (valid) {
|
this.subDisabled = true;
|
|
// 准备数据
|
const formData = {
|
...this.form,
|
HStopflag: this.form.HStopflag ? "true" : "false",
|
HUserName: this.user,
|
};
|
|
const sMainStr = JSON.stringify(formData);
|
|
// 直接发送JSON数据,不要使用FormData
|
const requestData = {
|
msg: sMainStr + ';' + this.user,
|
};
|
|
axios({
|
method: "POST",
|
url: this.$baseUrl + "/SaveGy_CurrencyList",
|
data: requestData, // 直接发送JSON对象
|
headers: {
|
'Content-Type': 'application/json', // 使用JSON格式
|
},
|
})
|
.then((response) => {
|
if (response.data.count == 1) {
|
this.$modal.msgSuccess(response.data.Message || "保存成功");
|
this.subDisabled = true;
|
|
// 保存成功后,如果是新增模式,可以继续添加,或者提示用户
|
|
} else {
|
this.$modal.msgError(response.data.Message || "保存失败");
|
this.subDisabled = false;
|
}
|
})
|
.catch((error) => {
|
this.$modal.msgError("保存失败: " + (error.message || "未知错误"));
|
this.subDisabled = false;
|
});
|
}
|
});
|
}
|
},
|
};
|
</script>
|
|
<style scoped>
|
.el-form-item {
|
margin-bottom: 22px;
|
}
|
|
.el-row {
|
margin-bottom: 10px;
|
}
|
|
.hidden-input {
|
display: none;
|
}
|
</style>
|