|
@@ -1,10 +1,11 @@
|
|
|
-import { MovableArea, MovableView, View, ScrollView } from '@tarojs/components'
|
|
|
|
|
|
|
+import { MovableArea, MovableView, View, ScrollView, Text, Image } from '@tarojs/components'
|
|
|
import './MoveOrderList.scss'
|
|
import './MoveOrderList.scss'
|
|
|
import { useEffect, useRef, useState } from 'react';
|
|
import { useEffect, useRef, useState } from 'react';
|
|
|
import { ColorType } from '@/context/themes/color';
|
|
import { ColorType } from '@/context/themes/color';
|
|
|
import Taro from '@tarojs/taro';
|
|
import Taro from '@tarojs/taro';
|
|
|
|
|
+import { IconDrag } from '@/components/basic/Icons';
|
|
|
|
|
|
|
|
-export default function Component(props: { array: any, itemHeight: number }) {
|
|
|
|
|
|
|
+export default function Component(props: { array: any, itemHeight: number, color?: string,update:Function }) {
|
|
|
const [list, setList] = useState(props.array)
|
|
const [list, setList] = useState(props.array)
|
|
|
const [movaleViewY, setMovaleViewY] = useState(0)
|
|
const [movaleViewY, setMovaleViewY] = useState(0)
|
|
|
const [dragElement, setDragElement] = useState(null)
|
|
const [dragElement, setDragElement] = useState(null)
|
|
@@ -73,10 +74,9 @@ export default function Component(props: { array: any, itemHeight: number }) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function pageScroll(clientY) {
|
|
function pageScroll(clientY) {
|
|
|
-
|
|
|
|
|
|
|
+ return
|
|
|
// console.log(clientY,contentY,contentHeight)
|
|
// console.log(clientY,contentY,contentHeight)
|
|
|
if ((clientY - contentY) + upperThreshold >= contentHeight) {
|
|
if ((clientY - contentY) + upperThreshold >= contentHeight) {
|
|
|
- console.log('ccc',(clientY - contentY) + props.itemHeight);
|
|
|
|
|
// var scroll = ref.current
|
|
// var scroll = ref.current
|
|
|
// debugger
|
|
// debugger
|
|
|
// (ref.current as any).scrollTo({scrollTop:100})
|
|
// (ref.current as any).scrollTo({scrollTop:100})
|
|
@@ -84,9 +84,9 @@ export default function Component(props: { array: any, itemHeight: number }) {
|
|
|
// setScrollTop(2200)
|
|
// setScrollTop(2200)
|
|
|
// setCanScroll(true)
|
|
// setCanScroll(true)
|
|
|
Taro.pageScrollTo({
|
|
Taro.pageScrollTo({
|
|
|
- selector:'#myScrollView',
|
|
|
|
|
- scrollTop:(clientY - contentY) + props.itemHeight,
|
|
|
|
|
- duration:200
|
|
|
|
|
|
|
+ selector: '#myScrollView',
|
|
|
|
|
+ scrollTop: (clientY - contentY) + props.itemHeight,
|
|
|
|
|
+ duration: 200
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
else if ((clientY - contentY) - lowThreshold <= 0) {
|
|
else if ((clientY - contentY) - lowThreshold <= 0) {
|
|
@@ -128,6 +128,9 @@ export default function Component(props: { array: any, itemHeight: number }) {
|
|
|
setChangedIndex(-1)
|
|
setChangedIndex(-1)
|
|
|
setCanScroll(true)
|
|
setCanScroll(true)
|
|
|
setHiddenContent(false)
|
|
setHiddenContent(false)
|
|
|
|
|
+ setMovaleViewY(-100)
|
|
|
|
|
+
|
|
|
|
|
+ props.update(list)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function computeFutureIndex(targetMoveDistance, dragElementIndex) {
|
|
function computeFutureIndex(targetMoveDistance, dragElementIndex) {
|
|
@@ -172,34 +175,35 @@ export default function Component(props: { array: any, itemHeight: number }) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return <View id="myScrollView" ref={ref} style={{ height: 400,overflow:'scroll' }} catchMove={!canScroll}>
|
|
|
|
|
- <MovableArea style={{ height: list.length * props.itemHeight }}>
|
|
|
|
|
|
|
+ return <View id="myScrollView" ref={ref} style={{ maxHeight: 400, overflow: 'scroll' }} catchMove>
|
|
|
|
|
+ <MovableArea style={{ height: list.length * props.itemHeight, width: '100vw' }}>
|
|
|
{list.map((item, index) => {
|
|
{list.map((item, index) => {
|
|
|
- var className = 'demo_item'
|
|
|
|
|
- if (lastTarget == index) {
|
|
|
|
|
- className += ' last_item'
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (dragIndex == index) {
|
|
|
|
|
- className += ' drag_item'
|
|
|
|
|
-
|
|
|
|
|
- // console.log(className)
|
|
|
|
|
- }
|
|
|
|
|
- return <View style={{ opacity: changedIndex == index && hiddenContent ? 0 : 1, height: props.itemHeight }}
|
|
|
|
|
- className={className}
|
|
|
|
|
|
|
+ return <View style={{ opacity: changedIndex == index && hiddenContent ? 0 : 1, height: props.itemHeight, width: '100vw' }}
|
|
|
onLongPress={(e) => longPress(e, index)}
|
|
onLongPress={(e) => longPress(e, index)}
|
|
|
|
|
+
|
|
|
onTouchMove={(e) => touchMove(e)}
|
|
onTouchMove={(e) => touchMove(e)}
|
|
|
onTouchEnd={(e) => touchEnd(e)}
|
|
onTouchEnd={(e) => touchEnd(e)}
|
|
|
- >{item}</View>
|
|
|
|
|
|
|
+ >
|
|
|
|
|
+ <View className='modal_order_item' style={{ height: 40}}>
|
|
|
|
|
+ <Text style={{ color: props.color }}>{item.name}</Text>
|
|
|
|
|
+ <IconDrag width={17} height={12} />
|
|
|
|
|
+ {/* <Image src={require('@assets/images/menu.png')} style={{width:20,height:20}}/> */}
|
|
|
|
|
+ </View>
|
|
|
|
|
+ </View>
|
|
|
})}
|
|
})}
|
|
|
- <MovableView style={{ height: props.itemHeight }}
|
|
|
|
|
|
|
+ <MovableView style={{ height: changedIndex>=0?props.itemHeight:0,width:'100vw' }}
|
|
|
direction='vertical'
|
|
direction='vertical'
|
|
|
disabled
|
|
disabled
|
|
|
animation={false}
|
|
animation={false}
|
|
|
y={movaleViewY}
|
|
y={movaleViewY}
|
|
|
>
|
|
>
|
|
|
- <View className='demo_item' style={{ backgroundColor: ColorType.fast }}>
|
|
|
|
|
- {dragElement}
|
|
|
|
|
|
|
+ <View className='drag_item' style={{ backgroundColor: props.color }}>
|
|
|
|
|
+ {
|
|
|
|
|
+ dragIndex >= 0 && <View className='modal_sel_item' style={{ height: 40, border:'none' }}>
|
|
|
|
|
+ <Text style={{ color: 'black',fontWeight:'bold' }}>{list[changedIndex].name}</Text>
|
|
|
|
|
+ <IconDrag width={17} height={12} />
|
|
|
|
|
+ </View>
|
|
|
|
|
+ }
|
|
|
</View>
|
|
</View>
|
|
|
</MovableView>
|
|
</MovableView>
|
|
|
</MovableArea>
|
|
</MovableArea>
|