wang
2024-03-28 04adb88a2ed54cdf4c2958c79972c30109b9b5b6
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
<template>
  <el-container>
    <el-header class="m-header" style="height: auto">
      <el-row :gutter="10" style="margin-bottom: 5px">
        <el-col :span="7">
          <el-date-picker
              v-model="datevalue"
              type="daterange"
              unlink-panels
              range-separator="到"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :shortcuts="shortcuts"
              :size="size"
              format="YYYY/MM/DD"
              value-format="YYYY-MM-DD"
          />
 
        </el-col>
 
        <el-col :span="2">
          <el-button
              id="select"
              type="primary"
              :icon="Search"
              @click="BtnSearchPurchaseOrder">查询
          </el-button>
        </el-col>
      </el-row>
    </el-header>
    <el-main style="padding-top: 5px;height:100%">
      <vxe-grid
 
          max-height="600"
          @filter-change="filterChanged"
          class="mytable-scrollbar"
          ref="xGrid"
          v-bind="gridOptions"
          v-on="gridEvents"
          @cell-dblclick="cellClickEvent"
      >
 
        <!--      @toolbar-button-click="toolbarButtonClickEvent"-->
        <!--      下拉显示所有信息插槽-->
        <template #content="{ row }">
          <ul class="expand-wrapper">
            <li v-for="(item,index) in gridOptions.columns" v-show="item.field!==undefined ">
              <span style="font-weight: bold">{{ item.title + ':  ' }}</span>
              <span>{{ row[item.field] }}</span>
            </li>
          </ul>
        </template>
 
        <!--左边固定显示的插槽-->
        <template #button_slot="{ row }">
          <el-button @click="getTableRow(row,'edit')" link type="primary" size="small">编辑</el-button>
          <!--          <el-button @click="getTableRow(row,'delete')" link type="primary" size="small">删除</el-button>-->
          <!--          <el-button @click="cellClickEvent" link type="primary" size="small">详情</el-button>-->
        </template>
 
 
        <template #num1_filter="{ column, $panel }">
          <div>
            <div v-for="(option, index) in column.filters" :key="index">
              <input type="type" v-model="option.data" @input="changeFilterEvent($event, option, $panel)"/>
            </div>
          </div>
        </template>
      </vxe-grid>
 
 
      <!--      详情框 部分1-->
      <vxe-modal v-model="showDetails" title="查看详情" width="600" height="80%" :mask="false" :lock-view="false"
                 resize>
        <el-container>
          <el-header height="35px"
                     style="margin: 0;padding: 0">
 
            <el-input v-model="showCGDH" placeholder="采购单号" disabled>
              <template #prepend>采购单号:</template>
            </el-input>
          </el-header>
          <el-main>
            <template #default>
              <vxe-table
                  border="default"
                  auto-resize
                  show-overflow
                  max-height="400"
                  :row-config="{isHover: true}"
                  :show-header="false"
                  :sync-resize="showDetails"
                  :data="detailData"
 
              >
                <vxe-column field="label" width="30%" class-name="v-column-label"></vxe-column>
                <vxe-column field="value"></vxe-column>
              </vxe-table>
            </template>
          </el-main>
          <el-footer height="40px">
            <el-row>
              <el-col :offset="20" :span="4">
                <el-button
                    id="Sure"
                    type="primary"
                    @click="SureReturn"
                >确认退货
                </el-button>
              </el-col>
 
            </el-row>
          </el-footer>
        </el-container>
      </vxe-modal>
      <!--      详情框 部分1 结束-->
    </el-main>
  </el-container>
</template>
 
 
<script setup>
 
import {ref} from "vue";
import {reactive} from "vue";
import {useRouter} from 'vue-router'
import {Search} from "@element-plus/icons-vue";
import dayjs from "dayjs";
import {ElMessage, ElMessageBox} from "element-plus";
 
 
let router = useRouter()
const getTableRow = (row, type) => {
  switch (type) {
    case 'edit' : {
      //alert('我接收到子组件传送的编辑信息')
      // router.push({path: '/main/purchaseOrder/DetailsPurchaseOrder', query: {id: row.id}})
      break
    }
    case 'delete': {
 
 
      alert('我接收到子组件传送的删除信息' + row.id)
      break
    }
  }
}
 
