22
schangxiang@126.com
2024-12-13 53243a336bb514d7ad7fc83b389a0331b2d87edc
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
// import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
import { ref } from "vue";
 
// dayjs.extend(utc);
export function formatUtcToData(data: string, formatString: string): string {
  return "";
  // return dayjs.utc(data).utcOffset(8).format(formatString);
}
// 保留3位小数
export function formatDecimalData(row: any, column: any): string {
  // console.log(row) //所有接口字段
  // console.log(column.label) //表头名称
  // console.log(Number(row[column.property]).toFixed(3)) //列的值
   let num = "-"
  if(Number(row[column.property])!=0 || Number(row[column.property])!=0.000){
    num = Number(row[column.property]).toFixed(3)
  }
  return num || row[column.property]
  // return Number(row[column.property]).toFixed(3) || row[column.property]
}
export function getSex(type: string) {
  if(type == '1') {
    return '男'
  }else {
    return '女'
  }
}
 
export function getTagType(status: number) {
  switch(status) {
    case 0:
      return 'success';
    case 1:
      return 'warning';
    case 2:
      return 'error'
    case 3:
      return 'info'
  }
}
 
export function getTagUseable(status: number) {
  switch(status) {
    case 0:
      return 'warning';
    case 1:
      return 'success';
  }
}
 
/**
 * 金融格式化
 * @param amount 金额stirng | number
 * @param precision 小数位数
 * @param unit 是否单单位
 * @returns 
 */
export function amountFormat(amount: string | number, precision: number, unit: boolean){
  if(amount =='')  {
    amount ='0'
    precision = precision > 0 && precision <= 20 ? precision : 2;
    amount =parseFloat((amount).replace(/[^\d.-]/g,"")).toFixed(precision)+""; 
  }
  let t ="";
  if(typeof amount === 'number') {
    amount = amount.toString();
  }
  const l = amount.split(".")[0].split("").reverse();
  let r = amount.split(".")[1] ? amount.split(".")[1] : '00';
  if(r.length == 1) {
    r += '0';
  }
  
  for(let i =0; i < l.length; i++){
      t += l[i]+((i +1)%3==0&&(i +1)!= l.length ?",":"");
  }
  if(unit){
    return t.split("").reverse().join("")+"."+ r +'元';
  }else{
    return t.split("").reverse().join("")+"."+ r;
  }
}
 
type Fun = () => any;
 
/**
 * 函数防抖
 * @param callback 触发的函数
 * @param delay  多长时间触发一次
 * @returns 
 */
export function debounce(callback: Fun, delay: number): Fun {
  let timer: any = null;
  return () => {
    if(timer) {
      clearTimeout(timer)
    }
    timer = setTimeout(() => {
      callback()
    },delay)
  }
}
 
 
/**
 * 函数节流
 * @param callback 
 * @param delay 
 * @returns 
 */
export function throttle(callback: Fun, delay: number): Fun {
  let flag = true;
  return () => {
    if(flag) {
      setTimeout(() => {
        callback()
        flag = true;
      },delay)
    }
    flag = false;
  }
}
 
/**
 * 二分法排序
 * @param arr 
 * @returns 
 */
export function sortord(arr: number[]): number[] {
  if(arr.length == 0) {
    return []
  }
 
  const centerIndex: number = Math.floor(arr.length / 2);
  const c: number = arr[centerIndex];
  const l: number[] = [];
  const r: number[] = [];
  for(let i=0;i<arr.length;i++) {
    if(arr[i] < c) {
      l.push(arr[i])
    }else {
      r.push(arr[i])
    }
  }
 
  return sortord(l).concat(c,sortord(r));
}
export function deepCopy(o: any) {
  if(['string','number','boolean','undefined'].includes(typeof o)) {
    return o;
  }
  if(Array.isArray(o)) {
    return [...o]
  }
  if(typeof o === 'object') {
    if(!o && o !== undefined && o !== '') {
      return null;
    }
    const newObj = {};
    Object.keys(o).forEach(key => {
      newObj[key] = deepCopy(o[key])
    })
    return newObj;
  }
 
}
 
export function getRouterPath(arr: any[]) {
  arr.map(item => {
    item.path = item.router;
    item.meta = {
      title: item.name,
      icon: item.icon
    }
    if(Array.isArray(item.children && item.children.length > 0)) {
      getRouterPath(item.children)
    }
 
    return item;
  })
}
 
export function getDate() {
  const date = new Date();
  //获取年
  const year = date.getFullYear();
  //获取月份
  let month: string | number = date.getMonth() + 1;
  month = month >= 10 ? month : '0'+ month;
  //日
  let day: string | number = date.getDate();
  day = day >= 10 ? day : '0' + day;
  return '' + year + month + day;
  
 
}
 
 
//时间加一天
export function addDate(dateC:any, days:any) {
  if (days == undefined || days == '') {
      days = 1;
  }
  const date = new Date(dateC);
  date.setDate(date.getDate() + days);
  const month = date.getMonth() + 1;
  const day = date.getDate();
  return date.getFullYear() + '-' + getFormatDate(month) + '-' + getFormatDate(day);
 
  function getFormatDate(arg:any) {
    if (arg == undefined || arg == '') {
        return '';
    }
  
    let re = arg + '';
    if (re.length < 2) {
        re = '0' + re;
    }
  
    return re;
  }
}
 
 //获取核销状态
 export function getHxTypeStatus(status: number,name?:any) {
  if(name){
    if(name.indexOf('中') !=-1 || name.indexOf('部分分拣') !=-1 || name.indexOf('部分核销') !=-1){
      return 'primary';
    }else if(name.indexOf('完成') !=-1 || name.indexOf('已全部') !=-1 || name.indexOf('已分拣') !=-1 || name.indexOf('全部分拣') !=-1 || name.indexOf('已下发') !=-1 || name == '归还'){
      return 'success';
    }else if(name.indexOf('删除') !=-1 || name.indexOf('撤销') !=-1){
      return 'info';
    }else{
      return 'warning';
    }
  }else{
    switch (status) {
      case 3:
        return "success";
      case 1:
        return "primary";
      case 2:
        return "info";
    }
    return "warning";
 
  }
  
}
 
