utils.js 22.6 KB
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 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788
/* eslint-disable no-plusplus,radix,prefer-destructuring */
/* 用于放公用方法 */
import moment from 'moment';
import lodash from 'lodash';
import { message, notification } from 'antd';
import { createContext } from 'react';

global.storeDropDownData = {};
global.storeStaticDropDownData = {};
// global.systemSettings = [];
// global.commonConst = [];
// global.dNetPrice = 6;
// global.dNetMoney = 6;
// global.sDateFormat = 'YYYY-MM-DD';
/*   日期控件显示格式   */
export const dateFormatA = 'YYYY-MM-DD HH:mm:ss';


/** 获取光标位置 */
export function getCursortPosition(obj) {
  let cursorIndex = 0;
  if (document.selection) {
    obj.focus();
    const range = document.selection.createRange();
    range.moveStart('character', -obj.value.length);
    cursorIndex = range.text.length;
  } else if (obj.selectionStart || obj.selectionStart === 0) {
    cursorIndex = obj.selectionStart;
  }
  return cursorIndex;
}

/* 为输入框聚焦 */
export function focus(id, e, currentRef = document) {
  const element = currentRef.querySelector(`#${id}`);
  if (element && !element.disabled && (element.localName === 'input' || element.localName === 'textarea')) {
    if (isNotEmptyObject(e)) {
      e.preventDefault();
    }
    element.focus();
    element.select();
    return true;
  }
  return false;
}

/**   判断是否是undefined   */
export function isUndefined(value) {
  return lodash.isUndefined(value);
}

/**   判断是否非undefined   */
export function isNotUndefined(value) {
  return !isUndefined(value);
}

/** 判断是否是为undefined或null */
export function isUndefinedNull(value) {
  return value === undefined || value === null;
}

/**   判断是否是空字符串   */
export function isEmptyStr(str) {
  return str === undefined || str === null || str.toString().trim() === '';
}

/**   判断是否是非空字符串   */
export function isNotEmptyStr(str) {
  return !isEmptyStr(str);
}

/**   判断是否是空数字   */
export function isEmptyNumber(num) {
  return num === undefined || num === '';
}

/**   判断是否是非空数字   */
export function isNotEmptyNumber(num) {
  return !isEmptyNumber(num);
}

/**   转换字符串为boolean   */
export function converStrToBoolean(str) {
  if (typeof str === 'boolean') {
    return str;
  }
  if (typeof str === 'string') {
    if (isNotEmptyStr(str) && str.toLocaleLowerCase() === 'true') {
      return true;
    }
  }
  return false;
}

/**   转换数字为boolean   */
export function converNumToBoolean(num) {
  if (typeof num === 'boolean') {
    return num;
  }
  if (typeof num === 'number') {
    if (isNotEmptyNumber(num) && num > 0) {
      return true;
    }
  }
  return false;
}

/**   转换数字字符串为boolean   */
export function converNumStrToBoolean(value) {
  if (typeof value === 'boolean') {
    return value;
  }
  if (typeof value === 'number') {
    if (isNotEmptyNumber(value) && value > 0) {
      return true;
    }
  }
  if (typeof value === 'string') {
    if (isNotEmptyStr(value) && value.toLocaleLowerCase() === 'true') {
      return true;
    }
  }
  return false;
}

/**   转换undefined为空字符串   */
export function strUndefinedToEmpty(str) {
  return isEmptyStr(str) ? '' : str;
}

/**   转换undefined为空对象   */
export function convertUndefinedToEmptyObject(obj) {
  return isEmptyObject(obj) ? {} : obj;
}

/**   转换undefined为空数组   */
export function convertUndefinedToEmptyArr(arr) {
  return isEmptyArr(arr) ? [] : arr;
}

/**   转换字符串为对象   */
export function convertStrToObj(str, defaultObj = {}) {
  let result = defaultObj;
  if (isEmptyStr(str)) {
    result = defaultObj;
  } else {
    try {
      result = JSON.parse(str);
    } catch (e) {
      try {
        result = JSON.parse(str.replace(/\r\n|\n|\r|\t/g, ' '));
      } catch (error) {
        console.log(`${str}JSON报错:`, e.message);
        result = defaultObj;
      }
    }
  }
  return result;
  // return isEmptyStr(str) && !isJSON(str) ? {} : JSON.parse(str);
}

/**   转换对象为字符串   */
export function convertObjToStr(obj) {
  return isEmptyObject(obj) ? '' : JSON.stringify(obj);
}

/**   创建随机数方法(最大值最小值创建)   */
export function getRandomByMinMax(min, max) {
  if (min >= max) {
    return 0;
  }
  return min + Math.round(Math.random() * (max - min));
}

/**   根据位数获取最小值   */
export function getMinByMum(mum) {
  if (mum <= 0 || mum === 1) {
    return 0;
  }
  let str = '1';
  for (let i = 1; i < mum; i++) {
    str += '0';
  }
  return Number.parseInt(str);
}

/**   根据位数获取最大值   */
export function getMaxByMum(mum) {
  let str = '';
  for (let i = 0; i < mum; i++) {
    str += '9';
  }
  return Number.parseInt(str);
}

/**   创建随机数方法(位数创建)   */
export function getRandomByNum(num) {
  return getRandomByMinMax(getMinByMum(num), getMaxByMum(num));
}

/**   创建主表id   */
export function createSid() {
  return Date.parse(new Date()).toString() + getRandomByNum(19);
}

/**   判断是否是空数组  (已废弃,请勿使用)  */
export function isEmptyArr(arr) {
  return arr === undefined || arr === null || arr.length === 0;
}

/**   判断是否是非空数组  (已废弃,请勿使用)  */
export function isNotEmptyArr(arr) {
  return !isEmptyArr(arr);
}

/**   判断是否是空数组   */
export function isEmptyArrNew(arr) {
  return Array.isArray(arr) && arr.length < 1;
}

/**   判断是否是非空数组   */
export function isNotEmptyArrNew(arr) {
  return Array.isArray(arr) && arr.length > 0;
}

/**   判断是否是空对象   */
export function isEmptyObject(obj) {
  return lodash.isEmpty(obj);
}

/**   判断是否是非空对象   */
export function isNotEmptyObject(obj) {
  return !lodash.isEmpty(obj);
}

/**   对象转数组   */
export function objectToArr(obj) {
  const arr = [];
  if (isNotEmptyObject(obj)) {
    for (const key of Object.keys(obj)) {
      const value = obj[key];
      arr.push({ value, sId: key });
    }
  }
  return arr;
}

/**   值是否为空  */
export function isEmpty(obj) {
  return obj === undefined || obj === null || obj === '';
}

/**   数组转对象   */
export function arrToObject(arr) {
  const obj = {};
  if (isNotEmptyArr(arr)) {
    for (const objEach of arr) {
      for (const key of objEach) {
        obj[key] = objEach[key];
      }
    }
  }
  return obj;
}

/**   转换boolean为是否显示   */
export function convertBooleanToDisplayBlock(ret) {
  return ret ? 'inline-block' : 'none';
}

/**   转换boolean为是否显示   */
export function convertBooleanToDisplay(ret) {
  return ret ? '' : 'none';
}

/**   转换字符串为数字   */
export function convertStrToNumber(str) {
  if (isNotEmptyStr(str) && typeof str === 'string') {
    const num = Number(str);
    return num;
  }
  return str;
}

/**   转换字符串为数字0   */
export function convertStrToNumber0(str) {
  if (typeof str === 'number') {
    return str;
  }
  if (isNotEmptyStr(str) && !isNaN(str)) {
    return Number(str);
  }
  return 0;
}

/**   转换字符串为数字undefined   */
export function convertStrToNumberUndefined(str) {
  if (typeof str === 'number') {
    return str;
  }
  if (isNotEmptyStr(str)) {
    return Number(str);
  }
  return undefined;
}

/**   转换数字为字符串   */
export function convertNumberToStr(num) {
  if (typeof num === 'string') {
    return num;
  }
  if (isNotEmptyNumber(num)) {
    return num.toString();
  }
  return '';
}

/**   转换日期控件格式   */
export function convertObjToMoment(obj, dateFormat) {
  if (isNotUndefined(obj) && obj !== null) {
    return moment(obj, dateFormat);
  }
  return null;
}

