bodyFatRatio.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <template>
  2. <view class="container">
  3. <view class="navigation-bar">体脂率</view>
  4. <view class="back" @click="onBack(0, $event)">
  5. <image src="/static/backArrow.png" mode="aspectFit" style="width:100%"></image>
  6. </view>
  7. <view class="blue" @click="onHelp(0, $event)">
  8. <image src="/static/home/blue.png" mode="aspectFit" style="width:100%"></image>
  9. </view>
  10. <view class="content">
  11. <!-- <text class="result-area">{{result}}</text> -->
  12. <view class="result-area">
  13. <view class="border">
  14. <image class="item-logo" src="../../static/home/bodyFatRatioLogo.png" mode=""></image>
  15. <view class="">
  16. {{result1}}
  17. </view>
  18. <view class="">
  19. {{result2}}
  20. </view>
  21. <!-- <view class="">
  22. 脂肪总重量/体脂率
  23. </view> -->
  24. </view>
  25. </view>
  26. <!-- <button class="help" @click="onHelp(0, $event)">宁哥笔记</button> -->
  27. <view class="input-area">
  28. <view class="waistline">
  29. <view class="input-title">腰围 : </view>
  30. <input class="input" type="number" placeholder="请输入腰围" v-model="waistline" />
  31. <text class="Company">厘米</text>
  32. </view>
  33. <view class="weight">
  34. <view class="input-title">体重 : </view>
  35. <input class="input" type="number" placeholder="请输入体重" v-model="weight" />
  36. <text class="Company">公斤</text>
  37. </view>
  38. </view>
  39. <button class="confirm" @click="onClick(0, $event)">确定</button>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. export default {
  45. data() {
  46. return {
  47. waistline:-1,
  48. weight:-1,
  49. result1:'',
  50. result2:'',
  51. }
  52. },
  53. onLoad() {
  54. this.waistline = 0;
  55. this.weight = 0;
  56. // console.log('waistline=',getApp().globalData.waistline);
  57. // console.log('weight=',getApp().globalData.weight);
  58. if(getApp().globalData.waistline != undefined)
  59. {
  60. this.waistline = getApp().globalData.waistline;
  61. }
  62. if(getApp().globalData.weight != undefined)
  63. {
  64. this.weight = getApp().globalData.weight;
  65. }
  66. },
  67. methods: {
  68. onBack: function(id,e) {
  69. //uni.navigateBack()//默认delta:1
  70. uni.navigateBack({
  71. delta:1,//返回层数,2则上上页
  72. })
  73. },
  74. onHelp: function(id,e) {
  75. uni.navigateTo({
  76. url: '/pages/bodyFatRatio/help',
  77. animationType: 'slide-in-left',
  78. animationDuration: 2000,
  79. success: res => {},
  80. fail: () => {},
  81. complete: () => {}
  82. });
  83. },
  84. onClick: function(id,e) {
  85. if(this.heartRate != -1 && this.age != -1)
  86. {
  87. getApp().globalData.waistline = this.waistline;
  88. getApp().globalData.weight = this.weight;
  89. //身体脂肪总重量(单位:千克)
  90. let fatWeight = -1;
  91. //体脂率=(身体脂肪总量÷体重)
  92. let fatRate = -1;
  93. // if(getApp().globalData.gender)
  94. // {
  95. // fatWeight = this.waistline - (this.weight*0.082+34.89);
  96. // fatRate = fatWeight/this.weight * 100;
  97. // }
  98. // else
  99. // {
  100. // fatWeight = this.waistline - (this.weight*0.082+44.74);
  101. // fatRate = fatWeight/this.weight * 100;
  102. // }
  103. if(getApp().globalData.gender)
  104. {//男
  105. fatWeight = (Number(this.waistline*0.74) - Number(this.weight*0.082+44.74));
  106. fatRate = fatWeight/this.weight* 100;
  107. }
  108. else
  109. {//女
  110. fatWeight = (Number(this.waistline*0.74) - Number(this.weight*0.082+34.89));
  111. fatRate = fatWeight/this.weight * 100;
  112. }
  113. console.log('Number(this.waistline*0.74)=',Number(this.waistline*0.74))
  114. console.log('Number(this.weight*0.082+34.89)=',Number(this.weight*0.082+34.89));
  115. console.log('fatWeight=',fatWeight);
  116. console.log('fatRate=',fatRate);
  117. // this.result = '身体脂肪总重量: '+ Math.round(fatWeight) + '公斤\n' + '体脂率: '+ Math.round(fatRate*100)/100+'%';
  118. this.result1 = '身体脂肪总重量: '+ Math.round(fatWeight) + '公斤';
  119. this.result2 = '体脂率: '+ Math.round(fatRate*100)/100+'%';
  120. // this.result = '你的最低有氧心率: '+ Math.round(lowestHeartRate) + '(次/分)\n' + '最高有氧心率: '+ Math.round(highestHeartRate)+ '(次/分)';
  121. getApp().globalData.fatWeight = this.fatWeight;
  122. getApp().globalData.fatRate = this.fatRate;
  123. }
  124. else
  125. {
  126. switch (id)
  127. {
  128. case 0:
  129. alert('请输入体重');
  130. break;
  131. case 1:
  132. alert('请输入身高');
  133. break;
  134. case 2:
  135. alert('请输入年龄');
  136. break;
  137. default:
  138. break;
  139. }
  140. }
  141. },
  142. }
  143. }
  144. </script>
  145. <style lang="scss">
  146. .container {
  147. display: flex;
  148. flex-direction: column;
  149. align-items: center;
  150. justify-content: center;
  151. width:100%;
  152. height: 100vh;
  153. }
  154. .navigation-bar
  155. {
  156. display: flex;
  157. align-items: center;
  158. justify-content: center;
  159. width: 100%;
  160. height: 8%;
  161. font-weight: 700;
  162. color: white;
  163. font-size: 37rpx;
  164. background-color: #C9C7AF;
  165. }
  166. .item-logo
  167. {
  168. z-index: 4;
  169. height: 21%;
  170. width: 15%;
  171. // margin: 1%;
  172. }
  173. .back{
  174. position: absolute;
  175. display: flex;
  176. align-items: center;
  177. justify-content: center;
  178. width: 3%;
  179. height: 3%;
  180. top: 2%;
  181. left: 3%;
  182. //testing
  183. // border: 1px solid rgb(255,0,0);
  184. }
  185. .blue{
  186. position: absolute;
  187. display: flex;
  188. align-items: center;
  189. justify-content: center;
  190. width: 7%;
  191. height: 7%;
  192. top: -1%;
  193. right: 3%;
  194. }
  195. .content{
  196. display: flex;
  197. flex-direction: column;
  198. align-items: center;
  199. justify-content: center;
  200. width:100%;
  201. height:100%;
  202. }
  203. .result-area{
  204. display: flex;
  205. align-items: center;
  206. justify-content: center;
  207. width:95%;
  208. height:30%;
  209. margin: 1%;
  210. border-radius: 25rpx;
  211. background-color: #C9C7AF;
  212. text-align: center;
  213. font-size: 44rpx;
  214. font-weight: 700;
  215. color: #7B784E;
  216. image{
  217. margin-top: 10%;
  218. }
  219. .border{
  220. border: 4rpx solid #F4F4F4;
  221. height: 90%;
  222. width: 90%;
  223. border-radius: 25rpx;
  224. view{
  225. margin-top: 5%;
  226. }
  227. }
  228. }
  229. .help{
  230. color: azure;
  231. background-color: rgb(0,0,0);
  232. }
  233. .input-area{
  234. // display: flex;
  235. flex-direction: column;
  236. align-items: center;
  237. justify-content: center;
  238. width:95%;
  239. height:60%;
  240. margin: 1%;
  241. font-size: 40rpx;
  242. font-weight: bold;
  243. .waistline{
  244. display: flex;
  245. flex-direction: row;
  246. align-items: center;
  247. justify-content: center;
  248. width:100%;
  249. height:20%;
  250. margin: 1%;
  251. border-radius: 25rpx;
  252. background: #FBF0EA;
  253. input{
  254. background: #F5DACB;
  255. }
  256. }
  257. .weight{
  258. display: flex;
  259. flex-direction: row;
  260. align-items: center;
  261. justify-content: center;
  262. width:100%;
  263. height:20%;
  264. margin-top: 3%;
  265. border-radius: 25rpx;
  266. background: #FEEBEA;
  267. input{
  268. background: #FBCDCC;
  269. }
  270. }
  271. .input-title{
  272. //testing
  273. // border: 1px solid rgb(255,0,0);
  274. }
  275. .input{
  276. display: flex;
  277. justify-content: center;
  278. align-items: center;
  279. background: #F4F4F4;
  280. border-radius: 4upx;
  281. height: 70upx;
  282. font-size: 28upx;
  283. line-height: 70upx;
  284. font-family: PingFang SC;
  285. font-weight: 500;
  286. color: #848484;
  287. text-align:center;
  288. margin: 1%;
  289. width: 75%;
  290. height: 120rpx;
  291. background: #D8D7C5;
  292. border-radius: 20rpx;
  293. font-size: 46rpx;
  294. }
  295. }
  296. .confirm{
  297. display: flex;
  298. flex-direction: column;
  299. align-items: center;
  300. justify-content: center;
  301. width:95%;
  302. height:7%;
  303. margin: 1%;
  304. background: #C9C7AF;
  305. border-radius: 24rpx;
  306. font-size: 49rpx;
  307. font-weight: bold;
  308. color: #7B784E;
  309. }
  310. .Company{
  311. position: absolute;
  312. right: 13%;
  313. }
  314. </style>