firstPlan.vue 13 KB

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