Commit 3445931e by 姜雷

调整请求逻辑

parent 11e46672
...@@ -62,7 +62,6 @@ class Index extends Component { ...@@ -62,7 +62,6 @@ class Index extends Component {
componentWillMount() { componentWillMount() {
this.loginHandle().then(() => { this.loginHandle().then(() => {
const { userinfo } = this.props;
let queryArr = Object.keys(this.$router.params); let queryArr = Object.keys(this.$router.params);
console.log(this.$router.params); console.log(this.$router.params);
...@@ -70,22 +69,10 @@ class Index extends Component { ...@@ -70,22 +69,10 @@ class Index extends Component {
console.log('scene:', scene); console.log('scene:', scene);
if (scene) { if (scene) {
Taro.showLoading();
let entity = this.getDeviceEntity(scene); let entity = this.getDeviceEntity(scene);
if (entity) { if (entity) {
getDeviceConfig({ this.getDeviceConfigHandle(entity);
customerId: userinfo.customerId,
...entity,
})
.then(res => {
console.log(res);
})
.catch(err => {
console.error(err);
Taro.showToast({
title: err.msg || '设备码有误',
icon: 'none',
});
});
} }
} }
}); });
...@@ -119,45 +106,19 @@ class Index extends Component { ...@@ -119,45 +106,19 @@ class Index extends Component {
} }
scanHandle() { scanHandle() {
const { userinfo, updateDeviceData, updatePayData } = this.props;
Taro.scanCode({ Taro.scanCode({
onlyFromCamera: true, onlyFromCamera: true,
scanType: ['qrCode'], scanType: ['qrCode'],
}) })
.then(res => { .then(res => {
console.log(res);
const { path, result } = res; const { path, result } = res;
if (path) { if (path) {
let queryArr = path.split('?'); let queryArr = path.split('?');
let queryStr = queryArr.length >= 2 ? queryArr[1] : ''; let queryStr = queryArr.length >= 2 ? queryArr[1] : '';
console.log(result, queryArr, queryStr); console.log(result, queryArr, queryStr);
const { serviceId, equipmentNum } = this.getDeviceEntity(queryStr); const entity = this.getDeviceEntity(queryStr);
this.getDeviceConfigHandle(entity);
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',
});
});
} else { } else {
Taro.showToast({ Taro.showToast({
title: '请扫描正确的设备码', title: '请扫描正确的设备码',
...@@ -170,6 +131,37 @@ class Index extends Component { ...@@ -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) { getUserInfoHandle(res) {
console.log(res); console.log(res);
const { detail } = 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