<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="setCheckBill"
|
:disabled="!isAuditable || 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 && form.HItemID > 0"
|
/>
|
<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="换算比例:" prop="HRate">
|
<el-input
|
v-model="form.HRate"
|
type="number"
|
placeholder="请输入换算比例"
|
min="0"
|
/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="8">
|
<el-form-item label="默认单位:">
|
<el-checkbox v-model="form.HStandard">设为默认单位</el-checkbox>
|
</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="8">
|
<el-form-item label="计量单位组:">
|
<div style="white-space: nowrap;">
|
<el-input
|
v-model="form.HUnitGroupName"
|
placeholder="请选择计量单位组"
|
readonly
|
style="width: 200px; display: inline-block;"
|
/>
|
<el-input v-model="form.HUnitGroupID" type="hidden" />
|
<el-button
|
type="primary"
|
icon="el-icon-search"
|
@click="selectUnitGroup"
|
style="width: 40px; margin-left: -30px; display: inline-block;"
|
></el-button>
|
</div>
|
</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-tab-pane label="制单信息" name="second">
|
<el-row>
|
<el-col :span="8">
|
<el-form-item label="制单人:">
|
<el-input
|
v-model="form.HMakeEmp"
|
readonly
|
:class="{ 'readonly-input': true }"
|
/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="8">
|
<el-form-item label="制单日期:">
|
<el-input
|
v-model="form.HMakeDate"
|
readonly
|
:class="{ 'readonly-input': true }"
|
/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
|
<el-row>
|
<el-col :span="8">
|
<el-form-item label="审核人:">
|
<el-input
|
v-model="form.HCheckEmp"
|
readonly
|
:class="{ 'readonly-input': true }"
|
/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="8">
|
<el-form-item label="审核日期:">
|
<el-input
|
v-model="form.HCheckDate"
|
readonly
|
:class="{ 'readonly-input': true }"
|
/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
|
<el-row>
|
<el-col :span="8">
|
<el-form-item label="禁用人:">
|
<el-input
|
v-model="form.HStopEmp"
|
readonly
|
:class="{ 'readonly-input': true }"
|
/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="8">
|
<el-form-item label="禁用日期:">
|
<el-input
|
v-model="form.HStopDate"
|
readonly
|
:class="{ 'readonly-input': true }"
|
/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</el-tab-pane>
|
</el-tabs>
|
</el-form>
|
|
<!-- 计量单位组选择弹窗 -->
|
<el-dialog
|
title="计量单位组列表"
|
:visible.sync="unitGroupDialogVisible"
|
width="90%"
|
top="5vh"
|
:close-on-click-modal="false"
|
append-to-body
|
>
|
<div style="height: 70vh;">
|
<iframe
|
:src="unitGroupIframeUrl"
|
frameborder="0"
|
width="100%"
|
height="100%"
|
></iframe>
|
</div>
|
<span slot="footer" class="dialog-footer">
|
<el-button @click="unitGroupDialogVisible = false">取 消</el-button>
|
<el-button type="primary" @click="confirmUnitGroup">确 定</el-button>
|
</span>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script>
|
import axios from "axios";
|
import dayjs from "dayjs";
|
|
export default {
|
name: "GyUnitEdit",
|
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,
|
isAuditable: false,
|
activeName: "first",
|
isIframe: false,
|
|
// 表单参数
|
form: {
|
HItemID: 0,
|
HNumber: "",
|
HName: "",
|
HHelpCode: "",
|
HRate: "1",
|
HStandard: false,
|
HStopflag: false,
|
HRemark: "",
|
HUnitGroupID: "0",
|
HUnitGroupName: "",
|
HMakeEmp: "",
|
HMakeDate: "",
|
HCheckEmp: "",
|
HCheckDate: "",
|
HStopEmp: "",
|
HStopDate: "",
|
HUserName: "",
|
OrganizationID: ""
|
},
|
|
// 计量单位组选择
|
unitGroupDialogVisible: false,
|
unitGroupIframeUrl: "",
|
selectedUnitGroup: null,
|
|
// 表单校验
|
rules: {
|
HNumber: [
|
{ required: true, message: "计量单位代码不能为空", trigger: "blur" },
|
{ max: 50, message: "长度不能超过50个字符", trigger: "blur" }
|
],
|
HName: [
|
{ required: true, message: "计量单位名称不能为空", trigger: "blur" },
|
{ max: 100, message: "长度不能超过100个字符", trigger: "blur" }
|
],
|
HRate: [
|
{ required: true, message: "换算比例不能为空", trigger: "blur" },
|
{
|
validator: (rule, value, callback) => {
|
if (value === '' || value === null) {
|
callback(new Error('换算比例不能为空'));
|
} else if (isNaN(value) || parseFloat(value) <= 0) {
|
callback(new Error('请输入大于0的数字'));
|
} else {
|
callback();
|
}
|
},
|
trigger: 'blur'
|
}
|
]
|
},
|
|
baseURL: process.env.VUE_APP_BASE_API || "http://47.96.97.237/API/",
|
user: "admin",
|
organizationID: ""
|
};
|
},
|
created() {
|
this.reset();
|
this.fetchData();
|
this.checkIframe();
|
},
|
mounted() {
|
this.user = sessionStorage["HUserName"] || "admin";
|
this.organizationID = sessionStorage["OrganizationID"] || "";
|
},
|
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;
|
this.isAuditable = false;
|
this.setDefaultValues();
|
}
|
},
|
|
// 从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_UnitDetail", {
|
params: {
|
HID: hID,
|
},
|
})
|
.then((response) => {
|
let result = response.data;
|
if (result.code == 1) {
|
var data = result.data.h_v_Edit_Gy_UnitList[0];
|
console.log("返回的数据:", data);
|
|
// 处理布尔值
|
const isStopped = data.禁用标记 === "true";
|
const isStandard = data.默认标记 === "true";
|
|
this.form = {
|
HItemID: operationType == 2 ? 0 : data.HItemID, // 复制时ID设为0
|
HNumber: data.计量单位代码,
|
HName: data.计量单位名称,
|
HHelpCode: data.助记代码,
|
HRate: data.换算比例 || "1",
|
HStandard: isStandard,
|
HStopflag: isStopped,
|
HRemark: data.备注 || "",
|
HUnitGroupID: data.HUnitGroupID || "0",
|
HUnitGroupName: data.计量单位组名称 || "",
|
HMakeEmp: data["创建人"] || "",
|
HMakeDate: data["创建日期"] ? dayjs(data["创建日期"]).format("YYYY-MM-DD") : "",
|
HCheckEmp: data["审核人"] || "",
|
HCheckDate: data["审核日期"] ? dayjs(data["审核日期"]).format("YYYY-MM-DD") : "",
|
HStopEmp: data["禁用人"] || "",
|
HStopDate: data["禁用日期"] ? dayjs(data["禁用日期"]).format("YYYY-MM-DD") : "",
|
HUserName: this.user,
|
OrganizationID: this.organizationID
|
};
|
|
this.isEditMode = operationType === 3;
|
this.isAuditable = !data["审核人"] && operationType === 3;
|
|
// 如果是已审核单据,禁用保存按钮
|
if (data["审核人"]) {
|
this.subDisabled = true;
|
}
|
} else {
|
this.$modal.msgError(result.msg || "获取数据失败");
|
}
|
})
|
.catch((error) => {
|
this.$modal.msgError("接口请求失败!");
|
})
|
.finally(() => {
|
this.formShow = true;
|
this.formLoading = false;
|
});
|
},
|
|
// 设置默认值
|
setDefaultValues() {
|
this.form.HMakeEmp = this.user;
|
this.form.HMakeDate = dayjs().format("YYYY-MM-DD");
|
this.form.OrganizationID = this.organizationID;
|
},
|
|
// 重置表单
|
reset() {
|
this.form = {
|
HItemID: 0,
|
HNumber: "",
|
HName: "",
|
HHelpCode: "",
|
HRate: "1",
|
HStandard: false,
|
HStopflag: false,
|
HRemark: "",
|
HUnitGroupID: "0",
|
HUnitGroupName: "",
|
HMakeEmp: "",
|
HMakeDate: "",
|
HCheckEmp: "",
|
HCheckDate: "",
|
HStopEmp: "",
|
HStopDate: "",
|
HUserName: this.user,
|
OrganizationID: this.organizationID
|
};
|
this.subDisabled = false;
|
},
|
|
// 选择计量单位组
|
selectUnitGroup() {
|
this.unitGroupIframeUrl = `/iframe/GyUnitGroup?type=select`;
|
this.unitGroupDialogVisible = true;
|
|
// 监听来自iframe的消息
|
window.addEventListener('message', this.handleUnitGroupMessage);
|
},
|
|
// 处理计量单位组选择消息
|
handleUnitGroupMessage(event) {
|
if (event.data && event.data.action === 'selectUnitGroup') {
|
this.selectedUnitGroup = event.data.data;
|
}
|
},
|
|
// 确认选择计量单位组
|
confirmUnitGroup() {
|
if (this.selectedUnitGroup) {
|
this.form.HUnitGroupID = this.selectedUnitGroup.HItemID;
|
this.form.HUnitGroupName = this.selectedUnitGroup.计量单位组;
|
}
|
this.unitGroupDialogVisible = false;
|
window.removeEventListener('message', this.handleUnitGroupMessage);
|
},
|
|
// 退出
|
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,
|
HStandard: this.form.HStandard ? "true" : "false",
|
HStopflag: this.form.HStopflag ? "true" : "false",
|
HRate: this.form.HRate.toString(), // 确保是字符串
|
HUserName: this.user,
|
OrganizationID: this.organizationID
|
};
|
|
// 构建与原页面相同的格式
|
const sMainStr = JSON.stringify(formData);
|
const additionalParams = `${this.user};${this.organizationID};${this.form.HRate}`;
|
const fullData = sMainStr + ';' + additionalParams;
|
|
const requestData = {
|
msg: fullData,
|
};
|
|
axios({
|
method: "POST",
|
url: this.baseURL + "SaveGy_UnitList",
|
data: requestData,
|
headers: {
|
'Content-Type': 'application/json',
|
},
|
})
|
.then((response) => {
|
if (response.data.count == 1) {
|
this.$modal.msgSuccess(response.data.Message || "保存成功");
|
this.subDisabled = true;
|
this.form.HItemID = response.data.data; // 获取返回的ID
|
|
// 如果是自动审核,执行审核
|
if (response.data.Verify === "Y") {
|
this.setCheckBillNoLayer();
|
}
|
|
// 通知父组件刷新
|
if (window.parent && window.parent.handleQuery) {
|
window.parent.handleQuery();
|
}
|
|
} else {
|
this.$modal.msgError(response.data.Message || "保存失败");
|
this.subDisabled = false;
|
}
|
})
|
.catch((error) => {
|
this.$modal.msgError("保存失败: " + (error.message || "未知错误"));
|
this.subDisabled = false;
|
});
|
} else {
|
this.$modal.msgError("请检查表单数据");
|
}
|
});
|
},
|
|
// 审核(带确认框)
|
setCheckBill() {
|
this.$confirm('确认要审核吗?', '提示', {
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
type: 'warning'
|
}).then(() => {
|
this.setCheckBillNoLayer();
|
}).catch(() => {
|
// 用户取消
|
});
|
},
|
|
// 审核(不带确认框)
|
setCheckBillNoLayer() {
|
if (!this.form.HItemID || this.form.HItemID == 0) {
|
this.$modal.msgError("请先保存单据");
|
return;
|
}
|
|
axios({
|
method: "GET",
|
url: this.baseURL + "Gy_Unit/AuditGy_Unit",
|
params: {
|
HInterID: this.form.HItemID,
|
Type: 1,
|
user: this.user
|
}
|
})
|
.then((response) => {
|
if (response.data.count == 1) {
|
this.$modal.msgSuccess("审核成功");
|
this.isAuditable = false;
|
this.subDisabled = true;
|
|
// 更新审核信息
|
this.form.HCheckEmp = this.user;
|
this.form.HCheckDate = dayjs().format("YYYY-MM-DD");
|
|
// 通知父组件刷新
|
if (window.parent && window.parent.handleQuery) {
|
window.parent.handleQuery();
|
}
|
} else {
|
this.$modal.msgError(response.data.Message || "审核失败");
|
}
|
})
|
.catch((error) => {
|
this.$modal.msgError("审核失败: " + (error.message || "未知错误"));
|
});
|
}
|
},
|
beforeDestroy() {
|
// 移除事件监听器
|
window.removeEventListener('message', this.handleUnitGroupMessage);
|
}
|
};
|
</script>
|
|
<style scoped>
|
.el-form-item {
|
margin-bottom: 22px;
|
}
|
|
.el-row {
|
margin-bottom: 10px;
|
}
|
|
.hidden-input {
|
display: none;
|
}
|
|
.readonly-input >>> .el-input__inner {
|
background-color: #f5f7fa;
|
color: #909399;
|
cursor: not-allowed;
|
}
|
</style>
|