调用方,要将调用方的this当作参数传进 回调方法中,在回调中 参数 即this
eg:
,checkCodeFun(code,self,callBack){
var that = this;
var code = code;
checkCode(that.$store.state.user.openId,{code: code,checkTypeValue:that.radioValue}).then((res) => {
let resp = res.data;
this.checkCodeRes.code = resp.code;
this.checkCodeRes.msg = resp.msg;
this.checkCodeRes.data.goodsName = resp.data.goodsName;
this.checkCodeRes.data.nowProcessedNum = resp.data.nowProcessedNum;
this.checkCodeRes.data.nowCompleteNum = resp.data.nowCompleteNum;
this.checkCodeRes.data.defectiveNum = resp.data.defectiveNum;
this.checkCodeRes.data.processName = resp.data.processName;
this.checkCodeRes.data.processKey = resp.data.processKey;
this.checkCodeRes.data.produceJobId = resp.data.produceJobId;
callBack(self,resp);
this.working(true);
}).catch((res) => {
uni.hideLoading();
console.log(8882)
console.error(res)
this.working(true);
})
}
var that = this;
that.checkCodeFun(code,that,function(self,data){
let that =self;
if(code.length>=8){//2位标识-5位序号-n位id
that.working(false);
if(data.code != 0){
that.addLog(1,data.msg);
return;
}
if(that.radioValue == 1){
uni.showLoading({
title:'提交中...'
})
scancodesubmit(that.$store.state.user.openId,{code: code}).then((res) => {
uni.hideLoading();
console.log(777)
console.log(res)
console.log(res.data)
let resp = res.data;
if(resp.code==0){
console.log(777.3)
that.addLog(1,resp.msg);
}else{
that.addLog(1,resp.msg);
}
that.working(true);
}).catch((res) => {
uni.hideLoading();
console.log(8882)
console.error(res)
that.working(true);
})
}
}else{
that.addLog(1,'非法条码:'+code);
}
})