export const statusEnumsQhbc = ref([
  {
      title: "订单件订单",
      value: 2
    },
    {
      title: "免费件订单",
      value: 3
    },
    {
      title: "手工件订单",
      value: 15
    },
    {
      title: "领用单订单",
      value: 4
    },
    {
      title: "借用单订单",
      value: 1
    },
  ]);
 
  
 
  //获取出库单状态 参数2:中文名称
export function getTypeStatus(status: number,name?:any) {
  if(name){
    if(name.indexOf('中') !=-1 || name.indexOf('部分') !=-1 || name.indexOf('部分核销') !=-1 || name.indexOf('部分收货') !=-1|| name.indexOf('归还中') !=-1|| name.indexOf('通过_未下发') !=-1|| name.indexOf('不需要复盘_生成报告') !=-1){
      return 'primary';
    }else if(name.indexOf('完成') !=-1 || name.indexOf('全部') !=-1 || name.indexOf('已分拣') !=-1 || name.indexOf('审核通过') !=-1 || name.indexOf('确认通过') !=-1 || name.indexOf('正常') !=-1 || name=='归还'|| name.indexOf('通过_已下发') !=-1|| name.indexOf('已盘点') !=-1|| name.indexOf('已复盘') !=-1|| name.indexOf('锁定解除') !=-1|| name.indexOf('已签收') !=-1){
      return 'success';
    }else if(name.indexOf('删除') !=-1 || name.indexOf('已取消') !=-1  || name.indexOf('撤销') !=-1 || name.indexOf('不通过') !=-1|| name.indexOf('驳回') !=-1){
      return 'info';
    } else if(name.indexOf('超时') !=-1 || name.indexOf('已关闭') !=-1){
      return 'danger';
    }else if(name.indexOf('未盘点') !=-1){
      return 'warning';
    }else{
      return 'warning';
    }
  }else{
    switch(status) {
        case 0:
            return 'warning';
        case 1:
            return 'primary';
        case 2:
            return 'success';
        case 5:
            return 'info';
    }
    return 'info';
  }
}
//获取出库单状态 
export function getTypeStatusForCommonOutOrder(status: number) {
    //这种类型都是3位数   0:新建 1:执行中 2:已完成
    switch(status) {
        case 0:
            return 'warning';
        case 1:
            return 'primary';
        case 2:
            return 'success';
    }
    return 'info';
}
//获取出库单状态 
export function getTypeStatusForCommonOutOrder2(status: number) {
  //这种类型都是3位数   1:新建 2:执行中 3:已完成
  switch(status) {
      case 1:
          return 'warning';
      case 2:
          return 'primary';
      case 3:
          return 'success';
  }
  return 'info';
}
 
//获取出库单状态字符
export function getStatusStr(status: number){
    switch(status) {
        case 0:
            return '新建';
        case 1:
            return '执行中';
        case 2:
            return '已完成';
        case 5:
            return '已删除';
            case 98:
              return '已作废';
            case 99:
              return '已撤销';
    }
    return '';
}
 
 
export function getStatusKcStr(status: number){
  switch(status) {
      case 0:
          return '未处理';
      case 1:
          return '处理中';
  }
  return '';
}
//DO单来源枚举
export const sourceEnum = ref([
  {
    title: "WMS",
    value: "0"
  },
  // {
  //   title: "WMS导入",
  //   value: "2"
  // },
  {
    title: "SAP",
    value: "1"
  },
]);
 
 
//单来源枚举
export  const boolEnum = ref([
  {
    title: "是",
    value: true
  },
  {
    title: "否",
    value: false
  }
]);
 
//获取到货单SAP收货状态 待发送=0, 发送完成=2,发送失败=1
export  const getSAPConfirmStatus = (status: number): string => {
  switch (status) {
    case 2:
    case 3:
      return "success";//发送完成=2
      case 0:
      case 99:
      return "warning";//待发送=0
    case 1:
      return "info";//发送失败=1
  }
 
  return "info";
};
 
  
//状态枚举
export  const statusEnumsFs = ref([
  {
    title: "待发送",
    value: "0"
  },
  {
    title: "发送失败",
    value: "1"
  },
  {
    title: "发送完成",
    value: "2"
  },
  {
    title: "强制完成",
    value: "3"
  },
  {
    title: "取消发送",
    value: "99"
  }
]);
 
 
export  const statusEnumsYwlx = ref([
  {
    title: "收货",
    value: "3"
  },
  {
    title: "撤销收货",
    value: "5"
  }
]);
 
export  const statusEnumsYwlxFh = ref([
  {
    title: "整单发货",
    value: "6"
  },
  {
    title: "发货",
    value: "2"
  }
]);
  //获取到货单SAP收货状态字符   待发送=0, 发送完成=2,发送失败=1
  export  const getSAPConfirmStatusStr = (status: number): string => {
    switch (status) {
      case 0:
        return "待发送";//待发送=0
      case 1:
        return "发送失败";//发送失败=1
      case 2:
        return "发送完成";//发送完成=2
             case 3:
        return "强制完成";
          case 99:
        return "取消发送";
    }
    return "";
  };
 
// 领用单 借用单 - 审核字样改为确认
  export const transferZw = (str?:string)=>{
    if(str?.indexOf('审核')!=-1){
      str = str?.replace('审核','确认')
    }
    return str
  }