const xGrid = ref()
 
const gridEvents = {
  toolbarButtonClick({code}) {
    const $grid = xGrid.value
    if ($grid) {
      switch (code) {
        case 'Sure': {
          if ($grid.getCheckboxRecords().length === 0) {
 
            MessageShow('请选择至少一条数据!', 'warning');
 
            return
          } else {
 
            MessageConfirmShow('确定', '您选择了' + $grid.getCheckboxRecords().length + '条数据!,是否确认退货?')
          }
          break
        }
        case 'Log': {
          MessageAlertShow('点击了退货记录!', '操作提示');
          break
        }
      }
    }
  },
  toolbarToolClick({code}) {
    const $grid = xGrid.value
    if ($grid) {
      switch (code) {
        case 'myPrint': {
          $grid.print()
          break
        }
      }
    }
  },
}
 
 
//查询按钮方法
const BtnSearchPurchaseOrder = () => {
 
  //开始时间,结束时间获取
  //MessageShow("开始时间"+datevalue._rawValue[0]+"\r\n结束时间\r\n"+datevalue._rawValue[1]);
 
  for (let i = 1; i < 6; i++) {
    const randomInt = Math.floor(Math.random() * 999) + 1000;//4位数随机数
    const randomSumInt = Math.floor(Math.random() * 99) + 10;//2位数随机数
    const randomOrderInt = Math.floor(Math.random() * 99) + 100;//3位数随机数
    const t = i % 2 === 0 ? 5 : 6;
    const s = i % 2 === 0 ? '入库' : i % 3 === 0 ? '退货' : '部分入库';
    const thdh = i % 2 === 0 ? '' : i % 3 === 0 ? 'THID' + randomOrderInt : '';
    const CGNo = 'NGCG231200' + randomOrderInt;//采购编号
    const wlNo = 'NGWL1000' + randomInt;
    const xh = 'NGXH' + randomSumInt;
    const wlmc = 'WLMC' + randomInt;
    const gys = '供应商' + randomSumInt;
    const xhdh = 'NG231200' + randomOrderInt;
    const w = i % 2 === 0 ? '3300' : i % 3 === 0 ? '3660' : i % 4 === 0 ? '2250' : '2580';
    const h = i % 2 === 0 ? '2440' : i % 3 === 0 ? '2440' : i % 4 === 0 ? '2000' : '2300';
    const dw = i % 2 === 0 ? '片' : i % 3 === 0 ? '平米' : i % 4 === 0 ? '包' : '吨';
    now.setDate(now.getDate() + 1);
    gridOptions.data.push({
      cgdh: CGNo,
      thdh: thdh,
      h: t,
      xh: xh,
      wlbh: wlNo,
      wlmc: wlmc,
      gys: gys,
      w: w,
      g: h,
      dw: dw,
      cgzt: s,
      rq: dayjs(now).format('YYYY-MM-DD'),
      yl: randomSumInt,
      sl: randomOrderInt,
      xsdh: xhdh,
      je: randomInt,
      6: '139xxxxxxxx',
 
    })
  }
 
}
 
 
//组件接收参数
const gridOptions = reactive({
  border: "full",//表格加边框
  keepSource: true,//保持源数据
  align: 'center',//文字居中
  stripe: true,//斑马纹
  rowConfig: {isCurrent: true, isHover: true, height: 50},//鼠标移动或选择高亮
  id: 'CustomerList',
  showFooter: true,//显示脚
  printConfig: {},
  importConfig: {},
  exportConfig: {},
  scrollY: {enabled: true},//开启虚拟滚动
  showOverflow: true,
  columnConfig: {
    resizable: true,
    useKey: true
  },
  filterConfig: {   //筛选配置项
    remote: true
  },
  customConfig: {
    storage: true
  },
  editConfig: {
    trigger: 'click',
    mode: 'row',
    showStatus: true
  },
  columns: [
    {type: 'expand', title: '', fixed: "left", slots: {content: 'content'}, width: 50},//详情
    {title: '操作', width: '8%', slots: {default: 'button_slot'}, fixed: "left"},
    {type: 'checkbox', fixed: "left", title: '', width: 50},
    {type: 'seq', fixed: "left", title: ' ', width: 50},
 
 
    {
      field: 'thdh',
      width: '10%',
      title: '退货单号',
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      sortable: true
    },
    {
      field: 'cgdh',
      width: '10%',
      title: '采购单号',
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      sortable: true
    },
    {field: 'cgzt', width: '10%', title: '状态', filters: [{data: ''}], slots: {filter: 'num1_filter'}, sortable: true},
    {
      field: 'gys',
      width: '10%',
      title: '供应商',
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      sortable: true
    },
    {
      field: 'wlbh',
      width: '10%',
      title: '物料编号',
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      sortable: true
    },
    {
      field: 'wlmc',
      width: '10%',
      title: '物料名称',
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      sortable: true
    },
    {field: 'w', width: '8%', title: '宽度', filters: [{data: ''}], slots: {filter: 'num1_filter'}, sortable: true},
    {field: 'g', width: '8%', title: '高度', filters: [{data: ''}], slots: {filter: 'num1_filter'}, sortable: true},
    {field: 'h', width: '8%', title: '厚度', filters: [{data: ''}], slots: {filter: 'num1_filter'}, sortable: true},
    {field: 'xh', width: '8%', title: '型号', filters: [{data: ''}], slots: {filter: 'num1_filter'}, sortable: true},
    {field: 'dw', width: '8%', title: '单位', filters: [{data: ''}], slots: {filter: 'num1_filter'}, sortable: true},
    {
      field: '6',
      width: '12%',
      title: '不含税单价',
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      sortable: true
    },
    {field: 'sl', width: '8%', title: '数量', filters: [{data: ''}], slots: {filter: 'num1_filter'}, sortable: true},
    {
      field: 'sl',
      width: '12%',
      title: '已采购数量',
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      sortable: true
    },
    {field: 'je', width: '8%', title: '金额', filters: [{data: ''}], slots: {filter: 'num1_filter'}, sortable: true},
    {
      field: 'je',
      width: '12%',
      title: '不含税金额',
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      sortable: true
    },
    {field: '6', width: '8%', title: '税率', filters: [{data: ''}], slots: {filter: 'num1_filter'}, sortable: true},
    {field: 'sl', width: '8%', title: '库存', filters: [{data: ''}], slots: {filter: 'num1_filter'}, sortable: true},
    {field: 'yl', width: '10%', title: '周用量', filters: [{data: ''}], slots: {filter: 'num1_filter'}, sortable: true},
    {field: 'yl', width: '10%', title: '月用量', filters: [{data: ''}], slots: {filter: 'num1_filter'}, sortable: true},
    {
      field: 'cgzt',
      width: '10%',
      title: '单据状态',
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      sortable: true
    },
    {
      field: 'xsdh',
      width: '10%',
      title: '销售单号',
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      sortable: true
    },
    {
      field: 'rq',
      width: '10%',
      title: '制单日期',
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      sortable: true
    },
    {field: '6', width: '10%', title: '制单人', filters: [{data: ''}], slots: {filter: 'num1_filter'}, sortable: true},
    {
      field: '6',
      width: '10%',
      title: '采购部门',
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      sortable: true
    },
    {
      field: '6',
      width: '10%',
      title: '采购组织',
      filters: [{data: ''}],
      slots: {filter: 'num1_filter'},
      sortable: true
    },
    {field: '6', width: '10%', title: '备注', filters: [{data: ''}], slots: {filter: 'num1_filter'}, sortable: true}
  ],//表头参数
  toolbarConfig: {
    buttons: [{type: 'text'}, {
      'name': '退货记录',
 
      'code': 'Log'
    },
      {
        'name': '确认退货',
        status: 'primary',
        'code': 'Sure'
      }],
    import: false,
    export: true,
    print: true,
    zoom: true,
    custom: true,
    style: 'paddling-left:10px'
  },//表头按钮
  data: [],//table body实际数据
  mergeFooterItems: [
    {row: 0, col: 0, rowspan: 1, colspan: 4}
  ],//合并脚
  footerMethod({columns, data}) {//页脚函数
    return [
      columns.map((column, columnIndex) => {
        if (columnIndex === 0) {
          return '合计:'
        }
        /* if (props.tableProp.footList.includes(column.field)) {
           return sumNum(data, column.field)
         }*/
        return ''
      })
    ]
  },
 
})
 
 
//详情框 部分2
const showCGDH = ref();
const showDetails = ref(false);
let detailData = [];
const cellClickEvent = ({row}) => {
  if (isQueryColumnId === false) {
    queryColumnId();
  }
 
  detailData = list.map(field => {
    return {label: queryColumnsTitle(field), value: row[field]}
  })
  showDetails.value = true;
  showCGDH.value = row['cgdh'];
}
 
