llj
2025-12-15 a0010bcabbfbc3771aa05d54094f5d02bcdd5609
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
<template>
  <el-dialog
    title="选择结算方式"
    :visible.sync="dialogVisible"
    width="80%"
    :before-close="handleClose"
    append-to-body
  >
    <div class="settle-style-dialog">
      <!-- 搜索区域 -->
      <el-card class="search-card">
        <div slot="header" class="clearfix">
          <span>查询条件</span>
          <el-button
            style="float: right; padding: 3px 0"
            type="text"
            @click="toggleCollapse"
          >
            {{ collapse ? '展开' : '收起' }}
          </el-button>
        </div>
 
        <el-form :model="queryParams" ref="queryForm" :inline="true">
          <el-row :gutter="20">
            <el-col :span="6">
              <el-form-item label="代码">
                <el-input
                  v-model="queryParams.HNumber"
                  placeholder="请输入代码"
                  clearable
                  @keyup.enter.native="handleQuery"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="名称">
                <el-input
                  v-model="queryParams.HName"
                  placeholder="请输入名称"
                  clearable
                  @keyup.enter.native="handleQuery"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="结算方式代码">
                <el-input
                  v-model="queryParams.HNumber2"
                  placeholder="请输入结算方式代码"
                  clearable
                  style="width: 190px"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="handleQuery">查询</el-button>
                <el-button icon="el-icon-refresh" @click="handleReset">重置</el-button>
                <el-button type="primary" @click="handleResCnz" style="margin-left: 10px">重新同步</el-button>
              </el-form-item>
            </el-col>
          </el-row>
 
          <!-- 高级搜索 -->
          <el-collapse-transition>
            <div v-show="!collapse">
              <el-row :gutter="20">
                <el-col :span="8">
                  <el-form-item label="过滤字段">
                    <el-select v-model="queryParams.ColName" placeholder="请选择字段" style="width: 100%">
                      <el-option value="0" label=""></el-option>
                      <el-option
                        v-for="column in visibleColumns"
                        :key="column.field"
                        :label="column.label"
                        :value="column.field"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="比较符">
                    <el-select v-model="queryParams.Comparator" placeholder="请选择比较符" style="width: 100%">
                      <el-option value="0" label=""></el-option>
                      <el-option label="=" value="=" />
                      <el-option label=">=" value=">=" />
                      <el-option label=">" value=">" />
                      <el-option label="<=" value="<=" />
                      <el-option label="<" value="<" />
                      <el-option label="<>" value="<>" />
                      <el-option label="包含" value="7" />
                      <el-option label="左包含" value="8" />
                      <el-option label="右包含" value="9" />
                      <el-option label="不包含" value="10" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="内容">
                    <el-input
                      v-model="queryParams.ColContent"
                      placeholder="请输入内容"
                      clearable
                      @keyup.enter.native="handleQuery"
                    />
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
          </el-collapse-transition>
 
          <!-- 当前过滤方案显示 -->
          <div v-if="currentFilterScheme" class="filter-scheme">
            {{ currentFilterScheme }}
          </div>
        </el-form>
      </el-card>
 
      <!-- 表格区域 -->
      <el-card class="table-card">
        <div slot="header" class="clearfix">
          <span>结算方式列表</span>
          <el-button-group style="float: right">
            <el-button type="primary" icon="el-icon-refresh" @click="handleRefresh">刷新</el-button>
            <el-button type="primary" icon="el-icon-close" @click="handleExit">退出</el-button>
          </el-button-group>
        </div>
 
        <el-table
          ref="table"
          :data="tableData"
          v-loading="loading"
          height="400"
          border
          highlight-current-row
          @row-dblclick="handleRowDblClick"
          @row-click="handleRowClick"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column
            v-for="column in tableColumns"
            :key="column.field"
            :prop="column.field"
            :label="column.label"
            :width="column.width"
            :align="column.align"
            :sortable="column.sortable"
            show-overflow-tooltip
          >
            <template slot-scope="{ row, column }">
              <span v-if="column.property.includes('时间') || column.property.includes('日期')">
                {{ formatDate(row[column.property]) }}
              </span>
              <span v-else>{{ row[column.property] }}</span>
            </template>
          </el-table-column>
        </el-table>
 
        <!-- 分页 -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pagination.page"
          :page-sizes="[50, 100, 500, 5000]"
          :page-size="pagination.size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pagination.total"
          style="margin-top: 15px; text-align: right;"
        />
      </el-card>
    </div>
  </el-dialog>
</template>
 
<script>
import axios from 'axios'
 
