|
@ -1,6 +1,6 @@ |
|
|
<template> |
|
|
<template> |
|
|
<view class="u-select"> |
|
|
<view class="u-select"> |
|
|
<!-- <view class="u-select__action" :class="{ |
|
|
<!-- <view class="u-select__action" :class="{ |
|
|
'u-select--border': border |
|
|
'u-select--border': border |
|
|
}" @tap.stop="selectHandler"> |
|
|
}" @tap.stop="selectHandler"> |
|
|
<view class="u-select__action__icon" :class="{ |
|
|
<view class="u-select__action__icon" :class="{ |
|
@ -9,429 +9,414 @@ |
|
|
<u-icon name="arrow-down-fill" size="26" color="#c0c4cc"></u-icon> |
|
|
<u-icon name="arrow-down-fill" size="26" color="#c0c4cc"></u-icon> |
|
|
</view> |
|
|
</view> |
|
|
</view> --> |
|
|
</view> --> |
|
|
<u-popup :blur="blur" :maskCloseAble="maskCloseAble" mode="bottom" :popup="false" v-model="popupValue" length="auto" :safeAreaInsetBottom="safeAreaInsetBottom" @close="close" :z-index="uZIndex"> |
|
|
<u-popup :blur="blur" :maskCloseAble="maskCloseAble" mode="bottom" :popup="false" v-model="popupValue" length="auto" :safeAreaInsetBottom="safeAreaInsetBottom" @close="close" :z-index="uZIndex"> |
|
|
<view class="u-select"> |
|
|
<view class="u-select"> |
|
|
<view class="u-select__header" @touchmove.stop.prevent=""> |
|
|
<view class="u-select__header" @touchmove.stop.prevent=""> |
|
|
<view |
|
|
<view class="u-select__header__cancel u-select__header__btn" :style="{ color: cancelColor }" hover-class="u-hover-class" :hover-stay-time="150" @tap.stop="getResult('cancel')"> |
|
|
class="u-select__header__cancel u-select__header__btn" |
|
|
{{ cancelText }} |
|
|
:style="{ color: cancelColor }" |
|
|
</view> |
|
|
hover-class="u-hover-class" |
|
|
<view class="u-select__header__title"> |
|
|
:hover-stay-time="150" |
|
|
{{ title }} |
|
|
@tap.stop="getResult('cancel')" |
|
|
</view> |
|
|
> |
|
|
<view class="u-select__header__confirm u-select__header__btn" :style="{ color: moving ? cancelColor : confirmColor }" hover-class="u-hover-class" :hover-stay-time="150" @touchmove.stop="" @tap.stop="getResult('confirm')"> |
|
|
{{cancelText}} |
|
|
{{ confirmText }} |
|
|
</view> |
|
|
</view> |
|
|
<view class="u-select__header__title"> |
|
|
</view> |
|
|
{{title}} |
|
|
<view class="u-select__body"> |
|
|
</view> |
|
|
<picker-view @change="columnChange" class="u-select__body__picker-view" :value="defaultSelector" @pickstart="pickstart" @pickend="pickend"> |
|
|
<view |
|
|
<picker-view-column v-for="(item, index) in columnData" :key="index"> |
|
|
class="u-select__header__confirm u-select__header__btn" |
|
|
<view class="u-select__body__picker-view__item" v-for="(item1, index1) in item" :key="index1"> |
|
|
:style="{ color: moving ? cancelColor : confirmColor }" |
|
|
<view class="u-line-1">{{ item1[labelName] }}</view> |
|
|
hover-class="u-hover-class" |
|
|
</view> |
|
|
:hover-stay-time="150" |
|
|
</picker-view-column> |
|
|
@touchmove.stop="" |
|
|
</picker-view> |
|
|
@tap.stop="getResult('confirm')" |
|
|
</view> |
|
|
> |
|
|
</view> |
|
|
{{confirmText}} |
|
|
</u-popup> |
|
|
</view> |
|
|
</view> |
|
|
</view> |
|
|
|
|
|
<view class="u-select__body"> |
|
|
|
|
|
<picker-view @change="columnChange" class="u-select__body__picker-view" :value="defaultSelector" @pickstart="pickstart" @pickend="pickend"> |
|
|
|
|
|
<picker-view-column v-for="(item, index) in columnData" :key="index"> |
|
|
|
|
|
<view class="u-select__body__picker-view__item" v-for="(item1, index1) in item" :key="index1"> |
|
|
|
|
|
<view class="u-line-1">{{ item1[labelName] }}</view> |
|
|
|
|
|
</view> |
|
|
|
|
|
</picker-view-column> |
|
|
|
|
|
</picker-view> |
|
|
|
|
|
</view> |
|
|
|
|
|
</view> |
|
|
|
|
|
</u-popup> |
|
|
|
|
|
</view> |
|
|
|
|
|
</template> |
|
|
</template> |
|
|
|
|
|
|
|
|
<script> |
|
|
<script> |
|
|
/** |
|
|
/** |
|
|
* select 列选择器 |
|
|
* select 列选择器 |
|
|
* @description 此选择器用于单列,多列,多列联动的选择场景。(从1.3.0版本起,不建议使用Picker组件的单列和多列模式,Select组件是专门为列选择而构造的组件,更简单易用。) |
|
|
* @description 此选择器用于单列,多列,多列联动的选择场景。(从1.3.0版本起,不建议使用Picker组件的单列和多列模式,Select组件是专门为列选择而构造的组件,更简单易用。) |
|
|
* @tutorial http://uviewui.com/components/select.html |
|
|
* @tutorial http://uviewui.com/components/select.html |
|
|
* @property {String} mode 模式选择,"single-column"-单列模式,"mutil-column"-多列模式,"mutil-column-auto"-多列联动模式 |
|
|
* @property {String} mode 模式选择,"single-column"-单列模式,"mutil-column"-多列模式,"mutil-column-auto"-多列联动模式 |
|
|
* @property {Array} list 列数据,数组形式,见官网说明 |
|
|
* @property {Array} list 列数据,数组形式,见官网说明 |
|
|
* @property {Boolean} v-model 布尔值变量,用于控制选择器的弹出与收起 |
|
|
* @property {Boolean} v-model 布尔值变量,用于控制选择器的弹出与收起 |
|
|
* @property {Boolean} safe-area-inset-bottom 是否开启底部安全区适配(默认false) |
|
|
* @property {Boolean} safe-area-inset-bottom 是否开启底部安全区适配(默认false) |
|
|
* @property {String} cancel-color 取消按钮的颜色(默认#606266) |
|
|
* @property {String} cancel-color 取消按钮的颜色(默认#606266) |
|
|
* @property {String} confirm-color 确认按钮的颜色(默认#2979ff) |
|
|
* @property {String} confirm-color 确认按钮的颜色(默认#2979ff) |
|
|
* @property {String} confirm-text 确认按钮的文字 |
|
|
* @property {String} confirm-text 确认按钮的文字 |
|
|
* @property {String} cancel-text 取消按钮的文字 |
|
|
* @property {String} cancel-text 取消按钮的文字 |
|
|
* @property {String} default-value 提供的默认选中的下标,见官网说明 |
|
|
* @property {String} default-value 提供的默认选中的下标,见官网说明 |
|
|
* @property {Boolean} mask-close-able 是否允许通过点击遮罩关闭Picker(默认true) |
|
|
* @property {Boolean} mask-close-able 是否允许通过点击遮罩关闭Picker(默认true) |
|
|
* @property {String Number} z-index 弹出时的z-index值(默认10075) |
|
|
* @property {String Number} z-index 弹出时的z-index值(默认10075) |
|
|
* @property {String} value-name 自定义list数据的value属性名 1.3.6 |
|
|
* @property {String} value-name 自定义list数据的value属性名 1.3.6 |
|
|
* @property {String} label-name 自定义list数据的label属性名 1.3.6 |
|
|
* @property {String} label-name 自定义list数据的label属性名 1.3.6 |
|
|
* @property {String} child-name 自定义list数据的children属性名,只对多列联动模式有效 1.3.7 |
|
|
* @property {String} child-name 自定义list数据的children属性名,只对多列联动模式有效 1.3.7 |
|
|
* @event {Function} confirm 点击确定按钮,返回当前选择的值 |
|
|
* @event {Function} confirm 点击确定按钮,返回当前选择的值 |
|
|
* @example <u-select v-model="show" :list="list"></u-select> |
|
|
* @example <u-select v-model="show" :list="list"></u-select> |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
export default { |
|
|
export default { |
|
|
emits: ["update:modelValue", "input", "confirm","cancel"], |
|
|
emits: ['update:modelValue', 'input', 'confirm', 'cancel'], |
|
|
props: { |
|
|
props: { |
|
|
// 通过双向绑定控制组件的弹出与收起 |
|
|
// 通过双向绑定控制组件的弹出与收起 |
|
|
value: { |
|
|
value: { |
|
|
type: Boolean, |
|
|
type: Boolean, |
|
|
default: false |
|
|
default: false |
|
|
}, |
|
|
}, |
|
|
modelValue: { |
|
|
modelValue: { |
|
|
type: Boolean, |
|
|
type: Boolean, |
|
|
default: false |
|
|
default: false |
|
|
}, |
|
|
}, |
|
|
// 列数据 |
|
|
// 列数据 |
|
|
list: { |
|
|
list: { |
|
|
type: Array, |
|
|
type: Array, |
|
|
default() { |
|
|
default() { |
|
|
return []; |
|
|
return [] |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
// 是否显示边框 |
|
|
// 是否显示边框 |
|
|
border: { |
|
|
border: { |
|
|
type: Boolean, |
|
|
type: Boolean, |
|
|
default: true |
|
|
default: true |
|
|
}, |
|
|
}, |
|
|
// "取消"按钮的颜色 |
|
|
// "取消"按钮的颜色 |
|
|
cancelColor: { |
|
|
cancelColor: { |
|
|
type: String, |
|
|
type: String, |
|
|
default: '#606266' |
|
|
default: '#606266' |
|
|
}, |
|
|
}, |
|
|
// "确定"按钮的颜色 |
|
|
// "确定"按钮的颜色 |
|
|
confirmColor: { |
|
|
confirmColor: { |
|
|
type: String, |
|
|
type: String, |
|
|
default: '#2979ff' |
|
|
default: '#2979ff' |
|
|
}, |
|
|
}, |
|
|
// 弹出的z-index值 |
|
|
// 弹出的z-index值 |
|
|
zIndex: { |
|
|
zIndex: { |
|
|
type: [String, Number], |
|
|
type: [String, Number], |
|
|
default: 0 |
|
|
default: 0 |
|
|
}, |
|
|
}, |
|
|
safeAreaInsetBottom: { |
|
|
safeAreaInsetBottom: { |
|
|
type: Boolean, |
|
|
type: Boolean, |
|
|
default: false |
|
|
default: false |
|
|
}, |
|
|
}, |
|
|
// 是否允许通过点击遮罩关闭Picker |
|
|
// 是否允许通过点击遮罩关闭Picker |
|
|
maskCloseAble: { |
|
|
maskCloseAble: { |
|
|
type: Boolean, |
|
|
type: Boolean, |
|
|
default: true |
|
|
default: true |
|
|
}, |
|
|
}, |
|
|
// 提供的默认选中的下标 |
|
|
// 提供的默认选中的下标 |
|
|
defaultValue: { |
|
|
defaultValue: { |
|
|
type: Array, |
|
|
type: Array, |
|
|
default() { |
|
|
default() { |
|
|
return [0]; |
|
|
return [0] |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
// 模式选择,single-column-单列,mutil-column-多列,mutil-column-auto-多列联动 |
|
|
// 模式选择,single-column-单列,mutil-column-多列,mutil-column-auto-多列联动 |
|
|
mode: { |
|
|
mode: { |
|
|
type: String, |
|
|
type: String, |
|
|
default: 'single-column' |
|
|
default: 'single-column' |
|
|
}, |
|
|
}, |
|
|
// 自定义value属性名 |
|
|
// 自定义value属性名 |
|
|
valueName: { |
|
|
valueName: { |
|
|
type: String, |
|
|
type: String, |
|
|
default: 'value' |
|
|
default: 'value' |
|
|
}, |
|
|
}, |
|
|
// 自定义label属性名 |
|
|
// 自定义label属性名 |
|
|
labelName: { |
|
|
labelName: { |
|
|
type: String, |
|
|
type: String, |
|
|
default: 'label' |
|
|
default: 'label' |
|
|
}, |
|
|
}, |
|
|
// 自定义多列联动模式的children属性名 |
|
|
// 自定义多列联动模式的children属性名 |
|
|
childName: { |
|
|
childName: { |
|
|
type: String, |
|
|
type: String, |
|
|
default: 'children' |
|
|
default: 'children' |
|
|
}, |
|
|
}, |
|
|
// 顶部标题 |
|
|
// 顶部标题 |
|
|
title: { |
|
|
title: { |
|
|
type: String, |
|
|
type: String, |
|
|
default: '' |
|
|
default: '' |
|
|
}, |
|
|
}, |
|
|
// 取消按钮的文字 |
|
|
// 取消按钮的文字 |
|
|
cancelText: { |
|
|
cancelText: { |
|
|
type: String, |
|
|
type: String, |
|
|
default: '取消' |
|
|
default: '取消' |
|
|
}, |
|
|
}, |
|
|
// 确认按钮的文字 |
|
|
// 确认按钮的文字 |
|
|
confirmText: { |
|
|
confirmText: { |
|
|
type: String, |
|
|
type: String, |
|
|
default: '确认' |
|
|
default: '确认' |
|
|
}, |
|
|
}, |
|
|
// 遮罩的模糊度 |
|
|
// 遮罩的模糊度 |
|
|
blur: { |
|
|
blur: { |
|
|
type: [Number, String], |
|
|
type: [Number, String], |
|
|
default: 0 |
|
|
default: 0 |
|
|
}, |
|
|
} |
|
|
}, |
|
|
}, |
|
|
data() { |
|
|
data() { |
|
|
return { |
|
|
return { |
|
|
popupValue: false, |
|
|
popupValue: false, |
|
|
// 用于列改变时,保存当前的索引,下一次变化时比较得出是哪一列发生了变化 |
|
|
// 用于列改变时,保存当前的索引,下一次变化时比较得出是哪一列发生了变化 |
|
|
defaultSelector: [0], |
|
|
defaultSelector: [0], |
|
|
// picker-view的数据 |
|
|
// picker-view的数据 |
|
|
columnData: [], |
|
|
columnData: [], |
|
|
// 每次队列发生变化时,保存选择的结果 |
|
|
// 每次队列发生变化时,保存选择的结果 |
|
|
selectValue: [], |
|
|
selectValue: [], |
|
|
// 上一次列变化时的index |
|
|
// 上一次列变化时的index |
|
|
lastSelectIndex: [], |
|
|
lastSelectIndex: [], |
|
|
// 列数 |
|
|
// 列数 |
|
|
columnNum: 0, |
|
|
columnNum: 0, |
|
|
// 列是否还在滑动中,微信小程序如果在滑动中就点确定,结果可能不准确 |
|
|
// 列是否还在滑动中,微信小程序如果在滑动中就点确定,结果可能不准确 |
|
|
moving: false |
|
|
moving: false |
|
|
}; |
|
|
} |
|
|
}, |
|
|
}, |
|
|
watch: { |
|
|
watch: { |
|
|
// 在select弹起的时候,重新初始化所有数据 |
|
|
// 在select弹起的时候,重新初始化所有数据 |
|
|
value: { |
|
|
value: { |
|
|
immediate: true, |
|
|
immediate: true, |
|
|
handler(val) { |
|
|
handler(val) { |
|
|
if(val) setTimeout(() => this.init(), 10); |
|
|
if (val) setTimeout(() => this.init(), 10) |
|
|
this.popupValue = val; |
|
|
this.popupValue = val |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
modelValue: { |
|
|
modelValue: { |
|
|
immediate: true, |
|
|
immediate: true, |
|
|
handler(val) { |
|
|
handler(val) { |
|
|
if(val) setTimeout(() => this.init(), 10); |
|
|
if (val) setTimeout(() => this.init(), 10) |
|
|
this.popupValue = val; |
|
|
this.popupValue = val |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
computed: { |
|
|
|
|
|
uZIndex() { |
|
|
|
|
|
// 如果用户有传递z-index值,优先使用 |
|
|
|
|
|
return this.zIndex ? this.zIndex : this.$u.zIndex.popup |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
methods: { |
|
|
|
|
|
// 标识滑动开始,只有微信小程序才有这样的事件 |
|
|
|
|
|
pickstart() { |
|
|
|
|
|
// #ifdef MP-WEIXIN |
|
|
|
|
|
this.moving = true |
|
|
|
|
|
// #endif |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
// 标识滑动结束 |
|
|
computed: { |
|
|
pickend() { |
|
|
uZIndex() { |
|
|
// #ifdef MP-WEIXIN |
|
|
// 如果用户有传递z-index值,优先使用 |
|
|
this.moving = false |
|
|
return this.zIndex ? this.zIndex : this.$u.zIndex.popup; |
|
|
// #endif |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
init() { |
|
|
methods: { |
|
|
this.setColumnNum() |
|
|
// 标识滑动开始,只有微信小程序才有这样的事件 |
|
|
this.setDefaultSelector() |
|
|
pickstart() { |
|
|
this.setColumnData() |
|
|
// #ifdef MP-WEIXIN |
|
|
this.setSelectValue() |
|
|
this.moving = true; |
|
|
}, |
|
|
// #endif |
|
|
// 获取默认选中列下标 |
|
|
}, |
|
|
setDefaultSelector() { |
|
|
// 标识滑动结束 |
|
|
// 如果没有传入默认选中的值,生成长度为columnNum,用0填充的数组 |
|
|
pickend() { |
|
|
this.defaultSelector = this.defaultValue.length == this.columnNum ? this.defaultValue : Array(this.columnNum).fill(0) |
|
|
// #ifdef MP-WEIXIN |
|
|
this.lastSelectIndex = this.$u.deepClone(this.defaultSelector) |
|
|
this.moving = false; |
|
|
}, |
|
|
// #endif |
|
|
// 计算列数 |
|
|
}, |
|
|
setColumnNum() { |
|
|
init() { |
|
|
// 单列的列数为1 |
|
|
this.setColumnNum(); |
|
|
if (this.mode == 'single-column') this.columnNum = 1 |
|
|
this.setDefaultSelector(); |
|
|
// 多列时,this.list数组长度就是列数 |
|
|
this.setColumnData(); |
|
|
else if (this.mode == 'mutil-column') this.columnNum = this.list.length |
|
|
this.setSelectValue(); |
|
|
// 多列联动时,通过历遍this.list的第一个元素,得出有多少列 |
|
|
}, |
|
|
else if (this.mode == 'mutil-column-auto') { |
|
|
// 获取默认选中列下标 |
|
|
let num = 1 |
|
|
setDefaultSelector() { |
|
|
let column = this.list |
|
|
// 如果没有传入默认选中的值,生成长度为columnNum,用0填充的数组 |
|
|
// 只要有元素并且第一个元素有children属性,继续历遍 |
|
|
this.defaultSelector = this.defaultValue.length == this.columnNum ? this.defaultValue : Array(this.columnNum).fill(0); |
|
|
while (column[0][this.childName]) { |
|
|
this.lastSelectIndex = this.$u.deepClone(this.defaultSelector); |
|
|
column = column[0] ? column[0][this.childName] : {} |
|
|
}, |
|
|
num++ |
|
|
// 计算列数 |
|
|
} |
|
|
setColumnNum() { |
|
|
this.columnNum = num |
|
|
// 单列的列数为1 |
|
|
} |
|
|
if(this.mode == 'single-column') this.columnNum = 1; |
|
|
}, |
|
|
// 多列时,this.list数组长度就是列数 |
|
|
// 获取需要展示在picker中的列数据 |
|
|
else if(this.mode == 'mutil-column') this.columnNum = this.list.length; |
|
|
setColumnData() { |
|
|
// 多列联动时,通过历遍this.list的第一个元素,得出有多少列 |
|
|
let data = [] |
|
|
else if(this.mode == 'mutil-column-auto') { |
|
|
this.selectValue = [] |
|
|
let num = 1; |
|
|
if (this.mode == 'mutil-column-auto') { |
|
|
let column = this.list; |
|
|
// 获得所有数据中的第一个元素 |
|
|
// 只要有元素并且第一个元素有children属性,继续历遍 |
|
|
let column = this.list[this.defaultSelector.length ? this.defaultSelector[0] : 0] |
|
|
while(column[0][this.childName]) { |
|
|
// 通过循环所有的列数,再根据设定列的数组,得出当前需要渲染的整个列数组 |
|
|
column = column[0] ? column[0][this.childName] : {}; |
|
|
for (let i = 0; i < this.columnNum; i++) { |
|
|
num ++; |
|
|
// 第一列默认为整个list数组 |
|
|
} |
|
|
if (i == 0) { |
|
|
this.columnNum = num; |
|
|
data[i] = this.list |
|
|
} |
|
|
column = column[this.childName] |
|
|
}, |
|
|
} else { |
|
|
// 获取需要展示在picker中的列数据 |
|
|
// 大于第一列时,判断是否有默认选中的,如果没有就用该列的第一项 |
|
|
setColumnData() { |
|
|
data[i] = column |
|
|
let data = []; |
|
|
column = column[this.defaultSelector[i]][this.childName] |
|
|
this.selectValue = []; |
|
|
} |
|
|
if(this.mode == 'mutil-column-auto') { |
|
|
} |
|
|
// 获得所有数据中的第一个元素 |
|
|
} else if (this.mode == 'single-column') { |
|
|
let column = this.list[this.defaultSelector.length ? this.defaultSelector[0] : 0]; |
|
|
data[0] = this.list |
|
|
// 通过循环所有的列数,再根据设定列的数组,得出当前需要渲染的整个列数组 |
|
|
} else { |
|
|
for (let i = 0; i < this.columnNum; i++) { |
|
|
data = this.list |
|
|
// 第一列默认为整个list数组 |
|
|
} |
|
|
if (i == 0) { |
|
|
this.columnData = data |
|
|
data[i] = this.list; |
|
|
}, |
|
|
column = column[this.childName]; |
|
|
// 获取默认选中的值,如果没有设置defaultValue,就默认选中每列的第一个 |
|
|
} else { |
|
|
setSelectValue() { |
|
|
// 大于第一列时,判断是否有默认选中的,如果没有就用该列的第一项 |
|
|
let tmp = null |
|
|
data[i] = column; |
|
|
for (let i = 0; i < this.columnNum; i++) { |
|
|
column = column[this.defaultSelector[i]][this.childName]; |
|
|
tmp = this.columnData[i][this.defaultSelector[i]] |
|
|
} |
|
|
const data = { |
|
|
} |
|
|
value: tmp ? tmp[this.valueName] : null, |
|
|
} else if(this.mode == 'single-column') { |
|
|
label: tmp ? tmp[this.labelName] : null |
|
|
data[0] = this.list; |
|
|
} |
|
|
} else { |
|
|
// 判断是否存在额外的参数,如果存在,就返回 |
|
|
data = this.list; |
|
|
if (tmp && tmp.extra) data.extra = tmp.extra |
|
|
} |
|
|
this.selectValue.push(data) |
|
|
this.columnData = data; |
|
|
} |
|
|
}, |
|
|
}, |
|
|
// 获取默认选中的值,如果没有设置defaultValue,就默认选中每列的第一个 |
|
|
// 列选项 |
|
|
setSelectValue() { |
|
|
columnChange(e) { |
|
|
let tmp = null; |
|
|
let index = null |
|
|
for(let i = 0; i < this.columnNum; i++) { |
|
|
const columnIndex = e.detail.value |
|
|
tmp = this.columnData[i][this.defaultSelector[i]]; |
|
|
// 由于后面是需要push进数组的,所以需要先清空数组 |
|
|
let data = { |
|
|
this.selectValue = [] |
|
|
value: tmp ? tmp[this.valueName] : null, |
|
|
if (this.mode == 'mutil-column-auto') { |
|
|
label: tmp ? tmp[this.labelName] : null |
|
|
// 对比前后两个数组,寻找变更的是哪一列,如果某一个元素不同,即可判定该列发生了变化 |
|
|
}; |
|
|
this.lastSelectIndex.map((val, idx) => { |
|
|
// 判断是否存在额外的参数,如果存在,就返回 |
|
|
if (val != columnIndex[idx]) index = idx |
|
|
if(tmp && tmp.extra) data.extra = tmp.extra; |
|
|
}) |
|
|
this.selectValue.push(data) |
|
|
this.defaultSelector = columnIndex |
|
|
} |
|
|
for (let i = index + 1; i < this.columnNum; i++) { |
|
|
}, |
|
|
// 当前变化列的下一列的数据,需要获取上一列的数据,同时需要指定是上一列的第几个的children,再往后的 |
|
|
// 列选项 |
|
|
// 默认是队列的第一个为默认选项 |
|
|
columnChange(e) { |
|
|
this.columnData[i] = this.columnData[i - 1][i - 1 == index ? columnIndex[index] : 0][this.childName] |
|
|
let index = null; |
|
|
// 改变的列之后的所有列,默认选中第一个 |
|
|
let columnIndex = e.detail.value; |
|
|
this.defaultSelector[i] = 0 |
|
|
// 由于后面是需要push进数组的,所以需要先清空数组 |
|
|
} |
|
|
this.selectValue = []; |
|
|
// 在历遍的过程中,可能由于上一步修改this.columnData,导致产生连锁反应,程序触发columnChange,会有多次调用 |
|
|
if(this.mode == 'mutil-column-auto') { |
|
|
// 只有在最后一次数据稳定后的结果是正确的,此前的历遍中,可能会产生undefined,故需要判断 |
|
|
// 对比前后两个数组,寻找变更的是哪一列,如果某一个元素不同,即可判定该列发生了变化 |
|
|
columnIndex.map((item, index) => { |
|
|
this.lastSelectIndex.map((val, idx) => { |
|
|
const data = this.columnData[index][columnIndex[index]] |
|
|
if (val != columnIndex[idx]) index = idx; |
|
|
const tmp = { |
|
|
}); |
|
|
value: data ? data[this.valueName] : null, |
|
|
this.defaultSelector = columnIndex; |
|
|
label: data ? data[this.labelName] : null |
|
|
for (let i = index + 1; i < this.columnNum; i++) { |
|
|
} |
|
|
// 当前变化列的下一列的数据,需要获取上一列的数据,同时需要指定是上一列的第几个的children,再往后的 |
|
|
// 判断是否有需要额外携带的参数 |
|
|
// 默认是队列的第一个为默认选项 |
|
|
if (data && data.extra !== undefined) tmp.extra = data.extra |
|
|
this.columnData[i] = this.columnData[i - 1][i - 1 == index ? columnIndex[index] : 0][this.childName]; |
|
|
this.selectValue.push(tmp) |
|
|
// 改变的列之后的所有列,默认选中第一个 |
|
|
}) |
|
|
this.defaultSelector[i] = 0; |
|
|
// 保存这一次的结果,用于下次列发生变化时作比较 |
|
|
} |
|
|
this.lastSelectIndex = columnIndex |
|
|
// 在历遍的过程中,可能由于上一步修改this.columnData,导致产生连锁反应,程序触发columnChange,会有多次调用 |
|
|
} else if (this.mode == 'single-column') { |
|
|
// 只有在最后一次数据稳定后的结果是正确的,此前的历遍中,可能会产生undefined,故需要判断 |
|
|
const data = this.columnData[0][columnIndex[0]] |
|
|
columnIndex.map((item, index) => { |
|
|
// 初始默认选中值 |
|
|
let data = this.columnData[index][columnIndex[index]]; |
|
|
const tmp = { |
|
|
let tmp = { |
|
|
value: data ? data[this.valueName] : null, |
|
|
value: data ? data[this.valueName] : null, |
|
|
label: data ? data[this.labelName] : null |
|
|
label: data ? data[this.labelName] : null, |
|
|
} |
|
|
}; |
|
|
// 判断是否有需要额外携带的参数 |
|
|
// 判断是否有需要额外携带的参数 |
|
|
if (data && data.extra !== undefined) tmp.extra = data.extra |
|
|
if(data && data.extra !== undefined) tmp.extra = data.extra; |
|
|
this.selectValue.push(tmp) |
|
|
this.selectValue.push(tmp); |
|
|
} else if (this.mode == 'mutil-column') { |
|
|
|
|
|
// 初始默认选中值 |
|
|
}) |
|
|
columnIndex.map((item, index) => { |
|
|
// 保存这一次的结果,用于下次列发生变化时作比较 |
|
|
const data = this.columnData[index][columnIndex[index]] |
|
|
this.lastSelectIndex = columnIndex; |
|
|
// 初始默认选中值 |
|
|
} else if(this.mode == 'single-column') { |
|
|
const tmp = { |
|
|
let data = this.columnData[0][columnIndex[0]]; |
|
|
value: data ? data[this.valueName] : null, |
|
|
// 初始默认选中值 |
|
|
label: data ? data[this.labelName] : null |
|
|
let tmp = { |
|
|
} |
|
|
value: data ? data[this.valueName] : null, |
|
|
// 判断是否有需要额外携带的参数 |
|
|
label: data ? data[this.labelName] : null, |
|
|
if (data && data.extra !== undefined) tmp.extra = data.extra |
|
|
}; |
|
|
this.selectValue.push(tmp) |
|
|
// 判断是否有需要额外携带的参数 |
|
|
}) |
|
|
if(data && data.extra !== undefined) tmp.extra = data.extra; |
|
|
} |
|
|
this.selectValue.push(tmp); |
|
|
}, |
|
|
} else if(this.mode == 'mutil-column') { |
|
|
close() { |
|
|
// 初始默认选中值 |
|
|
this.$emit('input', false) |
|
|
columnIndex.map((item, index) => { |
|
|
this.$emit('update:modelValue', false) |
|
|
let data = this.columnData[index][columnIndex[index]]; |
|
|
}, |
|
|
// 初始默认选中值 |
|
|
// 点击确定或者取消 |
|
|
let tmp = { |
|
|
getResult(event = null) { |
|
|
value: data ? data[this.valueName] : null, |
|
|
// #ifdef MP-WEIXIN |
|
|
label: data ? data[this.labelName] : null, |
|
|
if (this.moving) return |
|
|
}; |
|
|
// #endif |
|
|
// 判断是否有需要额外携带的参数 |
|
|
if (event) this.$emit(event, this.selectValue) |
|
|
if(data && data.extra !== undefined) tmp.extra = data.extra; |
|
|
this.close() |
|
|
this.selectValue.push(tmp); |
|
|
}, |
|
|
}) |
|
|
selectHandler() { |
|
|
} |
|
|
this.$emit('click') |
|
|
}, |
|
|
} |
|
|
close() { |
|
|
} |
|
|
this.$emit('input', false); |
|
|
} |
|
|
this.$emit("update:modelValue", false); |
|
|
|
|
|
}, |
|
|
|
|
|
// 点击确定或者取消 |
|
|
|
|
|
getResult(event = null) { |
|
|
|
|
|
// #ifdef MP-WEIXIN |
|
|
|
|
|
if (this.moving) return; |
|
|
|
|
|
// #endif |
|
|
|
|
|
if (event) this.$emit(event, this.selectValue); |
|
|
|
|
|
this.close(); |
|
|
|
|
|
}, |
|
|
|
|
|
selectHandler() { |
|
|
|
|
|
this.$emit('click'); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
</script> |
|
|
</script> |
|
|
|
|
|
|
|
|
<style scoped lang="scss"> |
|
|
<style scoped lang="scss"> |
|
|
@import "../../libs/css/style.components.scss"; |
|
|
@import '../../libs/css/style.components.scss'; |
|
|
|
|
|
|
|
|
.u-select { |
|
|
.u-select { |
|
|
|
|
|
&__action { |
|
|
|
|
|
position: relative; |
|
|
|
|
|
line-height: $u-form-item-height; |
|
|
|
|
|
height: $u-form-item-height; |
|
|
|
|
|
|
|
|
&__action { |
|
|
&__icon { |
|
|
position: relative; |
|
|
position: absolute; |
|
|
line-height: $u-form-item-height; |
|
|
right: 20rpx; |
|
|
height: $u-form-item-height; |
|
|
top: 50%; |
|
|
|
|
|
transition: transform 0.4s; |
|
|
&__icon { |
|
|
transform: translateY(-50%); |
|
|
position: absolute; |
|
|
z-index: 1; |
|
|
right: 20rpx; |
|
|
|
|
|
top: 50%; |
|
|
|
|
|
transition: transform .4s; |
|
|
|
|
|
transform: translateY(-50%); |
|
|
|
|
|
z-index: 1; |
|
|
|
|
|
|
|
|
|
|
|
&--reverse { |
|
|
&--reverse { |
|
|
transform: rotate(-180deg) translateY(50%); |
|
|
transform: rotate(-180deg) translateY(50%); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
&__hader { |
|
|
&__hader { |
|
|
&__title { |
|
|
&__title { |
|
|
color: $u-content-color; |
|
|
color: $u-content-color; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
&--border { |
|
|
&--border { |
|
|
border-radius: 6rpx; |
|
|
border-radius: 6rpx; |
|
|
border-radius: 4px; |
|
|
border-radius: 4px; |
|
|
border: 1px solid $u-form-item-border-color; |
|
|
border: 1px solid $u-form-item-border-color; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
&__header { |
|
|
&__header { |
|
|
@include vue-flex; |
|
|
@include vue-flex; |
|
|
align-items: center; |
|
|
align-items: center; |
|
|
justify-content: space-between; |
|
|
justify-content: space-between; |
|
|
height: 80rpx; |
|
|
height: 80rpx; |
|
|
padding: 0 40rpx; |
|
|
padding: 0 40rpx; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
&__body { |
|
|
&__body { |
|
|
width: 100%; |
|
|
width: 100%; |
|
|
height: 300rpx; |
|
|
height: 500rpx; |
|
|
overflow: hidden; |
|
|
overflow: hidden; |
|
|
background-color: #fff; |
|
|
background-color: #fff; |
|
|
|
|
|
|
|
|
&__picker-view { |
|
|
&__picker-view { |
|
|
height: 100%; |
|
|
height: 100%; |
|
|
box-sizing: border-box; |
|
|
box-sizing: border-box; |
|
|
|
|
|
|
|
|
&__item { |
|
|
&__item { |
|
|
@include vue-flex; |
|
|
@include vue-flex; |
|
|
align-items: center; |
|
|
align-items: center; |
|
|
justify-content: center; |
|
|
justify-content: center; |
|
|
font-size: 32rpx; |
|
|
font-size: 32rpx; |
|
|
color: $u-main-color; |
|
|
color: $u-main-color; |
|
|
padding: 0 8rpx; |
|
|
padding: 0 8rpx; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
</style> |
|
|
</style> |
|
|