# 弹窗组件

弹窗组件 基于el-dialog、el-drawer
Author yangmeng@expservice.com.cn

# 示例

普通新增 抽屉新增 全屏新增
<template>
  <ht-button @click="handleSave()">普通新增</ht-button>
  <ht-button @click="drawerSave()">抽屉新增</ht-button>
  <ht-button @click="bodyDialogSave()">全屏新增</ht-button>
  <div>
      <!-- expand-row-keys 展开列表已展开行key -->
      <!-- table-cb 列表展开默认值	 -->
      <!-- @expand-change 列表展开方法	 -->
    <ht-table
      ref="searchTable"
      ref-table="searchTable"
      :table-head="searchTableHead"
      :table-data="searchTableData"
      :expand-row-keys="expandRowKeys"
      :table-cb="handleSearchCb"
      @expand-change="handleExpandChange"
    >
    </ht-table>
    <div
      v-if="dialogVisible"
      :visible.sync="dialogVisible"
      :row-data="rowData"
      :operate-type="operateType"
    >
      <!-- ht-drawer  普通弹出标签 -->
      <!-- title  设置窗口标题 -->
      <!-- visible	设置是否可见 -->
      <ht-dialog
        v-if="dialogVisible"
        title="弹出窗口样例"
        :visible.sync="dialogVisible"
        :row-data="rowData"
        :operate-type="operateType"
      >
        <div style="text-align:left">
          <p>自定义窗口组件demo</p>
          <p>1. 支持 弹出窗口拖拽</p>
          <p>2. 支持 当前tab页弹出,可切换tab页</p>
          <p>3. 支持 各个tab页都可弹出窗口</p>
        </div>
      </ht-dialog>
    </div>
    <div
      v-if="drawerVisible"
      :visible.sync="drawerVisible"
      :row-data="rowData"
      :operate-type="drawerType"
    >
      <!-- ht-drawer抽屉弹出标签 -->
      <ht-drawer
        v-if="drawerVisible"
        title="抽屉弹出样例"
        :visible.sync="drawerVisible"
        :row-data="rowData"
        :operate-type="drawerType"
      >
        <div style="text-align:left">
          <p>自定义窗口组件demo</p>
        </div>
      </ht-drawer>
    </div>
    <div
      v-if="bodyDialogVisible"
      :visible.sync="bodyDialogVisible"
      :row-data="rowData"
      :operate-type="bodyDialogType"
    >
      <!-- ht-body-dialog全屏弹出标签 -->
      <!-- fullscreen设置全屏弹出	 -->
      <!-- close关闭窗口响应方法	 -->
      <ht-body-dialog 
        title="弹出窗口样例" 
        :fullscreen="true" 
        :show-close="true"  
        :visible.sync="bodyDialogVisible">
        <div style="text-align:left">
          <p>自定义全屏窗口组件demo</p>
        </div>
      </ht-body-dialog>
    </div>
  </div>
