Commit 3445931e by 姜雷

调整请求逻辑

parent 11e46672
......@@ -62,7 +62,6 @@ class Index extends Component {
componentWillMount() {
this.loginHandle().then(() => {
const { userinfo } = this.props;
let queryArr = Object.keys(this.$router.params);
console.log(this.$router.params);
......@@ -70,22 +69,10 @@ class Index extends Component {
console.log('scene:', scene);
if (scene) {
Taro.showLoading();
let entity = this.getDeviceEntity(scene);
if (entity) {
getDeviceConfig({
customerId: userinfo.customerId,
...entity,
})
.then(res => {
console.log(res);
})
.catch(err => {
console.error(err);
Taro.showToast({
title: err.msg || '设备码有误',
icon: 'none',
});
});
this.getDeviceConfigHandle(entity);
}
}
});
......@@ -119,45 +106,19 @@ class Index extends Component {
}
scanHandle() {
const { userinfo, updateDeviceData, updatePayData } = this.props;
Taro.scanCode({
onlyFromCamera: true,
scanType: ['qrCode'],
})
.then(res => {
console.log(res);
const { path, result } = res;
if (path) {
let queryArr = path.split('?');
let queryStr = queryArr.length >= 2 ? queryArr[1] : '';
console.log(result, queryArr, queryStr);
const { serviceId, equipmentNum } = this.getDeviceEntity(queryStr);
getDeviceConfig({
customerId: userinfo.customerId,
equipmentNum: equipmentNum,
serviceId: serviceId,
})
.then(res => {
console.log(res);
const { deviceInfoResponse, prepayConfigs } = res;
if (deviceInfoResponse.isUsed) {
console.log('设备使用中');
return;
}
deviceInfoResponse && updateDeviceData(deviceInfoResponse);
prepayConfigs && updatePayData(prepayConfigs);
Taro.navigateTo({
url: '/pages/pay/pay',
});
})
.catch(err => {
console.error(err);
Taro.showToast({
title: err.msg || '请扫描正确的设备码',
icon: 'none',
});
});
const entity = this.getDeviceEntity(queryStr);
this.getDeviceConfigHandle(entity);
} else {
Taro.showToast({
title: '请扫描正确的设备码',
......@@ -170,6 +131,37 @@ class Index extends Component {
});
}
getDeviceConfigHandle({ equipmentNum, serviceId }: DeviceEntity) {
Taro.showLoading();
const { userinfo, updateDeviceData, updatePayData } = this.props;
return getDeviceConfig({
customerId: userinfo.customerId,
equipmentNum: equipmentNum,
serviceId: serviceId,
})
.then(res => {
Taro.hideLoading();
console.log(res);
const { deviceInfoResponse, prepayConfigs } = res;
if (deviceInfoResponse.isUsed) {
console.log('设备使用中');
return;
}
deviceInfoResponse && updateDeviceData(deviceInfoResponse);
prepayConfigs && updatePayData(prepayConfigs);
Taro.navigateTo({
url: '/pages/pay/pay',
});
})
.catch(err => {
console.error(err);
Taro.showToast({
title: err.msg || '请扫描正确的设备码',
icon: 'none',
});
});
}
getUserInfoHandle(res) {
console.log(res);
const { detail } = res;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment