wangxinhui
昨天 a8756c3526832332db4ef5685348d9b188c2bf2b
´úÂë¹ÜÀí/WMS/WIDESEA_WMSClient/src/extension/stock/stockView.js
@@ -1,4 +1,3 @@
//此js文件是用来自定义扩展业务代码,可以扩展一些自定义页面或者重新配置生成的代码
import { el } from "element-plus/es/locales.mjs";
@@ -54,36 +53,58 @@
            return str = list[0] == "" ? "无" : str;
          }
        }
    if (column.field == 'materielInfo') {
    const today = new Date()
    column.formatter = (row) => {
        if (row.details.length > 0) {
            const today = new Date();
            const closestDate = row.details
                .map(x => {
                    const date = new Date(x.effectiveDate);
                    const diffInDays = Math.ceil((date - today) / (1000 * 60 * 60 * 24)); // æ”¹ä¸ºè®¡ç®—剩余天数
                    return { date, diffInDays };
                })
                .reduce((closest, current) => (current.diffInDays < closest.diffInDays ? current : closest))
                .date;
        if (column.field == 'materielInfo') {
        const today = new Date()
        column.formatter = (row) => {
            if (row.details.length > 0) {
                const today = new Date();
                const closestDate = row.details
                    .map(x => {
                        const date = new Date(x.effectiveDate);
                        const diffInDays = Math.ceil((date - today) / (1000 * 60 * 60 * 24)); // æ”¹ä¸ºè®¡ç®—剩余天数
                        return { date, diffInDays };
                    })
                    .reduce((closest, current) => (current.diffInDays < closest.diffInDays ? current : closest))
                    .date;
            const daysRemaining = Math.ceil((closestDate - today) / (1000 * 60 * 60 * 24));
            row.expiryDays = daysRemaining;
            if (daysRemaining <= 0) {
                return '<span style="color:rgb(30, 27, 27)">无保质期</span>';
                const daysRemaining = Math.ceil((closestDate - today) / (1000 * 60 * 60 * 24));
                row.expiryDays = daysRemaining;
                if (daysRemaining <= 0) {
                    return '<span style="color:rgb(30, 27, 27)">无保质期</span>';
                } else {
                    return '<span style="color: #F56C6C">' + daysRemaining + "天" + '</span>';
                }
            } else {
                return '<span style="color: #F56C6C">' + daysRemaining + "天" + '</span>';
                row.expiryDays = null;
                return '<span style="color:rgb(24, 18, 18)">无保质期</span>';
            }
        } else {
            row.expiryDays = null;
            return '<span style="color:rgb(24, 18, 18)">无保质期</span>';
        }
    }
        }
      }
      if (column.field == 'inventoryage') {
          const today = new Date()
          column.formatter = (row) => {
              if (row.details.length > 0) {
                  const closestDate = row.details
                      .map(x => {
                          const date = new Date(x.createDate);
                          const ageInDays = Math.ceil((today - date) / (1000 * 60 * 60 * 24));
                          return { date, ageInDays };
                      })
                      .reduce((closest, current) => (current.ageInDays < closest.ageInDays ? current : closest))
                      .date;
                  const inventoryAge = Math.ceil((today - closestDate) / (1000 * 60 * 60 * 24));
                  row.inventoryAge = inventoryAge;
                  return `${inventoryAge} å¤©`;
              }
              // å¦‚果没有明细,返回空或提示信息
              return '-';
          }
        }
        if (column.field == 'sumStock') {
          column.formatter = (row) => {
@@ -93,9 +114,9 @@
                .map(x => {
                  sum += (x.stockQuantity)
                })
              return '<span style="color: #F56C6C">' + sum.toFixed(3) + row.details[0].unit + '</span>';
              return '<span style="color: rgb(24, 18, 18)">' + sum.toFixed(3) + row.details[0].unit + '</span>';
            } else {
              return '<span style="color: #F56C6C">' + "1个" + '</span>';
              return '<span style="color: rgb(24, 18, 18)">' + "1个" + '</span>';
            }
          }
@@ -103,28 +124,17 @@
      })
      this.columns.forEach((column) => {
        column.cellStyle = (row) => {
        // åªå¤„理有保质期数据的情况
        if (row.expiryDays !== null && row.expiryDays !== undefined) {
            if (row.expiryDays <= 0) {
                return { background: 'red' }; // çº¢è‰²èƒŒæ™¯ï¼ˆå·²è¿‡æœŸï¼‰
            } else if (row.expiryDays <= 30) {
                return { background: 'yellow' }; // é»„色背景(临期)
          if (row.expirationlabel !== undefined && row.expirationlabel !== null) {
            if (row.expirationlabel === 2) {
              return { background: 'yellow' };
            } else if (row.expirationlabel === 3) {
              return { background: '#ffc0cb' };
            }
        }
        return {}; // é»˜è®¤æ— èƒŒæ™¯è‰²
    };
          }
          return {};
        };
      });
        //如果根据行的某个值设置整行颜色
        //设置整行背景颜色
        // x.cellStyle = (row, rowIndex, columnIndex) => {
        //   if (row.ProductCode == '10044464880643') {
        //     return { background: '#ddecfd' };
        //   }
        // };
        });
    },
    onInited() {
      //框架初始化配置后
@@ -172,4 +182,4 @@
    }
  }
};
export default extension;
export default extension;