export default {
  name: 'SettleStyleDialog',
  props: {
    visible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      dialogVisible: false,
      collapse: false,
      loading: false,
 
      // 查询参数
      queryParams: {
        HNumber: '',
        HName: '',
        HNumber2: '',
        ColName: '0',
        Comparator: '0',
        ColContent: ''
      },
 
      // 表格数据
      tableData: [],
      tableColumns: [],
      selectedRow: null,
      multipleSelection: [],
 
      // 分页
      pagination: {
        page: 1,
        size: 50,
        total: 0
      },
 
      // 过滤方案
      currentFilterScheme: '',
      HInterID_Choose: 0,
 
      // 隐藏字段
      hiddenFields: ["HItemID", "HUSEORGID", "HCREATEORGID", "父级ID"],
 
      baseURL: process.env.VUE_APP_BASE_API || 'http://47.96.97.237/API/',
      user: 'admin',
      HModName: 'Gy_SettleStyle',
      HModuleName: '结算方式维护',
      Organization: '100038'
    }
  },
  computed: {
    visibleColumns() {
      return this.tableColumns
        .filter(col => !this.hiddenFields.includes(col.field))
        .map(col => ({
          field: col.field,
          label: col.label
        }))
    }
  },
  watch: {
    visible: {
      immediate: true,
      handler(val) {
        this.dialogVisible = val
        if (val) {
          this.initData()
        }
      }
    },
    dialogVisible(val) {
      this.$emit('update:visible', val)
    }
  },
  methods: {
    // 初始化数据
    initData() {
      this.loadTableData()
      this.getDefaultFilterScheme()
    },
 
    // 加载表格数据
    async loadTableData() {
      this.loading = true
      try {
        const sWhere = this.buildQueryCondition()
 
        const response = await axios.get(`${this.baseURL}/Gy_SettleStyle/SettleStyleList`, {
          params: {
            sWhere: sWhere,
            user: this.user,
            Organization: this.Organization
          }
        })
 
        if (response.data.count === 1) {
          this.tableData = response.data.data
          console.log('结算方式数据:', this.tableData)
          this.pagination.total = response.data.total || response.data.data.length
          this.generateTableColumns(response.data.list)
        } else {
          this.$message.error(response.data.Message || '加载数据失败')
        }
      } catch (error) {
        console.error('加载结算方式数据失败:', error)
        this.$message.error('加载结算方式数据失败')
      } finally {
        this.loading = false
      }
    },
 
    // 构建查询条件
    buildQueryCondition() {
      let sWhere = ""
 
      // 基本查询条件
      if (this.queryParams.HNumber) {
        sWhere += ` and 结算方式代码 like '%${this.queryParams.HNumber}%'`
      }
      if (this.queryParams.HName) {
        sWhere += ` and 结算方式名称 like '%${this.queryParams.HName}%'`
      }
 
      // 高级过滤条件
      if (this.queryParams.ColName && this.queryParams.ColName !== "0" &&
          this.queryParams.Comparator && this.queryParams.Comparator !== "0") {
        let com = ""
        switch (this.queryParams.Comparator) {
          case "7":
            com = `like '%${this.queryParams.ColContent}%'`
            break
          case "8":
            com = `like '%${this.queryParams.ColContent}'`
            break
          case "9":
            com = `like '${this.queryParams.ColContent}%'`
            break
          case "10":
            com = `not like '%${this.queryParams.ColContent}%'`
            break
          default:
            com = `${this.queryParams.Comparator} '${this.queryParams.ColContent}'`
            break
        }
        sWhere += ` and ${this.queryParams.ColName} ${com}`
      }
 
      // 添加打开类型的过滤条件
      sWhere += this.addSWhereByOpenType()
 
      return sWhere
    },
 
    // 根据打开类型添加条件
    addSWhereByOpenType() {
      // 这里可以根据需要添加特定的过滤条件
      return " and 禁用标记 = ''"
    },
 
    // 生成表格列
    generateTableColumns(columnList) {
      this.tableColumns = []
 
      // 添加选择列
      this.tableColumns.push({ type: 'selection', fixed: 'left' })
 
      // 动态生成列
      if (columnList && columnList.length > 0) {
        columnList.forEach(item => {
          if (!this.hiddenFields.includes(item.ColmCols)) {
            const column = {
              field: item.ColmCols,
              label: item.ColmCols,
              align: 'center',
              sortable: true,
              width: 200
            }
 
            // 根据字段类型设置不同的模板
            if (item.ColmType === 'DateTime') {
              column.formatter = this.formatDate
            }
 
            this.tableColumns.push(column)
          }
        })
      } else {
        // 默认列(如果接口没有返回列信息)
        const defaultColumns = [
          { field: '结算方式代码', label: '结算方式代码', align: 'center', width: 120 },
          { field: '结算方式名称', label: '结算方式名称', align: 'center', width: 120 },
          { field: '条码编号', label: '条码编号', align: 'center', width: 120 },
          { field: '禁用标记', label: '禁用标记', align: 'center', width: 100 },
          { field: '备注', label: '备注', align: 'center', width: 150 },
          { field: '审核人', label: '审核人', align: 'center', width: 100 },
          { field: '创建人', label: '创建人', align: 'center', width: 100 },
          { field: '创建时间', label: '创建时间', align: 'center', width: 150 }
        ]
        this.tableColumns = [...this.tableColumns, ...defaultColumns]
      }
    },
 
    // 查询
    handleQuery() {
      this.pagination.page = 1
      this.loadTableData()
    },
 
    // 重置查询
    handleReset() {
      this.queryParams = {
        HNumber: '',
        HName: '',
        HNumber2: '',
        ColName: '0',
        Comparator: '0',
        ColContent: ''
      }
      this.pagination.page = 1
      this.loadTableData()
    },
 
    // 重新同步
    async handleResCnz() {
      if (!this.queryParams.HNumber2) {
        this.$message.warning('请输入结算方式代码')
        return
      }
 
      try {
        const response = await axios.get(`${this.baseURL}/Gy_SettleStyle/Gy_SettleStyleViewApi`, {
          params: {
            Number: this.queryParams.HNumber2,
            Type: 'JSFS'
          }
        })
 
        if (response.data.count === 1) {
          this.$message.success(response.data.Message)
          this.loadTableData() // 重新加载数据
        } else {
          this.$message.error(response.data.Message)
        }
      } catch (error) {
        console.error('重新同步失败:', error)
        this.$message.error('重新同步失败')
      }
    },
 
    // 刷新
    handleRefresh() {
      this.loadTableData()
    },
 
    // 切换折叠状态
    toggleCollapse() {
      this.collapse = !this.collapse
    },
 
    // 行双击事件
    handleRowDblClick(row) {
      this.selectedRow = row
      this.confirmSelection()
    },
 
    // 行点击事件
    handleRowClick(row) {
      this.$refs.table.toggleRowSelection(row)
      this.selectedRow = row
    },
 
    // 选择变化
    handleSelectionChange(selection) {
      this.multipleSelection = selection
      if (selection.length === 1) {
        this.selectedRow = selection[0]
      }
    },
 
    // 确认选择
    confirmSelection() {
      if (this.selectedRow) {
        this.$emit('selected', {
          HItemID: this.selectedRow.HItemID,
          结算方式名称: this.selectedRow.结算方式名称
        })
        this.dialogVisible = false
      } else {
        this.$message.warning('请选择一条数据')
      }
    },
 
    // 退出
    handleExit() {
      this.dialogVisible = false
    },
 
    // 关闭对话框
    handleClose(done) {
      this.$confirm('确认关闭?')
        .then(_ => {
          done()
        })
        .catch(_ => {})
    },
 
    // 分页大小改变
    handleSizeChange(size) {
      this.pagination.size = size
      this.pagination.page = 1
      this.loadTableData()
    },
 
    // 当前页改变
    handleCurrentChange(page) {
      this.pagination.page = page
      this.loadTableData()
    },
 
    // 格式化日期
    formatDate(dateString) {
      if (!dateString) return ''
      try {
        const date = new Date(dateString)
        return date.toLocaleDateString('zh-CN')
      } catch (error) {
        return dateString
      }
    },
 
    // 获取默认过滤方案
    async getDefaultFilterScheme() {
      try {
        const response = await axios.get(`${this.baseURL}/Xt_FastICScheme/Chooselist`, {
          params: {
            user: this.user,
            HModuleName: this.HModuleName,
            HInterID: 0,
            Type: "Default"
          }
        })
 
        if (response.data.count === 1) {
          const data = response.data.data[0]
          this.HInterID_Choose = data.hmainid
          this.currentFilterScheme = `当前过滤方案:${data.方案名称} (${data.备注})`
 
          // 应用过滤条件
          this.applyFilterConditions(response.data.data)
        }
      } catch (error) {
        console.error('获取过滤方案失败:', error)
      }
    },
 
    // 应用过滤条件
    applyFilterConditions(filterData) {
      filterData.forEach(item => {
        if (this.queryParams.hasOwnProperty(item.过滤字段ID)) {
          this.queryParams[item.过滤字段ID] = item.过滤值
        }
      })
    },
 
    // 保存过滤方案
    handleSaveScheme() {
      this.$message.info('保存方案功能')
    },
 
    // 读取过滤方案
    handleReadScheme() {
      this.$message.info('读取方案功能')
    },
 
    // 列设置
    handleColumnSetting() {
      this.$message.info('列设置功能')
    }
  }
}
</script>
 
<style scoped>
.settle-style-dialog {
  height: 70vh;
  display: flex;
  flex-direction: column;
}
 
.search-card {
  margin-bottom: 15px;
}
 
.table-card {
  flex: 1;
  display: flex;
  flex-direction: column;
}
 
.table-card >>> .el-card__body {
  flex: 1;
  display: flex;
  flex-direction: column;
}
 
.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}
 
.el-form-item {
  margin-bottom: 15px;
}
 
.el-table {
  flex: 1;
}
 
.filter-scheme {
  text-align: center;
  font-size: 15px;
  font-weight: bold;
  color: #fc9393;
  margin: 10px 0;
}
</style>