sadais-piui 1.2.7-beta138 → 1.2.7-beta139
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,247 +1,260 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<pi-popup-select
|
|
3
|
-
:value="val"
|
|
4
|
-
:custom-style="getPopupSelect.customStyle"
|
|
5
|
-
:custom-class="getPopupSelect.customClass"
|
|
6
|
-
:height="getPopupSelect.height"
|
|
7
|
-
:show-title="getPopupSelect.showTitle"
|
|
8
|
-
:title="getPopupSelect.title"
|
|
9
|
-
:title-padding="getPopupSelect.titlePadding"
|
|
10
|
-
:toolbar-position="getPopupSelect.toolbarPosition"
|
|
11
|
-
:on-confirm-close="getPopupSelect.onConfirmClose"
|
|
12
|
-
:on-cancel-close="getPopupSelect.onCancelClose"
|
|
13
|
-
:confirm-btn="getPopupSelect.confirmBtn"
|
|
14
|
-
:cancel-btn="getPopupSelect.cancelBtn"
|
|
15
|
-
:popup="getPopup"
|
|
16
|
-
@close="handlePopupClose"
|
|
17
|
-
@cancel="handleCancel"
|
|
18
|
-
@confirm="handleConfirm"
|
|
19
|
-
>
|
|
20
|
-
<slot name="header" />
|
|
21
|
-
<!-- 描述列 -->
|
|
22
|
-
<view
|
|
23
|
-
v-if="description"
|
|
24
|
-
class="pi-solid-bottom-2 pi-align-center pi-pd-32 pi-light-gray"
|
|
25
|
-
:style="[getItemAlignStyle]"
|
|
26
|
-
>
|
|
27
|
-
{{ description }}
|
|
28
|
-
</view>
|
|
29
|
-
<view
|
|
30
|
-
v-for="item in items"
|
|
31
|
-
:id="`id-${item[keyField]}`"
|
|
32
|
-
:key="item[keyField]"
|
|
33
|
-
:style="[
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
</
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
this
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
this.$emit('
|
|
229
|
-
this.
|
|
230
|
-
},
|
|
231
|
-
/**
|
|
232
|
-
* @vuese
|
|
233
|
-
*
|
|
234
|
-
*/
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
this
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
.
|
|
246
|
-
}
|
|
247
|
-
|
|
1
|
+
<template>
|
|
2
|
+
<pi-popup-select
|
|
3
|
+
:value="val"
|
|
4
|
+
:custom-style="getPopupSelect.customStyle"
|
|
5
|
+
:custom-class="getPopupSelect.customClass"
|
|
6
|
+
:height="getPopupSelect.height"
|
|
7
|
+
:show-title="getPopupSelect.showTitle"
|
|
8
|
+
:title="getPopupSelect.title"
|
|
9
|
+
:title-padding="getPopupSelect.titlePadding"
|
|
10
|
+
:toolbar-position="getPopupSelect.toolbarPosition"
|
|
11
|
+
:on-confirm-close="getPopupSelect.onConfirmClose"
|
|
12
|
+
:on-cancel-close="getPopupSelect.onCancelClose"
|
|
13
|
+
:confirm-btn="getPopupSelect.confirmBtn"
|
|
14
|
+
:cancel-btn="getPopupSelect.cancelBtn"
|
|
15
|
+
:popup="getPopup"
|
|
16
|
+
@close="handlePopupClose"
|
|
17
|
+
@cancel="handleCancel"
|
|
18
|
+
@confirm="handleConfirm"
|
|
19
|
+
>
|
|
20
|
+
<slot name="header" />
|
|
21
|
+
<!-- 描述列 -->
|
|
22
|
+
<view
|
|
23
|
+
v-if="description"
|
|
24
|
+
class="pi-solid-bottom-2 pi-align-center pi-pd-32 pi-light-gray"
|
|
25
|
+
:style="[getItemAlignStyle]"
|
|
26
|
+
>
|
|
27
|
+
{{ description }}
|
|
28
|
+
</view>
|
|
29
|
+
<view
|
|
30
|
+
v-for="item in items"
|
|
31
|
+
:id="`id-${item[keyField]}`"
|
|
32
|
+
:key="item[keyField]"
|
|
33
|
+
:style="[
|
|
34
|
+
itemStyle,
|
|
35
|
+
getItemStyle,
|
|
36
|
+
getItemAlignStyle,
|
|
37
|
+
{ color: item.color }
|
|
38
|
+
]"
|
|
39
|
+
:class="{
|
|
40
|
+
'pi-solid-bottom-1': showItemBottomBorder,
|
|
41
|
+
'pi-disabled': item.disabled
|
|
42
|
+
}"
|
|
43
|
+
class="pi-align-center pi-fz-30 pi-pd-lr-32"
|
|
44
|
+
hover-class="pi-hover-class"
|
|
45
|
+
@tap.stop="handleSelectItem(item)"
|
|
46
|
+
>
|
|
47
|
+
<!-- 自定义列表项 -->
|
|
48
|
+
<slot name="item" :item="item" class="pi-w-100P">
|
|
49
|
+
<template v-if="!item.loading">
|
|
50
|
+
{{ item[displayField] }}
|
|
51
|
+
</template>
|
|
52
|
+
<pi-loading v-else show />
|
|
53
|
+
</slot>
|
|
54
|
+
</view>
|
|
55
|
+
<!-- 取消action -->
|
|
56
|
+
<template v-if="cancelText">
|
|
57
|
+
<pi-gap height="20" />
|
|
58
|
+
<view
|
|
59
|
+
class="pi-align-center pi-fz-30 pi-pd-32 pi-light-gray"
|
|
60
|
+
hover-class="pi-hover-class"
|
|
61
|
+
:style="[getItemAlignStyle]"
|
|
62
|
+
@tap="handleCancel"
|
|
63
|
+
>
|
|
64
|
+
{{ cancelText }}
|
|
65
|
+
</view>
|
|
66
|
+
</template>
|
|
67
|
+
|
|
68
|
+
<slot name="footer" />
|
|
69
|
+
</pi-popup-select>
|
|
70
|
+
</template>
|
|
71
|
+
|
|
72
|
+
<script>
|
|
73
|
+
import ValueSync from '../../mixin/value-sync'
|
|
74
|
+
import { getConfig } from '../../config'
|
|
75
|
+
|
|
76
|
+
const TAG = 'PiActionSheet'
|
|
77
|
+
const { actionSheet } = getConfig()
|
|
78
|
+
|
|
79
|
+
const alignFlexMap = {
|
|
80
|
+
left: 'flex-start',
|
|
81
|
+
center: 'center',
|
|
82
|
+
right: 'flex-end'
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export default {
|
|
86
|
+
name: 'PiActionSheet',
|
|
87
|
+
// 混入v-model
|
|
88
|
+
mixins: [ValueSync],
|
|
89
|
+
props: {
|
|
90
|
+
// 初始值
|
|
91
|
+
value: {
|
|
92
|
+
required: false
|
|
93
|
+
},
|
|
94
|
+
// 自定义样式
|
|
95
|
+
customStyle: {
|
|
96
|
+
type: Object,
|
|
97
|
+
// {}
|
|
98
|
+
default() {
|
|
99
|
+
return actionSheet.customStyle
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
// 自定义样式类
|
|
103
|
+
customClass: {
|
|
104
|
+
type: String,
|
|
105
|
+
// ''
|
|
106
|
+
default() {
|
|
107
|
+
return actionSheet.customClass
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
// 选项列表
|
|
111
|
+
items: {
|
|
112
|
+
type: Array,
|
|
113
|
+
// []
|
|
114
|
+
default() {
|
|
115
|
+
return actionSheet.items
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
// 选项id字段
|
|
119
|
+
keyField: {
|
|
120
|
+
type: String,
|
|
121
|
+
// 'id'
|
|
122
|
+
default: actionSheet.keyField
|
|
123
|
+
},
|
|
124
|
+
// 选项显示字段
|
|
125
|
+
displayField: {
|
|
126
|
+
type: String,
|
|
127
|
+
// 'text'
|
|
128
|
+
default: actionSheet.displayField
|
|
129
|
+
},
|
|
130
|
+
// 自定义多列联动模式的children属性名
|
|
131
|
+
childField: {
|
|
132
|
+
type: String,
|
|
133
|
+
// 'children'
|
|
134
|
+
default: actionSheet.childField
|
|
135
|
+
},
|
|
136
|
+
// 行高 单位默认rpx
|
|
137
|
+
itemHeight: {
|
|
138
|
+
type: [String, Number],
|
|
139
|
+
// 110
|
|
140
|
+
default: actionSheet.itemHeight
|
|
141
|
+
},
|
|
142
|
+
// 是否显示item下边框
|
|
143
|
+
showItemBottomBorder: {
|
|
144
|
+
type: Boolean,
|
|
145
|
+
// true
|
|
146
|
+
default: actionSheet.showItemBottomBorder
|
|
147
|
+
},
|
|
148
|
+
// 行样式
|
|
149
|
+
itemStyle: {
|
|
150
|
+
type: Object,
|
|
151
|
+
// {}
|
|
152
|
+
default() {
|
|
153
|
+
return actionSheet.itemStyle
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
itemAlign: {
|
|
157
|
+
type: String,
|
|
158
|
+
// 'center'
|
|
159
|
+
default: actionSheet.itemAlign,
|
|
160
|
+
validator: function(value) {
|
|
161
|
+
return ['left', 'center', 'right'].includes(value)
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
// 弹窗选择参数设置
|
|
165
|
+
popupSelect: {
|
|
166
|
+
type: Object,
|
|
167
|
+
default() {
|
|
168
|
+
// 参照popup
|
|
169
|
+
return actionSheet.popupSelect
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
// 弹窗参数设置
|
|
173
|
+
popup: {
|
|
174
|
+
type: Object,
|
|
175
|
+
default() {
|
|
176
|
+
// 参照popup
|
|
177
|
+
return actionSheet.popup
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
// 选项上方的描述信息,不填则不显示
|
|
181
|
+
description: {
|
|
182
|
+
type: String,
|
|
183
|
+
// ''
|
|
184
|
+
default: actionSheet.description
|
|
185
|
+
},
|
|
186
|
+
// 取消按钮文字,不填则不显示
|
|
187
|
+
cancelText: {
|
|
188
|
+
type: String,
|
|
189
|
+
// ''
|
|
190
|
+
default: actionSheet.cancelText
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
data() {
|
|
194
|
+
return {}
|
|
195
|
+
},
|
|
196
|
+
computed: {
|
|
197
|
+
getPopupSelect() {
|
|
198
|
+
return this.$pi.lang.mergeDeep(actionSheet.popupSelect, this.popupSelect)
|
|
199
|
+
},
|
|
200
|
+
getPopup() {
|
|
201
|
+
const actionSheetPopup = this.$pi.lang.mergeDeep(
|
|
202
|
+
actionSheet.popup,
|
|
203
|
+
this.popupSelect.popup
|
|
204
|
+
)
|
|
205
|
+
return this.$pi.lang.mergeDeep(actionSheetPopup, this.popup)
|
|
206
|
+
},
|
|
207
|
+
getItemAlignStyle() {
|
|
208
|
+
return {
|
|
209
|
+
justifyContent: alignFlexMap[this.itemAlign]
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
getItemStyle() {
|
|
213
|
+
const itemHeight = this.$pi.common.addUnit(this.itemHeight)
|
|
214
|
+
return {
|
|
215
|
+
height: itemHeight,
|
|
216
|
+
lineHeight: itemHeight
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
indicatorStyle() {
|
|
220
|
+
const itemHeight = uni.upx2px(this.itemHeight)
|
|
221
|
+
return `height: ${itemHeight}px;line-height: ${itemHeight}px;`
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
methods: {
|
|
225
|
+
handlePopupClose() {
|
|
226
|
+
this.val = false
|
|
227
|
+
// 弹窗关闭
|
|
228
|
+
this.$emit('close')
|
|
229
|
+
this.handleEmitChange()
|
|
230
|
+
},
|
|
231
|
+
/**
|
|
232
|
+
* @vuese
|
|
233
|
+
* 取消选择
|
|
234
|
+
*/
|
|
235
|
+
handleCancel() {
|
|
236
|
+
this.$emit('cancel')
|
|
237
|
+
this.getPopupSelect.onCancelClose && this.handlePopupClose()
|
|
238
|
+
},
|
|
239
|
+
/**
|
|
240
|
+
* @vuese
|
|
241
|
+
* 确认选择
|
|
242
|
+
*/
|
|
243
|
+
handleConfirm() {
|
|
244
|
+
this.$emit('confirm')
|
|
245
|
+
this.getPopupSelect.onConfirmClose && this.handlePopupClose()
|
|
246
|
+
},
|
|
247
|
+
/**
|
|
248
|
+
* @vuese
|
|
249
|
+
* 确认选择
|
|
250
|
+
*/
|
|
251
|
+
handleSelectItem(item) {
|
|
252
|
+
if (item.disabled) return
|
|
253
|
+
this.$emit('select', item)
|
|
254
|
+
this.getPopupSelect.onConfirmClose && this.handlePopupClose()
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
</script>
|
|
259
|
+
|
|
260
|
+
<style lang="scss" scoped></style>
|
|
@@ -1,317 +1,332 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<pi-popup-select
|
|
3
|
-
:value="val"
|
|
4
|
-
:custom-style="getPopupSelect.customStyle"
|
|
5
|
-
:custom-class="getPopupSelect.customClass"
|
|
6
|
-
:height="getPopupSelect.height"
|
|
7
|
-
:show-title="getPopupSelect.showTitle"
|
|
8
|
-
:title="getPopupSelect.title"
|
|
9
|
-
:title-padding="getPopupSelect.titlePadding"
|
|
10
|
-
:toolbar-position="getPopupSelect.toolbarPosition"
|
|
11
|
-
:on-confirm-close="getPopupSelect.onConfirmClose"
|
|
12
|
-
:on-cancel-close="getPopupSelect.onCancelClose"
|
|
13
|
-
:confirm-btn="getConfirmBtn"
|
|
14
|
-
:cancel-btn="getCancelBtn"
|
|
15
|
-
:popup="getPopup"
|
|
16
|
-
@close="handlePopupClose"
|
|
17
|
-
@cancel="handleCancel"
|
|
18
|
-
@confirm="handleConfirm"
|
|
19
|
-
>
|
|
20
|
-
<slot name="header" />
|
|
21
|
-
<picker-view
|
|
22
|
-
v-if="val"
|
|
23
|
-
class="pi-text-center pi-h-100P"
|
|
24
|
-
:style="[customStyle]"
|
|
25
|
-
:class="[customClass]"
|
|
26
|
-
:indicator-style="indicatorStyle"
|
|
27
|
-
:value="pickerValue"
|
|
28
|
-
@pickstart="handlePickstart"
|
|
29
|
-
@pickend="handlePickend"
|
|
30
|
-
@change="handlePickerChange"
|
|
31
|
-
>
|
|
32
|
-
<picker-view-column v-for="(column, index) in columns" :key="index">
|
|
33
|
-
<view
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
</
|
|
41
|
-
|
|
42
|
-
<
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
//
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
return this.items
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
},
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
1
|
+
<template>
|
|
2
|
+
<pi-popup-select
|
|
3
|
+
:value="val"
|
|
4
|
+
:custom-style="getPopupSelect.customStyle"
|
|
5
|
+
:custom-class="getPopupSelect.customClass"
|
|
6
|
+
:height="getPopupSelect.height"
|
|
7
|
+
:show-title="getPopupSelect.showTitle"
|
|
8
|
+
:title="getPopupSelect.title"
|
|
9
|
+
:title-padding="getPopupSelect.titlePadding"
|
|
10
|
+
:toolbar-position="getPopupSelect.toolbarPosition"
|
|
11
|
+
:on-confirm-close="getPopupSelect.onConfirmClose"
|
|
12
|
+
:on-cancel-close="getPopupSelect.onCancelClose"
|
|
13
|
+
:confirm-btn="getConfirmBtn"
|
|
14
|
+
:cancel-btn="getCancelBtn"
|
|
15
|
+
:popup="getPopup"
|
|
16
|
+
@close="handlePopupClose"
|
|
17
|
+
@cancel="handleCancel"
|
|
18
|
+
@confirm="handleConfirm"
|
|
19
|
+
>
|
|
20
|
+
<slot name="header" />
|
|
21
|
+
<picker-view
|
|
22
|
+
v-if="val"
|
|
23
|
+
class="pi-text-center pi-h-100P"
|
|
24
|
+
:style="[customStyle]"
|
|
25
|
+
:class="[customClass]"
|
|
26
|
+
:indicator-style="indicatorStyle"
|
|
27
|
+
:value="pickerValue"
|
|
28
|
+
@pickstart="handlePickstart"
|
|
29
|
+
@pickend="handlePickend"
|
|
30
|
+
@change="handlePickerChange"
|
|
31
|
+
>
|
|
32
|
+
<picker-view-column v-for="(column, index) in columns" :key="index">
|
|
33
|
+
<view
|
|
34
|
+
v-for="item in column"
|
|
35
|
+
:key="item[keyField]"
|
|
36
|
+
:style="indicatorStyle"
|
|
37
|
+
>
|
|
38
|
+
{{ item[displayField] }}
|
|
39
|
+
</view>
|
|
40
|
+
</picker-view-column>
|
|
41
|
+
</picker-view>
|
|
42
|
+
<slot name="footer" />
|
|
43
|
+
</pi-popup-select>
|
|
44
|
+
</template>
|
|
45
|
+
|
|
46
|
+
<script>
|
|
47
|
+
import ValueSync from '../../mixin/value-sync'
|
|
48
|
+
import { getConfig } from '../../config'
|
|
49
|
+
|
|
50
|
+
const TAG = 'PiPicker'
|
|
51
|
+
const { picker } = getConfig()
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 注意: default-value数组的长度,必须与列数相同,否则无效。
|
|
55
|
+
* 单列模式 如设置default-value为[1]表示默认选中第2个(从0开始),[5]表示选中第6个。
|
|
56
|
+
* 多列模式 如设置default-value为[1, 3]表示第一列默认选中第2个,第二列默认选中第4个。
|
|
57
|
+
*/
|
|
58
|
+
export default {
|
|
59
|
+
name: 'PiPicker',
|
|
60
|
+
// 混入v-model
|
|
61
|
+
mixins: [ValueSync],
|
|
62
|
+
props: {
|
|
63
|
+
// 初始值
|
|
64
|
+
value: {
|
|
65
|
+
required: false
|
|
66
|
+
},
|
|
67
|
+
// 自定义样式
|
|
68
|
+
customStyle: {
|
|
69
|
+
type: Object,
|
|
70
|
+
// {}
|
|
71
|
+
default() {
|
|
72
|
+
return picker.customStyle
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
// 自定义样式类
|
|
76
|
+
customClass: {
|
|
77
|
+
type: String,
|
|
78
|
+
// ''
|
|
79
|
+
default() {
|
|
80
|
+
return picker.customClass
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
// 选项列表
|
|
84
|
+
items: {
|
|
85
|
+
type: Array,
|
|
86
|
+
// []
|
|
87
|
+
default() {
|
|
88
|
+
return picker.items
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
// 选项id字段
|
|
92
|
+
keyField: {
|
|
93
|
+
type: String,
|
|
94
|
+
// 'id'
|
|
95
|
+
default: picker.keyField
|
|
96
|
+
},
|
|
97
|
+
// 选项显示字段
|
|
98
|
+
displayField: {
|
|
99
|
+
type: String,
|
|
100
|
+
// 'text'
|
|
101
|
+
default: picker.displayField
|
|
102
|
+
},
|
|
103
|
+
// 自定义多列联动模式的children属性名
|
|
104
|
+
childField: {
|
|
105
|
+
type: String,
|
|
106
|
+
// 'children'
|
|
107
|
+
default: picker.childField
|
|
108
|
+
},
|
|
109
|
+
// 默认值,单选是传Object,多选时传Array
|
|
110
|
+
defaultValue: {
|
|
111
|
+
type: Array,
|
|
112
|
+
// null
|
|
113
|
+
default: picker.defaultValue
|
|
114
|
+
},
|
|
115
|
+
// 选择器类型
|
|
116
|
+
type: {
|
|
117
|
+
// 'single', 'multi', 'multi-auto'
|
|
118
|
+
type: String,
|
|
119
|
+
// 'single'
|
|
120
|
+
default: picker.type,
|
|
121
|
+
validator: function(value) {
|
|
122
|
+
return ['single', 'multi', 'multi-auto'].includes(value)
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
// 行高 单位默认rpx
|
|
126
|
+
itemHeight: {
|
|
127
|
+
type: [String, Number],
|
|
128
|
+
// 110
|
|
129
|
+
default: picker.itemHeight
|
|
130
|
+
},
|
|
131
|
+
// 是否显示item下边框
|
|
132
|
+
showItemBottomBorder: {
|
|
133
|
+
type: Boolean,
|
|
134
|
+
// true
|
|
135
|
+
default: picker.showItemBottomBorder
|
|
136
|
+
},
|
|
137
|
+
// 行样式
|
|
138
|
+
itemStyle: {
|
|
139
|
+
type: Object,
|
|
140
|
+
// {}
|
|
141
|
+
default() {
|
|
142
|
+
return picker.itemStyle
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
// 弹窗选择参数设置
|
|
146
|
+
popupSelect: {
|
|
147
|
+
type: Object,
|
|
148
|
+
default() {
|
|
149
|
+
// 参照popup
|
|
150
|
+
return picker.popupSelect
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
// 确认按钮配置
|
|
154
|
+
confirmBtn: {
|
|
155
|
+
type: Object,
|
|
156
|
+
default() {
|
|
157
|
+
return picker.confirmBtn
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
// 取消按钮配置
|
|
161
|
+
cancelBtn: {
|
|
162
|
+
type: Object,
|
|
163
|
+
default() {
|
|
164
|
+
return picker.cancelBtn
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
// 弹窗参数设置
|
|
168
|
+
popup: {
|
|
169
|
+
type: Object,
|
|
170
|
+
default() {
|
|
171
|
+
// 参照popup
|
|
172
|
+
return picker.popup
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
data() {
|
|
177
|
+
return {
|
|
178
|
+
pickerValue: [],
|
|
179
|
+
scrolling: false // picker是否在滚动中,小程序在scrolling中点确定,选择的项目不正确
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
computed: {
|
|
183
|
+
getPopupSelect() {
|
|
184
|
+
return this.$pi.lang.mergeDeep(picker.popupSelect, this.popupSelect)
|
|
185
|
+
},
|
|
186
|
+
getConfirmBtn() {
|
|
187
|
+
const pickerConfirmBtn = this.$pi.lang.mergeDeep(
|
|
188
|
+
picker.confirmBtn,
|
|
189
|
+
this.popupSelect.confirmBtn
|
|
190
|
+
)
|
|
191
|
+
const mergeConfirmBtn = this.$pi.lang.mergeDeep(
|
|
192
|
+
pickerConfirmBtn,
|
|
193
|
+
this.confirmBtn
|
|
194
|
+
)
|
|
195
|
+
if (!mergeConfirmBtn.disabled) {
|
|
196
|
+
mergeConfirmBtn.disabled = this.scrolling
|
|
197
|
+
}
|
|
198
|
+
return mergeConfirmBtn
|
|
199
|
+
},
|
|
200
|
+
getCancelBtn() {
|
|
201
|
+
const pickerCancelBtn = this.$pi.lang.mergeDeep(
|
|
202
|
+
picker.cancelBtn,
|
|
203
|
+
this.popupSelect.cancelBtn
|
|
204
|
+
)
|
|
205
|
+
return this.$pi.lang.mergeDeep(pickerCancelBtn, this.cancelBtn)
|
|
206
|
+
},
|
|
207
|
+
getPopup() {
|
|
208
|
+
const pickerPopup = this.$pi.lang.mergeDeep(
|
|
209
|
+
picker.popup,
|
|
210
|
+
this.popupSelect.popup
|
|
211
|
+
)
|
|
212
|
+
return this.$pi.lang.mergeDeep(pickerPopup, this.popup)
|
|
213
|
+
},
|
|
214
|
+
getItemStyle() {
|
|
215
|
+
const itemHeight = this.$pi.common.addUnit(this.itemHeight)
|
|
216
|
+
return {
|
|
217
|
+
height: itemHeight,
|
|
218
|
+
lineHeight: itemHeight
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
indicatorStyle() {
|
|
222
|
+
const itemHeight = uni.upx2px(this.itemHeight)
|
|
223
|
+
return `height: ${itemHeight}px;line-height: ${itemHeight}px;`
|
|
224
|
+
},
|
|
225
|
+
columns() {
|
|
226
|
+
if (this.type === 'single') return [this.items]
|
|
227
|
+
if (this.type === 'multi') return this.items
|
|
228
|
+
if (this.type === 'multi-auto') {
|
|
229
|
+
let columns = this.items
|
|
230
|
+
return this.pickerValue.map((value, index) => {
|
|
231
|
+
const returnValue = [...columns]
|
|
232
|
+
const column = columns[value]
|
|
233
|
+
if (column[this.childField] && column[this.childField].length) {
|
|
234
|
+
columns = column[this.childField]
|
|
235
|
+
}
|
|
236
|
+
return returnValue
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return this.items
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
watch: {
|
|
244
|
+
value: {
|
|
245
|
+
deep: true,
|
|
246
|
+
immediate: true,
|
|
247
|
+
handler(value) {
|
|
248
|
+
// 每次弹窗显示,进行数据初始化
|
|
249
|
+
value && this.init()
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
methods: {
|
|
254
|
+
init() {
|
|
255
|
+
if (this.defaultValue) {
|
|
256
|
+
this.pickerValue = this.defaultValue
|
|
257
|
+
} else {
|
|
258
|
+
if (this.type === 'single') this.pickerValue = [0]
|
|
259
|
+
if (this.type === 'multi') return (this.pickerValue = [0, 0])
|
|
260
|
+
if (this.type === 'multi-auto') {
|
|
261
|
+
let count = 1
|
|
262
|
+
let column = this.items
|
|
263
|
+
// 只要有元素并且第一个元素有children属性,继续历遍
|
|
264
|
+
while (column[0][this.childField]) {
|
|
265
|
+
column = column[0] ? column[0][this.childField] : {}
|
|
266
|
+
count++
|
|
267
|
+
}
|
|
268
|
+
this.pickerValue = new Array(count).fill(0)
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
handlePickstart() {
|
|
273
|
+
this.scrolling = true
|
|
274
|
+
},
|
|
275
|
+
// 标识滑动结束
|
|
276
|
+
handlePickend() {
|
|
277
|
+
this.scrolling = false
|
|
278
|
+
},
|
|
279
|
+
handlePopupClose() {
|
|
280
|
+
this.val = false
|
|
281
|
+
// 弹窗关闭
|
|
282
|
+
this.$emit('close')
|
|
283
|
+
this.handleEmitChange()
|
|
284
|
+
},
|
|
285
|
+
handlePickerChange(e) {
|
|
286
|
+
let pickerValue = e.detail.value
|
|
287
|
+
|
|
288
|
+
if (this.type === 'multi-auto') {
|
|
289
|
+
// 如果是多列联动,pickerValue的值需要重新生成
|
|
290
|
+
// 第几列发生变化
|
|
291
|
+
let columnIndex = this.pickerValue.findIndex(
|
|
292
|
+
(p, i) => pickerValue[i] !== p
|
|
293
|
+
)
|
|
294
|
+
pickerValue = pickerValue.slice(0, columnIndex + 1)
|
|
295
|
+
let columnValue = pickerValue[columnIndex]
|
|
296
|
+
let columns = this.columns[columnIndex]
|
|
297
|
+
let column = columns[columnValue]
|
|
298
|
+
while (column[this.childField]) {
|
|
299
|
+
columns = column[this.childField]
|
|
300
|
+
column = columns[0]
|
|
301
|
+
columnIndex++
|
|
302
|
+
pickerValue[columnIndex] = 0
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
this.pickerValue = pickerValue
|
|
306
|
+
},
|
|
307
|
+
/**
|
|
308
|
+
* @vuese
|
|
309
|
+
* 取消选择
|
|
310
|
+
*/
|
|
311
|
+
handleCancel() {
|
|
312
|
+
this.$emit('cancel')
|
|
313
|
+
this.onCancelClose && this.handlePopupClose()
|
|
314
|
+
},
|
|
315
|
+
/**
|
|
316
|
+
* @vuese
|
|
317
|
+
* 确认选择
|
|
318
|
+
*/
|
|
319
|
+
handleConfirm() {
|
|
320
|
+
if (this.scrolling) return
|
|
321
|
+
this.$emit('confirm', this.pickerValue)
|
|
322
|
+
this.onConfirmClose && this.handlePopupClose()
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
</script>
|
|
327
|
+
|
|
328
|
+
<style lang="scss" scoped>
|
|
329
|
+
.pi-picker {
|
|
330
|
+
height: 50vh;
|
|
331
|
+
}
|
|
332
|
+
</style>
|