plan.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <template>
  2. <view>
  3. <uni-nav-bar id="nav-bar" status-bar="true" @clickLeft="onBack()" title="健身计划" color="#000000" fixed="true" :border="false">
  4. <!-- <view slot="left">
  5. <view class=" flex align-center margin-left">
  6. <image class="p-left-arrow" src="../../../static/p-left-arrow.png"></image>
  7. </view>
  8. </view> -->
  9. </uni-nav-bar>
  10. <view class="card-view text-center">
  11. <!-- @tap="showModal" data-target="showPickerModal" data-type="target_weight" -->
  12. <view class="plan-w" style="margin-top: 34px;">
  13. <view class="plan-w-child">
  14. <image src="../../../static/plan_w_bg.png"></image>
  15. </view>
  16. <view class="plan-w-child">
  17. <image class="plan-w-img" src="../../../static/plan_w.png"></image>
  18. <view class="padding-sm make-text-bPurple text-11px">
  19. <span style="font-size: 29px;">{{ currenWeight }}</span>
  20. 公斤
  21. </view>
  22. <view class="text-gray text-13px">累计减重</view>
  23. </view>
  24. </view>
  25. <view class="plan-Tip flex justify-center align-center">
  26. <view class="plan-Tip-child make-text-bPurple flex justify-center align-center">每天努力一点,离成功更近一步,加油!</view>
  27. </view>
  28. </view>
  29. <view class="card-view flex-sub text-center bg-white margin-top">
  30. <view class="plan-tagert flex justify-center align-center">
  31. <view class="plan-tagert-child make-text-bPurple flex justify-start align-center">
  32. <image class="avatar-img" :src="avatarUrl"></image>
  33. <view class="flex flex-direction justify-between">
  34. <view class="text-black text-bold padding-left-lg margin-xs" style="text-align: start;">每天目标</view>
  35. <view class="flex text-gray border">
  36. <view class="padding-left-lg margin-xs flex" style="position: relative; flex-shrink: 0; " @tap="showModal"
  37. data-target="showPickerModal" data-type="target_calorie">
  38. <view class="make-text-bPurple text-xl margin-right-sm ">{{ currentPlanData.calorie}}</view>
  39. <view>大卡</view>
  40. <view class="only-arrow"></view>
  41. </view>
  42. <view class="padding-left-lg margin-xs flex" style="position: relative;flex-shrink: 0;" @tap="showModal"
  43. data-target="showPickerModal" data-type="target_minute">
  44. <view class="make-text-bPurple text-xl margin-right-sm">{{ currentPlanData.sportTime }}</view>
  45. <view>分钟</view>
  46. <view class="only-arrow"></view>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="cu-bar bg-white">
  53. <view class="action">
  54. <image style="width: 42rpx;height: 42rpx; margin-right: 26rpx;" src="../../../static/plan_w.png"></image>
  55. <span style="font-weight: bold;">终极目标</span>
  56. </view>
  57. <view class="action resetBtn" style="margin-right: 60rpx;" @tap="onReset"><text class="text-13px text-white" style="letter-spacing: 1px;">自动生成计划</text></view>
  58. </view>
  59. <view class="cu-form-group" @tap="showModal" data-target="showPickerModal" data-type="startTime">
  60. <view class="flex justify-center align-center">
  61. <image class="plan-litle-img" src="../../../static/plan_t.png"></image>
  62. <view class="title make-text-bPurple">开始时间</view>
  63. </view>
  64. <view class="picker flex" style="position: relative;">
  65. <view>{{ startTime }}</view>
  66. <view class="only-arrow"></view>
  67. </view>
  68. </view>
  69. <view class="cu-form-group" style="border-top:none" data-target="showPickerModal" data-type="endTime">
  70. <view class="flex justify-center align-center">
  71. <image class="plan-m-img" src="../../../static/plan_m.png"></image>
  72. <view class="title text-gray" style="font-size: 12px;">计划总天数 {{ currentDays }} 天,加油!</view>
  73. </view>
  74. </view>
  75. <view class="cu-form-group" style="border-top:none" @tap="showModal" data-target="showPickerModal" data-type="endTime">
  76. <view class="flex justify-center align-center">
  77. <image class="plan-litle-img" src="../../../static/plan_e.png"></image>
  78. <view class="title make-text-bPurple">截止时间</view>
  79. </view>
  80. <view class="picker flex" style="position: relative;">
  81. <view>{{ endTime }}</view>
  82. <view class="only-arrow"></view>
  83. </view>
  84. </view>
  85. </view>
  86. <view class="flex flex-direction" style="padding: 23px 42rpx 46px"><button class="cu-btn make-bg-bPurple text-white lg"
  87. @tap="onUpdatePlanInfo">确定</button></view>
  88. <view class="cu-modal bottom-modal" :class="modalName == 'showPickerModal' ? 'show' : ''" @touchmove.stop.prevent="moveHandle">
  89. <view class="cu-dialog" style="border-top-right-radius: 20rpx; border-top-left-radius: 20rpx;">
  90. <myPicker v-if="modalName == 'showPickerModal' ? true:false" :pickerObj="pickerObj" @confirmEvent="onConfirm"
  91. @cancelEvent="onCancel"></myPicker>
  92. </view>
  93. </view>
  94. </view>
  95. </template>
  96. <script>
  97. import config from '../../../common/config.js';
  98. import date from '../../../util/util-js/date.js';
  99. import reqUtil from '../../../util/util-js/requstUtil.js';
  100. import myPicker from '@/components/slambb-picker/slambb-picker.vue';
  101. import pickerData from '@/components/slambb-picker/picker.js';
  102. import utilData from '@/util/util-js/util-data.js';
  103. import {
  104. mapState,
  105. mapMutations
  106. } from 'vuex';
  107. export default {
  108. computed: mapState(['planData', 'avatarUrl', 'days', "defaultPlanData", "remainingDays"]),
  109. components: {
  110. myPicker
  111. },
  112. data() {
  113. return {
  114. startTime: '',
  115. endTime: '',
  116. pickerObj: {
  117. pickerType: 'dateItem',
  118. pickerTitle: '记时间'
  119. },
  120. modalName: null,
  121. pikerType: '',
  122. oldPlanData: null,
  123. // 当前plan页面的数据
  124. currentPlanData: null,
  125. // 当前天数
  126. currentDays: 0,
  127. //如果需要更新
  128. hasUpdate: false,
  129. //显示的重量
  130. currenWeight: 0
  131. };
  132. },
  133. onLoad: function(option) {
  134. this.oldPlanData = JSON.parse(JSON.stringify(this.planData));
  135. this.currentPlanData = JSON.parse(JSON.stringify(this.planData));
  136. this.startTime = this.currentPlanData.startTime;
  137. this.endTime = this.currentPlanData.endTime;
  138. this.currentDays = this.days;
  139. // 用累计的卡路里来计算当前累计的重量
  140. // let weight = this.currentPlanData.cumulativeCalorie *2 / 7000;
  141. let weight = utilData.calorieConversionKg(this.currentPlanData.cumulativeCalorie);
  142. this.currenWeight = weight.toFixed(2);
  143. },
  144. methods: {
  145. ...mapMutations(['addlocalCalorie']),
  146. DateChange(e) {
  147. this.planData.startTime = e.detail.value;
  148. },
  149. onConfirm(args) {
  150. this.hasUpdate = true;
  151. console.log('onConfirm', args);
  152. // detail.__args__[0]
  153. // let args = data;
  154. //月0~11
  155. if (this.pikerType == 'startTime') {
  156. let nDate = new Date();
  157. nDate.setFullYear(args.value[0], args.value[1] - 1, args.value[2]);
  158. // 判断日期
  159. // console.log(date.formatDate(nDate),"==",date.formatDate(nDate).replace(/-/g, '/'))
  160. var sDate1 = Date.parse(date.formatDate(nDate));
  161. var sDate2 = Date.parse(this.endTime);
  162. var dateSpan = sDate2 - sDate1;
  163. if (dateSpan > 0) {
  164. this.startTime = date.formatDate(nDate);
  165. this.currentPlanData.startTime = date.formatTime(nDate);
  166. this.currentDays = Math.floor(Math.abs(dateSpan) / (24 * 3600 * 1000));
  167. } else {
  168. uni.showToast({
  169. title: "开始日期超过截止日期!",
  170. icon: "none"
  171. })
  172. }
  173. } else if (this.pikerType == 'endTime') {
  174. let nDate = new Date();
  175. nDate.setFullYear(args.value[0], args.value[1] - 1, args.value[2]);
  176. // 判断日期
  177. var sDate1 = Date.parse(this.startTime.replace(/-/g, '/'));
  178. var sDate2 = Date.parse(date.formatDate(nDate).replace(/-/g, '/'));
  179. var dateSpan = sDate2 - sDate1;
  180. // console.log(dateSpan);
  181. if (dateSpan > 0) {
  182. this.endTime = date.formatDate(nDate);
  183. this.currentPlanData.endTime = date.formatTime(nDate);
  184. this.currentDays = Math.floor(Math.abs(dateSpan) / (24 * 3600 * 1000));
  185. } else {
  186. uni.showToast({
  187. title: "开始日期不能超过或等于截止日期!",
  188. icon: "none"
  189. })
  190. }
  191. } else if (this.pikerType == 'target_weight') {
  192. console.log('target_weight:');
  193. this.currentPlanData.targetWeight = args.value;
  194. } else if (this.pikerType == 'target_calorie') {
  195. console.log('target_calorie:');
  196. this.currentPlanData.calorie = parseInt(args.value);
  197. } else if (this.pikerType == 'target_minute') {
  198. console.log('target_minute:');
  199. this.currentPlanData.sportTime = parseInt(args.value);
  200. }
  201. this.hideModal();
  202. },
  203. onCancel(value) {
  204. console.log('onCancel', value);
  205. this.modalName = null;
  206. },
  207. showModal(e) {
  208. // console.log(e.currentTarget.type);
  209. this.modalName = e.currentTarget.dataset.target;
  210. this.pikerType = e.currentTarget.dataset.type;
  211. switch (this.pikerType) {
  212. case 'target_weight':
  213. this.$set(this.pickerObj, 'pickerLeftList', pickerData.getWeightList().leftList);
  214. this.$set(this.pickerObj, 'pickerRightList', pickerData.getWeightList().rightList);
  215. this.$set(this.pickerObj, 'pickerType', 'doubleItem');
  216. this.$set(this.pickerObj, 'pickerUnit', '斤');
  217. this.$set(this.pickerObj, 'pickerTitle', '记体重');
  218. this.$set(this.pickerObj, 'showInput', true);
  219. break;
  220. case 'startTime':
  221. case 'endTime':
  222. this.$set(this.pickerObj, 'pickerType', 'dateItem');
  223. this.$set(this.pickerObj, 'pickerTitle', '记时间');
  224. this.$set(this.pickerObj, 'showInput', false);
  225. break;
  226. case 'target_calorie':
  227. this.$set(this.pickerObj, 'pickerLeftList', pickerData.getCalorieList().calorieList);
  228. this.$set(this.pickerObj, 'pickerRightList', []);
  229. this.$set(this.pickerObj, 'pickerUnit', '大卡');
  230. this.$set(this.pickerObj, 'pickerType', 'singleItem');
  231. this.$set(this.pickerObj, 'pickerTitle', '卡路里');
  232. this.$set(this.pickerObj, 'defaultValue', this.currentPlanData.calorie);
  233. this.$set(this.pickerObj, 'showInput', true);
  234. break;
  235. case 'target_minute':
  236. this.$set(this.pickerObj, 'pickerLeftList', pickerData.getMinuteList().minuteList);
  237. this.$set(this.pickerObj, 'pickerRightList', []);
  238. this.$set(this.pickerObj, 'pickerUnit', '分钟');
  239. this.$set(this.pickerObj, 'pickerType', 'singleItem');
  240. this.$set(this.pickerObj, 'pickerTitle', '预计时间');
  241. this.$set(this.pickerObj, 'defaultValue', this.currentPlanData.sportTime);
  242. this.$set(this.pickerObj, 'showInput', true);
  243. break;
  244. }
  245. },
  246. hideModal(e) {
  247. this.modalName = null;
  248. this.pikerType = '';
  249. },
  250. moveHandle() {
  251. return;
  252. },
  253. onUpdatePlanInfo() {
  254. let that = this;
  255. console.warn(that.currentPlanData);
  256. if (!that.hasUpdate) {
  257. uni.showToast({
  258. title: '没有数据更新',
  259. icon: 'none'
  260. });
  261. return;
  262. }
  263. if (that.currentPlanData.startTime > that.currentPlanData.endTime||
  264. date.datedifference(that.currentPlanData.startTime, that.currentPlanData.endTime) == 0) {
  265. uni.showToast({
  266. title: '截止时间不能早于或等于开始时间',
  267. icon: 'none'
  268. });
  269. return;
  270. }
  271. // console.warn(that.currentPlanData);
  272. // return;
  273. reqUtil.requestData(config.URL.FITNESSPROGRAM, that.currentPlanData, 'POST').then(
  274. res => {
  275. console.log('更新信息成功', res);
  276. if (res.code == 0) {
  277. uni.showToast({
  278. title: '更新成功',
  279. mask: true,
  280. duration: 1000
  281. });
  282. that.oldPlanData = res.data;
  283. that.hasUpdate = false;
  284. that.$store.state.planData = Object.assign(that.$store.state.planData, res.data, {
  285. sportTime: Number(that.currentPlanData.sportTime)
  286. });
  287. // console.log("========",that.planData);
  288. that.$store.state.days = date.datedifference(res.data.startTime, res.data.endTime) + 1;
  289. let nDate = new Date();
  290. let tempTime = date.formatDate(nDate);
  291. that.$store.state.remainingDays = date.datedifference(tempTime, res.data.endTime) + 1;
  292. // console.log("remainingDays==", that.remainingDays);
  293. setTimeout(function() {
  294. // console.log("updateArcbarData==setTimeout");
  295. that.addlocalCalorie(0);
  296. // uni.$emit('updateArcbarData', 'plan');
  297. //todo 首页不需要back
  298. // uni.navigateBack();
  299. }, 500);
  300. }
  301. },
  302. e => {
  303. console.log(e);
  304. }
  305. );
  306. },
  307. //重置默认信息
  308. onReset() {
  309. uni.showToast({
  310. title: '生成计划成功!',
  311. icon: 'none',
  312. })
  313. this.hasUpdate = true;
  314. // 拷贝
  315. this.currentPlanData = JSON.parse(JSON.stringify(this.defaultPlanData));
  316. this.startTime = this.currentPlanData.startTime;
  317. this.endTime = this.currentPlanData.endTime;
  318. this.currentDays = date.datedifference(this.startTime, this.endTime);
  319. // console.log("this.defaultPlanData=",this.defaultPlanData);
  320. },
  321. onBack() {
  322. uni.navigateBack({
  323. delta: 1
  324. })
  325. }
  326. }
  327. };
  328. </script>
  329. <style>
  330. .plan-w {
  331. position: relative;
  332. /* width: 464rpx; */
  333. height: 464rpx;
  334. }
  335. .plan-w-bg-img {
  336. position: absolute;
  337. left: 0;
  338. right: 0;
  339. top: 0;
  340. bottom: 0;
  341. margin: auto;
  342. width: 464rpx;
  343. height: 464rpx;
  344. }
  345. .plan-w-child {
  346. position: absolute;
  347. left: 0;
  348. right: 0;
  349. top: 0;
  350. bottom: 0;
  351. margin: auto;
  352. width: 464rpx;
  353. height: 464rpx;
  354. display: flex;
  355. flex-direction: column;
  356. justify-content: center;
  357. align-items: center;
  358. }
  359. .plan-w-img {
  360. width: 46rpx;
  361. height: 46rpx;
  362. }
  363. .plan-Tip {
  364. height: 90rpx;
  365. margin: 60rpx 0;
  366. }
  367. .plan-Tip-child {
  368. background-color: #f5f5ff;
  369. border-radius: 20px;
  370. width: 614rpx;
  371. height: 90rpx;
  372. margin: 60rpx 0;
  373. }
  374. .plan-litle-img {
  375. width: 32rpx;
  376. height: 32rpx;
  377. margin-right: 32rpx;
  378. }
  379. .plan-m-img {
  380. width: 1rpx;
  381. height: 110rpx;
  382. margin: 0 41rpx 0 14rpx;
  383. border: 1rpx dashed rgba(151, 151, 255, 1);
  384. }
  385. .resetBtn {
  386. background-color: rgba(151, 151, 255, 1);
  387. border-radius: 3px;
  388. padding: 10rpx 32rpx;
  389. }
  390. .plan-tagert {
  391. margin: 20px 0;
  392. height: 208rpx;
  393. }
  394. .plan-tagert-child {
  395. background-color: #f5f5ff;
  396. border-radius: 20px;
  397. width: 614rpx;
  398. height: 208rpx;
  399. padding-left: 40rpx;
  400. }
  401. .avatar-img {
  402. width: 96rpx;
  403. height: 96rpx;
  404. border: 4rpx solid rgba(151, 151, 255, 1);
  405. border-radius: 45px;
  406. flex-shrink: 0;
  407. }
  408. </style>