<template>
|
<div style="padding: 15px; height: 100vh;">
|
<el-card style="margin-bottom: 15px;">
|
<el-form :inline="true" :model="queryForm" class="demo-form-inline">
|
<el-form-item label="过滤列">
|
<el-input
|
v-model="queryForm.Value"
|
placeholder="请输入过滤列"
|
@keyup.enter.native="handleQuery"
|
></el-input>
|
</el-form-item>
|
<el-form-item>
|
<el-button type="primary" @click="handleQuery">快速查询</el-button>
|
</el-form-item>
|
</el-form>
|
</el-card>
|
|
<div style="height: calc(100% - 100px);">
|
<el-table
|
ref="mainTable"
|
:data="tableData"
|
stripe
|
border
|
highlight-current-row
|
height="100%"
|
@row-dblclick="handleRowDblclick"
|
@row-click="handleRowClick"
|
:row-class-name="tableRowClassName"
|
>
|
<el-table-column type="radio" width="55">
|
<template slot-scope="scope">
|
<el-radio
|
v-model="selectedRowId"
|
:label="scope.row.HItemID"
|
@change="handleRadioChange(scope.row)"
|
></el-radio>
|
</template>
|
</el-table-column>
|
<el-table-column prop="HItemID" label="单位组ID" width="150" v-if="false"></el-table-column>
|
<el-table-column prop="计量单位组代码" label="计量单位组代码" width="150"></el-table-column>
|
<el-table-column prop="计量单位组" label="计量单位组" width="150" sortable></el-table-column>
|
</el-table>
|
|
<el-pagination
|
background
|
layout="total, sizes, prev, pager, next"
|
:total="total"
|
:page-sizes="[50, 500, 5000, 50000]"
|
:page-size="pageSize"
|
:current-page="currentPage"
|
@size-change="handleSizeChange"
|
@current-change="handleCurrentChange"
|
style="margin-top: 10px; text-align: right;"
|
>
|
</el-pagination>
|
</div>
|
</div>
|
</template>
|
|
<script>
|
import axios from "axios";
|
|
export default {
|
name: "GyUnitGroupSelect",
|
data() {
|
return {
|
queryForm: {
|
Value: "",
|
},
|
tableData: [],
|
selectedRow: null,
|
selectedRowId: null, // 用于radio绑定
|
total: 0,
|
currentPage: 1,
|
pageSize: 50,
|
type: "select", // 从URL参数中获取
|
baseURL: process.env.VUE_APP_BASE_API || "http://47.96.97.237/API/",
|
};
|
},
|
created() {
|
this.getUrlParams();
|
this.getUnitGroupList();
|
},
|
methods: {
|
// 从URL获取参数
|
getUrlParams() {
|
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) {
|
const key = decodeURIComponent(pair[0]);
|
const value = decodeURIComponent(pair[1]);
|
if (key === 'type') {
|
this.type = value;
|
}
|
}
|
}
|
},
|
|
// 查询数据
|
handleQuery() {
|
this.currentPage = 1;
|
this.getUnitGroupList();
|
},
|
|
// 获取计量单位组列表
|
getUnitGroupList() {
|
axios
|
.get(this.baseURL + "Web/GetUnitGroupList_Json", {
|
params: {
|
Unit: this.queryForm.Value || "",
|
},
|
})
|
.then((response) => {
|
if (response.data && response.data.data) {
|
this.tableData = response.data.data;
|
this.total = response.data.data.length;
|
|
// 重置选中状态
|
this.selectedRow = null;
|
this.selectedRowId = null;
|
} else {
|
this.tableData = [];
|
this.total = 0;
|
}
|
})
|
.catch((error) => {
|
console.error("获取计量单位组列表失败:", error);
|
this.$message.error("获取数据失败");
|
});
|
},
|
|
// 返回选择结果 - 修改这里确保能返回信息
|
handleReturn() {
|
if (!this.selectedRow) {
|
this.$message.warning("请选择一条数据");
|
return;
|
}
|
|
// 首先尝试通过postMessage传递数据
|
if (window.parent) {
|
window.parent.postMessage({
|
action: 'selectUnitGroup',
|
data: this.selectedRow
|
}, '*');
|
}
|
|
// 同时尝试调用父窗口的方法
|
if (window.parent.GetHUnitGroupNameValue) {
|
window.parent.GetHUnitGroupNameValue([this.selectedRow]);
|
}
|
|
// 关闭当前窗口
|
this.closeWindow();
|
},
|
|
// 双击行事件 - 修改这里确保能关闭窗口
|
handleRowDblclick(row) {
|
this.selectedRow = row;
|
this.selectedRowId = row.HItemID;
|
this.$refs.mainTable.setCurrentRow(row);
|
|
// 传递数据给父窗口
|
if (window.parent) {
|
window.parent.postMessage({
|
action: 'selectUnitGroup',
|
data: this.selectedRow
|
}, '*');
|
}
|
|
if (window.parent.GetHUnitGroupNameValue) {
|
window.parent.GetHUnitGroupNameValue([this.selectedRow]);
|
}
|
|
// 关闭窗口
|
this.closeWindow();
|
},
|
|
// 单击行事件
|
handleRowClick(row) {
|
this.selectedRow = row;
|
this.selectedRowId = row.HItemID;
|
this.$refs.mainTable.setCurrentRow(row);
|
// 传递数据给父窗口
|
if (window.parent) {
|
window.parent.postMessage({
|
action: 'selectUnitGroup',
|
data: this.selectedRow
|
}, '*');
|
}
|
|
if (window.parent.GetHUnitGroupNameValue) {
|
window.parent.GetHUnitGroupNameValue([this.selectedRow]);
|
}
|
},
|
|
// Radio选择变化
|
handleRadioChange(row) {
|
this.selectedRow = row;
|
this.$refs.mainTable.setCurrentRow(row);
|
},
|
|
// 关闭窗口的通用方法
|
closeWindow() {
|
try {
|
// 尝试使用layer关闭
|
if (parent.layer) {
|
const index = parent.layer.getFrameIndex(window.name);
|
if (index !== null && index !== undefined) {
|
parent.layer.close(index);
|
return;
|
}
|
}
|
|
// 尝试使用window.close
|
if (window.opener || window.parent !== window) {
|
window.close();
|
return;
|
}
|
|
// 尝试发送关闭消息
|
if (window.parent) {
|
window.parent.postMessage({ action: 'closeSelectDialog' }, '*');
|
}
|
|
console.log("无法自动关闭窗口,请手动关闭");
|
} catch (e) {
|
console.log("关闭窗口失败:", e);
|
}
|
},
|
|
// 设置表格行样式
|
tableRowClassName({ row, rowIndex }) {
|
if (this.selectedRow && row.HItemID === this.selectedRow.HItemID) {
|
return 'selected-row';
|
}
|
return '';
|
},
|
|
// 分页大小改变
|
handleSizeChange(val) {
|
this.pageSize = val;
|
this.currentPage = 1;
|
// 这里可以根据需要重新加载数据
|
},
|
|
// 当前页改变
|
handleCurrentChange(val) {
|
this.currentPage = val;
|
// 这里可以根据需要重新加载数据
|
},
|
},
|
};
|
</script>
|
|
<style scoped>
|
/* 确保表格撑满容器 */
|
.demo-form-inline {
|
margin-bottom: 0;
|
}
|
|
/* 表格容器样式 */
|
.table-container {
|
height: calc(100% - 60px);
|
overflow: auto;
|
}
|
|
/* 选中行样式 */
|
.el-table .selected-row {
|
background-color: #f0f9ff !important;
|
}
|
|
.el-table .selected-row:hover > td {
|
background-color: #e6f7ff !important;
|
}
|
</style>
|
|
<style>
|
/* 全局样式,确保在表格内部生效 */
|
.el-table .cell .el-radio {
|
margin-right: 0;
|
}
|
|
.el-table .cell .el-radio__label {
|
display: none;
|
}
|
</style>
|