dayCalorie.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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">{{resultStr}}</text>
  9. <button class="help" @click="onHelp(0, $event)">宁哥笔记</button>
  10. <view class="select-area">
  11. <view :class="(selected != index)?'block':'block-selected'" v-for="(option,index) in optionArr" @click="onClick(index, $event)">{{option}}</view>
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. data() {
  19. return {
  20. resultStr:'',
  21. optionArr:[
  22. '办公室久坐没有什么运动',
  23. '每周轻松1-3次运动',
  24. '每周中等强度3-5次',
  25. '每周大强度运动5-7次以上',
  26. '大强度训练每周8次以上',
  27. ],
  28. selected:0,
  29. }
  30. },
  31. onLoad() {
  32. if(getApp().globalData.bmr !=undefined)
  33. {
  34. let calorie = getApp().globalData.bmr * 1.2;
  35. this.resultStr = '每天消耗的总热量: ' + Math.round(calorie);
  36. }
  37. else
  38. {
  39. uni.navigateBack({
  40. delta:1,
  41. animationType: 'slide-in-left',
  42. animationDuration: 2000,
  43. success: res => {
  44. alert('清先测量基础代谢');
  45. },
  46. fail: () => {},
  47. complete: () => {}
  48. });
  49. }
  50. },
  51. methods: {
  52. onBack: function(id,e) {
  53. //uni.navigateBack()//默认delta:1
  54. uni.navigateBack({
  55. delta:1,//返回层数,2则上上页
  56. })
  57. },
  58. onHelp: function(id,e) {
  59. uni.navigateTo({
  60. url: '/pages/dayCalorie/help',
  61. animationType: 'slide-in-left',
  62. animationDuration: 2000,
  63. success: res => {},
  64. fail: () => {},
  65. complete: () => {}
  66. });
  67. },
  68. onClick: function(id,e) {
  69. // console.log(id);
  70. this.selected = id;
  71. let calorie = -1;
  72. switch (id){
  73. case 0:
  74. calorie = getApp().globalData.bmr * 1.2;
  75. break;
  76. case 1:
  77. calorie = getApp().globalData.bmr * 1.375;
  78. break;
  79. case 2:
  80. calorie = getApp().globalData.bmr * 1.5;
  81. break;
  82. case 3:
  83. calorie = getApp().globalData.bmr * 1.725;
  84. break;
  85. case 4:
  86. calorie = getApp().globalData.bmr * 1.9;
  87. break;
  88. default:
  89. break;
  90. }
  91. getApp().globalData.calorie = calorie;
  92. this.resultStr = '每天消耗的总热量: ' + Math.round(calorie);
  93. },
  94. }
  95. }
  96. </script>
  97. <style lang="scss">
  98. .container {
  99. display: flex;
  100. flex-direction: column;
  101. align-items: center;
  102. justify-content: center;
  103. width:100%;
  104. height: 100vh;
  105. }
  106. .navigation-bar
  107. {
  108. display: flex;
  109. align-items: center;
  110. justify-content: center;
  111. width: 100%;
  112. height: 10%;
  113. font-weight: 700;
  114. color: white;
  115. background-color: rgb(115,164,164);
  116. }
  117. .back{
  118. position: absolute;
  119. display: flex;
  120. align-items: center;
  121. justify-content: center;
  122. width: 2%;
  123. height: 2%;
  124. top: 3%;
  125. left: 1%;
  126. //testing
  127. // border: 1px solid rgb(255,0,0);
  128. }
  129. .content{
  130. display: flex;
  131. flex-direction: column;
  132. align-items: center;
  133. justify-content: center;
  134. width:100%;
  135. height:100%;
  136. }
  137. .result-area{
  138. display: flex;
  139. align-items: center;
  140. justify-content: center;
  141. width:60%;
  142. height:30%;
  143. margin: 1%;
  144. border-radius: 25rpx;
  145. background-color: rgb(115,164,164);
  146. }
  147. .help{
  148. color: azure;
  149. background-color: rgb(0,0,0);
  150. }
  151. .select-area{
  152. display: flex;
  153. flex-direction: column;
  154. align-items: center;
  155. justify-content: center;
  156. width:60%;
  157. height:60%;
  158. margin: 1%;
  159. }
  160. .block{
  161. width:60%;
  162. height:60%;
  163. margin: 1%;
  164. background-color: rgb(115,164,164);
  165. }
  166. .block-selected{
  167. width:60%;
  168. height:60%;
  169. margin: 1%;
  170. box-shadow: 3px 3px 6px 3px rgba(0, 0, 0, 1);
  171. background-color: rgb(115,164,164);
  172. }
  173. </style>