项目开发小记: 相同货品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);

posted on 2018-03-30 11:17  LCFLY  阅读(337)  评论(0编辑  收藏  举报

导航