zoukankan      html  css  js  c++  java
  • 项目开发小记: 相同货品ID 请求拿到不同批次号数据 赋值给获取ID的数据数组

    const serialNoData = [];
    return new Promise( async (resolve, reject) => {
                            
        let _batchSerialNos;
        try{
            _batchSerialNos = await this.$kgw.getBatchGetSerialNo({
               goodsId: goodsId
            });
            _batchSerialNos.forEach((item,index) => {
               if(!serialNoData[item.goodsId]){
                     serialNoData[item.goodsId] = [item];
                 }else{
                     serialNoData[item.goodsId].push(item);
                 }
           })
    
                 resolve(serialNoData);
           } catch(err){
                 reject(false)
           }
                            
    });

    将拿到的数据将货品ID 作为键存起开作为一个HASH 如果没有存在当前货品ID就直接赋值,如果存在就PUSH进当前货品ID对应的数组中

    
    
    _batchSerialNo && turnDatas.forEach((goodsItem,index) => {

    if
    (_batchSerialNo[goodsItem.goodsId] && (goodsItem.isOnBatch || goodsItem.proIsOnBatch)) { this.$set(goodsItem,'batchNo',_batchSerialNo[goodsItem.goodsId][0].serialNo) this.$set(goodsItem,'expireTime',_batchSerialNo[goodsItem.goodsId][0].expireDate) this.$set(goodsItem,'isCanAlter',_batchSerialNo[goodsItem.goodsId][0].isCanAlter) this.$set(goodsItem,'produceTime',this.$kgw.$DC.formatDate()) const start = new Date().getTime(),     end = new Date(_batchSerialNo[goodsItem.goodsId][0].expireDate).getTime(); this.$set(goodsItem,'intervalTime',end - start) batchSerialNo[goodsItem.goodsId].splice(0, 1); }

    });

    遍历数组根据hash  赋值 赋值每次都赋值index == 0的数据,或者最后赋值数组length-1,赋值之后将货品ID对应的数组,根据赋值的index 删除,splice(index,1);

  • 相关阅读:
    kubernetes架构部署
    GitLab+Jenkins+Ansible
    python之字典方法
    Python之列表方法
    python之字符串方法
    Python编写从ZabbixAPI获取信息
    Django基础
    扫描某个包下所有的类,输出所有使用了特定注解的类的注解值
    日志切面和统一异常处理
    Mybatis动态排序问题
  • 原文地址:https://www.cnblogs.com/lcf1314/p/8675166.html
Copyright © 2011-2022 走看看