diff --git a/src/filters/filter.js b/src/filters/filter.js index a4d895d..2f977eb 100644 --- a/src/filters/filter.js +++ b/src/filters/filter.js @@ -46,15 +46,19 @@ export function calcBMI(height, weight) { const bmiObj = {}; // 计算 BMI 指数 const bmi = weight / (realHeight * realHeight); - bmiObj.bmi = bmi; + bmiObj.bmi = bmi.toFixed(1); if (bmi < 18.5) { bmiObj.result = '体重过轻'; + bmiObj.color = '#2ea7e0'; } else if (bmi >= 18.5 && bmi < 24.9) { bmiObj.result = '正常体重'; + bmiObj.color = '#189b3b'; } else if (bmi >= 25 && bmi < 29.9) { bmiObj.result = '超重'; + bmiObj.color = '#ff5f8b'; } else { - bmiObj.result = '肥胖'; + bmiObj.color = '#189b3b'; + bmiObj.result = '暂无数据'; } return bmiObj; } diff --git a/src/views/insight/index.vue b/src/views/insight/index.vue index 7dc94f4..ff9c419 100644 --- a/src/views/insight/index.vue +++ b/src/views/insight/index.vue @@ -64,8 +64,8 @@

{{ bmi.result }}

更新 - +
{ xdata.push(item.key); ydata.push({ - value: item.value, + value: item.value == null ? 0 : item.value, label: { show: true }, @@ -1548,13 +1520,89 @@ export default { }); }); }, + // 获取用户信息 + getPersonInfo() { + let reqParams = { + personId: this.$store.getters.personId + }; + APIHealthUser.personInfo(reqParams) + .then(res => { + const data = res.data.data; + if (data) { + this.bmi.height = data.height; + this.bmi.weight = data.weight; + this.bmi.curHeight = data.height; + this.bmi.curWeight = data.weight; + const bmiResult = this.$calcBMI(data.height, data.weight); + this.bmi.value = bmiResult.bmi; + this.bmi.result = bmiResult.result; + this.personData = { ...data } + console.log("bmi信息", bmiResult); + } + }) + .catch(error => { + console.log('error', error); + this.showOverlay = false; + this.isPageShow = true; + }) + .finally(() => { + + }) + }, + // 更新用户信息 + updatePerson() { + let reqBody = { + ...this.personData + + }; + reqBody.height = Number(this.bmi.height); + reqBody.weight = Number(this.bmi.weight); + console.log('reqBody', reqBody); + ToastService.loading({ + message: '更新中' + }); + APIHealthUser.updatePerson(reqBody) + .then(res => { + ToastService.clear(); + console.log(res.data); + if (res.data.stateCode == 1) { + ToastService.success({ + message: '更新成功' + }); + setTimeout(() => { + this.getPersonInfo(); + }, 1000); + } else { + DialogService.confirm({ + title: res.data.message + }); + } + }) + .catch(e => { + ToastService.clear(); + DialogService.confirm({ + title: e.message || '服务器异常' + }); + }); + }, // 更新bmi onUpdateBmi() { // 打开输入弹窗 this.bmi.isBmiShow = true; }, onConfirmBmi() { - + if (isNull(this.bmi.height) || isNull(this.bmi.weight)) { + this.bmi.height = this.bmi.curHeight; + this.bmi.weight = this.bmi.curWeight; + return DialogService.confirm({ + title: '身高和体重不能为空' + }) + } + this.updatePerson(); + }, + onCancelBmi() { + this.bmi.height = this.bmi.curHeight; + this.bmi.weight = this.bmi.curWeight; } } }; diff --git a/src/views/insight/signsReport.vue b/src/views/insight/signsReport.vue index fa40d9a..732ce2a 100644 --- a/src/views/insight/signsReport.vue +++ b/src/views/insight/signsReport.vue @@ -158,12 +158,12 @@
-
+