/**   转换日期控件格式(默认日期)   */
export function convertObjToMomentDefault(obj, dateFormat) {
  if (isNotUndefined(obj) && obj !== null) {
    return moment(obj, dateFormat);
  }
  return moment().format(dateFormat);
}

/** 是否是数字 */
export function isNum(value) {
  if (value === '') return false;
  value = convertStrToNumberUndefined(value);
  if (isNaN(value)) return false;
  return typeof value === 'number';
}

/** 是否不是数字 */
export function isNotNum(value) {
  return !isNum(value);
}

/**   创建新Tab标签Id   */
export function createNewTabId() {
  return new Date().getTime().toString();
}

/** 去除小数末尾0 */
export function parseFloatNum(value) {
  return parseFloat(value);
}

/** 去除小数末尾0 */
export function convertToNum(value) {
  return isNum(parseFloatNum(value)) ? parseFloatNum(value) : 0;
}

/** 转换成相应小数位的数字 */
export function convertFixNum(value, num) {
  const iFix = '10000000000'.substring(0, num + 1);
  return convertStrToNumber(Math.round(value * convertStrToNumber(iFix)) / convertStrToNumber(iFix));
}

/**   过滤非数字(n位小数)   */
export function filterDisNumberN(value, n) {
  if (typeof value === 'string' && isEmptyStr(value)) {
    return value;
  }
  let str = convertNumberToStr(value).replace(/[^\d.\d]/g, '');
  str += str.indexOf('.') < 0 ? '.000000000000000000' : '000000000000000000000';
  return convertStrToNumber(str).toFixed(n);
}

/** 不为数字转为1,为数字的去除小数末尾0 */
export function convertIsNotNumToNumber1(value) {
  if (isNum(value)) {
    return parseFloat(value) === 0 ? 1 : value;
  }
  return 1;
}

/** 空转0 */
export function isNull(value, defaultValue) {
  return isEmpty(value) ? defaultValue : value;
}

/** 空转0 */
export function nullIf(value, defaultValue) {
  return value === defaultValue ? undefined : value;
}

/**   对象循环赋值返回新对象{key: key}   */
export function returnObjValue(sAssignField) {
  const obj = {};
  const arrayObj = sAssignField.split(',');
  for (const child of arrayObj) {
    const childArray = child.split(':');
    obj[childArray[0]] = childArray[1];
  }
  return obj;
}

/**   对象是否存在某值   */
export function getObjKeyByValue(obj, value) {
  if (isNotEmptyObject(obj) && isNotEmptyStr(value)) {
    for (const key of Object.keys(obj)) {
      if (obj[key] === value) {
        return key;
      }
    }
  }
  return '';
}

export function getStoreStaticDropDownData(formId, fieldName) {
  if (global.storeStaticDropDownData[formId + fieldName]) {
    return global.storeStaticDropDownData[formId + fieldName];
  }

  const configData = global.storeDropDownData[formId] || {};
  const { formData } = configData;
  let staticDropDownData = {};
  if (formData && formData[0]) {
    const { gdsconfigformslave = [] } = formData[0];
    const iIndex = gdsconfigformslave.findIndex(item => item.sName === fieldName);
    if (iIndex !== -1) {
      let showDropDown = gdsconfigformslave[iIndex].showDropDown;
      if (showDropDown) {
        try {
          showDropDown = JSON.parse(showDropDown);
        } catch (error) {
          showDropDown = null;
        }
        if (showDropDown) {
          staticDropDownData = showDropDown;
        }
      }
    }
  }
  global.storeStaticDropDownData[formId + fieldName] = staticDropDownData;
  return staticDropDownData;
}

/**   获取存储下拉数据   */
export function getStoreDropDownData(formId, name, fieldName) {
  const allName = (fieldName === 'sCustomerId' || fieldName === 'sCustomerNo' || fieldName === 'sCustomerName' ||
  fieldName === 'sMaterialsId' || fieldName === 'sMaterialsNo' || fieldName === 'sMaterialsName' ||
  fieldName === 'sProcessId' || fieldName === 'sProcessNo' || fieldName === 'sProcessName' ||
  fieldName === 'sProductId' || fieldName === 'sProductNo' || fieldName === 'sProductName') ?
    fieldName : formId + name + fieldName;
  const dropDownData = global.storeDropDownData[allName];
  return dropDownData;
}