//获取表列
let list = [];
let columnIndex = 4;//列标头从第几列开始的
let isQueryColumnId = false;
const queryColumnId = () => {
 
  while (columnIndex < gridOptions.columns.length) {
    list.push(gridOptions.columns[columnIndex].field);
    columnIndex++;
  }
  isQueryColumnId = true;
  return list;
}
 
//获取表列名
function queryColumnsTitle(cn) {
  let i = 0;
  while (i < gridOptions.columns.length + 1) {
    if (gridOptions.columns[i].field === cn) {
      return gridOptions.columns[i].title;
    }
    i++;
  }
}
 
// 详情框部分2 结束
 
const SureReturn = () => {
 
  MessageConfirmShow('退货', '是否确认退货?')
 
}
 
//详情框 部分2 结束
 
 
const now = new Date()
 
//时间快捷选择
const datevalue = ref('')
const shortcuts = [
  {
    text: '近一周',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
      return [start, end]
    },
  },
  {
    text: '近一个月',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
      return [start, end]
    },
  },
  {
    text: '近三个月',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
      return [start, end]
    },
  },
]
 
 
//页面逻辑代码执行
function logicExecute(type) {
  const $grid = xGrid.value
  switch (type) {
    case '确定':
      //多选退货逻辑代码TODO
      MessageShow('操作成功!', 'success');
      break;
    case '退货':
      //单退货逻辑代码TODO
      MessageShow('操作成功!', 'success');
      break;
    default:
      MessageShow('未知操作!', 'error');
      break;
  }
  return true;
}
 
 
//提示信息
//信息内容,显示方式,显示标题,类型
const MessageShow = (content, type = 'success') => {
  ElMessage({
    message: content,
    type: type,
    showClose: true,
  })
}
 
//操作确认类信息:操作类型,提示内容,提示标头,提示类型
const MessageConfirmShow = (czType, content, title = '操作确认提示', type = 'warning') => {
  ElMessageBox.confirm(
      content,
      title,
      {
        cancelButtonText: '取消',
        confirmButtonText: '确定',
        type: type,
        center: true,
      }
  )
      //点击了确定
      .then(() => {
 
        logicExecute(czType);
 
        return true;
      })
      //点击了取消
      .catch(() => {
        return false;
      })
}
 
//弹窗信息
const MessageAlertShow = (content, title, type = 'info') => {
 
  ElMessageBox.alert(content, title, {
    // 禁止自动对焦
    //autofocus: false,
    confirmButtonText: 'OK',
    /*callback: (action: Action) => {
      MessageShow(`action: ${action}`,type)
    },*/
  })
}
 
</script>
 
 
<style scoped>
:deep(.v-column-label div span) {
  font-weight: bold;
}
</style>