一、案例

1、uniapp记录请求用时

async postFunc(){
	//开始进行入库报工的业务
	let param = this.WareHouseBillListId+","+BatchSNQr+","+this.SiteID+","+this.QTY+","+this.ListLotCode;
	const result = await this.http.post('api/View_Ware_WareHBOutOfStore/submitOfR',JSON.stringify(param),true);
	resultText = result.msgContent
	if(result.success){
		uni.showToast({
			title: '出库成功,待回传ERP!',
			icon:'none',
			duration:2000
		})
		//新增回传ERP
		const startTime = Date.now(); // 记录开始时间
		try {
			//回传ERP
			const item = this.$refs.whCardRef.item;
			console.log('单据主键:', item.OutWareHouseBill_Id);
			const res = await this.sendWareBillInfoToERP(item.OutWareHouseBill_Id);
			
			const endTime = Date.now(); // 记录结束时间
			const duration = (endTime - startTime) / 1000; // 除以1000转秒
			
			if(res[0] == "Y"){
				uni.showToast({
					title: '单据已抛转ERP:SAP用时 '+duration.toFixed(1)+'秒',
					icon:'success',
					duration:3000
				})
			}else{
				uni.showToast({
					title: '回传失败: '+ res[1] +'SAP用时:' + duration.toFixed(1)+'秒',
					icon:'none',
					duration:4000
				})
			}
		} catch (error) {
			const endTime = Date.now(); // 记录结束时间
			const duration = (endTime - startTime) / 1000; // 除以1000转秒
			
			uni.showToast({
				title: '回传异常:'+error.message+'用时'+duration.toFixed(1)+' 秒',
				icon:'none',
				duration:3000
			})
		}
		
		this.IsSubmit = true;
	}else{
		uni.showToast({
			title:resultText,
			icon:'none',
			duration:2000
		})
	}
	if(this.MissionQTY <= 0){
		this.close()
	}
	
},
//回传ERP
async sendWareBillInfoToERP(billID) {
    const url = 'api/View_Ware_WareHBOutOfStore/sendWareBillInfoToERP?billID=' + billID;
    
    try {
        const result = await this.http.post(url, {}, true);
        const resultText = result.message;
        
        if (result.code == 200) {
            return ["Y"];
        } else {
            return ["N", resultText];
        }
    } catch (error) {
        return ["N", error.message];
    }
},
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