qq_41295110
6 天以前 c466006a64f1cbbcbf04e0ae4a2d73de302aa92a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<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>