123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478 |
- <template>
- <view :class="['lb-picker', inline ? 'lb-picker-inline' : '']">
- <!-- 默认插槽 -->
- <view v-if="!inline"
- class="lb-picker-default-slot"
- @tap="show">
- <slot></slot>
- </view>
- <!-- 遮罩层 -->
- <view v-if="visible && showMask && !inline"
- :class="['lb-picker-mask', animation ? 'lb-picker-mask-animation' : '']"
- :style="{
- backgroundColor: maskBgColor,
- zIndex: zIndex - 1
- }"
- @tap.stop="handleMaskTap"
- @touchmove.stop.prevent="moveHandle">
- </view>
- <view v-if="visible || inline"
- ref="container"
- :class="[
- 'lb-picker-container',
- !inline ? 'lb-picker-container-fixed' : '',
- animation ? 'lb-picker-container-animation' : '',
- containerVisible ? 'lb-picker-container-show' : ''
- ]"
- :style="{
- borderRadius: `${radius} ${radius} 0 0`,
- zIndex: zIndex
- }">
- <view v-if="showHeader"
- class="lb-picker-header">
- <!-- 头部顶部插槽 -->
- <slot name="header-top"></slot>
- <view class="lb-picker-header-actions">
- <!-- 取消 -->
- <view class="lb-picker-action lb-picker-action-cancel"
- @tap.stop="handleCancel">
- <slot v-if="$slots['cancel-text']"
- name="cancel-text">
- </slot>
- <text v-else
- class="lb-picker-action-cancel-text"
- :style="{ color: cancelColor }">{{ cancelText }}</text>
- </view>
- <!-- 中间 -->
- <view class="lb-picker-action lb-picker-center"
- v-if="$slots['action-center']">
- <slot name="action-center"></slot>
- </view>
- <!-- 确定 -->
- <view class="lb-picker-action lb-picker-action-confirm"
- @tap.stop="handleConfirm">
- <slot v-if="$slots['confirm-text']"
- name="confirm-text"> </slot>
- <text v-else
- class="lb-picker-action-confirm-text"
- :style="{ color: confirmColor }">{{ confirmText }}</text>
- </view>
- </view>
- <!-- 头部底部插槽 -->
- <slot name="header-bottom"></slot>
- </view>
- <view :class="[
- 'lb-picker-content',
- safeAreaInsetBottom ? 'lb-picker-content-safe-buttom' : ''
- ]">
- <!-- 选择器顶部插槽 -->
- <slot name="picker-top"></slot>
- <view class="lb-picker-content-main"
- :style="{ height: pickerContentHeight }">
- <!-- loading -->
- <view v-if="loading"
- class="lb-picker-loading">
- <slot name="loading">
- <image class="lb-picker-loading-img"
- src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAPFklEQVR4Xu2dTXbUOBeGpToHF7OGFTSsAFhBJytoWAFkUnKNoFdAWEGHUVmZJKygwwpIVkB6BYQVdDIj4Ry5zw3210W++pFtSb6S3pqWpHv9Xj2WZMtXUuAHBaDAWgUktIECUGC9AgAEvQMKbFAAgKB7QAEAgj4ABfopgBGkn26olYkCACSTQOMy+ykAQPrphlqZKABARg700dHRg+vr69+klE/run5E7kgpL+q6Pp9Op2d7e3uXI7uYtXkAMmL4tdZvhRBvhBAP1rhBcBwopd6N6GbWpgHICOGnUePm5uaTEOKppfnzoih2MZpYquWwGABxKKZtU1VVfZJS7tiWp3J1XZ+WZbnbpQ7KDlcAgAzXsFMLi8Xi1WQyOepUqSlsjNmbz+fHfeqiTj8FAEg/3XrX0lp/7jC1umvnXCn1rLdxVOysAADpLFn/Cs3a45/+LQhRFMVDrEWGKNitLgDppteg0ovFYmcymdDivPfPGLM7n89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KAJCA8QAgAcV2ZAqAOBLSppnma7p/bMquK8MhofMQ/2OrC0ACR6yqqnMp5ZM+Zrmkwunje6x1AEjgyC0Wi95ZJDll+wgs22jmAMgI0vfMZn+mlKJkB/gFVACABBS7NUVrkevr61PbqRZNrabT6c7Yh8mMINXoJgHIiCHQWm9LknclhDhQSlE5/EZQAICMIPqyyTt5oihhHv0oT9R5URSnGDXGDRAAGVd/WGeuAABhHiC4N64CAGRc/WGduQIAhHmA4N64CgCQcfWHdeYKABDmAYJ74yoAQMbVH9aZKwBAmAcI7o2rwL9NuZ5QQgPItwAAAABJRU5ErkJggg==">
- </image>
- </slot>
- </view>
- <!-- 暂无数据 -->
- <view v-if="isEmpty && !loading && mode !== 'dateSelector'"
- class="lb-picker-empty">
- <slot name="empty">
- <text class="lb-picker-empty-text"
- :style="{ color: emptyColor }">{{ emptyText }}</text>
- </slot>
- </view>
- <!-- 单选 -->
- <selector-picker v-if="mode === 'selector' && !loading && !isEmpty"
- :ref="mode"
- :value="value"
- :list="list"
- :mode="mode"
- :props="pickerProps"
- :height="pickerContentHeight"
- :inline="inline"
- :column-style="columnStyle"
- :active-column-style="activeColumnStyle"
- :align="align"
- :press-enable="pressEnable"
- :press-time="pressTime"
- :formatter="formatter"
- @change="handleChange">
- </selector-picker>
- <!-- 多列联动 -->
- <multi-selector-picker v-if="mode === 'multiSelector' && !loading && !isEmpty"
- :ref="mode"
- :value="value"
- :list="list"
- :mode="mode"
- :level="level"
- :visible="visible"
- :props="pickerProps"
- :height="pickerContentHeight"
- :inline="inline"
- :column-style="columnStyle"
- :active-column-style="activeColumnStyle"
- :align="align"
- :press-enable="pressEnable"
- :press-time="pressTime"
- :formatter="formatter"
- @change="handleChange">
- </multi-selector-picker>
- <!-- 非联动选择 -->
- <unlinked-selector-picker v-if="mode === 'unlinkedSelector' && !loading && !isEmpty"
- :ref="mode"
- :value="value"
- :list="list"
- :mode="mode"
- :visible="visible"
- :props="pickerProps"
- :height="pickerContentHeight"
- :inline="inline"
- :column-style="columnStyle"
- :active-column-style="activeColumnStyle"
- :align="align"
- :press-enable="pressEnable"
- :press-time="pressTime"
- :formatter="formatter"
- @change="handleChange">
- </unlinked-selector-picker>
- <!-- 日期选择 -->
- <date-selector-picker v-if="mode === 'dateSelector' && !loading"
- :ref="mode"
- :value="value"
- :mode="mode"
- :visible="visible"
- :height="pickerContentHeight"
- :inline="inline"
- :column-style="columnStyle"
- :active-column-style="activeColumnStyle"
- :align="align"
- :formatter="formatter"
- :format="format"
- :display-format="displayFormat"
- :start-date="startDate"
- :end-date="endDate"
- :default-time-limit="defaultTimeLimit"
- :is-show-chinese="isShowChinese"
- :ch-config="pickerChConfig"
- :filter="filter"
- @change="handleChange">
- </date-selector-picker>
- </view>
- <!-- 选择器底部插槽 -->
- <slot name="picker-bottom"></slot>
- </view>
- </view>
- </view>
- </template>
- <script>
- const defaultMaskBgColor = 'rgba(0, 0, 0, 0)'
- const defaultProps = {
- label: 'label',
- value: 'value',
- children: 'children'
- }
- const defaultChConfig = {
- year: '年',
- month: '月',
- day: '日',
- hour: '时',
- minute: '分',
- second: '秒'
- }
- // #ifdef APP-NVUE
- const animation = weex.requireModule('animation')
- // #endif
- import { getColumns } from './utils'
- import SelectorPicker from './pickers/selector-picker'
- import MultiSelectorPicker from './pickers/multi-selector-picker'
- import UnlinkedSelectorPicker from './pickers/unlinked-selector-picker'
- import DateSelectorPicker from './pickers/date-selector-picker'
- export default {
- components: {
- SelectorPicker,
- MultiSelectorPicker,
- UnlinkedSelectorPicker,
- DateSelectorPicker
- },
- props: {
- value: [String, Number, Array],
- list: Array,
- mode: {
- type: String,
- default: 'selector'
- },
- level: {
- type: Number,
- default: 1
- },
- props: {
- type: Object
- },
- cancelText: {
- type: String,
- default: '取消'
- },
- cancelColor: {
- type: String,
- default: '#999'
- },
- confirmText: {
- type: String,
- default: '确定'
- },
- confirmColor: {
- type: String,
- default: '#007aff'
- },
- canHide: {
- type: Boolean,
- default: true
- },
- emptyColor: {
- type: String,
- default: '#999'
- },
- emptyText: {
- type: String,
- default: '暂无数据'
- },
- radius: String,
- columnNum: {
- type: Number,
- default: 5
- },
- loading: Boolean,
- closeOnClickMask: {
- type: Boolean,
- default: true
- },
- showMask: {
- type: Boolean,
- default: true
- },
- maskColor: {
- type: String,
- default: 'rgba(0, 0, 0, 0.4)'
- },
- dataset: Object,
- inline: Boolean,
- showHeader: {
- type: Boolean,
- default: true
- },
- animation: {
- type: Boolean,
- default: true
- },
- zIndex: {
- type: Number,
- default: 999
- },
- safeAreaInsetBottom: {
- type: Boolean,
- default: true
- },
- disabled: Boolean,
- columnStyle: Object,
- activeColumnStyle: Object,
- align: {
- type: String,
- default: 'center'
- },
- pressEnable: Boolean,
- pressTime: {
- type: Number,
- default: 500
- },
- formatter: Function,
- format: {
- type: String,
- default: 'YYYY-MM-DD'
- },
- displayFormat: {
- type: String,
- default: 'YYYY-MM-DD'
- },
- startDate: String,
- endDate: String,
- defaultTimeLimit: {
- type: Number,
- default: 20
- },
- isShowChinese: {
- type: Boolean,
- default: true
- },
- chConfig: Object,
- filter: Function
- },
- data () {
- return {
- visible: false,
- containerVisible: false,
- maskBgColor: defaultMaskBgColor,
- myValue: this.value,
- picker: {},
- pickerProps: Object.assign({}, defaultProps, this.props),
- pickerChConfig: Object.assign({}, defaultChConfig, this.chConfig)
- }
- },
- computed: {
- pickerContentHeight () {
- return 34 * this.columnNum + 'px'
- },
- isEmpty () {
- if (this.mode === 'dateSelector') return false
- if (!this.list && this.mode !== 'dateSelector') return true
- if (this.list && !this.list.length) return true
- return false
- }
- },
- methods: {
- show () {
- if (this.inline || this.disabled) return
- this.visible = true
- setTimeout(() => {
- this.maskBgColor = this.maskColor
- // #ifndef APP-NVUE
- this.containerVisible = true
- // #endif
- // #ifdef APP-NVUE
- this.wxAnimation(0)
- // #endif
- }, 20)
- },
- hide () {
- if (this.inline) return
- this.maskBgColor = defaultMaskBgColor
- // #ifndef APP-NVUE
- this.containerVisible = false
- // #endif
- // #ifdef APP-NVUE
- this.wxAnimation('100%')
- // #endif
- setTimeout(() => {
- this.visible = false
- }, 300)
- },
- handleCancel () {
- this.$emit('cancel', this.picker)
- if (this.canHide && !this.inline) {
- this.hide()
- }
- },
- handleConfirm () {
- if (this.isEmpty) {
- this.$emit('confirm', null)
- this.hide()
- } else {
- const picker = { ...this.picker }
- this.$refs[this.mode].isConfirmChange = true
- this.myValue = picker.value
- this.$emit('confirm', this.picker)
- if (this.canHide) this.hide()
- }
- },
- handleChange ({ value, valueArr, item, index, change }) {
- if (this.mode === 'dateSelector') {
- this.picker.valueArr = valueArr
- }
- this.picker.value = value
- this.picker.item = item
- this.picker.index = index
- this.picker.change = change
- this.picker.dataset = this.dataset || {}
- if (this.$refs[this.mode] && this.inline) {
- this.$refs[this.mode].isConfirmChange = true
- }
- this.$emit('change', this.picker)
- },
- handleMaskTap () {
- if (this.closeOnClickMask) {
- this.hide()
- }
- },
- moveHandle () {},
- // #ifdef APP-NVUE
- wxAnimation (num) {
- const $container = this.$refs.container
- animation.transition($container, {
- styles: {
- transform: `translateY(${num})`
- },
- duration: 300
- })
- },
- // #endif
- getColumnsInfo (value, type = 1) {
- let columnsInfo = getColumns(
- {
- value,
- list: this.list,
- mode: this.mode,
- props: this.pickerProps,
- level: this.level
- },
- type
- )
- if (columnsInfo) {
- if (this.mode === 'selector') {
- columnsInfo.index = columnsInfo.index[0]
- }
- } else {
- columnsInfo = {}
- }
- columnsInfo.dataset = this.dataset || {}
- return columnsInfo
- }
- },
- watch: {
- value (newVal) {
- this.myValue = newVal
- },
- myValue (newVal) {
- this.$emit('input', newVal)
- },
- visible (newVisible) {
- if (newVisible) {
- this.$emit('show')
- } else {
- this.$emit('hide')
- }
- },
- props (newProps) {
- this.pickerProps = Object.assign({}, defaultProps, newProps)
- },
- chConfig (newVal) {
- this.pickerChConfig = Object.assign({}, defaultChConfig, newVal)
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @import "./style/picker.scss";
- </style>
|