// 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
|
}
|