/**   存储下拉数据   */
export function setStoreDropDownData(formId, name, fieldName, dropDownData) {
  const allName = (fieldName === 'sCustomerId' || fieldName === 'sCustomerNo' || fieldName === 'sCustomerName' ||
  fieldName === 'sMaterialsId' || fieldName === 'sMaterialsNo' || fieldName === 'sMaterialsName' ||
  fieldName === 'sProcessId' || fieldName === 'sProcessNo' || fieldName === 'sProcessName' ||
  fieldName === 'sProductId' || fieldName === 'sProductNo' || fieldName === 'sProductName') ?
    fieldName : formId + name + fieldName;
  global.storeDropDownData[allName] = dropDownData;
  return true;
}

/**   存储下拉数据   */
export function clearStoreDropDownData() {
  global.storeDropDownData = {};
  return true;
}

/**   存储下拉数据   */
export function clearFormStoreDropDownData(formId) {
  for (const key of Object.keys(global.storeDropDownData)) {
    if (key.indexOf(formId) > -1) {
      global.storeDropDownData[key] = [];
    }
  }
  return true;
}

message.config({
  top: 20,
  duration: 3,
  maxCount: 5,
});

notification.config({
  placement: 'bottomRight',
  bottom: 50,
  duration: null,
  rtl: false,
});


