plan.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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 = date.datedifference(this.startTime, this.endTime);
  167. this.currentDays = Math.floor(Math.abs(dateSpan) / (24 * 3600 * 1000));
  168. } else {
  169. uni.showToast({
  170. title: "开始日期超过截止日期!",
  171. icon: "none"
  172. })
  173. }
  174. } else if (this.pikerType == 'endTime') {
  175. let nDate = new Date();
  176. nDate.setFullYear(args.value[0], args.value[1] - 1, args.value[2]);
  177. // 判断日期
  178. var sDate1 = Date.parse(this.startTime.replace(/-/g, '/'));
  179. var sDate2 = Date.parse(date.formatDate(nDate).replace(/-/g, '/'));
  180. var dateSpan = sDate2 - sDate1;
  181. // console.log(dateSpan);
  182. if (dateSpan > 0) {
  183. this.endTime = date.formatDate(nDate);
  184. this.currentPlanData.endTime = date.formatTime(nDate);
  185. // this.currentDays = date.datedifference(this.startTime, this.endTime);
  186. this.currentDays = Math.floor(Math.abs(dateSpan) / (24 * 3600 * 1000));
  187. } else {
  188. uni.showToast({
  189. title: "开始日期不能超过或等于截止日期!",
  190. icon: "none"
  191. })
  192. }
  193. } else if (this.pikerType == 'target_weight') {
  194. console.log('target_weight:');
  195. this.currentPlanData.targetWeight = args.value;
  196. } else if (this.pikerType == 'target_calorie') {
  197. console.log('target_calorie:');
  198. this.currentPlanData.calorie = parseInt(args.value);
  199. } else if (this.pikerType == 'target_minute') {
  200. console.log('target_minute:');
  201. this.currentPlanData.sportTime = parseInt(args.value);
  202. }
  203. this.hideModal();
  204. },
  205. onCancel(value) {
  206. console.log('onCancel', value);
  207. this.modalName = null;
  208. },
  209. showModal(e) {
  210. // console.log(e.currentTarget.type);
  211. this.modalName = e.currentTarget.dataset.target;
  212. this.pikerType = e.currentTarget.dataset.type;
  213. switch (this.pikerType) {
  214. case 'target_weight':
  215. this.$set(this.pickerObj, 'pickerLeftList', pickerData.getWeightList().leftList);
  216. this.$set(this.pickerObj, 'pickerRightList', pickerData.getWeightList().rightList);
  217. this.$set(this.pickerObj, 'pickerType', 'doubleItem');
  218. this.$set(this.pickerObj, 'pickerUnit', '斤');
  219. this.$set(this.pickerObj, 'pickerTitle', '记体重');
  220. this.$set(this.pickerObj, 'showInput', true);
  221. break;
  222. case 'startTime':
  223. case 'endTime':
  224. this.$set(this.pickerObj, 'pickerType', 'dateItem');
  225. this.$set(this.pickerObj, 'pickerTitle', '记时间');
  226. this.$set(this.pickerObj, 'showInput', false);
  227. break;
  228. case 'target_calorie':
  229. this.$set(this.pickerObj, 'pickerLeftList', pickerData.getCalorieList().calorieList);
  230. this.$set(this.pickerObj, 'pickerRightList', []);
  231. this.$set(this.pickerObj, 'pickerUnit', '大卡');
  232. this.$set(this.pickerObj, 'pickerType', 'singleItem');
  233. this.$set(this.pickerObj, 'pickerTitle', '卡路里');
  234. this.$set(this.pickerObj, 'defaultValue', this.currentPlanData.calorie);
  235. this.$set(this.pickerObj, 'showInput', true);
  236. break;
  237. case 'target_minute':
  238. this.$set(this.pickerObj, 'pickerLeftList', pickerData.getMinuteList().minuteList);
  239. this.$set(this.pickerObj, 'pickerRightList', []);
  240. this.$set(this.pickerObj, 'pickerUnit', '分钟');
  241. this.$set(this.pickerObj, 'pickerType', 'singleItem');
  242. this.$set(this.pickerObj, 'pickerTitle', '预计时间');
  243. this.$set(this.pickerObj, 'defaultValue', this.currentPlanData.sportTime);
  244. this.$set(this.pickerObj, 'showInput', true);
  245. break;
  246. }
  247. },
  248. hideModal(e) {
  249. this.modalName = null;
  250. this.pikerType = '';
  251. },
  252. moveHandle() {
  253. return;
  254. },
  255. onUpdatePlanInfo() {
  256. let that = this;
  257. console.warn(that.currentPlanData);
  258. if (!that.hasUpdate) {
  259. uni.showToast({
  260. title: '没有数据更新',
  261. icon: 'none'
  262. });
  263. return;
  264. }
  265. if (that.currentPlanData.startTime > that.currentPlanData.endTime||
  266. date.datedifference(that.currentPlanData.startTime, that.currentPlanData.endTime) == 0) {
  267. uni.showToast({
  268. title: '截止时间不能早于或等于开始时间',
  269. icon: 'none'
  270. });
  271. return;
  272. }
  273. // console.warn(that.currentPlanData);
  274. // return;
  275. reqUtil.requestData(config.URL.FITNESSPROGRAM, that.currentPlanData, 'POST').then(
  276. res => {
  277. console.log('更新信息成功', res);
  278. if (res.code == 0) {
  279. uni.showToast({
  280. title: '更新成功',
  281. mask: true,
  282. duration: 1000
  283. });
  284. that.oldPlanData = res.data;
  285. that.hasUpdate = false;
  286. that.$store.state.planData = Object.assign(that.$store.state.planData, res.data, {
  287. sportTime: Number(that.currentPlanData.sportTime)
  288. });
  289. // console.log("========",that.planData);
  290. that.$store.state.days = date.datedifference(res.data.startTime, res.data.endTime) + 1;
  291. let nDate = new Date();
  292. let tempTime = date.formatDate(nDate);
  293. that.$store.state.remainingDays = date.datedifference(tempTime, res.data.endTime) + 1;
  294. // console.log("remainingDays==", that.remainingDays);
  295. setTimeout(function() {
  296. // console.log("updateArcbarData==setTimeout");
  297. that.addlocalCalorie(0);
  298. // uni.$emit('updateArcbarData', 'plan');
  299. uni.navigateBack();
  300. }, 500);
  301. }
  302. },
  303. e => {
  304. console.log(e);
  305. }
  306. );
  307. },
  308. //重置默认信息
  309. onReset() {
  310. uni.showToast({
  311. title: '生成计划成功!',
  312. icon: 'none',
  313. })
  314. this.hasUpdate = true;
  315. // 拷贝
  316. this.currentPlanData = JSON.parse(JSON.stringify(this.defaultPlanData));
  317. this.startTime = this.currentPlanData.startTime;
  318. this.endTime = this.currentPlanData.endTime;
  319. this.currentDays = date.datedifference(this.startTime, this.endTime);
  320. // console.log("this.defaultPlanData=",this.defaultPlanData);
  321. },
  322. onBack() {
  323. uni.navigateBack({
  324. delta: 1
  325. })
  326. }
  327. }
  328. };
  329. </script>
  330. <style>
  331. .plan-w {
  332. position: relative;
  333. /* width: 464rpx; */
  334. height: 464rpx;
  335. }
  336. .plan-w-bg-img {
  337. position: absolute;
  338. left: 0;
  339. right: 0;
  340. top: 0;
  341. bottom: 0;
  342. margin: auto;
  343. width: 464rpx;
  344. height: 464rpx;
  345. }
  346. .plan-w-child {
  347. position: absolute;
  348. left: 0;
  349. right: 0;
  350. top: 0;
  351. bottom: 0;
  352. margin: auto;
  353. width: 464rpx;
  354. height: 464rpx;
  355. display: flex;
  356. flex-direction: column;
  357. justify-content: center;
  358. align-items: center;
  359. }
  360. .plan-w-img {
  361. width: 46rpx;
  362. height: 46rpx;
  363. }
  364. .plan-Tip {
  365. height: 90rpx;
  366. margin: 60rpx 0;
  367. }
  368. .plan-Tip-child {
  369. background-color: #f5f5ff;
  370. border-radius: 20px;
  371. width: 614rpx;
  372. height: 90rpx;
  373. margin: 60rpx 0;
  374. }
  375. .plan-litle-img {
  376. width: 32rpx;
  377. height: 32rpx;
  378. margin-right: 32rpx;
  379. }
  380. .plan-m-img {
  381. width: 1rpx;
  382. height: 110rpx;
  383. margin: 0 41rpx 0 14rpx;
  384. border: 1rpx dashed rgba(151, 151, 255, 1);
  385. }
  386. .resetBtn {
  387. background-color: rgba(151, 151, 255, 1);
  388. border-radius: 3px;
  389. padding: 10rpx 32rpx;
  390. }
  391. .plan-tagert {
  392. margin: 20px 0;
  393. height: 208rpx;
  394. }
  395. .plan-tagert-child {
  396. background-color: #f5f5ff;
  397. border-radius: 20px;
  398. width: 614rpx;
  399. height: 208rpx;
  400. padding-left: 40rpx;
  401. }
  402. .avatar-img {
  403. width: 96rpx;
  404. height: 96rpx;
  405. border: 4rpx solid rgba(151, 151, 255, 1);
  406. border-radius: 45px;
  407. flex-shrink: 0;
  408. }
  409. </style>