|
|
@@ -1,20 +1,32 @@
|
|
|
-import { PickerView, PickerViewColumn, View } from "@tarojs/components";
|
|
|
+import { PickerView, PickerViewColumn, View, Text } from "@tarojs/components";
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
|
|
-export default function Component(props: { value: number[], onChange: Function, items: any[],height?:number }) {
|
|
|
- const [v,setV] = useState([0])
|
|
|
+export default function Component(props: { value: number[], onChange: Function, items: any[], height?: number, showBtns?: boolean, onCancel?: Function, }) {
|
|
|
+ const [v, setV] = useState([0])
|
|
|
useEffect(() => {
|
|
|
setV(props.value)
|
|
|
}, [props.value])
|
|
|
|
|
|
function onPickerChange(e) {
|
|
|
setV(e.detail.value)
|
|
|
+ if (props.showBtns) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
props.onChange(e.detail.value)
|
|
|
}
|
|
|
- return <PickerView value={v}
|
|
|
+
|
|
|
+ function cancel() {
|
|
|
+ props.onCancel && props.onCancel()
|
|
|
+ }
|
|
|
+
|
|
|
+ function confirm() {
|
|
|
+ props.onChange(v)
|
|
|
+ }
|
|
|
+
|
|
|
+ return <View><PickerView value={v}
|
|
|
onChange={onPickerChange}
|
|
|
- indicatorStyle='height: 50px;'
|
|
|
- style={props.height?`width: 100%; height: ${props.height}px;`:`width: 100%; height: 100px;`}>
|
|
|
+ indicatorStyle='height: 50px;'
|
|
|
+ style={props.height ? `width: 100%; height: ${props.height}px;` : `width: 100%; height: 100px;`}>
|
|
|
{
|
|
|
props.items.map(item => {
|
|
|
return <PickerViewColumn>
|
|
|
@@ -26,5 +38,13 @@ export default function Component(props: { value: number[], onChange: Function,
|
|
|
</PickerViewColumn>
|
|
|
})
|
|
|
}
|
|
|
- </PickerView>
|
|
|
+
|
|
|
+ </PickerView >
|
|
|
+ {
|
|
|
+ props.showBtns ? <View style={{ marginBottom: 20, display: 'flex', flexDirection: 'row', width: '100%' }}>
|
|
|
+ <Text style={{ flex: 1, textAlign: 'center' }} onClick={cancel}>取消</Text>
|
|
|
+ <Text style={{ flex: 1, textAlign: 'center' }} onClick={confirm}>确认</Text>
|
|
|
+ </View> : null
|
|
|
+ }
|
|
|
+ </View>
|
|
|
}
|