/**   获取存储下拉数据   */
export function getNewToken(token) {
  if (token !== null && token !== undefined) {
    const newToken = token.replace(/\//g, '+').replace(/&/g, '==').replace(/ /g, 'E');
    return newToken;
  }
}

/**   判断是否为json字符串   */
export function isJSON(str) {
  if (typeof str === 'string') {
    try {
      const obj = JSON.parse(str);
      if (typeof obj === 'object' && obj) {
        return true;
      } else {
        return false;
      }
    } catch (e) {
      return false;
    }
  }
}

/**   数组生成tree   */
export function genTreeByArr(arr, idName, pidName) {
  const tempArr = JSON.parse(JSON.stringify(arr));
  const formatObj = tempArr.reduce((pre, cur) => {
    return { ...pre, [cur[idName]]: cur };
  }, {});
  const formatArray = tempArr.reduce((pre, cur) => {
    const pid = cur[pidName] !== '' ? cur[pidName] : '';
    const parent = pid ? formatObj[pid] : false;
    if (parent) {
      if (parent.children) {
        parent.children.push(cur);
      } else {
        parent.children = [cur];
      }
    } else {
      pre.push(cur);
    }
    return pre;
  }, []);
  return formatArray;
}

export function genTreeDataByArr(arr, idName, pidName) {
  /*  idName:sId, pidName: sFatherSlaveId */
  const sParentIdMap = {};
  if (isNotEmptyArr(arr)) {
    arr.forEach((item) => {
      const sOriginalId = item.sOriginalId;
      if (isNotEmptyObject(sOriginalId)) {
        sParentIdMap[sOriginalId] = item[idName];
      }
    });
    console.log('sParentIdMap', sParentIdMap);
    arr.forEach((item) => {
      const sFatherOldId = item[pidName];
      const sFatherSlaveIdNew = sParentIdMap[sFatherOldId];
      // const sFatherSlaveIdNew = sParentIdMap.get(item[pidName]);
      if (isEmptyObject(sFatherSlaveIdNew)) {
        item[pidName] = '';
      } else {
        item[pidName] = sFatherSlaveIdNew;
      }
    });
  }
  return arr;
}

/**   根据条件过滤出来数组生成tree   */
export function genTreeByFilterArr(arr, idName, pidName, selfKey, filterValue) {
  let tempArr = JSON.parse(JSON.stringify(arr));
  if (isNotEmptyObject(filterValue)) {
    tempArr = tempArr.filter(item => item[selfKey] === filterValue);
  }
  const formatObj = tempArr.reduce((pre, cur) => {
    return { ...pre, [cur[idName]]: cur };
  }, {});
  const formatArray = tempArr.reduce((pre, cur) => {
    const pid = cur[pidName] !== '' ? cur[pidName] : '';
    const parent = pid ? formatObj[pid] : false;
    if (parent) {
      if (parent.children) {
        parent.children.push(cur);
      } else {
        parent.children = [cur];
      }
    } else {
      pre.push(cur);
    }
    return pre;
  }, []);
  return formatArray;
}

/* 解决订单新增多个主产品时 数据层级错乱问题 处理方式为第一个层级形成后 第二个树形打造时 不处理已形成的树形数据 */
export function genTreeDataByArrSales(arr, idName, pidName) {
  /*  idName:sId, pidName: sFatherSlaveId */
  const sParentIdMap = {};
  if (isNotEmptyArr(arr)) {
    arr.forEach((item) => {
      const sOriginalId = item.sOriginalId;
      if (isNotEmptyObject(sOriginalId) && !item.bTreeFinish) {
        sParentIdMap[sOriginalId] = item[idName];
      }
    });
    arr.forEach((item) => {
      if (!item.bTreeFinish) {
        const sFatherOldId = item[pidName];
        const sFatherSlaveIdNew = sParentIdMap[sFatherOldId];
        // const sFatherSlaveIdNew = sParentIdMap.get(item[pidName]);
        if (isEmptyObject(sFatherSlaveIdNew)) {
          item[pidName] = '';
        } else {
          item[pidName] = sFatherSlaveIdNew;
        }
        item.bTreeFinish = true;
      }
    });
  }
  return arr;
}
/* 将部件、材料、工序的sSlaveId 均换成最新的 */
export function genSlaveNewId(arr, tableName, idName, oldName, baseObj) {
  /*  controlData, key, idName: 'sSlaveId', oldName:'sOriginalId', slaveRow */
  if (isNotEmptyArr(arr) && tableName !== 'slave') {
    const filterData = arr.filter(item => item[oldName] === baseObj[oldName]);
    if (isNotEmptyArr(filterData)) {
      filterData.forEach((item) => {
        item.sSlaveId = baseObj.sId;
        const index = arr.findIndex(child => child.sId === item.sId);
        if (index > -1) {
          arr[index] = item;
        }
      });
    }
  }
  return arr;
}


export const myContext = createContext(null);

export function reducer(state, action) {
  const [type, payload] = action;
  switch (type) {
    case 'saveState':
      return {
        ...state,
        ...payload,
      };
    default:
      return {
        ...state,
        ...payload,
      };
  }
}
// 将数组根据条件分组
export function groupBy(array, key) {
  return array.reduce((result, currentItem) => {
    // 使用 key 函数提取分组键
    const groupKey = key(currentItem);
    // 确保 result 对象中有对应分组的数组
    if (!result[groupKey]) {
      result[groupKey] = [];
    }

    // 将当前项添加到对应分组的数组中
    result[groupKey].push(currentItem);
    // console.log('result', result);
    return result;
  }, {});
}

/* 配置支持日期格式化, 接收日期,格式2个参数,返回格式化后的日期 */
export function getDate(date, dateFormat) {
  const result = moment(date).format(dateFormat);
  return result;
}

/* 根据表名返回选中行对象 */
export function getSelectedData(props, tableName) {
  const selectedRowKeys = props[`${tableName}SelectedRowKeys`] || [];
  let selectedDataIndex = -1;
  const tableData = props[`${tableName}Data`];
  if (isNotEmptyArr(tableData)) {
    if (isNotEmptyArr(selectedRowKeys)) {
      selectedDataIndex = tableData.findIndex(item => item.sId === selectedRowKeys[0]);
    } else {
      selectedDataIndex = 0;
    }
  }

  if (selectedDataIndex > -1) {
    return props[`${tableName}Data`][selectedDataIndex];
  } else {
    return {};
  }
}

/* 根据传入的类型 生成批次号的通用方法 */
export function getDefineNo(app, sModelsType, tableName, masterData, tableRow, tableConfig) {
  const models = tableName === 'materials' ? 'Materials' :
    sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('quotation/') || sModelsType.includes('productStock/') ? 'Product' : 'Materials';
  /* 只要tableRow中有sDefineNo字段 */
  let bHasDefineNo = 'sDefineNo' in tableRow;
  if (!bHasDefineNo && isNotEmptyObject(tableConfig)) {
    const iIndex = tableConfig.gdsconfigformslave.findIndex(item => item.sName === 'sDefineNo');
    if (iIndex > -1) {
      bHasDefineNo = true;
    }
  }
  if (bHasDefineNo) {
    if (models === 'Materials') {
      let iIndex = app.systemData.findIndex(item => item.sName === 'CbxMaterialsDefine');
      if (isNotEmptyObject(masterData) && (isNotEmptyObject(masterData?.sMinusSrcId) || isNotEmptyObject(masterData?.sMinusUsed))) {
        iIndex = -1;
      }
      if (iIndex > -1) {
        const sCbxMaterialsDefine = app.systemData[iIndex].sValue;
        if (sCbxMaterialsDefine === 'datenum') {
          tableRow.sDefineNo = moment(new Date()).format('YYYYMMDD');
        } else if (sCbxMaterialsDefine === 'datetimenum') {
          tableRow.sDefineNo = moment(new Date()).format('YYYYMMDDHHmm');
        } else if (sCbxMaterialsDefine === 'yearnum') {
          tableRow.sDefineNo = moment(new Date()).format('YYYY');
        } else if (sCbxMaterialsDefine === 'yearmonthnum') {
          tableRow.sDefineNo = moment(new Date()).format('YYYYMM');
        } else if (sCbxMaterialsDefine === 'worknum') {
          tableRow.sDefineNo = tableRow.sWorkOrderNo;
        } else if (sCbxMaterialsDefine === 'manuualno') {
          tableRow.sDefineNo = tableRow.sManualNo;
        } else if (sCbxMaterialsDefine === 'createnownum') { /* 批号根据生产日期+当前日期 */
          tableRow.sDefineNo = moment(tableRow.tProductionDate).format('YYYYMMDDHHmm') + moment(new Date()).format('YYYYMMDDHHmm');
        }
      }
    } else if (sModelsType === 'productStock/productInStore' || sModelsType === 'outside/outsideinstoreAll') { /* 成品入库、整单发外入库 */
      if (bHasDefineNo) {
        let iIndex = app.systemData.findIndex(item => item.sName === 'CbxProductDefine');
        if (isNotEmptyObject(masterData.sMinusSrcId) || isNotEmptyObject(masterData.sMinusUsed)) {
          iIndex = -1;
        }
        if (iIndex > -1) {
          const sCbxProductDefine = app.systemData[iIndex].sValue;
          if (sCbxProductDefine === 'datenum') {
            tableRow.sDefineNo = moment(new Date()).format('YYYYMMDD');
          } else if (sCbxProductDefine === 'datetimenum') {
            tableRow.sDefineNo = moment(new Date()).format('YYYYMMDDHHmm');
          } else if (sCbxProductDefine === 'yearnum') {
            tableRow.sDefineNo = moment(new Date()).format('YYYY');
          } else if (sCbxProductDefine === 'yearmonthnum') {
            tableRow.sDefineNo = moment(new Date()).format('YYYYMM');
          } else if (sCbxProductDefine === 'worknum') {
            tableRow.sDefineNo = tableRow.sWorkOrderNo;
          } else if (sCbxProductDefine === 'manuualno') {
            tableRow.sDefineNo = tableRow.sManualNo;
          } else if (sCbxProductDefine === 'worktimenum') { /* 批号根据工单号码+日期时间批号 */
            tableRow.sDefineNo = tableRow.sWorkOrderNo + moment(new Date()).format('YYYYMMDDHH');
          } else if (sCbxProductDefine === 'yearToDate') { /* 2259 批号根据工单制单日期年月日,年取两位 */
            tableRow.sDefineNo = moment(masterData.tCreateDate || new Date()).format('YYMMDD');
          }
        }
      }
    }
  }

  return tableRow;
}


// 获取选中数据index
export function getSelectedDataIndex(props, tableName) {
  const selectedRowKeys = props[`${tableName}SelectedRowKeys`] || [];

  let selectedDataIndex = -1;
  const tableData = props[`${tableName}Data`];
  if (isNotEmptyArr(tableData)) {
    if (isNotEmptyArr(selectedRowKeys)) {
      selectedDataIndex = tableData.findIndex(item => item.sId === selectedRowKeys[0]);
    } else {
      selectedDataIndex = 0;
    }
  }
  return selectedDataIndex;
}