bodyFatRatio.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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=""></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 = "";
  55. this.weight = "";
  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. let num1 = 0;
  94. let num2 = 0;
  95. if(getApp().globalData.gender == 0)
  96. {//男
  97. num1 = this.waistline*0.74;
  98. num2 = this.weight*0.082+44.74;
  99. fatWeight = Number(num1) - Number(num2);
  100. fatRate = fatWeight/this.weight* 100;
  101. }
  102. else
  103. {//女
  104. num1 = this.waistline*0.74;
  105. num2 = (this.weight*0.082)+Number(34.89);
  106. fatWeight = num1 - num2;
  107. fatRate = fatWeight/this.weight * 100;
  108. }
  109. this.result1 = '身体脂肪总重量: '+ Math.round(fatWeight) + '公斤';
  110. this.result2 = '体脂率: '+ Math.round(fatRate*100)/100+'%';
  111. getApp().globalData.fatWeight = this.fatWeight;
  112. getApp().globalData.fatRate = this.fatRate;
  113. }
  114. else
  115. {
  116. switch (id)
  117. {
  118. case 0:
  119. alert('请输入体重');
  120. break;
  121. case 1:
  122. alert('请输入身高');
  123. break;
  124. case 2:
  125. alert('请输入年龄');
  126. break;
  127. default:
  128. break;
  129. }
  130. }
  131. },
  132. }
  133. }
  134. </script>
  135. <style lang="scss">
  136. .container {
  137. display: flex;
  138. flex-direction: column;
  139. align-items: center;
  140. justify-content: center;
  141. width:100%;
  142. height: 100vh;
  143. }
  144. .navigation-bar
  145. {
  146. display: flex;
  147. align-items: center;
  148. justify-content: center;
  149. width: 100%;
  150. height: 8%;
  151. font-weight: 700;
  152. color: white;
  153. font-size: 37rpx;
  154. background-color: #C9C7AF;
  155. }
  156. .item-logo
  157. {
  158. z-index: 4;
  159. height: 21%;
  160. width: 15%;
  161. // margin: 1%;
  162. }
  163. .back{
  164. position: absolute;
  165. display: flex;
  166. align-items: center;
  167. justify-content: center;
  168. width: 3%;
  169. height: 3%;
  170. top: 2%;
  171. left: 3%;
  172. //testing
  173. // border: 1px solid rgb(255,0,0);
  174. }
  175. .blue{
  176. position: absolute;
  177. display: flex;
  178. align-items: center;
  179. justify-content: center;
  180. width: 7%;
  181. height: 7%;
  182. top: 1%;
  183. right: 3%;
  184. border-radius: 50%;
  185. width: 75rpx;
  186. height: 75rpx;
  187. border-radius: 50%;
  188. overflow: hidden;
  189. image{
  190. width: 100%;
  191. height: 75rpx;
  192. }
  193. }
  194. .content{
  195. display: flex;
  196. flex-direction: column;
  197. align-items: center;
  198. justify-content: center;
  199. width:100%;
  200. height:100%;
  201. }
  202. .result-area{
  203. display: flex;
  204. align-items: center;
  205. justify-content: center;
  206. width:95%;
  207. height:30%;
  208. margin: 1%;
  209. border-radius: 25rpx;
  210. background-color: #C9C7AF;
  211. text-align: center;
  212. font-size: 44rpx;
  213. font-weight: 700;
  214. color: #7B784E;
  215. image{
  216. margin-top: 10%;
  217. }
  218. .border{
  219. border: 4rpx solid #F4F4F4;
  220. height: 90%;
  221. width: 90%;
  222. border-radius: 25rpx;
  223. view{
  224. margin-top: 5%;
  225. }
  226. }
  227. }
  228. .help{
  229. color: azure;
  230. background-color: rgb(0,0,0);
  231. }
  232. .input-area{
  233. // display: flex;
  234. flex-direction: column;
  235. align-items: center;
  236. justify-content: center;
  237. width:95%;
  238. height:60%;
  239. margin: 1%;
  240. font-size: 36rpx;
  241. font-weight: bold;
  242. .waistline{
  243. display: flex;
  244. flex-direction: row;
  245. align-items: center;
  246. justify-content: center;
  247. width:100%;
  248. height:20%;
  249. margin: 1%;
  250. border-radius: 25rpx;
  251. background: #FBF0EA;
  252. input{
  253. background: #F5DACB;
  254. }
  255. }
  256. .weight{
  257. display: flex;
  258. flex-direction: row;
  259. align-items: center;
  260. justify-content: center;
  261. width:100%;
  262. height:20%;
  263. margin-top: 3%;
  264. border-radius: 25rpx;
  265. background: #FEEBEA;
  266. input{
  267. background: #FBCDCC;
  268. }
  269. }
  270. .input-title{
  271. //testing
  272. // border: 1px solid rgb(255,0,0);
  273. }
  274. .input{
  275. display: flex;
  276. justify-content: center;
  277. align-items: center;
  278. background: #F4F4F4;
  279. border-radius: 4upx;
  280. height: 70upx;
  281. font-size: 28upx;
  282. line-height: 70upx;
  283. font-family: PingFang SC;
  284. font-weight: 500;
  285. color: #848484;
  286. text-align:center;
  287. margin: 1%;
  288. width: 75%;
  289. height: 120rpx;
  290. background: #D8D7C5;
  291. border-radius: 20rpx;
  292. font-size: 46rpx;
  293. }
  294. }
  295. .confirm{
  296. display: flex;
  297. flex-direction: column;
  298. align-items: center;
  299. justify-content: center;
  300. width:95%;
  301. height:7%;
  302. margin: 1%;
  303. background: #C9C7AF;
  304. border-radius: 24rpx;
  305. font-size: 49rpx;
  306. font-weight: bold;
  307. color: #7B784E;
  308. }
  309. .Company{
  310. position: absolute;
  311. right: 13%;
  312. }
  313. </style>