bodyFatRatio.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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="content">
  8. <text class="result-area">{{result}}</text>
  9. <button class="help" @click="onHelp(0, $event)">宁哥笔记</button>
  10. <view class="input-area">
  11. <view class="waistline">
  12. <view class="input-title">腰围 : </view>
  13. <input class="input" type="number" placeholder="请输入腰围" v-model="waistline" />
  14. </view>
  15. <view class="weight">
  16. <view class="input-title">体重 : </view>
  17. <input class="input" type="number" placeholder="请输入体重" v-model="weight" />
  18. </view>
  19. </view>
  20. <button class="confirm" @click="onClick(0, $event)">确定</button>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. data() {
  27. return {
  28. waistline:-1,
  29. weight:-1,
  30. result:'',
  31. }
  32. },
  33. onLoad() {
  34. this.waistline = 0;
  35. this.weight = 0;
  36. // console.log('waistline=',getApp().globalData.waistline);
  37. // console.log('weight=',getApp().globalData.weight);
  38. if(getApp().globalData.waistline != undefined)
  39. {
  40. this.waistline = getApp().globalData.waistline;
  41. }
  42. if(getApp().globalData.weight != undefined)
  43. {
  44. this.weight = getApp().globalData.weight;
  45. }
  46. },
  47. methods: {
  48. onBack: function(id,e) {
  49. //uni.navigateBack()//默认delta:1
  50. uni.navigateBack({
  51. delta:1,//返回层数,2则上上页
  52. })
  53. },
  54. onHelp: function(id,e) {
  55. uni.navigateTo({
  56. url: '/pages/bodyFatRatio/help',
  57. animationType: 'slide-in-left',
  58. animationDuration: 2000,
  59. success: res => {},
  60. fail: () => {},
  61. complete: () => {}
  62. });
  63. },
  64. onClick: function(id,e) {
  65. if(this.heartRate != -1 && this.age != -1)
  66. {
  67. getApp().globalData.waistline = this.waistline;
  68. getApp().globalData.weight = this.weight;
  69. //身体脂肪总重量(单位:千克)
  70. let fatWeight = -1;
  71. //体脂率=(身体脂肪总量÷体重)
  72. let fatRate = -1;
  73. if(getApp().globalData.gender)
  74. {
  75. fatWeight = this.waistline - (this.weight*0.082+34.89);
  76. fatRate = fatWeight/this.weight * 100;
  77. }
  78. else
  79. {
  80. fatWeight = this.waistline - (this.weight*0.082+44.74);
  81. fatRate = fatWeight/this.weight * 100;
  82. }
  83. this.result = '身体脂肪总重量: '+ Math.round(fatWeight) + '千克\n' + '体脂率: '+ Math.round(fatRate)+'%';
  84. getApp().globalData.fatWeight = this.fatWeight;
  85. getApp().globalData.fatRate = this.fatRate;
  86. }
  87. else
  88. {
  89. switch (id)
  90. {
  91. case 0:
  92. alert('请输入体重');
  93. break;
  94. case 1:
  95. alert('请输入身高');
  96. break;
  97. case 2:
  98. alert('请输入年龄');
  99. break;
  100. default:
  101. break;
  102. }
  103. }
  104. },
  105. }
  106. }
  107. </script>
  108. <style lang="scss">
  109. .container {
  110. display: flex;
  111. flex-direction: column;
  112. align-items: center;
  113. justify-content: center;
  114. width:100%;
  115. height: 100vh;
  116. }
  117. .navigation-bar
  118. {
  119. display: flex;
  120. align-items: center;
  121. justify-content: center;
  122. width: 100%;
  123. height: 10%;
  124. font-weight: 700;
  125. color: white;
  126. background-color: rgb(115,164,164);
  127. }
  128. .back{
  129. position: absolute;
  130. display: flex;
  131. align-items: center;
  132. justify-content: center;
  133. width: 2%;
  134. height: 2%;
  135. top: 3%;
  136. left: 1%;
  137. //testing
  138. // border: 1px solid rgb(255,0,0);
  139. }
  140. .content{
  141. display: flex;
  142. flex-direction: column;
  143. align-items: center;
  144. justify-content: center;
  145. width:100%;
  146. height:100%;
  147. }
  148. .result-area{
  149. display: flex;
  150. align-items: center;
  151. justify-content: center;
  152. width:60%;
  153. height:30%;
  154. margin: 1%;
  155. border-radius: 25rpx;
  156. background-color: rgb(115,164,164);
  157. }
  158. .help{
  159. color: azure;
  160. background-color: rgb(0,0,0);
  161. }
  162. .input-area{
  163. display: flex;
  164. flex-direction: column;
  165. align-items: center;
  166. justify-content: center;
  167. width:60%;
  168. height:60%;
  169. margin: 1%;
  170. .waistline{
  171. display: flex;
  172. flex-direction: row;
  173. align-items: center;
  174. justify-content: center;
  175. width:100%;
  176. height:100%;
  177. margin: 1%;
  178. border-radius: 25rpx;
  179. background-color: rgb(115,164,164);
  180. }
  181. .weight{
  182. display: flex;
  183. flex-direction: row;
  184. align-items: center;
  185. justify-content: center;
  186. width:100%;
  187. height:100%;
  188. margin: 3%;
  189. border-radius: 25rpx;
  190. background-color: rgb(115,164,164);
  191. }
  192. .input-title{
  193. //testing
  194. // border: 1px solid rgb(255,0,0);
  195. }
  196. .input{
  197. display: flex;
  198. justify-content: center;
  199. align-items: center;
  200. background: #F4F4F4;
  201. border-radius: 4upx;
  202. height: 70upx;
  203. font-size: 28upx;
  204. line-height: 70upx;
  205. font-family: PingFang SC;
  206. font-weight: 500;
  207. color: #848484;
  208. text-align:center;
  209. margin: 1%;
  210. }
  211. }
  212. .confirm{
  213. display: flex;
  214. flex-direction: column;
  215. align-items: center;
  216. justify-content: center;
  217. width:10%;
  218. height:10%;
  219. margin: 1%;
  220. }
  221. </style>