</template>
<script>
export default {
  name: 'HtballWindow', // 要与菜单表中字段component_name一致
  components: {},
  data() {
    return {
      operateType: '', // 操作类型
      drawerType: '', // 操作类型
      bodyDialogType: '', // 操作类型
      drawerVisible: false,
      dialogVisible: false,
      bodyDialogVisible: false,
      expandRowKeys: [], // 展开列表已展开行key
      searchTableHead: [
        {
          type: 'expand', // 定义展开列
          render: (scope) => {
            // filter:定义条件传
            // const filter = { account: scope.row.account };
            // 模拟返回的后端数据
            const detailData = {
              'current': 1,
              'pages': 1,
              'size': 10,
              'total': 7,
              'hitCount': true,
              'searchCount': true,
              'orders': [],
              'optimizeCountSql': true,
              'records':
                [
                  { 'transHash': {}},
                  { 'account': '1022',
                    'userName': '张三',
                    'rownums': 1,
                    'count': 1,
                    'date': '2023-01-01'
                  },
                  { 'account': '1033',
                    'userName': '李四',
                    'rownums': 2,
                    'count': 2,
                    'date': '2023-01-01'
                  },
                  { 'account': '1044',
                    'userName': '王五',
                    'rownums': 3,
                    'count': 3,
                    'date': '2023-01-01'
                  }
                ]
            };
            return (
              <ht-table
                ref={`searchTable-${scope.$index}`}
                ref-table={`searchTable-${scope.$index}`}
                table-head={this.matHead}
                table-data={detailData}
                table-type='expand'
                // table-fetch 调用后台方法
                // table-fetch={searchDetailData}
                // table-filter 过滤条件
                // table-filter={filter}
                max-width='90%'
              />
            );
          }
        },
        {
          type: 'action',
          label: '操作',
          content: ['编辑', '明细'], // 行操作按钮编辑
          action: [
            (row, index) => this.handleEdit(row, index),
            // 明细查询必须包含【明细】俩字,否则会失效 例如:XX明细
            (row, index) => this.handleDetail(row, index)
          ]
        },
        {
          label: '账号',
          prop: 'account',
          width: 'auto'// 自适应撑满页面
        },
        {
          label: '姓名',
          prop: 'userName',
          width: 'auto'
        },
        {
          label: '数量',
          prop: 'count',
          width: 'auto'
        },
        {
          label: '日期',
          prop: 'date',
          width: 'auto'
        }
      ],
      searchTableData: {},
      matHead: [
        {
          label: '账号',
          prop: 'account',
          width: 'auto'// 自适应撑满页面
        },
        {
          label: '姓名',
          prop: 'userName',
          width: 'auto'
        },
        {
          label: '数量',
          prop: 'count',
          width: 'auto'
        },
        {
          label: '日期',
          prop: 'date',
          width: 'auto'
        }
      ],
      detailHeadList: [
        {
          label: '账号',
          prop: 'account',
          width: '100px'
        },
        {
          label: '姓名',
          prop: 'userName'
        },
        {
          label: '数量',
          prop: 'count'
        },
        {
          label: '日期',
          prop: 'date'
        }
      ]

    };
  },
  mounted() {
    this.$nextTick(() => {
      this.handleSearch2();
    });
  },
  methods: {
    /**
     * @todo: 展开列表方法
     * @author: yangmeng@expservice.com.cn
     * @Date: 2023-05-30 17:00:06
     */
    async handleExpandChange(row) {
      if (!row['expanded']) {
        //设置虚拟数据
        row['detailList'] = {
          'current': 1,
          'pages': 1,
          'size': 10,
          'total': 7,
          'hitCount': true,
          'searchCount': true,
          'orders': [],
          'optimizeCountSql': true,
          'records':
            [
              { 'transHash': {}},
              { 'account': '1022', 'userName': '张三', 'rownums': 1, 'count': 1, 'date': '2023-01-01' },
              { 'account': '1033', 'userName': '李四', 'rownums': 2, 'count': 2, 'date': '2023-01-01' },
              { 'account': '1044', 'userName': '王五', 'rownums': 3, 'count': 3, 'date': '2023-01-01' }
            ]
        };
        //打开展开列表
        row['expanded'] = true;
        this.expandRowKeys.push(row.rownums);
      } else {
        //收起展开列表
        row['expanded'] = false;
        row['detailList'] = {};
        this.expandRowKeys.splice(this.expandRowKeys.findIndex((x) => x === row.rownums), 1);
      }
    },
    /**
     * @todo: 展开列表默认值
     * @author: yangmeng@expservice.com.cn
     * @Date: 2023-05-30 17:00:06
     */
    handleSearchCb(recordList, resultData) {
      // 展开列表默认值
      if (this.searchTableData) {
        this.searchTableData.records = recordList;
        this.expandRowKeys = [];
        //循环searchTableData,并将对象里的detailList设置为{}
        this.searchTableData.records.forEach((item) => {
          item['detailList'] = {}; // 设置明细默认值
          item['expanded'] = false;
        });
      }
    },

    /**
     * @todo: 子明细信息页
     * @author: yangmeng@expservice.com.cn
     * @Date: 2023-05-30 17:02:10
     */
    async handleDetail(row, index) {
      // 传给后台的参数
      // const filter = { id: row.account };
      // 调用后台的方法
      // const detailData = await this.$crud.fetchTable('', findById, filter);
      const detailData = {
        'current': 1,
        'pages': 1,
        'size': 10,
        'total': 7,
        'hitCount': true,
        'searchCount': true,
        'orders': [],
        'optimizeCountSql': true,
        'records':
          [
            { 'transHash': {}},
            { 'account': '1022', 'userName': '张三', 'rownums': 1, 'count': 1, 'date': '2023-01-01' },
            { 'account': '1033', 'userName': '李四', 'rownums': 2, 'count': 2, 'date': '2023-01-01' },
            { 'account': '1044', 'userName': '王五', 'rownums': 3, 'count': 3, 'date': '2023-01-01' }
          ]
      };
      return (
        <ht-table ref={`detailHead-${index}`}
          ref-table={`detailHead-${index}`}
          table-head={this.detailHeadList}
          table-data={detailData} />
      );
    },

    /**
     * @todo:虚拟数据查询方法
     * @author: qinpeng
     * @Date: 2023-05-26 09:28:12
     */
    async handleSearch2(event) {
      try {
        //设置虚拟数据
        this.searchTableData = {
          'current': 1,
          'pages': 1,
          'size': 10,
          'total': 7,
          'hitCount': true,
          'searchCount': true,
          'orders': [],
          'optimizeCountSql': true,
          'records':
            [
              { 'transHash': {}},
              { 'account': '1022', 'userName': '张三', 'rownums': 1, 'count': 1, 'date': '2023-01-01' },
              { 'account': '1033', 'userName': '李四', 'rownums': 2, 'count': 2, 'date': '2023-01-01' },
              { 'account': '1044', 'userName': '王五', 'rownums': 3, 'count': 3, 'date': '2023-01-01' }
            ]
        };
      } catch (e) {
        this.$notify.message(e, 'error');
      }
    },
    /**
     * @todo: 普通新增按钮
     * @author: qinpeng
     * @Date: 2023-05-26 14:48:38
     */
    handleSave() {
      this.operateType = 'insert';
      //打开弹窗
      this.dialogVisible = true;
      this.rowData = {};
    },
    /**
     * @todo: 抽屉新增按钮
     * @author: qinpeng
     * @Date: 2023-05-26 14:48:38
     */
    drawerSave() {
      this.drawerType = 'insert';
      //打开抽屉
      this.drawerVisible = true;
      this.rowData = {};
    },
    /**
     * @todo: 全屏新增按钮
     * @author: qinpeng
     * @Date: 2023-05-26 14:48:38
     */
    bodyDialogSave() {
      this.bodyDialogType = 'insert';
      this.bodyDialogVisible = true;
      this.rowData = {};
    },
    /**
     * @todo: 编辑按钮
     * @author: songgangyu@scisoft.cn
     * @Date: 2023-05-25 15:22:11
     */
    handleEdit(row) {
      this.operateType = 'update';
      this.dialogVisible = true;
      this.rowData = row;
      // 编辑赋值(正式需要放到created() {}中)
      if (this.rowData.id) {
        this.id = this.rowData.id;
        //将行对象的值赋予给searchEditList
        this.$crud.setEditValue(this.searchEditList, this.rowData);
        this.searchEditList[0].disabled = true;
      }
    }
  }
};
</script>
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
Expand Copy

# 版本

  • v1.0.1