baby.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <view class='baby'>
  3. <view v-if="baby">
  4. <view class="baby-info" @tap.stap="navTo('/pages/index/applyInfo?type=user')">
  5. <image :src="baby.headImg" mode="" />
  6. <view>
  7. <view class="name">{{ baby.babyName }}</view>
  8. <view class="babyBirthday">{{ babyBirthday }}</view>
  9. </view>
  10. </view>
  11. </view>
  12. <zd-empty v-else :src="'/static/img/common/empty_page.png'" desc="暂未添加宝贝"></zd-empty>
  13. </view>
  14. </template>
  15. <script>
  16. import moment from '@/common/moment';
  17. import { mapState } from 'vuex';
  18. import zdEmpty from '@/components/zd-empty/index';
  19. export default {
  20. data() {
  21. return {
  22. babyBirthday: '',
  23. }
  24. },
  25. computed: {
  26. ...mapState({
  27. baby: 'baby',
  28. onlineId: 'onlineId',
  29. offlineId: 'offlineId'
  30. })
  31. },
  32. components: {
  33. zdEmpty
  34. },
  35. onLoad(options) {
  36. // 来自微信小程序的跳转
  37. if (options && options.type === 'weapp') {
  38. // 获取报名信息
  39. this.$mStore.dispatch('getUserInfoOnline',{
  40. competitionChildId: this.onlineId
  41. })
  42. .then(async res => {
  43. const { baby } = res.data;
  44. const duration = moment.duration(moment().diff(baby.babyBirthday));
  45. this.babyBirthday = duration.years() + '年' + duration.months() + '月' + duration.days() + '天';
  46. }).catch(() => {
  47. console.log('catch');
  48. });
  49. }
  50. if (this.baby) {
  51. const duration = moment.duration(moment().diff(this.baby.babyBirthday));
  52. this.babyBirthday = duration.years() + '年' + duration.months() + '月' + duration.days() + '天';
  53. }
  54. },
  55. onShow() {},
  56. methods: {
  57. navTo(route) {
  58. this.$mRouter.push({route})
  59. }
  60. }
  61. }
  62. </script>
  63. <style lang="scss">
  64. .baby-info {
  65. width: 686upx;
  66. height: 166upx;
  67. background: #FFFFFF;
  68. border-radius: 20upx;
  69. border: 2upx solid #4CD84A;
  70. margin: 50upx auto 0;
  71. display: flex;
  72. align-items: center;
  73. image {
  74. width: 100upx;
  75. height: 100upx;
  76. border-radius: 50%;
  77. margin: 0 50upx 0 30upx;
  78. }
  79. .name {
  80. font-size: 32upx;
  81. font-family: PingFangSC-Semibold, PingFang SC;
  82. font-weight: 600;
  83. color: #161616;
  84. line-height: 44upx;
  85. }
  86. .babyBirthday {
  87. font-size: 28upx;
  88. font-family: PingFangSC-Regular, PingFang SC;
  89. font-weight: 400;
  90. color: #999999;
  91. line-height: 40upx;
  92. margin-top: 4upx;
  93. }
  94. }
  95. </style>