basalMetabolism.vue 5.5 KB

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