🦄 refactor:搜索历史加入购物车100%

This commit is contained in:
Haiyi
2022-09-16 18:08:04 +08:00
parent 7ddb3bf784
commit 9342906c67
16 changed files with 1065 additions and 101 deletions
+24 -39
View File
@@ -58,52 +58,37 @@ const AddressList = memo((props: Params) => {
// 列表选择
const { fetchData: selectFetch } = mpsaleOrderaddress()
const handleSelect = async (item: any, index: number) => {
Taro.showLoading({
title: '请稍等...',
mask: true
})
const res = await selectFetch({ address_id: item.id, id: Number(router.params.orderId), shipment_mode: 2 })
if (res.msg === 'success') {
Taro.hideLoading()
Taro.showToast({
title: '成功',
icon: 'success'
})
Taro.navigateBack({
delta: 1
})
} else {
Taro.hideLoading()
Taro.showToast({
title: res.msg,
icon: 'error'
if (router.params.orderId) {
Taro.showLoading({
title: '请稍等...',
mask: true
})
const res = await selectFetch({ address_id: item.id, id: Number(router.params.orderId), shipment_mode: 2 })
if (res.msg === 'success') {
Taro.hideLoading()
Taro.showToast({
title: '成功',
icon: 'success'
})
Taro.navigateBack({
delta: 1
})
} else {
Taro.hideLoading()
Taro.showToast({
title: res.msg,
icon: 'error'
})
}
}
props.onSelect && props.onSelect(item, index);
if (focusBorderEnabled) {
setFocusId(item?.id);
}
}
// 删除地址
// const { fetchData: deleteFetch } = addressDeleteApi()
// const handleDelete = (item: any) => {
// showModal(({
// title: "提示",
// content: "是否删除地址?",
// async success(ev) {
// if (ev.confirm) {
// const result = await deleteFetch({ id: item.id });
// if (result.success) {
// alert.success("删除成功");
// getData();
// } else {
// alert.success(result.msg);
// }
// }
// }
// }))
// }
return (
<View className="address-scroll-view">
<ScrollView scrollY refresherEnabled={props.refresherEnabled} enhanced refresherTriggered={refreshState} onRefresherRefresh={handleRefresh}>
@@ -114,7 +99,7 @@ const AddressList = memo((props: Params) => {
// data.length>0?
// data.map((item,index)=>{
return (
<View onLongPress={() => handleDelete(item)} onClick={() => handleSelect(item, index)} className={`address-list ${focusId == item.id && 'address-active'}`}>
<View onClick={() => handleSelect(item, index)} className={`address-list ${focusId == item.id && 'address-active'}`}>
<View className="address-user">
{item.name}
{
+8 -5
View File
@@ -20,7 +20,10 @@ interface props {
name?: string,
roll?: number | string,
buyNums?: number | string,
}
id?: number
},
goodList?: any[],
onBlur?: (a: any, c: any) => void
}
@@ -28,7 +31,6 @@ export default memo((props: props) => {
const [value, setValue] = useState<any>({ count: props.value.nums })
const onInputEven = (e) => {
let res = e.detail.value
if (props.modeFont !== 2) {
if (Number(res) == 0 || Number(res) < 1) {
@@ -59,7 +61,7 @@ export default memo((props: props) => {
}
<View className={styles.rightGoodbox}>
<View className={styles.leftFontsbox}>
<View className={styles.title}>{props.value?.code} {props.value?.name}环保黑</View>
<View className={styles.title}>{props.value?.code} {props.value?.name}</View>
{/* <View className={styles.productName}>0681# 26S全棉平纹</View> */}
<View className={styles.productNums}>剩:{props.value?.roll}件</View>
</View>
@@ -72,7 +74,7 @@ export default memo((props: props) => {
</View>
</View>
<View className={styles.numsBox}>
<Input type={type as any} value={value.count} onInput={onInputEven}></Input>
<Input type={type as any} value={value.count} onInput={onInputEven} onBlur={(e) => props.onBlur?.(e, props.value.id)}></Input>
{/* <Input type={type as any} value={value.count} onInput={($event) => onInputEven($event, props.value)}></Input> */}
</View>
@@ -88,4 +90,5 @@ export default memo((props: props) => {
</View>
</View>
)
})
})
// ($event) => onInputEven($event, props.value)
@@ -138,4 +138,11 @@
z-index: 999;
bottom: calc($customTabBarHeight + env(safe-area-inset-bottom));
}
.noBottom {
width: 100%;
position: fixed;
z-index: 999;
bottom: env(safe-area-inset-bottom);
}
}
+35 -16
View File
@@ -8,7 +8,6 @@ import Goods from "@/components/goodsItem"
import BottomCustomer from "@/components/BottomCustomer"
import VirtualList from '@tarojs/components/virtual-list'
import DotLoading from "@/components/dotLoading"
interface prosObj {
showPopup?: false | true,
closePopup?: () => void,
@@ -17,7 +16,7 @@ interface prosObj {
handCheck?: (any) => void,
addNums?: (any) => void
reduceNums?: (any) => void
oninputEvent?: (e: string, res: object) => void,
// oninputEvent?: (e: string, res: object) => void,
getSearchData: (any) => void,
handPlus: (any) => void,
handSure: () => void,
@@ -28,7 +27,9 @@ interface prosObj {
},
modeFont: Number | string,
clientName: string,
clientId: Number
clientId: Number,
hasBottom?: true | false, //默认不占位底部
onBlur?: (e: string, res: object) => void
}
export default memo(forwardRef((props: prosObj, ref) => {
const {
@@ -39,14 +40,16 @@ export default memo(forwardRef((props: prosObj, ref) => {
handCheck,
addNums,
reduceNums,
oninputEvent,
// oninputEvent,
getSearchData,
handPlus,
obj = {},
modeFont = 0,
clientName = '',
clientId = -1,
handSure
handSure,
hasBottom = true,
onBlur
} = props
useImperativeHandle(ref, () => ({
@@ -78,26 +81,39 @@ export default memo(forwardRef((props: prosObj, ref) => {
//选择的条数或者米数
const selectNums = useMemo(() => {
var s = 0;
goodList.forEach(function (val, idx, arr) {
if (val.showInput) {
s += val.nums;
let arr: any = []
goodList.forEach(item => {
if (item.showInput) {
arr.push(Number(item.nums))
}
}, 0);
return s;
})
let hate = sum(arr)
return hate
}, [goodList])
// onInputEven={(e, obj) => oninputEvent?.(e, obj)}
// onInputEven={(e, item) => oninputEvent?.(e, item)}
function sum(arr) {
var s = 0;
for (var i = arr.length - 1; i >= 0; i--) {
s += arr[i];
}
return s;
}
const rows = memo(({ id, index, style, data }: any) => {
let item = data[index]
return (
<>
<Goods modeFont={(modeFont as number)}
<Goods
onBlur={(e, id) => onBlur?.(e, id)}
modeFont={(modeFont as number)}
handPlus={(item) => handPlus?.(item)}
value={item || {}}
clickAdd={(item) => addNums?.(item)}
clickReduce={(item) => { reduceNums?.(item) }}></Goods>
clickReduce={(item) => { reduceNums?.(item) }}
goodList={goodList}
></Goods>
</>
)
})
@@ -151,7 +167,10 @@ export default memo(forwardRef((props: prosObj, ref) => {
<View className={styles.loading_more}>加载中<DotLoading /></View>
</>
}
<View className={styles.posBox}>
{
!hasBottom && <View style={{ height: '100rpx' }}></View>
}
<View className={classnames(hasBottom === true ? styles.posBox : styles.noBottom)}>
<BottomCustomer clientName={clientName} clientId={clientId} isDisabled={selectTotal > 0 && clientName !== '' ? false : true} handSure={() => { handSure() }}></BottomCustomer>
</View>
</View>