firstPlan.vue 14 KB

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