| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <template>
- <!-- 时间选择器弹窗 -->
- <uni-popup ref="popup" type="bottom" :safe-area="false">
- <view class="custom-picker">
- <view class="custom-picker__header">
- <view class="cancel" :style="{ color: canceColor }" @tap="onCancel">{{ cancelText }}</view>
- <view class="title">{{ title }}</view>
- <view class="confirm" :style="{ color: confirmColor }" @tap="onConfirm">{{ confirmText }}</view>
- </view>
- <picker-view :indicator-class="indicatorClass" :indicator-style="indicatorStyle" class="picker-view"
- :value="value" @change="bindChange" @pickstart="pickstart" @pickend="pickend">
- <picker-view-column>
- <view class="picker-view__item" v-for="(item,index) in rangeList[0]" :key="index">{{item}}</view>
- </picker-view-column>
- <picker-view-column>
- <view class="picker-view__item" v-for="(item,index) in rangeList[1]" :key="index">{{item}}</view>
- </picker-view-column>
- <view class="picker-view__segmentation">{{ segmentation }}</view>
- <picker-view-column>
- <view class="picker-view__item" v-for="(item,index) in rangeList[2]" :key="index">{{item}}</view>
- </picker-view-column>
- <picker-view-column>
- <view class="picker-view__item" v-for="(item,index) in rangeList[3]" :key="index">{{item}}</view>
- </picker-view-column>
- </picker-view>
- </view>
- </uni-popup>
- </template>
-
- <script>
- import {
- props,
- range
- } from './utils2.js';
- export default {
- name: 'TimePickerPopup',
- props: props,
- data() {
- return {
- rangeList: range,
- pickerValue: [0, 0, 0, 0],
- isScoll: false, // 是否正在滚动
- }
- },
- methods: {
- /**
- * 开启弹窗
- */
- open() {
- // 判断是否传入props -> value
- if (Array.isArray(this.value) && this.value.length) {
- this.pickerValue = this.value.map((item, index) => this.rangeList[index].findIndex(child =>
- child == this.value[index]));
- } else {
- this.pickerValue = [0, 0, 0, 0];
- }
- this.$refs.popup.open();
- },
- /**
- * 关闭弹窗
- */
- close() {
- this.$refs.popup.close();
- // 重置选中数据
- this.pickerValue = [0, 0, 0, 0];
- },
- /**
- * 点击确定
- */
- onConfirm() {
- if (!this.isScoll) {
- let data = this.value || ['00', '00', '00', '00'];
- if (this.pickerValue && this.pickerValue.length) {
- data = this.pickerValue.map((item, index) => String(this.rangeList[index][item]));
- }
- this.$emit('confirm', data);
- this.close();
- }
- },
- /**
- * 点击取消
- */
- onCancel() {
- this.close();
- },
- /**
- * 滚动开始
- */
- pickstart() {
- this.isScoll = true;
- },
- /**
- * 滚动结束
- */
- pickend() {
- this.isScoll = false;
- },
- /**
- * 选择器改变
- * @param {Object} e
- */
- bindChange(e) {
- this.pickerValue = e.detail.value;
- },
- }
- }
- </script>
-
- <style lang="scss" scoped>
- .custom-picker {
- width: 100%;
- height: 620rpx;
- background-color: #fff;
- padding-bottom: 0;
- padding-bottom: constant(safe-area-inset-bottom);
- padding-bottom: env(safe-area-inset-bottom);
-
- .custom-picker__header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 30rpx 40rpx;
-
- .cancel {
- color: #666;
- }
-
- .title {
- font-size: 32rpx;
- color: #333;
- }
-
- .confirm {
- color: #2bb781;
- }
- }
- }
-
- .picker-view {
- width: 100%;
- height: 100%;
- margin-top: 20rpx;
-
- .picker-view__item {
- line-height: 100rpx;
- text-align: center;
- }
-
- // /deep/ .__indicator {
- // height: 100rpx;
- // color: #2bb781;
- // }
-
- .picker-view__segmentation {
- display: flex;
- align-items: center;
- }
- }
- </style>
|