top-box.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <view>
  3. <!-- 头部信息 -->
  4. <view class="home-topinfo">
  5. <!-- 更新时间戳 -->
  6. <view class="refresh-time" :style="'top:'+ capsuleBottom + 'px;left:'+ capsuleMiddle + 'px;' ">
  7. <text class="time-text">更新于: {{timeStamp}}</text>
  8. </view>
  9. </view>
  10. <view style="display: flex;margin-top: -450rpx;
  11. margin-bottom: 120rpx;">
  12. <image class="children-avatar" :src="childreninfo.avatar" @click="showChildrenList"></image>
  13. <view class="children-name">
  14. <text class="name">{{childreninfo.name}}</text>
  15. <view class="detail-box">
  16. <text class="detail" @click="setSemesterPicker = true">{{semester}}</text>
  17. <!-- 选择学期 -->
  18. <view class="select-icon">
  19. <u-icon name="arrow-down" color="#FFF" @click="setSemesterPicker = true"></u-icon>
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. <u-picker class="picker" :show="setSemesterPicker" :closeOnClickOverlay="true" :columns="semesterList" ref="uPicker"
  25. @confirm="pickerConfirm" @cancel="pickerCancel" @change="changeHandler" :immediateChange="true"></u-picker>
  26. <!-- 切换孩子 -->
  27. <view class="list-box" v-show="show">
  28. <view class="children-item" v-for="(item,index) in parentdetail.childrenList" :key="index"
  29. @click="switchChildren(item)">
  30. <view class="item-box">
  31. <image class="item-avatar" :src="item.avatar"></image>
  32. <text class="item-text">{{item.name}}</text>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import {
  40. mapState,
  41. mapMutations
  42. } from 'vuex'
  43. export default {
  44. name: "top-box",
  45. props: {
  46. timeStamp: {
  47. type: String,
  48. default: false
  49. }
  50. },
  51. created() {
  52. this.getCapsuleSite()
  53. },
  54. data() {
  55. return {
  56. show: false,
  57. setSemesterPicker: false,
  58. //下边界坐标
  59. capsuleBottom: 0,
  60. capsuleMiddle: 0,
  61. temp: '',
  62. };
  63. },
  64. computed: {
  65. ...mapState('m_children', ['childreninfo', 'semester', 'semesterList']),
  66. ...mapState('m_parent', ['parentdetail'])
  67. },
  68. methods: {
  69. ...mapMutations('m_children', ['updateChildrenInfo', 'updateChildrenSemester']),
  70. changeHandler(e){
  71. //更新学期存储与显示
  72. this.temp = e.value[0]
  73. },
  74. //学期选择
  75. pickerConfirm(e) {
  76. //拼接图表数据
  77. this.updateChildrenSemester(this.temp)
  78. if(this.semester == e.value[0]){
  79. let that = this
  80. setTimeout(function (){
  81. uni.$showMsg('切换完成',1000)
  82. that.setSemesterPicker = false
  83. },100)
  84. }else{
  85. this.updateChildrenSemester(e.value[0])
  86. this.setSemesterPicker = false
  87. }
  88. },
  89. //取消选择
  90. pickerCancel() {
  91. uni.$showMsg('取消选择',1000)
  92. this.setSemesterPicker = false
  93. },
  94. //头部孩子选择
  95. showChildrenList(e) {
  96. console.log('chooseChildren' + e)
  97. this.show = !this.show
  98. },
  99. switchChildren(item) {
  100. console.log(item);
  101. this.updateChildrenInfo(item)
  102. this.show = false
  103. },
  104. //获取胶囊位置信息
  105. getCapsuleSite(){
  106. let res=uni.getMenuButtonBoundingClientRect()
  107. this.capsuleBottom = res.bottom + 5
  108. this.capsuleMiddle = res.left
  109. }
  110. }
  111. }
  112. </script>
  113. <style lang="scss">
  114. .home-topinfo {
  115. height: 600rpx;
  116. background: linear-gradient(#0080ff, $page-background-color);
  117. }
  118. .children-avatar {
  119. margin-left: 40rpx;
  120. width: 100rpx;
  121. height: 100rpx;
  122. border-radius: 100%;
  123. border: 4rpx solid #FFFFFF;
  124. box-shadow: 0 10rpx 20rpx rgba(0, 0, 0, 0.2);
  125. }
  126. .children-name {
  127. margin-left: 25rpx;
  128. padding-top: 5rpx;
  129. display: flex;
  130. flex-direction: column;
  131. justify-content: center;
  132. .name {
  133. color: #3B4144;
  134. font-size: 36rpx;
  135. font-weight: bold;
  136. }
  137. .detail-box {
  138. display: flex;
  139. .detail {
  140. color: #FFFFFF;
  141. font-weight: bold;
  142. font-size: 30rpx;
  143. }
  144. .select-icon {
  145. margin:7rpx 0 0 10rpx;
  146. width: 30rpx;
  147. height: 30rpx;
  148. }
  149. }
  150. }
  151. .refresh-time {
  152. position: relative;
  153. .time-text {
  154. padding: 10rpx;
  155. font-size: 24rpx;
  156. color: #FFFFFF;
  157. font-weight: bold;
  158. }
  159. }
  160. .list-box {
  161. margin: -100rpx 40rpx 120rpx 33rpx;
  162. display: flex;
  163. flex-wrap: wrap;
  164. .children-item {
  165. margin: 0 10rpx 0 10rpx;
  166. .item-box {
  167. display: flex;
  168. flex-direction: column;
  169. justify-content: center;
  170. align-items: center;
  171. .item-avatar {
  172. width: 90rpx;
  173. height: 90rpx;
  174. border-radius: 50rpx;
  175. border: 4rpx solid #FFFFFF;
  176. }
  177. .item-text {
  178. font-size: 24rpx;
  179. font-weight: bold;
  180. color: #6b778d;
  181. }
  182. }
  183. }
  184. }
  185. .t-icon {
  186. width: 40rpx;
  187. height: 40rpx;
  188. }
  189. </style>