云链智安app
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <!-- 时间选择器弹窗 -->
  3. <uni-popup ref="popup" type="bottom" :safe-area="false">
  4. <view class="custom-picker">
  5. <view class="custom-picker__header">
  6. <view class="cancel" :style="{ color: canceColor }" @tap="onCancel">{{ cancelText }}</view>
  7. <view class="title">{{ title }}</view>
  8. <view class="confirm" :style="{ color: confirmColor }" @tap="onConfirm">{{ confirmText }}</view>
  9. </view>
  10. <picker-view :indicator-class="indicatorClass" :indicator-style="indicatorStyle" class="picker-view"
  11. :value="value" @change="bindChange" @pickstart="pickstart" @pickend="pickend">
  12. <picker-view-column>
  13. <view class="picker-view__item" v-for="(item,index) in rangeList[0]" :key="index">{{item}}</view>
  14. </picker-view-column>
  15. <picker-view-column>
  16. <view class="picker-view__item" v-for="(item,index) in rangeList[1]" :key="index">{{item}}</view>
  17. </picker-view-column>
  18. <view class="picker-view__segmentation">{{ segmentation }}</view>
  19. <picker-view-column>
  20. <view class="picker-view__item" v-for="(item,index) in rangeList[2]" :key="index">{{item}}</view>
  21. </picker-view-column>
  22. <picker-view-column>
  23. <view class="picker-view__item" v-for="(item,index) in rangeList[3]" :key="index">{{item}}</view>
  24. </picker-view-column>
  25. </picker-view>
  26. </view>
  27. </uni-popup>
  28. </template>
  29. <script>
  30. import {
  31. props,
  32. range
  33. } from './utils2.js';
  34. export default {
  35. name: 'TimePickerPopup',
  36. props: props,
  37. data() {
  38. return {
  39. rangeList: range,
  40. pickerValue: [0, 0, 0, 0],
  41. isScoll: false, // 是否正在滚动
  42. }
  43. },
  44. methods: {
  45. /**
  46. * 开启弹窗
  47. */
  48. open() {
  49. // 判断是否传入props -> value
  50. if (Array.isArray(this.value) && this.value.length) {
  51. this.pickerValue = this.value.map((item, index) => this.rangeList[index].findIndex(child =>
  52. child == this.value[index]));
  53. } else {
  54. this.pickerValue = [0, 0, 0, 0];
  55. }
  56. this.$refs.popup.open();
  57. },
  58. /**
  59. * 关闭弹窗
  60. */
  61. close() {
  62. this.$refs.popup.close();
  63. // 重置选中数据
  64. this.pickerValue = [0, 0, 0, 0];
  65. },
  66. /**
  67. * 点击确定
  68. */
  69. onConfirm() {
  70. if (!this.isScoll) {
  71. let data = this.value || ['00', '00', '00', '00'];
  72. if (this.pickerValue && this.pickerValue.length) {
  73. data = this.pickerValue.map((item, index) => String(this.rangeList[index][item]));
  74. }
  75. this.$emit('confirm', data);
  76. this.close();
  77. }
  78. },
  79. /**
  80. * 点击取消
  81. */
  82. onCancel() {
  83. this.close();
  84. },
  85. /**
  86. * 滚动开始
  87. */
  88. pickstart() {
  89. this.isScoll = true;
  90. },
  91. /**
  92. * 滚动结束
  93. */
  94. pickend() {
  95. this.isScoll = false;
  96. },
  97. /**
  98. * 选择器改变
  99. * @param {Object} e
  100. */
  101. bindChange(e) {
  102. this.pickerValue = e.detail.value;
  103. },
  104. }
  105. }
  106. </script>
  107. <style lang="scss" scoped>
  108. .custom-picker {
  109. width: 100%;
  110. height: 620rpx;
  111. background-color: #fff;
  112. padding-bottom: 0;
  113. padding-bottom: constant(safe-area-inset-bottom);
  114. padding-bottom: env(safe-area-inset-bottom);
  115. .custom-picker__header {
  116. display: flex;
  117. align-items: center;
  118. justify-content: space-between;
  119. padding: 30rpx 40rpx;
  120. .cancel {
  121. color: #666;
  122. }
  123. .title {
  124. font-size: 32rpx;
  125. color: #333;
  126. }
  127. .confirm {
  128. color: #2bb781;
  129. }
  130. }
  131. }
  132. .picker-view {
  133. width: 100%;
  134. height: 100%;
  135. margin-top: 20rpx;
  136. .picker-view__item {
  137. line-height: 100rpx;
  138. text-align: center;
  139. }
  140. // /deep/ .__indicator {
  141. // height: 100rpx;
  142. // color: #2bb781;
  143. // }
  144. .picker-view__segmentation {
  145. display: flex;
  146. align-items: center;
  147. }
  148. }
  149. </style>