🎈 perf(优化所有输入框):
This commit is contained in:
parent
d06f4137c6
commit
812971f6b2
@ -1,61 +1,67 @@
|
||||
import { Input, Text, Textarea, View } from '@tarojs/components'
|
||||
import { memo } from 'react'
|
||||
import './index.scss'
|
||||
|
||||
import { Input, Text, Textarea, View } from "@tarojs/components"
|
||||
import { memo } from "react"
|
||||
import "./index.scss"
|
||||
|
||||
interface ListParams{
|
||||
label: string, //左边label
|
||||
onInput?: (ev:Object)=>void, // 输入框输入
|
||||
onClick?:()=>any, //点击列表
|
||||
placeholder?:string, // 提示文本
|
||||
children?: any, // 插槽
|
||||
type?: string // 类型:1.input,2.textarea,3.select,
|
||||
primordialType?: 'text'|'number'|'idcard'|'digit'
|
||||
value?: any,
|
||||
style?: object, //整行样式
|
||||
labelStyle?: object, // label样式
|
||||
contentStyle?: object,
|
||||
interface ListParams {
|
||||
label: string //左边label
|
||||
onInput?: (ev: Object) => void // 输入框输入
|
||||
onClick?: () => any //点击列表
|
||||
placeholder?: string // 提示文本
|
||||
children?: any // 插槽
|
||||
type?: string // 类型:1.input,2.textarea,3.select,
|
||||
primordialType?: 'text' | 'number' | 'idcard' | 'digit'
|
||||
value?: any
|
||||
style?: object //整行样式
|
||||
labelStyle?: object // label样式
|
||||
contentStyle?: object
|
||||
required?: boolean
|
||||
}
|
||||
|
||||
// 表单列表
|
||||
const FromList = memo((props:ListParams)=>{
|
||||
const {type="input",value="",style={},labelStyle={},contentStyle={},required=false} = props;
|
||||
|
||||
const FromList = memo((props: ListParams) => {
|
||||
const { type = 'input', value = '', style = {}, labelStyle = {}, contentStyle = {}, required = false } = props
|
||||
|
||||
return (
|
||||
<View style={style} className="form-list">
|
||||
<View style={labelStyle} className={`form-list-label ${required&&"form-list-label-required"}`}>{props.label}</View>
|
||||
<View onClick={props?.onClick} className="form-list-right">
|
||||
{
|
||||
props.children??
|
||||
<View style={contentStyle} onClick={props?.onClick} className="form-list-right-meet">
|
||||
{
|
||||
type=="input"?
|
||||
<View className="form-list-input">
|
||||
<Input value={value} placeholder-class="phcolor" type={props.primordialType||'text'} onInput={props?.onInput} placeholder={props.placeholder} />
|
||||
{value&&
|
||||
<View><Text onClick={()=>props.onInput&&props.onInput({detail: {value: ""}})} className="iconfont icon-qingkong"/></View>
|
||||
}
|
||||
</View>:
|
||||
type=="textarea"?<Textarea value={value} placeholder-class="phcolor" onInput={props?.onInput} placeholder={props.placeholder} />:
|
||||
<>
|
||||
{
|
||||
props.value?<View>{value}</View>:
|
||||
<View className="form-list-right-placeholder">
|
||||
{props.placeholder}
|
||||
<View style={style} className='form-list'>
|
||||
<View style={labelStyle} className={`form-list-label ${required && 'form-list-label-required'}`}>
|
||||
{props.label}
|
||||
</View>
|
||||
<View onClick={props?.onClick} className='form-list-right'>
|
||||
{props.children ?? (
|
||||
<View style={contentStyle} onClick={props?.onClick} className='form-list-right-meet'>
|
||||
{type == 'input' ? (
|
||||
<View className='form-list-input'>
|
||||
<Input
|
||||
alwaysEmbed={true}
|
||||
cursorSpacing={150}
|
||||
value={value}
|
||||
placeholder-class='phcolor'
|
||||
type={props.primordialType || 'text'}
|
||||
onInput={props?.onInput}
|
||||
placeholder={props.placeholder}
|
||||
/>
|
||||
{value && (
|
||||
<View>
|
||||
<Text onClick={() => props.onInput && props.onInput({ detail: { value: '' } })} className='iconfont icon-qingkong' />
|
||||
</View>
|
||||
}
|
||||
<View className="form-list-right-enter"><Text className="iconfont icon-a-moreback"></Text></View>
|
||||
)}
|
||||
</View>
|
||||
) : type == 'textarea' ? (
|
||||
<Textarea value={value} placeholder-class='phcolor' onInput={props?.onInput} placeholder={props.placeholder} />
|
||||
) : (
|
||||
<>
|
||||
{props.value ? <View>{value}</View> : <View className='form-list-right-placeholder'>{props.placeholder}</View>}
|
||||
<View className='form-list-right-enter'>
|
||||
<Text className='iconfont icon-a-moreback'></Text>
|
||||
</View>
|
||||
</>
|
||||
}
|
||||
)}
|
||||
</View>
|
||||
}
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
})
|
||||
|
||||
const A = ()=>{
|
||||
|
||||
}
|
||||
export default FromList;
|
||||
const A = () => {}
|
||||
export default FromList
|
||||
|
@ -1,63 +1,64 @@
|
||||
import { Input, Text, Textarea, View } from '@tarojs/components'
|
||||
import { memo } from 'react'
|
||||
import './index.scss'
|
||||
|
||||
import { Input, Text, Textarea, View } from "@tarojs/components"
|
||||
import { memo } from "react"
|
||||
import "./index.scss"
|
||||
|
||||
interface ListParams{
|
||||
label: string, //左边label
|
||||
onInput?: (ev:Object)=>void, // 输入框输入
|
||||
onClick?:()=>any, //点击列表
|
||||
placeholder?:string, // 提示文本
|
||||
children?: any, // 插槽
|
||||
type?: string // 类型:1.input,2.textarea,3.select
|
||||
value?: any,
|
||||
style?: object, //整行样式
|
||||
labelStyle?: object, // label样式
|
||||
contentStyle?: object,
|
||||
required?: boolean,
|
||||
showIcon?: boolean, // 是否显示右边的箭头,type=select
|
||||
interface ListParams {
|
||||
label: string //左边label
|
||||
onInput?: (ev: Object) => void // 输入框输入
|
||||
onClick?: () => any //点击列表
|
||||
placeholder?: string // 提示文本
|
||||
children?: any // 插槽
|
||||
type?: string // 类型:1.input,2.textarea,3.select
|
||||
value?: any
|
||||
style?: object //整行样式
|
||||
labelStyle?: object // label样式
|
||||
contentStyle?: object
|
||||
required?: boolean
|
||||
showIcon?: boolean // 是否显示右边的箭头,type=select
|
||||
}
|
||||
|
||||
// 表单列表
|
||||
const FromList = memo((props:ListParams)=>{
|
||||
const {type="input",value="",style={},labelStyle={},contentStyle={},required=false,showIcon=true} = props;
|
||||
|
||||
const FromList = memo((props: ListParams) => {
|
||||
const { type = 'input', value = '', style = {}, labelStyle = {}, contentStyle = {}, required = false, showIcon = true } = props
|
||||
|
||||
return (
|
||||
<View style={style} className="From-list-certification">
|
||||
<View style={labelStyle} className={`From-list-certification-label ${required&&"From-list-certification-label-required"}`}>{props.label}</View>
|
||||
<View onClick={props?.onClick} className="From-list-certification-right">
|
||||
{
|
||||
props.children??
|
||||
<View style={contentStyle} onClick={props?.onClick} className="From-list-certification-right-meet">
|
||||
{
|
||||
type=="input"?
|
||||
<View className="From-list-certification-input">
|
||||
<Input value={value} placeholder-class="phcolor" onInput={props?.onInput} placeholder={props.placeholder} />
|
||||
{value&&
|
||||
<View><Text onClick={()=>props.onInput&&props.onInput({detail: {value: ""}})} className="iconfont icon-qingkong"/></View>
|
||||
}
|
||||
</View>:
|
||||
type=="textarea"?<Textarea value={value} placeholder-class="phcolor" onInput={props?.onInput} placeholder={props.placeholder} />:
|
||||
<>
|
||||
{
|
||||
props.value?<View>{value}</View>:
|
||||
<View className="From-list-certification-right-placeholder">
|
||||
{props.placeholder}
|
||||
<View style={style} className='From-list-certification'>
|
||||
<View style={labelStyle} className={`From-list-certification-label ${required && 'From-list-certification-label-required'}`}>
|
||||
{props.label}
|
||||
</View>
|
||||
<View onClick={props?.onClick} className='From-list-certification-right'>
|
||||
{props.children ?? (
|
||||
<View style={contentStyle} onClick={props?.onClick} className='From-list-certification-right-meet'>
|
||||
{type == 'input' ? (
|
||||
<View className='From-list-certification-input'>
|
||||
<Input
|
||||
alwaysEmbed={true}
|
||||
cursorSpacing={150}
|
||||
value={value}
|
||||
placeholder-class='phcolor'
|
||||
onInput={props?.onInput}
|
||||
placeholder={props.placeholder}
|
||||
/>
|
||||
{value && (
|
||||
<View>
|
||||
<Text onClick={() => props.onInput && props.onInput({ detail: { value: '' } })} className='iconfont icon-qingkong' />
|
||||
</View>
|
||||
}
|
||||
<View className="From-list-certification-right-enter">
|
||||
{showIcon&&<Text className="iconfont icon-a-moreback"></Text>}
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
) : type == 'textarea' ? (
|
||||
<Textarea value={value} placeholder-class='phcolor' onInput={props?.onInput} placeholder={props.placeholder} />
|
||||
) : (
|
||||
<>
|
||||
{props.value ? <View>{value}</View> : <View className='From-list-certification-right-placeholder'>{props.placeholder}</View>}
|
||||
<View className='From-list-certification-right-enter'>{showIcon && <Text className='iconfont icon-a-moreback'></Text>}</View>
|
||||
</>
|
||||
}
|
||||
)}
|
||||
</View>
|
||||
}
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
})
|
||||
|
||||
const A = ()=>{
|
||||
|
||||
}
|
||||
export default FromList;
|
||||
const A = () => {}
|
||||
export default FromList
|
||||
|
@ -1,115 +1,110 @@
|
||||
import { Input, View } from "@tarojs/components"
|
||||
import { useEffect, useMemo, useRef, useState } from "react"
|
||||
import { Input, View } from '@tarojs/components'
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import Big from 'big.js'
|
||||
import styles from "./index.module.scss"
|
||||
import styles from './index.module.scss'
|
||||
type params = {
|
||||
minNum?: number, //最小值
|
||||
maxNum?: number, //最大值
|
||||
step?: number, //步长
|
||||
defaultNum?: number, //默认值
|
||||
digits?: number //多少位小数
|
||||
onChange?:(val:number) => void,
|
||||
onBlue?:(val:number) => void, //失去焦点触发
|
||||
onClickBtn?:(val:number) => void,
|
||||
unit?: string,
|
||||
disable?: true|false, //是否禁用
|
||||
minNum?: number //最小值
|
||||
maxNum?: number //最大值
|
||||
step?: number //步长
|
||||
defaultNum?: number //默认值
|
||||
digits?: number //多少位小数
|
||||
onChange?: (val: number) => void
|
||||
onBlue?: (val: number) => void //失去焦点触发
|
||||
onClickBtn?: (val: number) => void
|
||||
unit?: string
|
||||
disable?: true | false //是否禁用
|
||||
}
|
||||
export default ({minNum = 0, maxNum = 10000, step=1, digits = 0, defaultNum = 0, onChange, onBlue, onClickBtn, unit = '', disable = false}: params) => {
|
||||
const [value, setValue] = useState<any>({count:defaultNum})
|
||||
export default ({ minNum = 0, maxNum = 10000, step = 1, digits = 0, defaultNum = 0, onChange, onBlue, onClickBtn, unit = '', disable = false }: params) => {
|
||||
const [value, setValue] = useState<any>({ count: defaultNum })
|
||||
|
||||
const onPlus = () => {
|
||||
if(disable) return false
|
||||
let {count} = value
|
||||
let num_res = Big(count).add(step).toNumber()
|
||||
num_res = num_res >= maxNum?maxNum:num_res
|
||||
num_res = formatDigits(num_res)
|
||||
setValue({...value, count:num_res})
|
||||
onChange?.(parseFloat(num_res))
|
||||
onClickBtn?.(parseFloat(num_res))
|
||||
}
|
||||
const minus = () => {
|
||||
if(disable) return false
|
||||
let {count} = value
|
||||
let num_res = Big(count).minus(step).toNumber()
|
||||
num_res = num_res < minNum?minNum:num_res
|
||||
setValue({...value, count:num_res})
|
||||
onChange?.(parseFloat(num_res))
|
||||
onClickBtn?.(parseFloat(num_res))
|
||||
}
|
||||
const onPlus = () => {
|
||||
if (disable) return false
|
||||
let { count } = value
|
||||
let num_res = Big(count).add(step).toNumber()
|
||||
num_res = num_res >= maxNum ? maxNum : num_res
|
||||
num_res = formatDigits(num_res)
|
||||
setValue({ ...value, count: num_res })
|
||||
onChange?.(parseFloat(num_res))
|
||||
onClickBtn?.(parseFloat(num_res))
|
||||
}
|
||||
const minus = () => {
|
||||
if (disable) return false
|
||||
let { count } = value
|
||||
let num_res = Big(count).minus(step).toNumber()
|
||||
num_res = num_res < minNum ? minNum : num_res
|
||||
setValue({ ...value, count: num_res })
|
||||
onChange?.(parseFloat(num_res))
|
||||
onClickBtn?.(parseFloat(num_res))
|
||||
}
|
||||
|
||||
//保留小数
|
||||
const formatDigits = (num) => {
|
||||
num = num + ''
|
||||
if(num.includes('.')&&digits > 0) {
|
||||
console.log('num::',num.includes('.'))
|
||||
let res = num.split('.')
|
||||
let last_num = res[1].substr(0, digits)
|
||||
return res[0] + '.' + last_num
|
||||
}
|
||||
return parseFloat(num)
|
||||
//保留小数
|
||||
const formatDigits = (num) => {
|
||||
num = num + ''
|
||||
if (num.includes('.') && digits > 0) {
|
||||
console.log('num::', num.includes('.'))
|
||||
let res = num.split('.')
|
||||
let last_num = res[1].substr(0, digits)
|
||||
return res[0] + '.' + last_num
|
||||
}
|
||||
return parseFloat(num)
|
||||
}
|
||||
|
||||
//检查数据
|
||||
const checkData = (val) => {
|
||||
let num = parseFloat(val)
|
||||
if(num > maxNum) return maxNum
|
||||
if(num < minNum) return minNum
|
||||
return val
|
||||
//检查数据
|
||||
const checkData = (val) => {
|
||||
let num = parseFloat(val)
|
||||
if (num > maxNum) return maxNum
|
||||
if (num < minNum) return minNum
|
||||
return val
|
||||
}
|
||||
|
||||
const onInputEven = (e) => {
|
||||
let res = e.detail.value
|
||||
if (res === '') {
|
||||
setValue({ ...value, count: minNum })
|
||||
onChange?.(minNum)
|
||||
} else if (!isNaN(Number(res))) {
|
||||
let count = formatDigits(res)
|
||||
count = checkData(count)
|
||||
setValue({ ...value, count })
|
||||
onChange?.(parseFloat(count as string))
|
||||
} else {
|
||||
let num = parseFloat(res)
|
||||
if (!isNaN(num)) {
|
||||
let count = formatDigits(num)
|
||||
count = checkData(count)
|
||||
setValue({ ...value, count })
|
||||
onChange?.(count as number)
|
||||
} else {
|
||||
setValue({ ...value, count: defaultNum })
|
||||
onChange?.(defaultNum)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const onInputEven = (e) => {
|
||||
let res = e.detail.value
|
||||
if(res === '') {
|
||||
setValue({...value, count:minNum})
|
||||
onChange?.(minNum)
|
||||
}
|
||||
else if(!isNaN(Number(res))) {
|
||||
let count = formatDigits(res)
|
||||
count = checkData(count)
|
||||
setValue({...value, count})
|
||||
onChange?.(parseFloat(count as string))
|
||||
} else {
|
||||
let num = parseFloat(res)
|
||||
if(!isNaN(num)) {
|
||||
let count = formatDigits(num)
|
||||
count = checkData(count)
|
||||
setValue({...value, count})
|
||||
onChange?.(count as number)
|
||||
} else {
|
||||
setValue({...value, count:defaultNum})
|
||||
onChange?.(defaultNum)
|
||||
}
|
||||
|
||||
}
|
||||
const onBluerEven = () => {
|
||||
let num = parseFloat(value.count)
|
||||
if (!isNaN(num)) {
|
||||
let count = formatDigits(num)
|
||||
count = checkData(count)
|
||||
setValue({ ...value, count })
|
||||
onBlue?.(count as number)
|
||||
} else {
|
||||
setValue({ ...value, count: defaultNum })
|
||||
onBlue?.(defaultNum)
|
||||
}
|
||||
|
||||
const onBluerEven = () => {
|
||||
let num = parseFloat(value.count)
|
||||
if(!isNaN(num)) {
|
||||
let count = formatDigits(num)
|
||||
count = checkData(count)
|
||||
setValue({...value, count})
|
||||
onBlue?.(count as number)
|
||||
} else {
|
||||
setValue({...value, count:defaultNum})
|
||||
onBlue?.(defaultNum)
|
||||
}
|
||||
}
|
||||
return (
|
||||
<View className={styles.main}>
|
||||
<View className={styles.reduce} onClick={() => minus()}>-</View>
|
||||
<View className={styles.input}>
|
||||
<Input
|
||||
value={String(value.count)}
|
||||
onInput={onInputEven}
|
||||
onBlur={onBluerEven}
|
||||
type='digit'
|
||||
disabled={disable}
|
||||
/>
|
||||
<View className={styles.unit}>{unit}</View>
|
||||
</View>
|
||||
<View className={styles.plus} onClick={() => onPlus()}>+</View>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
}
|
||||
return (
|
||||
<View className={styles.main}>
|
||||
<View className={styles.reduce} onClick={() => minus()}>
|
||||
-
|
||||
</View>
|
||||
<View className={styles.input}>
|
||||
<Input value={String(value.count)} onInput={onInputEven} onBlur={onBluerEven} type='digit' disabled={disable} alwaysEmbed={true} cursorSpacing={150} />
|
||||
<View className={styles.unit}>{unit}</View>
|
||||
</View>
|
||||
<View className={styles.plus} onClick={() => onPlus()}>
|
||||
+
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
@ -1,111 +1,107 @@
|
||||
import { Input, View } from "@tarojs/components"
|
||||
import { useEffect, useMemo, useRef, useState } from "react"
|
||||
import { Input, View } from '@tarojs/components'
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import Big from 'big.js'
|
||||
import styles from "./index.module.scss"
|
||||
import styles from './index.module.scss'
|
||||
type params = {
|
||||
minNum?: number, //最小值
|
||||
maxNum?: number, //最大值
|
||||
step?: number, //步长
|
||||
defaultNum?: number, //默认值
|
||||
digits?: number //多少位小数
|
||||
onChange?:(val:number) => void,
|
||||
onBlue?:(val:number) => void, //失去焦点触发
|
||||
onClickBtn?:(val:number) => void,
|
||||
unit?: string
|
||||
minNum?: number //最小值
|
||||
maxNum?: number //最大值
|
||||
step?: number //步长
|
||||
defaultNum?: number //默认值
|
||||
digits?: number //多少位小数
|
||||
onChange?: (val: number) => void
|
||||
onBlue?: (val: number) => void //失去焦点触发
|
||||
onClickBtn?: (val: number) => void
|
||||
unit?: string
|
||||
}
|
||||
export default ({minNum = 0, maxNum = 100, step=1, digits = 0, defaultNum = 0, onChange, onBlue, onClickBtn, unit = ''}: params) => {
|
||||
const [value, setValue] = useState<any>({count:defaultNum})
|
||||
export default ({ minNum = 0, maxNum = 100, step = 1, digits = 0, defaultNum = 0, onChange, onBlue, onClickBtn, unit = '' }: params) => {
|
||||
const [value, setValue] = useState<any>({ count: defaultNum })
|
||||
|
||||
const onPlus = () => {
|
||||
let {count} = value
|
||||
let num_res = Big(count).add(step).toNumber()
|
||||
num_res = num_res >= maxNum?maxNum:num_res
|
||||
num_res = formatDigits(num_res)
|
||||
setValue({...value, count:num_res})
|
||||
onChange?.(parseFloat(num_res))
|
||||
onClickBtn?.(parseFloat(num_res))
|
||||
}
|
||||
const minus = () => {
|
||||
let {count} = value
|
||||
let num_res = Big(count).minus(step).toNumber()
|
||||
num_res = num_res < minNum?0:num_res
|
||||
setValue({...value, count:num_res})
|
||||
onChange?.(parseFloat(num_res))
|
||||
onClickBtn?.(parseFloat(num_res))
|
||||
}
|
||||
const onPlus = () => {
|
||||
let { count } = value
|
||||
let num_res = Big(count).add(step).toNumber()
|
||||
num_res = num_res >= maxNum ? maxNum : num_res
|
||||
num_res = formatDigits(num_res)
|
||||
setValue({ ...value, count: num_res })
|
||||
onChange?.(parseFloat(num_res))
|
||||
onClickBtn?.(parseFloat(num_res))
|
||||
}
|
||||
const minus = () => {
|
||||
let { count } = value
|
||||
let num_res = Big(count).minus(step).toNumber()
|
||||
num_res = num_res < minNum ? 0 : num_res
|
||||
setValue({ ...value, count: num_res })
|
||||
onChange?.(parseFloat(num_res))
|
||||
onClickBtn?.(parseFloat(num_res))
|
||||
}
|
||||
|
||||
//保留小数
|
||||
const formatDigits = (num) => {
|
||||
num = num + ''
|
||||
if(num.includes('.')&&digits > 0) {
|
||||
console.log('num::',num.includes('.'))
|
||||
let res = num.split('.')
|
||||
let last_num = res[1].substr(0, digits)
|
||||
return res[0] + '.' + last_num
|
||||
}
|
||||
return parseFloat(num)
|
||||
//保留小数
|
||||
const formatDigits = (num) => {
|
||||
num = num + ''
|
||||
if (num.includes('.') && digits > 0) {
|
||||
console.log('num::', num.includes('.'))
|
||||
let res = num.split('.')
|
||||
let last_num = res[1].substr(0, digits)
|
||||
return res[0] + '.' + last_num
|
||||
}
|
||||
return parseFloat(num)
|
||||
}
|
||||
|
||||
//检查数据
|
||||
const checkData = (val) => {
|
||||
let num = parseFloat(val)
|
||||
if(num > maxNum) return maxNum
|
||||
if(num < minNum) return minNum
|
||||
return val
|
||||
//检查数据
|
||||
const checkData = (val) => {
|
||||
let num = parseFloat(val)
|
||||
if (num > maxNum) return maxNum
|
||||
if (num < minNum) return minNum
|
||||
return val
|
||||
}
|
||||
|
||||
const onInputEven = (e) => {
|
||||
let res = e.detail.value
|
||||
if (res === '') {
|
||||
setValue({ ...value, count: minNum })
|
||||
onChange?.(minNum)
|
||||
} else if (!isNaN(Number(res))) {
|
||||
let count = formatDigits(res)
|
||||
count = checkData(count)
|
||||
setValue({ ...value, count })
|
||||
onChange?.(parseFloat(count as string))
|
||||
} else {
|
||||
let num = parseFloat(res)
|
||||
if (!isNaN(num)) {
|
||||
let count = formatDigits(num)
|
||||
count = checkData(count)
|
||||
setValue({ ...value, count })
|
||||
onChange?.(count as number)
|
||||
} else {
|
||||
setValue({ ...value, count: defaultNum })
|
||||
onChange?.(defaultNum)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const onInputEven = (e) => {
|
||||
let res = e.detail.value
|
||||
if(res === '') {
|
||||
setValue({...value, count:minNum})
|
||||
onChange?.(minNum)
|
||||
}
|
||||
else if(!isNaN(Number(res))) {
|
||||
let count = formatDigits(res)
|
||||
count = checkData(count)
|
||||
setValue({...value, count})
|
||||
onChange?.(parseFloat(count as string))
|
||||
} else {
|
||||
let num = parseFloat(res)
|
||||
if(!isNaN(num)) {
|
||||
let count = formatDigits(num)
|
||||
count = checkData(count)
|
||||
setValue({...value, count})
|
||||
onChange?.(count as number)
|
||||
} else {
|
||||
setValue({...value, count:defaultNum})
|
||||
onChange?.(defaultNum)
|
||||
}
|
||||
|
||||
}
|
||||
const onBluerEven = () => {
|
||||
let num = parseFloat(value.count)
|
||||
if (!isNaN(num)) {
|
||||
let count = formatDigits(num)
|
||||
count = checkData(count)
|
||||
setValue({ ...value, count })
|
||||
onBlue?.(count as number)
|
||||
} else {
|
||||
setValue({ ...value, count: defaultNum })
|
||||
onBlue?.(defaultNum)
|
||||
}
|
||||
|
||||
const onBluerEven = () => {
|
||||
let num = parseFloat(value.count)
|
||||
if(!isNaN(num)) {
|
||||
let count = formatDigits(num)
|
||||
count = checkData(count)
|
||||
setValue({...value, count})
|
||||
onBlue?.(count as number)
|
||||
} else {
|
||||
setValue({...value, count:defaultNum})
|
||||
onBlue?.(defaultNum)
|
||||
}
|
||||
}
|
||||
return (
|
||||
<View className={styles.main}>
|
||||
<View className={styles.reduce} onClick={() => minus()}>-</View>
|
||||
<View className={styles.input}>
|
||||
<Input
|
||||
value={String(value.count)}
|
||||
onInput={onInputEven}
|
||||
onBlur={onBluerEven}
|
||||
type='digit'
|
||||
/>
|
||||
<View className={styles.unit}>{unit}</View>
|
||||
</View>
|
||||
<View className={styles.plus} onClick={() => onPlus()}>+</View>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
}
|
||||
return (
|
||||
<View className={styles.main}>
|
||||
<View className={styles.reduce} onClick={() => minus()}>
|
||||
-
|
||||
</View>
|
||||
<View className={styles.input}>
|
||||
<Input value={String(value.count)} onInput={onInputEven} onBlur={onBluerEven} type='digit' alwaysEmbed={true} cursorSpacing={150} />
|
||||
<View className={styles.unit}>{unit}</View>
|
||||
</View>
|
||||
<View className={styles.plus} onClick={() => onPlus()}>
|
||||
+
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
@ -1,118 +1,146 @@
|
||||
import { GetProductKindListApi } from "@/api/material";
|
||||
import Popup, {Params as PopuParams} from "@/components/popup"
|
||||
import { Input, ScrollView, Text, Textarea, View } from "@tarojs/components"
|
||||
import { useDidShow } from "@tarojs/taro";
|
||||
import classnames from "classnames";
|
||||
import { memo, useEffect, useRef, useState } from "react";
|
||||
import styles from './index.module.scss'
|
||||
import { GetProductKindListApi } from '@/api/material'
|
||||
import Popup, { Params as PopuParams } from '@/components/popup'
|
||||
import { Input, ScrollView, Text, Textarea, View } from '@tarojs/components'
|
||||
import { useDidShow } from '@tarojs/taro'
|
||||
import classnames from 'classnames'
|
||||
import { memo, useEffect, useRef, useState } from 'react'
|
||||
import styles from './index.module.scss'
|
||||
|
||||
type params = {
|
||||
onFiltr?: (val:object) => void //确定搜索
|
||||
onRest?: (val:Object) => void //重置
|
||||
onFiltr?: (val: object) => void //确定搜索
|
||||
onRest?: (val: Object) => void //重置
|
||||
} & PopuParams
|
||||
export default memo(({onClose, onFiltr, show = false, onRest}:params) => {
|
||||
export default memo(({ onClose, onFiltr, show = false, onRest }: params) => {
|
||||
//搜索条件
|
||||
const [filterObj, setFilterObj] = useState({
|
||||
seriesName: '',
|
||||
seriesId: '',
|
||||
width: '',
|
||||
weight: '',
|
||||
element: '',
|
||||
})
|
||||
|
||||
//搜索条件
|
||||
const [filterObj, setFilterObj] = useState({
|
||||
seriesName: '',
|
||||
seriesId: '',
|
||||
width: '',
|
||||
weight: '',
|
||||
element: '',
|
||||
})
|
||||
const selectFieldValue = useRef({ width: '幅宽', weight: '克重', element: '成分', seriesName: '系列' })
|
||||
|
||||
const selectFieldValue = useRef({width:'幅宽', weight:'克重', element:'成分', seriesName:'系列'})
|
||||
//获取系列
|
||||
const { fetchData: kindFetchData } = GetProductKindListApi()
|
||||
const [kindList, setKindList] = useState<any[]>([])
|
||||
const getCategoryList = async () => {
|
||||
let { data } = await kindFetchData()
|
||||
setKindList(data.list)
|
||||
}
|
||||
|
||||
//获取系列
|
||||
const {fetchData: kindFetchData} = GetProductKindListApi()
|
||||
const [kindList, setKindList] = useState<any[]>([])
|
||||
const getCategoryList = async () => {
|
||||
let {data} = await kindFetchData()
|
||||
setKindList(data.list)
|
||||
useEffect(() => {
|
||||
show && getCategoryList()
|
||||
}, [show])
|
||||
|
||||
//切换系列
|
||||
const changeKind = (e) => {
|
||||
setFilterObj({ ...filterObj, seriesId: e.id, seriesName: e.name })
|
||||
}
|
||||
|
||||
const onCloseEven = () => {
|
||||
onClose?.()
|
||||
}
|
||||
|
||||
//重置数据
|
||||
const onRestEven = () => {
|
||||
let res = {
|
||||
seriesName: '',
|
||||
seriesId: '',
|
||||
width: '',
|
||||
weight: '',
|
||||
element: '',
|
||||
}
|
||||
setFilterObj(res)
|
||||
onFiltr?.(filterObj)
|
||||
onClose?.()
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
show&&getCategoryList()
|
||||
}, [show])
|
||||
//提交搜索
|
||||
const onVerify = () => {
|
||||
onFiltr?.({ data: filterObj, field: selectFieldValue.current })
|
||||
onClose?.()
|
||||
}
|
||||
|
||||
//切换系列
|
||||
const changeKind = (e) => {
|
||||
setFilterObj({...filterObj, seriesId:e.id, seriesName: e.name})
|
||||
}
|
||||
//获取幅宽或克重输入值或成分
|
||||
const setFieldData = (e, field) => {
|
||||
filterObj[field] = e.detail.value
|
||||
setFilterObj({ ...filterObj })
|
||||
}
|
||||
|
||||
const onCloseEven = () => {
|
||||
onClose?.()
|
||||
}
|
||||
|
||||
//重置数据
|
||||
const onRestEven = () => {
|
||||
let res = {
|
||||
seriesName: '',
|
||||
seriesId: '',
|
||||
width: '',
|
||||
weight: '',
|
||||
element: '',
|
||||
}
|
||||
setFilterObj(res)
|
||||
onFiltr?.(filterObj)
|
||||
onClose?.()
|
||||
}
|
||||
|
||||
//提交搜索
|
||||
const onVerify = () => {
|
||||
onFiltr?.({data:filterObj, field: selectFieldValue.current})
|
||||
onClose?.()
|
||||
}
|
||||
|
||||
//获取幅宽或克重输入值或成分
|
||||
const setFieldData = (e, field) => {
|
||||
filterObj[field] = e.detail.value
|
||||
setFilterObj({...filterObj})
|
||||
}
|
||||
|
||||
return (
|
||||
<Popup position="right" show={show} showTitle={false} onClose={() => onCloseEven()} showIconButton={true}>
|
||||
<View className={styles.popup_main}>
|
||||
<View className={styles.popup_title}>全部筛选</View>
|
||||
<ScrollView scrollY className={styles.scroll}>
|
||||
<View className={styles.popup_filter}>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>系列</View>
|
||||
<View className={styles.btn_list}>
|
||||
{kindList.map(item => <View key={item.id} onClick={() => changeKind(item)} className={classnames(styles.btn_item, (filterObj.seriesId == item.id)&&styles.select_btn_item)}>{item.name}</View>)}
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>幅宽</View>
|
||||
<View className={styles.btn_list_input}>
|
||||
<View className={styles.btn_width}><Input value={filterObj.width} onBlur={(e) => setFieldData(e,'width')} placeholder="请输入幅宽" placeholderStyle="font-size: 26rpx"/></View>
|
||||
<View className={styles.unit}>cm</View>
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>克重</View>
|
||||
<View className={styles.btn_list_input}>
|
||||
<View className={styles.btn_width}><Input value={filterObj.weight} onBlur={(e) => setFieldData(e,'weight')} placeholder="请输入克重" placeholderStyle="font-size: 26rpx"/></View>
|
||||
<View className={styles.unit}>kg</View>
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>成分</View>
|
||||
<View className={styles.btn_list_element}>
|
||||
<Textarea placeholder="请输入" cursorSpacing={60} value={filterObj.element} onInput={(e) => setFieldData(e, 'element')}/>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View className="common_safe_area_y"></View>
|
||||
</View>
|
||||
</ScrollView>
|
||||
<View className={styles.btns_con}>
|
||||
<View className={styles.btns_two}>
|
||||
<View className={styles.rest_btn} onClick={() => onRestEven()}>重置</View>
|
||||
<View className={styles.verify_btn } onClick={() => onVerify()}>确认</View>
|
||||
</View>
|
||||
</View>
|
||||
return (
|
||||
<Popup position='right' show={show} showTitle={false} onClose={() => onCloseEven()} showIconButton={true}>
|
||||
<View className={styles.popup_main}>
|
||||
<View className={styles.popup_title}>全部筛选</View>
|
||||
<ScrollView scrollY className={styles.scroll}>
|
||||
<View className={styles.popup_filter}>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>系列</View>
|
||||
<View className={styles.btn_list}>
|
||||
{kindList.map((item) => (
|
||||
<View
|
||||
key={item.id}
|
||||
onClick={() => changeKind(item)}
|
||||
className={classnames(styles.btn_item, filterObj.seriesId == item.id && styles.select_btn_item)}>
|
||||
{item.name}
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
</View>
|
||||
</Popup>
|
||||
)
|
||||
})
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>幅宽</View>
|
||||
<View className={styles.btn_list_input}>
|
||||
<View className={styles.btn_width}>
|
||||
<Input
|
||||
alwaysEmbed={true}
|
||||
cursorSpacing={150}
|
||||
value={filterObj.width}
|
||||
onBlur={(e) => setFieldData(e, 'width')}
|
||||
placeholder='请输入幅宽'
|
||||
placeholderStyle='font-size: 26rpx'
|
||||
/>
|
||||
</View>
|
||||
<View className={styles.unit}>cm</View>
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>克重</View>
|
||||
<View className={styles.btn_list_input}>
|
||||
<View className={styles.btn_width}>
|
||||
<Input
|
||||
value={filterObj.weight}
|
||||
alwaysEmbed={true}
|
||||
cursorSpacing={150}
|
||||
onBlur={(e) => setFieldData(e, 'weight')}
|
||||
placeholder='请输入克重'
|
||||
placeholderStyle='font-size: 26rpx'
|
||||
/>
|
||||
</View>
|
||||
<View className={styles.unit}>kg</View>
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>成分</View>
|
||||
<View className={styles.btn_list_element}>
|
||||
<Textarea placeholder='请输入' cursorSpacing={60} value={filterObj.element} onInput={(e) => setFieldData(e, 'element')} />
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View className='common_safe_area_y'></View>
|
||||
</View>
|
||||
</ScrollView>
|
||||
<View className={styles.btns_con}>
|
||||
<View className={styles.btns_two}>
|
||||
<View className={styles.rest_btn} onClick={() => onRestEven()}>
|
||||
重置
|
||||
</View>
|
||||
<View className={styles.verify_btn} onClick={() => onVerify()}>
|
||||
确认
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</Popup>
|
||||
)
|
||||
})
|
||||
|
@ -1,128 +1,166 @@
|
||||
import { GetProductKindListApi } from "@/api/material";
|
||||
import Popup, {Params as PopuParams} from "@/components/popup"
|
||||
import { Input, ScrollView, Text, Textarea, View } from "@tarojs/components"
|
||||
import { useDidShow } from "@tarojs/taro";
|
||||
import classnames from "classnames";
|
||||
import { useEffect, useState } from "react";
|
||||
import styles from './index.module.scss'
|
||||
import { GetProductKindListApi } from '@/api/material'
|
||||
import Popup, { Params as PopuParams } from '@/components/popup'
|
||||
import { Input, ScrollView, Text, Textarea, View } from '@tarojs/components'
|
||||
import { useDidShow } from '@tarojs/taro'
|
||||
import classnames from 'classnames'
|
||||
import { useEffect, useState } from 'react'
|
||||
import styles from './index.module.scss'
|
||||
|
||||
type params = {
|
||||
onFiltr?: (val:object) => void
|
||||
onFiltr?: (val: object) => void
|
||||
} & PopuParams
|
||||
export default ({onClose, onFiltr, show = false}:params) => {
|
||||
export default ({ onClose, onFiltr, show = false }: params) => {
|
||||
//搜索条件
|
||||
const [filterObj, setFilterObj] = useState({
|
||||
seriesId: '',
|
||||
minWidth: '',
|
||||
maxWidth: '',
|
||||
minWeight: '',
|
||||
maxWeight: '',
|
||||
element: '',
|
||||
})
|
||||
|
||||
//搜索条件
|
||||
const [filterObj, setFilterObj] = useState({
|
||||
seriesId: '',
|
||||
minWidth: '',
|
||||
maxWidth: '',
|
||||
minWeight: '',
|
||||
maxWeight: '',
|
||||
element: ''
|
||||
//获取系列
|
||||
const { fetchData: kindFetchData } = GetProductKindListApi()
|
||||
const [kindList, setKindList] = useState<any[]>([])
|
||||
const getCategoryList = async () => {
|
||||
let { data } = await kindFetchData()
|
||||
setKindList(data.list)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
show && getCategoryList()
|
||||
}, [show])
|
||||
|
||||
//切换系列
|
||||
const changeKind = (e) => {
|
||||
setFilterObj({ ...filterObj, seriesId: e.id })
|
||||
}
|
||||
|
||||
const onCloseEven = () => {
|
||||
onClose?.()
|
||||
}
|
||||
const onRest = () => {
|
||||
console.log('12123')
|
||||
setFilterObj({
|
||||
seriesId: '',
|
||||
minWidth: '',
|
||||
maxWidth: '',
|
||||
minWeight: '',
|
||||
maxWeight: '',
|
||||
element: '',
|
||||
})
|
||||
}
|
||||
useEffect(() => {
|
||||
console.log(filterObj)
|
||||
}, [filterObj])
|
||||
|
||||
//获取系列
|
||||
const {fetchData: kindFetchData} = GetProductKindListApi()
|
||||
const [kindList, setKindList] = useState<any[]>([])
|
||||
const getCategoryList = async () => {
|
||||
let {data} = await kindFetchData()
|
||||
setKindList(data.list)
|
||||
}
|
||||
const onVerify = () => {
|
||||
console.log(filterObj)
|
||||
onFiltr?.(filterObj)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
show&&getCategoryList()
|
||||
}, [show])
|
||||
const setNumber = (e, field) => {
|
||||
console.log(e)
|
||||
let num = parseFloat(e.detail.value)
|
||||
if (isNaN(num)) {
|
||||
filterObj[field] = null
|
||||
} else {
|
||||
filterObj[field] = parseFloat(num.toFixed(2))
|
||||
}
|
||||
setFilterObj({ ...filterObj })
|
||||
}
|
||||
|
||||
//切换系列
|
||||
const changeKind = (e) => {
|
||||
setFilterObj({...filterObj, seriesId:e.id})
|
||||
}
|
||||
|
||||
const onCloseEven = () => {
|
||||
onClose?.()
|
||||
}
|
||||
const onRest = () => {
|
||||
console.log('12123')
|
||||
setFilterObj({
|
||||
seriesId: '',
|
||||
minWidth: '',
|
||||
maxWidth: '',
|
||||
minWeight: '',
|
||||
maxWeight: '',
|
||||
element: ''
|
||||
})
|
||||
}
|
||||
useEffect(() => {
|
||||
console.log(filterObj)
|
||||
}, [filterObj])
|
||||
|
||||
const onVerify = () => {
|
||||
console.log(filterObj)
|
||||
onFiltr?.(filterObj)
|
||||
}
|
||||
|
||||
const setNumber = (e, field) => {
|
||||
console.log(e)
|
||||
let num = parseFloat(e.detail.value)
|
||||
if(isNaN(num)) {
|
||||
filterObj[field] = null
|
||||
} else {
|
||||
filterObj[field] = parseFloat(num.toFixed(2))
|
||||
}
|
||||
setFilterObj({...filterObj})
|
||||
}
|
||||
|
||||
const setElement = (e) => {
|
||||
let res = e.detail.value
|
||||
setFilterObj({...filterObj, element:res})
|
||||
}
|
||||
return (
|
||||
|
||||
<Popup position="right" show={show} showTitle={false} onClose={() => onCloseEven()} showIconButton={true}>
|
||||
<View className={styles.popup_main}>
|
||||
<View className={styles.popup_title}>全部筛选</View>
|
||||
<ScrollView scrollY className={styles.scroll}>
|
||||
<View className={styles.popup_filter}>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>系列</View>
|
||||
<View className={styles.btn_list}>
|
||||
{kindList.map(item => <View key={item.id} onClick={() => changeKind(item)} className={classnames(styles.btn_item, (filterObj.seriesId == item.id)&&styles.select_btn_item)}>{item.name}</View>)}
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>幅宽</View>
|
||||
<View className={styles.btn_list_input}>
|
||||
<View className={styles.btn_width}><Input value={filterObj.minWidth} type="digit" onBlur={(e) => setNumber(e,'minWidth')} placeholder="请输入幅宽" placeholderStyle="font-size: 26rpx"/></View>
|
||||
<View className={styles.unit}>cm</View>
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>克重</View>
|
||||
<View className={styles.btn_list_input}>
|
||||
<View className={styles.btn_width}><Input type="digit" value={filterObj.minWeight} onBlur={(e) => setNumber(e,'minWeight')} placeholder="自定义最低值" placeholderStyle="font-size: 26rpx"/></View>
|
||||
<Text>—</Text>
|
||||
<View className={styles.btn_width}><Input type="digit" value={filterObj.maxWeight} onBlur={(e) => setNumber(e,'maxWeight')} placeholder="自定义最高值" placeholderStyle="font-size: 26rpx"/></View>
|
||||
<View className={styles.unit}>g</View>
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>成分</View>
|
||||
<View className={styles.btn_list_element}>
|
||||
<Textarea placeholder="请输入" cursorSpacing={60} value={filterObj.element} onInput={(e) => setElement(e)}/>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View className="common_safe_area_y"></View>
|
||||
</View>
|
||||
</ScrollView>
|
||||
<View className={styles.btns_con}>
|
||||
<View className={styles.btns_two}>
|
||||
<View className={styles.rest_btn} onClick={() => onRest()}>重置</View>
|
||||
<View className={styles.verify_btn } onClick={() => onVerify()}>确认</View>
|
||||
</View>
|
||||
</View>
|
||||
const setElement = (e) => {
|
||||
let res = e.detail.value
|
||||
setFilterObj({ ...filterObj, element: res })
|
||||
}
|
||||
return (
|
||||
<Popup position='right' show={show} showTitle={false} onClose={() => onCloseEven()} showIconButton={true}>
|
||||
<View className={styles.popup_main}>
|
||||
<View className={styles.popup_title}>全部筛选</View>
|
||||
<ScrollView scrollY className={styles.scroll}>
|
||||
<View className={styles.popup_filter}>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>系列</View>
|
||||
<View className={styles.btn_list}>
|
||||
{kindList.map((item) => (
|
||||
<View
|
||||
key={item.id}
|
||||
onClick={() => changeKind(item)}
|
||||
className={classnames(styles.btn_item, filterObj.seriesId == item.id && styles.select_btn_item)}>
|
||||
{item.name}
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>幅宽</View>
|
||||
<View className={styles.btn_list_input}>
|
||||
<View className={styles.btn_width}>
|
||||
<Input
|
||||
alwaysEmbed={true}
|
||||
cursorSpacing={150}
|
||||
value={filterObj.minWidth}
|
||||
type='digit'
|
||||
onBlur={(e) => setNumber(e, 'minWidth')}
|
||||
placeholder='请输入幅宽'
|
||||
placeholderStyle='font-size: 26rpx'
|
||||
/>
|
||||
</View>
|
||||
<View className={styles.unit}>cm</View>
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>克重</View>
|
||||
<View className={styles.btn_list_input}>
|
||||
<View className={styles.btn_width}>
|
||||
<Input
|
||||
type='digit'
|
||||
value={filterObj.minWeight}
|
||||
onBlur={(e) => setNumber(e, 'minWeight')}
|
||||
placeholder='自定义最低值'
|
||||
placeholderStyle='font-size: 26rpx'
|
||||
alwaysEmbed={true}
|
||||
cursorSpacing={150}
|
||||
/>
|
||||
</View>
|
||||
<Text>—</Text>
|
||||
<View className={styles.btn_width}>
|
||||
<Input
|
||||
type='digit'
|
||||
value={filterObj.maxWeight}
|
||||
onBlur={(e) => setNumber(e, 'maxWeight')}
|
||||
placeholder='自定义最高值'
|
||||
placeholderStyle='font-size: 26rpx'
|
||||
alwaysEmbed={true}
|
||||
cursorSpacing={150}
|
||||
/>
|
||||
</View>
|
||||
<View className={styles.unit}>g</View>
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>成分</View>
|
||||
<View className={styles.btn_list_element}>
|
||||
<Textarea placeholder='请输入' cursorSpacing={60} value={filterObj.element} onInput={(e) => setElement(e)} />
|
||||
</View>
|
||||
</View>
|
||||
</Popup>
|
||||
|
||||
)
|
||||
}
|
||||
<View className='common_safe_area_y'></View>
|
||||
</View>
|
||||
</ScrollView>
|
||||
<View className={styles.btns_con}>
|
||||
<View className={styles.btns_two}>
|
||||
<View className={styles.rest_btn} onClick={() => onRest()}>
|
||||
重置
|
||||
</View>
|
||||
<View className={styles.verify_btn} onClick={() => onVerify()}>
|
||||
确认
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</Popup>
|
||||
)
|
||||
}
|
||||
|
@ -1,83 +1,113 @@
|
||||
import { Input, View } from "@tarojs/components";
|
||||
import styles from "./index.module.scss"
|
||||
import CloseBtn from "@/components/closeBtn"
|
||||
import classnames from "classnames";
|
||||
import { debounce } from "@/common/util";
|
||||
import { forwardRef, memo, useEffect, useImperativeHandle, useRef, useState } from "react";
|
||||
import { Input, View } from '@tarojs/components'
|
||||
import styles from './index.module.scss'
|
||||
import CloseBtn from '@/components/closeBtn'
|
||||
import classnames from 'classnames'
|
||||
import { debounce } from '@/common/util'
|
||||
import { forwardRef, memo, useEffect, useImperativeHandle, useRef, useState } from 'react'
|
||||
|
||||
type Params = {
|
||||
clickOnSearch?: (val: string) => void
|
||||
disabled?: false|true,
|
||||
placeholder?: string,
|
||||
changeOnSearch?:(any) => void,
|
||||
showIcon?: false|true,
|
||||
placeIcon?: 'out'|'inner',
|
||||
style?: Object,
|
||||
showBtn?: false|true,
|
||||
btnStyle?: Object,
|
||||
btnTitle?: string,
|
||||
debounceTime?: number //防抖时间,不设默认为零
|
||||
defaultValue?: string
|
||||
clickOnSearch?: (val: string) => void
|
||||
disabled?: false | true
|
||||
placeholder?: string
|
||||
changeOnSearch?: (any) => void
|
||||
showIcon?: false | true
|
||||
placeIcon?: 'out' | 'inner'
|
||||
style?: Object
|
||||
showBtn?: false | true
|
||||
btnStyle?: Object
|
||||
btnTitle?: string
|
||||
debounceTime?: number //防抖时间,不设默认为零
|
||||
defaultValue?: string
|
||||
}
|
||||
|
||||
export default memo(forwardRef(({
|
||||
clickOnSearch, //点击筛选按钮触发
|
||||
changeOnSearch, //输入文字触发
|
||||
disabled = false, //是否禁用
|
||||
placeholder = '输入搜索内容',
|
||||
showIcon = true, //是否显示关闭图标
|
||||
showBtn = false, //是否显示搜索按钮
|
||||
btnStyle = {},
|
||||
placeIcon = 'inner', //搜索图标位置:inner在里面,out在外面
|
||||
btnTitle = '搜索', //搜索文字
|
||||
debounceTime = 0, //防抖时间,不设默认为零
|
||||
defaultValue = '' //默认值
|
||||
}:Params, ref) => {
|
||||
const [inputCon , setInputCon] = useState('')
|
||||
const debounceTimeRef = useRef(0)
|
||||
useEffect(() => {
|
||||
export default memo(
|
||||
forwardRef(
|
||||
(
|
||||
{
|
||||
clickOnSearch, //点击筛选按钮触发
|
||||
changeOnSearch, //输入文字触发
|
||||
disabled = false, //是否禁用
|
||||
placeholder = '输入搜索内容',
|
||||
showIcon = true, //是否显示关闭图标
|
||||
showBtn = false, //是否显示搜索按钮
|
||||
btnStyle = {},
|
||||
placeIcon = 'inner', //搜索图标位置:inner在里面,out在外面
|
||||
btnTitle = '搜索', //搜索文字
|
||||
debounceTime = 0, //防抖时间,不设默认为零
|
||||
defaultValue = '', //默认值
|
||||
}: Params,
|
||||
ref,
|
||||
) => {
|
||||
const [inputCon, setInputCon] = useState('')
|
||||
const debounceTimeRef = useRef(0)
|
||||
useEffect(() => {
|
||||
setInputCon(defaultValue)
|
||||
}, [defaultValue])
|
||||
}, [defaultValue])
|
||||
|
||||
useEffect(() => {
|
||||
useEffect(() => {
|
||||
debounceTimeRef.current = debounceTime
|
||||
}, [debounceTime])
|
||||
}, [debounceTime])
|
||||
|
||||
const onInputEven = (e) => {
|
||||
const onInputEven = (e) => {
|
||||
const value = e.detail.value
|
||||
changeData(value)
|
||||
}
|
||||
}
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
clearInput
|
||||
}))
|
||||
useImperativeHandle(ref, () => ({
|
||||
clearInput,
|
||||
}))
|
||||
|
||||
const clearInput = () => {
|
||||
const clearInput = () => {
|
||||
setInputCon('')
|
||||
changeOnSearch?.('')
|
||||
}
|
||||
}
|
||||
|
||||
const changeData = debounce((value) => {
|
||||
const changeData = debounce((value) => {
|
||||
setInputCon(value)
|
||||
changeOnSearch?.(value)
|
||||
}, debounceTimeRef.current)
|
||||
}, debounceTimeRef.current)
|
||||
|
||||
const onSearch = () => {
|
||||
const onSearch = () => {
|
||||
clickOnSearch?.(inputCon)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
return (
|
||||
<>
|
||||
<View className={styles.search_main} >
|
||||
<View className={styles.search_con}>
|
||||
{showIcon&&<View className={classnames('iconfont', 'icon-sousuo', styles.icon_a_sousuo1_self, placeIcon=='inner'?styles.icon_inner:styles.icon_out)}></View>}
|
||||
<Input placeholderStyle='color:#ABABAB; font-size:26rpx' onConfirm={onSearch} className={classnames(placeIcon=='out'&&styles.input_out)} disabled={disabled} value={inputCon} placeholder={placeholder} onInput={(e) => onInputEven(e)}></Input>
|
||||
{!!inputCon&&<View className={styles.search_closeBtn}>
|
||||
<CloseBtn onClose={() => clearInput()} styleObj={{width: '20rpx', height:'20rpx', backgroundColor:'#fff', border:'0'}}/>
|
||||
</View>}
|
||||
<View className={styles.search_main}>
|
||||
<View className={styles.search_con}>
|
||||
{showIcon && (
|
||||
<View
|
||||
className={classnames(
|
||||
'iconfont',
|
||||
'icon-sousuo',
|
||||
styles.icon_a_sousuo1_self,
|
||||
placeIcon == 'inner' ? styles.icon_inner : styles.icon_out,
|
||||
)}></View>
|
||||
)}
|
||||
<Input
|
||||
alwaysEmbed={true}
|
||||
cursorSpacing={150}
|
||||
placeholderStyle='color:#ABABAB; font-size:26rpx'
|
||||
onConfirm={onSearch}
|
||||
className={classnames(placeIcon == 'out' && styles.input_out)}
|
||||
disabled={disabled}
|
||||
value={inputCon}
|
||||
placeholder={placeholder}
|
||||
onInput={(e) => onInputEven(e)}></Input>
|
||||
{!!inputCon && (
|
||||
<View className={styles.search_closeBtn}>
|
||||
<CloseBtn onClose={() => clearInput()} styleObj={{ width: '20rpx', height: '20rpx', backgroundColor: '#fff', border: '0' }} />
|
||||
</View>
|
||||
{showBtn&&<View style={btnStyle} className={styles.btn} onClick = {onSearch}>{btnTitle}</View>}
|
||||
)}
|
||||
</View>
|
||||
{showBtn && (
|
||||
<View style={btnStyle} className={styles.btn} onClick={onSearch}>
|
||||
{btnTitle}
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
</>
|
||||
)
|
||||
}))
|
||||
)
|
||||
},
|
||||
),
|
||||
)
|
||||
|
@ -1,52 +1,62 @@
|
||||
import { Input, View } from "@tarojs/components";
|
||||
import { memo, ReactHTMLElement, ReactNode, useDebugValue, useMemo } from "react";
|
||||
import styles from './index.module.scss';
|
||||
import { Input, View } from '@tarojs/components'
|
||||
import { memo, ReactHTMLElement, ReactNode, useDebugValue, useMemo } from 'react'
|
||||
import styles from './index.module.scss'
|
||||
|
||||
type Params = {
|
||||
showIcon?: false|true,
|
||||
disabled?: false|true,
|
||||
placeholder?: string,
|
||||
title?: string,
|
||||
showTitle?: false|true,
|
||||
showBorder?: false|true,
|
||||
changeOnInput?: (string) => void,
|
||||
clickOnInput?: () => void,
|
||||
children?: ReactNode
|
||||
height?: string,
|
||||
titleStyle?: Object,
|
||||
styleObj?: Object
|
||||
|
||||
showIcon?: false | true
|
||||
disabled?: false | true
|
||||
placeholder?: string
|
||||
title?: string
|
||||
showTitle?: false | true
|
||||
showBorder?: false | true
|
||||
changeOnInput?: (string) => void
|
||||
clickOnInput?: () => void
|
||||
children?: ReactNode
|
||||
height?: string
|
||||
titleStyle?: Object
|
||||
styleObj?: Object
|
||||
}
|
||||
|
||||
export default memo((props: Params) => {
|
||||
let {
|
||||
showTitle = true,
|
||||
title = '标题',
|
||||
showIcon = false,
|
||||
disabled = false,
|
||||
placeholder = '请输入',
|
||||
showBorder = true,
|
||||
changeOnInput,
|
||||
clickOnInput,
|
||||
height = '80rpx',
|
||||
titleStyle = {}
|
||||
} = props
|
||||
let {
|
||||
showTitle = true,
|
||||
title = '标题',
|
||||
showIcon = false,
|
||||
disabled = false,
|
||||
placeholder = '请输入',
|
||||
showBorder = true,
|
||||
changeOnInput,
|
||||
clickOnInput,
|
||||
height = '80rpx',
|
||||
titleStyle = {},
|
||||
} = props
|
||||
|
||||
let stylen = useMemo(() => {
|
||||
if(!showBorder) {
|
||||
return { borderBottom: 0 }
|
||||
}
|
||||
return {}
|
||||
}, [showBorder])
|
||||
return (
|
||||
<View className={styles.searchInput_main} style={{height: height, ...stylen}}>
|
||||
{showTitle&&<View className={styles.searchInput_title} style={titleStyle}>{title}</View>}
|
||||
<View className={styles.searchInput_con}>
|
||||
{!props.children&&<Input disabled={disabled} placeholder={placeholder} onClick={() => clickOnInput?.()} onInput={(e) => changeOnInput?.(e.detail.value)}/>
|
||||
||<>{props.children}</>
|
||||
}
|
||||
</View>
|
||||
{showIcon&&<View className={`iconfont icon-jiantou ${styles.icon_more_self}`}></View>}
|
||||
let stylen = useMemo(() => {
|
||||
if (!showBorder) {
|
||||
return { borderBottom: 0 }
|
||||
}
|
||||
return {}
|
||||
}, [showBorder])
|
||||
return (
|
||||
<View className={styles.searchInput_main} style={{ height: height, ...stylen }}>
|
||||
{showTitle && (
|
||||
<View className={styles.searchInput_title} style={titleStyle}>
|
||||
{title}
|
||||
</View>
|
||||
)
|
||||
})
|
||||
)}
|
||||
<View className={styles.searchInput_con}>
|
||||
{(!props.children && (
|
||||
<Input
|
||||
alwaysEmbed={true}
|
||||
cursorSpacing={150}
|
||||
disabled={disabled}
|
||||
placeholder={placeholder}
|
||||
onClick={() => clickOnInput?.()}
|
||||
onInput={(e) => changeOnInput?.(e.detail.value)}
|
||||
/>
|
||||
)) || <>{props.children}</>}
|
||||
</View>
|
||||
{showIcon && <View className={`iconfont icon-jiantou ${styles.icon_more_self}`}></View>}
|
||||
</View>
|
||||
)
|
||||
})
|
||||
|
@ -1,15 +1,15 @@
|
||||
import { Image, Input, Text, View } from '@tarojs/components'
|
||||
import styles from './index.module.scss'
|
||||
import useLogin from '@/use/useLogin'
|
||||
import classnames from "classnames";
|
||||
import classnames from 'classnames'
|
||||
import { formatImgUrl } from '@/common/fotmat'
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { alert } from '@/common/common';
|
||||
import CloseBtn from '@/components/closeBtn';
|
||||
import SuccessBind from './component/successBind';
|
||||
import Taro, { useDidShow } from "@tarojs/taro";
|
||||
import { BindInvitationInfoApi, GetInvitationInfoApi } from '@/api/user';
|
||||
import { debounce, getFilterData, throttle } from '@/common/util';
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { alert } from '@/common/common'
|
||||
import CloseBtn from '@/components/closeBtn'
|
||||
import SuccessBind from './component/successBind'
|
||||
import Taro, { useDidShow } from '@tarojs/taro'
|
||||
import { BindInvitationInfoApi, GetInvitationInfoApi } from '@/api/user'
|
||||
import { debounce, getFilterData, throttle } from '@/common/util'
|
||||
export default () => {
|
||||
useLogin()
|
||||
|
||||
@ -20,81 +20,94 @@ export default () => {
|
||||
const [submitData, setSubmitData] = useState({
|
||||
invitation_code: '',
|
||||
})
|
||||
|
||||
|
||||
//获取业务员信息
|
||||
type Param = {invitation_code: string, name: string, phone: string}
|
||||
const [salesMan, setSalesMan] = useState<Param|null>(null)
|
||||
const {fetchData: GetInvitationInfoFetchData} = GetInvitationInfoApi()
|
||||
type Param = { invitation_code: string; name: string; phone: string }
|
||||
const [salesMan, setSalesMan] = useState<Param | null>(null)
|
||||
const { fetchData: GetInvitationInfoFetchData } = GetInvitationInfoApi()
|
||||
const getInvitationInfo = async () => {
|
||||
let res = await GetInvitationInfoFetchData(getFilterData({...submitData}))
|
||||
res.success?setSalesMan(res.data):setSalesMan(null)
|
||||
let res = await GetInvitationInfoFetchData(getFilterData({ ...submitData }))
|
||||
res.success ? setSalesMan(res.data) : setSalesMan(null)
|
||||
}
|
||||
useEffect(() => {
|
||||
if(submitData.invitation_code.length === 4)
|
||||
getInvitationInfo()
|
||||
if (submitData.invitation_code.length === 4) getInvitationInfo()
|
||||
}, [submitData])
|
||||
|
||||
const onInputCode = (e) => {
|
||||
const value = e.detail.value.replace(/[\W]/g, "")
|
||||
setSubmitData((val) => ({...val, invitation_code:value}))
|
||||
const value = e.detail.value.replace(/[\W]/g, '')
|
||||
setSubmitData((val) => ({ ...val, invitation_code: value }))
|
||||
}
|
||||
|
||||
const oncloseEven = () => {
|
||||
setSubmitData((val) => ({...val, invitation_code:''}))
|
||||
setSubmitData((val) => ({ ...val, invitation_code: '' }))
|
||||
setSalesMan(null)
|
||||
}
|
||||
|
||||
//绑定业务员
|
||||
const [bindShow, setBindShow] = useState(false)
|
||||
const {fetchData: bindInvitationInfoFetchData} = BindInvitationInfoApi()
|
||||
const { fetchData: bindInvitationInfoFetchData } = BindInvitationInfoApi()
|
||||
const onSubmit = async () => {
|
||||
if(!submitData.invitation_code) return alert.error('请输入邀请码')
|
||||
let res = await bindInvitationInfoFetchData({...submitData})
|
||||
if(res.success) setBindShow(() => true)
|
||||
if (!submitData.invitation_code) return alert.error('请输入邀请码')
|
||||
let res = await bindInvitationInfoFetchData({ ...submitData })
|
||||
if (res.success) setBindShow(() => true)
|
||||
}
|
||||
|
||||
const onScanCode = () => {
|
||||
Taro.scanCode({
|
||||
success: (res) => {
|
||||
setSubmitData(() => ({invitation_code: res.result}))
|
||||
}
|
||||
setSubmitData(() => ({ invitation_code: res.result }))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//获取粘贴版内容
|
||||
const onClipboardData = () => {
|
||||
Taro.getClipboardData({
|
||||
success: function (res){
|
||||
success: function (res) {
|
||||
let val = res.data.match(/InviteCode:([a-zA-Z0-9]{4})/)
|
||||
if(val) setSubmitData((e) => ({...e, invitation_code: val?val[1]:''}))
|
||||
}
|
||||
if (val) setSubmitData((e) => ({ ...e, invitation_code: val ? val[1] : '' }))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<View className={styles.bindSalesmanPage_main}>
|
||||
<View className={styles.header_image}>
|
||||
<Image src={formatImgUrl('/mall/invite_code_bg.png')} mode="aspectFill"/>
|
||||
<Image src={formatImgUrl('/mall/invite_code_bg.png')} mode='aspectFill' />
|
||||
</View>
|
||||
<View className={styles.inputCode}>
|
||||
<Input maxlength={4} value={submitData.invitation_code} placeholder='请输入邀请码' onInput={onInputCode} type="text" />
|
||||
<View className={styles.close_btn} >
|
||||
{submitData.invitation_code&&<CloseBtn styleObj={{backgroundColor: '#ccc', color: '#fff'}} onClose={oncloseEven}/>}
|
||||
<Input
|
||||
alwaysEmbed={true}
|
||||
cursorSpacing={150}
|
||||
maxlength={4}
|
||||
value={submitData.invitation_code}
|
||||
placeholder='请输入邀请码'
|
||||
onInput={onInputCode}
|
||||
type='text'
|
||||
/>
|
||||
<View className={styles.close_btn}>
|
||||
{submitData.invitation_code && <CloseBtn styleObj={{ backgroundColor: '#ccc', color: '#fff' }} onClose={oncloseEven} />}
|
||||
</View>
|
||||
<View className={styles.scan_code} onClick={() => onScanCode()}>
|
||||
<Text className={classnames('iconfont icon-saomazhifu', styles.miconfont)}></Text>
|
||||
</View>
|
||||
</View>
|
||||
{salesMan&&<View className={styles.salesman_name}><Text>邀请人:</Text><Text>{`${salesMan.name} (${salesMan.phone})`}</Text></View>}
|
||||
<View className={classnames(styles.btns, salesMan&&styles.select_btns)} onClick={onSubmit}>提交</View>
|
||||
{salesMan && (
|
||||
<View className={styles.salesman_name}>
|
||||
<Text>邀请人:</Text>
|
||||
<Text>{`${salesMan.name} (${salesMan.phone})`}</Text>
|
||||
</View>
|
||||
)}
|
||||
<View className={classnames(styles.btns, salesMan && styles.select_btns)} onClick={onSubmit}>
|
||||
提交
|
||||
</View>
|
||||
<View className={styles.message}>
|
||||
<Text>温馨提示</Text>
|
||||
<Text>1. 新用户授权手机号码后,7天内可以输入邀请码,超过时间不能输入。</Text>
|
||||
<Text>2. 一个手机只能输入一次邀请码。输入邀请码。</Text>
|
||||
</View>
|
||||
<View className='common_safe_area_y'></View>
|
||||
<SuccessBind show={bindShow} onClose={() => setBindShow(false)} saleMan={salesMan?.name}/>
|
||||
<SuccessBind show={bindShow} onClose={() => setBindShow(false)} saleMan={salesMan?.name} />
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1,115 +1,156 @@
|
||||
import Popup, {Params as PopuParams} from "@/components/popup"
|
||||
import { Input, ScrollView, Text, Textarea, View } from "@tarojs/components"
|
||||
import classnames from "classnames";
|
||||
import { useEffect, useState } from "react";
|
||||
import styles from './index.module.scss'
|
||||
import Popup, { Params as PopuParams } from '@/components/popup'
|
||||
import { Input, ScrollView, Text, Textarea, View } from '@tarojs/components'
|
||||
import classnames from 'classnames'
|
||||
import { useEffect, useState } from 'react'
|
||||
import styles from './index.module.scss'
|
||||
|
||||
type params = {
|
||||
onFiltr?: (val:object) => void
|
||||
onFiltr?: (val: object) => void
|
||||
} & PopuParams
|
||||
export default ({onClose, onFiltr, show = false}:params) => {
|
||||
const [filterObj, setFilterObj] = useState({
|
||||
series: '',
|
||||
minWidth: '',
|
||||
maxWidth: '',
|
||||
minWeight: '',
|
||||
maxWeight: '',
|
||||
element: ''
|
||||
|
||||
export default ({ onClose, onFiltr, show = false }: params) => {
|
||||
const [filterObj, setFilterObj] = useState({
|
||||
series: '',
|
||||
minWidth: '',
|
||||
maxWidth: '',
|
||||
minWeight: '',
|
||||
maxWeight: '',
|
||||
element: '',
|
||||
})
|
||||
const onCloseEven = () => {
|
||||
onClose?.()
|
||||
}
|
||||
const onRest = () => {
|
||||
console.log('12123')
|
||||
setFilterObj({
|
||||
series: '',
|
||||
minWidth: '',
|
||||
maxWidth: '',
|
||||
minWeight: '',
|
||||
maxWeight: '',
|
||||
element: '',
|
||||
})
|
||||
const onCloseEven = () => {
|
||||
onClose?.()
|
||||
}
|
||||
const onRest = () => {
|
||||
console.log('12123')
|
||||
setFilterObj({
|
||||
series: '',
|
||||
minWidth: '',
|
||||
maxWidth: '',
|
||||
minWeight: '',
|
||||
maxWeight: '',
|
||||
element: ''
|
||||
})
|
||||
}
|
||||
useEffect(() => {
|
||||
console.log(filterObj)
|
||||
}, [filterObj])
|
||||
}
|
||||
useEffect(() => {
|
||||
console.log(filterObj)
|
||||
}, [filterObj])
|
||||
|
||||
const onVerify = () => {
|
||||
console.log(filterObj)
|
||||
onFiltr?.(filterObj)
|
||||
}
|
||||
const onVerify = () => {
|
||||
console.log(filterObj)
|
||||
onFiltr?.(filterObj)
|
||||
}
|
||||
|
||||
const setNumber = (e, field) => {
|
||||
console.log(e)
|
||||
let num = parseFloat(e.detail.value)
|
||||
if(isNaN(num)) {
|
||||
filterObj[field] = null
|
||||
} else {
|
||||
filterObj[field] = parseFloat(num.toFixed(2))
|
||||
}
|
||||
setFilterObj({...filterObj})
|
||||
const setNumber = (e, field) => {
|
||||
console.log(e)
|
||||
let num = parseFloat(e.detail.value)
|
||||
if (isNaN(num)) {
|
||||
filterObj[field] = null
|
||||
} else {
|
||||
filterObj[field] = parseFloat(num.toFixed(2))
|
||||
}
|
||||
setFilterObj({ ...filterObj })
|
||||
}
|
||||
|
||||
const setElement = (e) => {
|
||||
let res = e.detail.value
|
||||
setFilterObj({...filterObj, element:res})
|
||||
}
|
||||
return (
|
||||
|
||||
<Popup position="right" show={show} showTitle={false} onClose={() => onCloseEven()} showIconButton={true}>
|
||||
<View className={styles.popup_main}>
|
||||
<View className={styles.popup_title}>全部筛选</View>
|
||||
|
||||
<ScrollView scrollY className={styles.scroll}>
|
||||
<View className={styles.popup_filter}>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>系列</View>
|
||||
<View className={styles.btn_list}>
|
||||
<View className={classnames(styles.btn_item, styles.select_btn_item)}>不限</View>
|
||||
<View className={styles.btn_item}>不限</View>
|
||||
<View className={styles.btn_item}>不限</View>
|
||||
<View className={styles.btn_item}>不限</View>
|
||||
<View className={styles.btn_item}>不限</View>
|
||||
<View className={styles.btn_item}>不限</View>
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>幅宽</View>
|
||||
<View className={styles.btn_list_input}>
|
||||
<View className={styles.btn_width}><Input value={filterObj.minWidth} type="digit" onBlur={(e) => setNumber(e,'minWidth')} placeholder="自定义最低值" placeholderStyle="font-size: 26rpx"/></View>
|
||||
<Text>—</Text>
|
||||
<View className={styles.btn_width}><Input value={filterObj.maxWidth} type="digit" onBlur={(e) => setNumber(e,'maxWidth')} placeholder="自定义最高值" placeholderStyle="font-size: 26rpx"/></View>
|
||||
<View className={styles.unit}>cm</View>
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>克重</View>
|
||||
<View className={styles.btn_list_input}>
|
||||
<View className={styles.btn_width}><Input type="digit" value={filterObj.minWeight} onBlur={(e) => setNumber(e,'minWeight')} placeholder="自定义最低值" placeholderStyle="font-size: 26rpx"/></View>
|
||||
<Text>—</Text>
|
||||
<View className={styles.btn_width}><Input type="digit" value={filterObj.maxWeight} onBlur={(e) => setNumber(e,'maxWeight')} placeholder="自定义最高值" placeholderStyle="font-size: 26rpx"/></View>
|
||||
<View className={styles.unit}>g</View>
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>成分</View>
|
||||
<View className={styles.btn_list_element}>
|
||||
<Textarea placeholder="请输入" cursorSpacing={60} value={filterObj.element} onInput={(e) => setElement(e)}/>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View className="common_safe_area_y"></View>
|
||||
</View>
|
||||
</ScrollView>
|
||||
<View className={styles.btns_con}>
|
||||
<View className={styles.btns_two}>
|
||||
<View className={styles.rest_btn} onClick={() => onRest()}>重置</View>
|
||||
<View className={styles.verify_btn } onClick={() => onVerify()}>确认</View>
|
||||
</View>
|
||||
</View>
|
||||
const setElement = (e) => {
|
||||
let res = e.detail.value
|
||||
setFilterObj({ ...filterObj, element: res })
|
||||
}
|
||||
return (
|
||||
<Popup position='right' show={show} showTitle={false} onClose={() => onCloseEven()} showIconButton={true}>
|
||||
<View className={styles.popup_main}>
|
||||
<View className={styles.popup_title}>全部筛选</View>
|
||||
|
||||
<ScrollView scrollY className={styles.scroll}>
|
||||
<View className={styles.popup_filter}>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>系列</View>
|
||||
<View className={styles.btn_list}>
|
||||
<View className={classnames(styles.btn_item, styles.select_btn_item)}>不限</View>
|
||||
<View className={styles.btn_item}>不限</View>
|
||||
<View className={styles.btn_item}>不限</View>
|
||||
<View className={styles.btn_item}>不限</View>
|
||||
<View className={styles.btn_item}>不限</View>
|
||||
<View className={styles.btn_item}>不限</View>
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>幅宽</View>
|
||||
<View className={styles.btn_list_input}>
|
||||
<View className={styles.btn_width}>
|
||||
<Input
|
||||
alwaysEmbed={true}
|
||||
cursorSpacing={150}
|
||||
value={filterObj.minWidth}
|
||||
type='digit'
|
||||
onBlur={(e) => setNumber(e, 'minWidth')}
|
||||
placeholder='自定义最低值'
|
||||
placeholderStyle='font-size: 26rpx'
|
||||
/>
|
||||
</View>
|
||||
<Text>—</Text>
|
||||
<View className={styles.btn_width}>
|
||||
<Input
|
||||
alwaysEmbed={true}
|
||||
cursorSpacing={150}
|
||||
value={filterObj.maxWidth}
|
||||
type='digit'
|
||||
onBlur={(e) => setNumber(e, 'maxWidth')}
|
||||
placeholder='自定义最高值'
|
||||
placeholderStyle='font-size: 26rpx'
|
||||
/>
|
||||
</View>
|
||||
<View className={styles.unit}>cm</View>
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>克重</View>
|
||||
<View className={styles.btn_list_input}>
|
||||
<View className={styles.btn_width}>
|
||||
<Input
|
||||
alwaysEmbed={true}
|
||||
cursorSpacing={150}
|
||||
type='digit'
|
||||
value={filterObj.minWeight}
|
||||
onBlur={(e) => setNumber(e, 'minWeight')}
|
||||
placeholder='自定义最低值'
|
||||
placeholderStyle='font-size: 26rpx'
|
||||
/>
|
||||
</View>
|
||||
<Text>—</Text>
|
||||
<View className={styles.btn_width}>
|
||||
<Input
|
||||
alwaysEmbed={true}
|
||||
cursorSpacing={150}
|
||||
type='digit'
|
||||
value={filterObj.maxWeight}
|
||||
onBlur={(e) => setNumber(e, 'maxWeight')}
|
||||
placeholder='自定义最高值'
|
||||
placeholderStyle='font-size: 26rpx'
|
||||
/>
|
||||
</View>
|
||||
<View className={styles.unit}>g</View>
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>成分</View>
|
||||
<View className={styles.btn_list_element}>
|
||||
<Textarea placeholder='请输入' cursorSpacing={60} value={filterObj.element} onInput={(e) => setElement(e)} />
|
||||
</View>
|
||||
</View>
|
||||
</Popup>
|
||||
|
||||
)
|
||||
}
|
||||
<View className='common_safe_area_y'></View>
|
||||
</View>
|
||||
</ScrollView>
|
||||
<View className={styles.btns_con}>
|
||||
<View className={styles.btns_two}>
|
||||
<View className={styles.rest_btn} onClick={() => onRest()}>
|
||||
重置
|
||||
</View>
|
||||
<View className={styles.verify_btn} onClick={() => onVerify()}>
|
||||
确认
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</Popup>
|
||||
)
|
||||
}
|
||||
|
@ -48,7 +48,6 @@ export default memo(({ show = false, onClose, onSuccess, defaultValue }: ReasonI
|
||||
placeholder='请输入文件夹名称'
|
||||
className={styles.input}
|
||||
alwaysEmbed={true}
|
||||
// adjustPosition={true}
|
||||
cursorSpacing={100}
|
||||
onInput={changeInput}
|
||||
value={defaultValue?.name}
|
||||
|
@ -1,113 +1,108 @@
|
||||
import { Input, View } from "@tarojs/components"
|
||||
import { useEffect, useMemo, useRef, useState } from "react"
|
||||
import { Input, View } from '@tarojs/components'
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import Big from 'big.js'
|
||||
import styles from "./index.module.scss"
|
||||
import styles from './index.module.scss'
|
||||
type params = {
|
||||
minNum?: number, //最小值
|
||||
maxNum?: number, //最大值
|
||||
step?: number, //步长
|
||||
defaultNum?: number, //默认值
|
||||
digits?: number //多少位小数
|
||||
onChange?:(val: number, obj?: any) => void,
|
||||
onBlue?:(val:number, obj?: any) => void, //失去焦点触发
|
||||
onClickBtn?:(val:number, obj?: any) => void,
|
||||
unit?: string,
|
||||
otherData?: any
|
||||
minNum?: number //最小值
|
||||
maxNum?: number //最大值
|
||||
step?: number //步长
|
||||
defaultNum?: number //默认值
|
||||
digits?: number //多少位小数
|
||||
onChange?: (val: number, obj?: any) => void
|
||||
onBlue?: (val: number, obj?: any) => void //失去焦点触发
|
||||
onClickBtn?: (val: number, obj?: any) => void
|
||||
unit?: string
|
||||
otherData?: any
|
||||
}
|
||||
export default ({minNum = 0, maxNum = 100, step=1, digits = 0, defaultNum = 0, onChange, onBlue, onClickBtn, unit = '', otherData}: params) => {
|
||||
const [value, setValue] = useState<any>({count:defaultNum})
|
||||
|
||||
|
||||
const onPlus = () => {
|
||||
let {count} = value
|
||||
let num_res = Big(count).add(step).toNumber()
|
||||
num_res = num_res >= maxNum?maxNum:num_res
|
||||
num_res = formatDigits(num_res)
|
||||
setValue({...value, count:num_res})
|
||||
onChange?.(parseFloat(num_res), otherData)
|
||||
onClickBtn?.(parseFloat(num_res), otherData)
|
||||
}
|
||||
const minus = () => {
|
||||
let {count} = value
|
||||
let num_res = Big(count).minus(step).toNumber()
|
||||
num_res = num_res < minNum?0:num_res
|
||||
setValue({...value, count:num_res})
|
||||
onChange?.(parseFloat(num_res), otherData)
|
||||
onClickBtn?.(parseFloat(num_res), otherData)
|
||||
}
|
||||
export default ({ minNum = 0, maxNum = 100, step = 1, digits = 0, defaultNum = 0, onChange, onBlue, onClickBtn, unit = '', otherData }: params) => {
|
||||
const [value, setValue] = useState<any>({ count: defaultNum })
|
||||
|
||||
//保留小数
|
||||
const formatDigits = (num) => {
|
||||
num = num + ''
|
||||
if(num.includes('.')&&digits > 0) {
|
||||
console.log('num::',num.includes('.'))
|
||||
let res = num.split('.')
|
||||
let last_num = res[1].substr(0, digits)
|
||||
return res[0] + '.' + last_num
|
||||
}
|
||||
return parseFloat(num)
|
||||
}
|
||||
const onPlus = () => {
|
||||
let { count } = value
|
||||
let num_res = Big(count).add(step).toNumber()
|
||||
num_res = num_res >= maxNum ? maxNum : num_res
|
||||
num_res = formatDigits(num_res)
|
||||
setValue({ ...value, count: num_res })
|
||||
onChange?.(parseFloat(num_res), otherData)
|
||||
onClickBtn?.(parseFloat(num_res), otherData)
|
||||
}
|
||||
const minus = () => {
|
||||
let { count } = value
|
||||
let num_res = Big(count).minus(step).toNumber()
|
||||
num_res = num_res < minNum ? 0 : num_res
|
||||
setValue({ ...value, count: num_res })
|
||||
onChange?.(parseFloat(num_res), otherData)
|
||||
onClickBtn?.(parseFloat(num_res), otherData)
|
||||
}
|
||||
|
||||
//检查数据
|
||||
const checkData = (val) => {
|
||||
let num = parseFloat(val)
|
||||
if(num > maxNum) return maxNum
|
||||
if(num < minNum) return minNum
|
||||
return val
|
||||
//保留小数
|
||||
const formatDigits = (num) => {
|
||||
num = num + ''
|
||||
if (num.includes('.') && digits > 0) {
|
||||
console.log('num::', num.includes('.'))
|
||||
let res = num.split('.')
|
||||
let last_num = res[1].substr(0, digits)
|
||||
return res[0] + '.' + last_num
|
||||
}
|
||||
|
||||
return parseFloat(num)
|
||||
}
|
||||
|
||||
const onInputEven = (e) => {
|
||||
let res = e.detail.value
|
||||
if(res === '') {
|
||||
setValue({...value, count:minNum})
|
||||
onChange?.(minNum, otherData)
|
||||
}
|
||||
else if(!isNaN(Number(res))) {
|
||||
let count = formatDigits(res)
|
||||
count = checkData(count)
|
||||
setValue({...value, count})
|
||||
onChange?.(parseFloat(count as string), otherData)
|
||||
} else {
|
||||
let num = parseFloat(res)
|
||||
if(!isNaN(num)) {
|
||||
let count = formatDigits(num)
|
||||
count = checkData(count)
|
||||
setValue({...value, count})
|
||||
onChange?.(count as number, otherData)
|
||||
} else {
|
||||
setValue({...value, count:defaultNum})
|
||||
onChange?.(defaultNum, otherData)
|
||||
}
|
||||
|
||||
}
|
||||
//检查数据
|
||||
const checkData = (val) => {
|
||||
let num = parseFloat(val)
|
||||
if (num > maxNum) return maxNum
|
||||
if (num < minNum) return minNum
|
||||
return val
|
||||
}
|
||||
|
||||
const onInputEven = (e) => {
|
||||
let res = e.detail.value
|
||||
if (res === '') {
|
||||
setValue({ ...value, count: minNum })
|
||||
onChange?.(minNum, otherData)
|
||||
} else if (!isNaN(Number(res))) {
|
||||
let count = formatDigits(res)
|
||||
count = checkData(count)
|
||||
setValue({ ...value, count })
|
||||
onChange?.(parseFloat(count as string), otherData)
|
||||
} else {
|
||||
let num = parseFloat(res)
|
||||
if (!isNaN(num)) {
|
||||
let count = formatDigits(num)
|
||||
count = checkData(count)
|
||||
setValue({ ...value, count })
|
||||
onChange?.(count as number, otherData)
|
||||
} else {
|
||||
setValue({ ...value, count: defaultNum })
|
||||
onChange?.(defaultNum, otherData)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const onBluerEven = () => {
|
||||
let num = parseFloat(value.count)
|
||||
if(!isNaN(num)) {
|
||||
let count = formatDigits(num)
|
||||
count = checkData(count)
|
||||
setValue({...value, count})
|
||||
onBlue?.(count as number, otherData)
|
||||
} else {
|
||||
setValue({...value, count:defaultNum})
|
||||
onBlue?.(defaultNum, otherData)
|
||||
}
|
||||
}
|
||||
return (
|
||||
<View className={styles.main}>
|
||||
<View className={styles.reduce} onClick={() => minus()}>-</View>
|
||||
<View className={styles.input}>
|
||||
<Input
|
||||
value={String(value.count)}
|
||||
onInput={onInputEven}
|
||||
onBlur={onBluerEven}
|
||||
type='digit'
|
||||
/>
|
||||
<View className={styles.unit}>{unit}</View>
|
||||
</View>
|
||||
<View className={styles.plus} onClick={() => onPlus()}>+</View>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
const onBluerEven = () => {
|
||||
let num = parseFloat(value.count)
|
||||
if (!isNaN(num)) {
|
||||
let count = formatDigits(num)
|
||||
count = checkData(count)
|
||||
setValue({ ...value, count })
|
||||
onBlue?.(count as number, otherData)
|
||||
} else {
|
||||
setValue({ ...value, count: defaultNum })
|
||||
onBlue?.(defaultNum, otherData)
|
||||
}
|
||||
}
|
||||
return (
|
||||
<View className={styles.main}>
|
||||
<View className={styles.reduce} onClick={() => minus()}>
|
||||
-
|
||||
</View>
|
||||
<View className={styles.input}>
|
||||
<Input value={String(value.count)} onInput={onInputEven} onBlur={onBluerEven} type='digit' alwaysEmbed={true} cursorSpacing={150} />
|
||||
<View className={styles.unit}>{unit}</View>
|
||||
</View>
|
||||
<View className={styles.plus} onClick={() => onPlus()}>
|
||||
+
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
@ -1,115 +1,156 @@
|
||||
import Popup, {Params as PopuParams} from "@/components/popup"
|
||||
import { Input, ScrollView, Text, Textarea, View } from "@tarojs/components"
|
||||
import classnames from "classnames";
|
||||
import { useEffect, useState } from "react";
|
||||
import styles from './index.module.scss'
|
||||
import Popup, { Params as PopuParams } from '@/components/popup'
|
||||
import { Input, ScrollView, Text, Textarea, View } from '@tarojs/components'
|
||||
import classnames from 'classnames'
|
||||
import { useEffect, useState } from 'react'
|
||||
import styles from './index.module.scss'
|
||||
|
||||
type params = {
|
||||
onFiltr?: (val:object) => void
|
||||
onFiltr?: (val: object) => void
|
||||
} & PopuParams
|
||||
export default ({onClose, onFiltr, show = false}:params) => {
|
||||
const [filterObj, setFilterObj] = useState({
|
||||
series: '',
|
||||
minWidth: '',
|
||||
maxWidth: '',
|
||||
minWeight: '',
|
||||
maxWeight: '',
|
||||
element: ''
|
||||
|
||||
export default ({ onClose, onFiltr, show = false }: params) => {
|
||||
const [filterObj, setFilterObj] = useState({
|
||||
series: '',
|
||||
minWidth: '',
|
||||
maxWidth: '',
|
||||
minWeight: '',
|
||||
maxWeight: '',
|
||||
element: '',
|
||||
})
|
||||
const onCloseEven = () => {
|
||||
onClose?.()
|
||||
}
|
||||
const onRest = () => {
|
||||
console.log('12123')
|
||||
setFilterObj({
|
||||
series: '',
|
||||
minWidth: '',
|
||||
maxWidth: '',
|
||||
minWeight: '',
|
||||
maxWeight: '',
|
||||
element: '',
|
||||
})
|
||||
const onCloseEven = () => {
|
||||
onClose?.()
|
||||
}
|
||||
const onRest = () => {
|
||||
console.log('12123')
|
||||
setFilterObj({
|
||||
series: '',
|
||||
minWidth: '',
|
||||
maxWidth: '',
|
||||
minWeight: '',
|
||||
maxWeight: '',
|
||||
element: ''
|
||||
})
|
||||
}
|
||||
useEffect(() => {
|
||||
console.log(filterObj)
|
||||
}, [filterObj])
|
||||
}
|
||||
useEffect(() => {
|
||||
console.log(filterObj)
|
||||
}, [filterObj])
|
||||
|
||||
const onVerify = () => {
|
||||
console.log(filterObj)
|
||||
onFiltr?.(filterObj)
|
||||
}
|
||||
const onVerify = () => {
|
||||
console.log(filterObj)
|
||||
onFiltr?.(filterObj)
|
||||
}
|
||||
|
||||
const setNumber = (e, field) => {
|
||||
console.log(e)
|
||||
let num = parseFloat(e.detail.value)
|
||||
if(isNaN(num)) {
|
||||
filterObj[field] = null
|
||||
} else {
|
||||
filterObj[field] = parseFloat(num.toFixed(2))
|
||||
}
|
||||
setFilterObj({...filterObj})
|
||||
const setNumber = (e, field) => {
|
||||
console.log(e)
|
||||
let num = parseFloat(e.detail.value)
|
||||
if (isNaN(num)) {
|
||||
filterObj[field] = null
|
||||
} else {
|
||||
filterObj[field] = parseFloat(num.toFixed(2))
|
||||
}
|
||||
setFilterObj({ ...filterObj })
|
||||
}
|
||||
|
||||
const setElement = (e) => {
|
||||
let res = e.detail.value
|
||||
setFilterObj({...filterObj, element:res})
|
||||
}
|
||||
return (
|
||||
|
||||
<Popup position="right" show={show} showTitle={false} onClose={() => onCloseEven()} showIconButton={true}>
|
||||
<View className={styles.popup_main}>
|
||||
<View className={styles.popup_title}>全部筛选</View>
|
||||
|
||||
<ScrollView scrollY className={styles.scroll}>
|
||||
<View className={styles.popup_filter}>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>系列</View>
|
||||
<View className={styles.btn_list}>
|
||||
<View className={classnames(styles.btn_item, styles.select_btn_item)}>不限</View>
|
||||
<View className={styles.btn_item}>不限</View>
|
||||
<View className={styles.btn_item}>不限</View>
|
||||
<View className={styles.btn_item}>不限</View>
|
||||
<View className={styles.btn_item}>不限</View>
|
||||
<View className={styles.btn_item}>不限</View>
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>幅宽</View>
|
||||
<View className={styles.btn_list_input}>
|
||||
<View className={styles.btn_width}><Input value={filterObj.minWidth} type="digit" onBlur={(e) => setNumber(e,'minWidth')} placeholder="自定义最低值" placeholderStyle="font-size: 26rpx"/></View>
|
||||
<Text>—</Text>
|
||||
<View className={styles.btn_width}><Input value={filterObj.maxWidth} type="digit" onBlur={(e) => setNumber(e,'maxWidth')} placeholder="自定义最高值" placeholderStyle="font-size: 26rpx"/></View>
|
||||
<View className={styles.unit}>cm</View>
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>克重</View>
|
||||
<View className={styles.btn_list_input}>
|
||||
<View className={styles.btn_width}><Input type="digit" value={filterObj.minWeight} onBlur={(e) => setNumber(e,'minWeight')} placeholder="自定义最低值" placeholderStyle="font-size: 26rpx"/></View>
|
||||
<Text>—</Text>
|
||||
<View className={styles.btn_width}><Input type="digit" value={filterObj.maxWeight} onBlur={(e) => setNumber(e,'maxWeight')} placeholder="自定义最高值" placeholderStyle="font-size: 26rpx"/></View>
|
||||
<View className={styles.unit}>g</View>
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>成分</View>
|
||||
<View className={styles.btn_list_element}>
|
||||
<Textarea placeholder="请输入" cursorSpacing={60} value={filterObj.element} onInput={(e) => setElement(e)}/>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View className="common_safe_area_y"></View>
|
||||
</View>
|
||||
</ScrollView>
|
||||
<View className={styles.btns_con}>
|
||||
<View className={styles.btns_two}>
|
||||
<View className={styles.rest_btn} onClick={() => onRest()}>重置</View>
|
||||
<View className={styles.verify_btn } onClick={() => onVerify()}>确认</View>
|
||||
</View>
|
||||
</View>
|
||||
const setElement = (e) => {
|
||||
let res = e.detail.value
|
||||
setFilterObj({ ...filterObj, element: res })
|
||||
}
|
||||
return (
|
||||
<Popup position='right' show={show} showTitle={false} onClose={() => onCloseEven()} showIconButton={true}>
|
||||
<View className={styles.popup_main}>
|
||||
<View className={styles.popup_title}>全部筛选</View>
|
||||
|
||||
<ScrollView scrollY className={styles.scroll}>
|
||||
<View className={styles.popup_filter}>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>系列</View>
|
||||
<View className={styles.btn_list}>
|
||||
<View className={classnames(styles.btn_item, styles.select_btn_item)}>不限</View>
|
||||
<View className={styles.btn_item}>不限</View>
|
||||
<View className={styles.btn_item}>不限</View>
|
||||
<View className={styles.btn_item}>不限</View>
|
||||
<View className={styles.btn_item}>不限</View>
|
||||
<View className={styles.btn_item}>不限</View>
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>幅宽</View>
|
||||
<View className={styles.btn_list_input}>
|
||||
<View className={styles.btn_width}>
|
||||
<Input
|
||||
alwaysEmbed={true}
|
||||
cursorSpacing={150}
|
||||
value={filterObj.minWidth}
|
||||
type='digit'
|
||||
onBlur={(e) => setNumber(e, 'minWidth')}
|
||||
placeholder='自定义最低值'
|
||||
placeholderStyle='font-size: 26rpx'
|
||||
/>
|
||||
</View>
|
||||
<Text>—</Text>
|
||||
<View className={styles.btn_width}>
|
||||
<Input
|
||||
alwaysEmbed={true}
|
||||
cursorSpacing={150}
|
||||
value={filterObj.maxWidth}
|
||||
type='digit'
|
||||
onBlur={(e) => setNumber(e, 'maxWidth')}
|
||||
placeholder='自定义最高值'
|
||||
placeholderStyle='font-size: 26rpx'
|
||||
/>
|
||||
</View>
|
||||
<View className={styles.unit}>cm</View>
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>克重</View>
|
||||
<View className={styles.btn_list_input}>
|
||||
<View className={styles.btn_width}>
|
||||
<Input
|
||||
alwaysEmbed={true}
|
||||
cursorSpacing={150}
|
||||
type='digit'
|
||||
value={filterObj.minWeight}
|
||||
onBlur={(e) => setNumber(e, 'minWeight')}
|
||||
placeholder='自定义最低值'
|
||||
placeholderStyle='font-size: 26rpx'
|
||||
/>
|
||||
</View>
|
||||
<Text>—</Text>
|
||||
<View className={styles.btn_width}>
|
||||
<Input
|
||||
alwaysEmbed={true}
|
||||
cursorSpacing={150}
|
||||
type='digit'
|
||||
value={filterObj.maxWeight}
|
||||
onBlur={(e) => setNumber(e, 'maxWeight')}
|
||||
placeholder='自定义最高值'
|
||||
placeholderStyle='font-size: 26rpx'
|
||||
/>
|
||||
</View>
|
||||
<View className={styles.unit}>g</View>
|
||||
</View>
|
||||
</View>
|
||||
<View className={styles.popup_filter_item}>
|
||||
<View className={styles.title}>成分</View>
|
||||
<View className={styles.btn_list_element}>
|
||||
<Textarea placeholder='请输入' cursorSpacing={60} value={filterObj.element} onInput={(e) => setElement(e)} />
|
||||
</View>
|
||||
</View>
|
||||
</Popup>
|
||||
|
||||
)
|
||||
}
|
||||
<View className='common_safe_area_y'></View>
|
||||
</View>
|
||||
</ScrollView>
|
||||
<View className={styles.btns_con}>
|
||||
<View className={styles.btns_two}>
|
||||
<View className={styles.rest_btn} onClick={() => onRest()}>
|
||||
重置
|
||||
</View>
|
||||
<View className={styles.verify_btn} onClick={() => onVerify()}>
|
||||
确认
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</Popup>
|
||||
)
|
||||
}
|
||||
|
@ -1,28 +1,27 @@
|
||||
import FromList from '@/components/FromList'
|
||||
import { Button, Input, Text, Textarea, View } from '@tarojs/components'
|
||||
import Taro, { setNavigationBarTitle, useRouter } from '@tarojs/taro'
|
||||
import { weightAddApi, weightDetailApi, weightEditApi } from '@/api/weightList'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { alert, retrieval } from '@/common/common'
|
||||
import './index.scss'
|
||||
import useLogin from '@/use/useLogin'
|
||||
|
||||
import FromList from "@/components/FromList"
|
||||
import { Button, Input, Text, Textarea, View } from "@tarojs/components"
|
||||
import Taro, { setNavigationBarTitle, useRouter } from "@tarojs/taro"
|
||||
import {weightAddApi, weightDetailApi,weightEditApi} from "@/api/weightList"
|
||||
import { useEffect, useState } from "react"
|
||||
import { alert, retrieval } from "@/common/common"
|
||||
import "./index.scss"
|
||||
import useLogin from "@/use/useLogin"
|
||||
|
||||
export default ()=>{
|
||||
export default () => {
|
||||
useLogin()
|
||||
const {type,id} = useRouter().params;
|
||||
useEffect(()=>{
|
||||
if(type=="add"){
|
||||
setNavigationBarTitle({title:"添加码单信息"})
|
||||
}else{
|
||||
initalFormData();
|
||||
setNavigationBarTitle({title:"修改码单信息"})
|
||||
const { type, id } = useRouter().params
|
||||
useEffect(() => {
|
||||
if (type == 'add') {
|
||||
setNavigationBarTitle({ title: '添加码单信息' })
|
||||
} else {
|
||||
initalFormData()
|
||||
setNavigationBarTitle({ title: '修改码单信息' })
|
||||
}
|
||||
},[]);
|
||||
}, [])
|
||||
// 获取编辑码单信息
|
||||
const {fetchData: getFromData} = weightDetailApi()
|
||||
const initalFormData = async ()=>{
|
||||
const detail = await getFromData({id});
|
||||
const { fetchData: getFromData } = weightDetailApi()
|
||||
const initalFormData = async () => {
|
||||
const detail = await getFromData({ id })
|
||||
setFormData({
|
||||
title: detail.data.title,
|
||||
purchaser_name: detail.data.purchaser_name,
|
||||
@ -33,74 +32,108 @@ export default ()=>{
|
||||
}
|
||||
// 保存
|
||||
const [formData, setFormData] = useState({
|
||||
title: "",
|
||||
purchaser_name: "",
|
||||
phone: "",
|
||||
title: '',
|
||||
purchaser_name: '',
|
||||
phone: '',
|
||||
is_default: false,
|
||||
id: 0
|
||||
id: 0,
|
||||
})
|
||||
const rules = {
|
||||
title: [{
|
||||
message: "请输入抬头"
|
||||
}],
|
||||
purchaser_name: [{
|
||||
message: "请输入客户名称"
|
||||
}],
|
||||
phone: [{
|
||||
message: "请输入正确的电话号码", regex: /^1[3|5|6|9|2|8|7]\d{9}$/
|
||||
}]
|
||||
title: [
|
||||
{
|
||||
message: '请输入抬头',
|
||||
},
|
||||
],
|
||||
purchaser_name: [
|
||||
{
|
||||
message: '请输入客户名称',
|
||||
},
|
||||
],
|
||||
phone: [
|
||||
{
|
||||
message: '请输入正确的电话号码',
|
||||
regex: /^1[3|5|6|9|2|8|7]\d{9}$/,
|
||||
},
|
||||
],
|
||||
}
|
||||
const {fetchData} = weightAddApi()
|
||||
const {fetchData: editFetch} = weightEditApi()
|
||||
const handleSave = ()=>{
|
||||
retrieval(formData, rules).then(async ()=>{
|
||||
const result = type=="add"?await fetchData({
|
||||
title: formData.title,
|
||||
purchaser_name: formData.purchaser_name,
|
||||
phone: formData.phone,
|
||||
is_default: formData.is_default,
|
||||
}):await editFetch({
|
||||
title: formData.title,
|
||||
purchaser_name: formData.purchaser_name,
|
||||
phone: formData.phone,
|
||||
is_default: formData.is_default,
|
||||
id: formData.id
|
||||
});
|
||||
if(result.success){
|
||||
Taro.eventCenter.trigger("weightList:refresh");
|
||||
Taro.navigateBack();
|
||||
alert.success("保存成功");
|
||||
}else{
|
||||
alert.error(result.msg);
|
||||
}
|
||||
}).catch((message)=>{
|
||||
alert.none(message)
|
||||
})
|
||||
const { fetchData } = weightAddApi()
|
||||
const { fetchData: editFetch } = weightEditApi()
|
||||
const handleSave = () => {
|
||||
retrieval(formData, rules)
|
||||
.then(async () => {
|
||||
const result =
|
||||
type == 'add'
|
||||
? await fetchData({
|
||||
title: formData.title,
|
||||
purchaser_name: formData.purchaser_name,
|
||||
phone: formData.phone,
|
||||
is_default: formData.is_default,
|
||||
})
|
||||
: await editFetch({
|
||||
title: formData.title,
|
||||
purchaser_name: formData.purchaser_name,
|
||||
phone: formData.phone,
|
||||
is_default: formData.is_default,
|
||||
id: formData.id,
|
||||
})
|
||||
if (result.success) {
|
||||
Taro.eventCenter.trigger('weightList:refresh')
|
||||
Taro.navigateBack()
|
||||
alert.success('保存成功')
|
||||
} else {
|
||||
alert.error(result.msg)
|
||||
}
|
||||
})
|
||||
.catch((message) => {
|
||||
alert.none(message)
|
||||
})
|
||||
}
|
||||
// 监听表单完善
|
||||
const [hozon, setHozon] = useState(false);
|
||||
useEffect(()=>{
|
||||
if(retrieval){
|
||||
retrieval(formData).then(()=>setHozon(true)).catch(()=>setHozon(false))
|
||||
const [hozon, setHozon] = useState(false)
|
||||
useEffect(() => {
|
||||
if (retrieval) {
|
||||
retrieval(formData)
|
||||
.then(() => setHozon(true))
|
||||
.catch(() => setHozon(false))
|
||||
}
|
||||
},[formData])
|
||||
}, [formData])
|
||||
|
||||
return (
|
||||
<View className="add-address">
|
||||
<FromList onInput={(ev:any)=>setFormData({...formData,title:ev.detail.value})} value={formData["title"]} label="抬头" placeholder="请输入码单显示抬头信息"/>
|
||||
<FromList onInput={(ev:any)=>setFormData({...formData,purchaser_name:ev.detail.value})} value={formData["purchaser_name"]} label="客户" placeholder="请输入码单显示客户名称"/>
|
||||
<FromList onInput={(ev:any)=>setFormData({...formData,phone:ev.detail.value})} value={formData["phone"]} label="联系方式" placeholder="请输入码单显示联系号码"/>
|
||||
<View className="add-address-default">
|
||||
<View className='add-address'>
|
||||
<FromList
|
||||
onInput={(ev: any) => setFormData({ ...formData, title: ev.detail.value })}
|
||||
value={formData['title']}
|
||||
label='抬头'
|
||||
placeholder='请输入码单显示抬头信息'
|
||||
/>
|
||||
<FromList
|
||||
onInput={(ev: any) => setFormData({ ...formData, purchaser_name: ev.detail.value })}
|
||||
value={formData['purchaser_name']}
|
||||
label='客户'
|
||||
placeholder='请输入码单显示客户名称'
|
||||
/>
|
||||
<FromList
|
||||
onInput={(ev: any) => setFormData({ ...formData, phone: ev.detail.value })}
|
||||
value={formData['phone']}
|
||||
label='联系方式'
|
||||
placeholder='请输入码单显示联系号码'
|
||||
/>
|
||||
<View className='add-address-default'>
|
||||
<Text>设为默认地址</Text>
|
||||
<View onClick={()=>setFormData({...formData ,is_default: !formData.is_default})}>
|
||||
{
|
||||
formData.is_default?<View className="add-address-default-active"><Text className="iconfont icon-tick"/></View>
|
||||
:<View className="add-address-default-noactive"></View>
|
||||
}
|
||||
<View onClick={() => setFormData({ ...formData, is_default: !formData.is_default })}>
|
||||
{formData.is_default ? (
|
||||
<View className='add-address-default-active'>
|
||||
<Text className='iconfont icon-tick' />
|
||||
</View>
|
||||
) : (
|
||||
<View className='add-address-default-noactive'></View>
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<Button style={{"background": hozon?'#007aff':''}} hoverClass="none" className="add-address-save" onClick={handleSave}>保存</Button>
|
||||
|
||||
<Button style={{ background: hozon ? '#007aff' : '' }} hoverClass='none' className='add-address-save' onClick={handleSave}>
|
||||
保存
|
||||
</Button>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user