大货码单对接完成

This commit is contained in:
czm 2022-12-28 19:52:55 +08:00
parent 6048dd888c
commit 7f101dabd3
25 changed files with 789 additions and 285 deletions

View File

@ -14,6 +14,7 @@
"import/no-commonjs": "off",
"react/display-name": "off",
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": "warn"
"@typescript-eslint/no-use-before-define": "warn",
"array-callback-return": 0
}
}

View File

@ -0,0 +1,135 @@
import React, { useContext, useReducer } from 'react'
import { CustomPrintCalculationApi } from '@/api/codeManage'
interface params {
productData?: any
dispatch?: any
}
interface PropsType {
children: React.ReactNode
}
type ACTIONTYPE =
| { type: 'setInitData'; data: any }
| { type: 'updateData'; data: any }
| { type: 'changeAdjustType'; data: number }
| { type: 'changeSaveStatus'; data: boolean }
function createCtx<A extends {} | null>() {
const ctx = React.createContext<A | undefined>(undefined)
function useCtx() {
const c = useContext(ctx)
if (c === undefined) { throw new Error('useCtx must be inside a Provider with a value') }
return c
}
return [useCtx, ctx.Provider] as const
}
export const [useCurrenCode, CurrentUserProvider] = createCtx<params>()
export default (props: PropsType) => {
const initialState = {
data: null, // 码单数据
adjust_type: 1, // 码单调整类型
custom_print_id: 0, // 自定义码单id
sale_order_id: 0, // 销售码单id
admin_data: null, // 需要传给后端的数据
save_status: false, // 是否保存了数据
}
function reducer(state: typeof initialState, action: ACTIONTYPE) {
switch (action.type) {
case 'setInitData':
return onInitData(state, action)
case 'updateData':
return onUpdateData(state, action)
case 'changeAdjustType':
return { ...state, adjust_type: action.data }
case 'changeSaveStatus':
return { ...state, save_status: action.data }
default:
throw new Error('reducer没找到对应的type')
}
}
// 初始化数据
const onInitData = (state, action) => {
const { data, custom_print_id, sale_order_id } = action
const custom_order_total = {
total_weight_error: data?.total_weight_error,
total_sale_weight: data?.total_sale_weight,
total_amount: data?.total_amount,
}
data.weight_admin = 0
data.price_admin = 0
data.weight_error_admin = 0
data?.product_details?.map((item, index) => {
item.weight_admin = 0
item.price_admin = 0
item.weight_error_admin = 0
item.index_str = index.toString()
return item?.product_color_details?.map((citem, cindex) => {
citem.index_str = `${item.index_str}_${cindex}` // 通过这个可以快速定位数组位置
citem.weight_setting = citem.weight
citem.weight_error_setting = citem.weight_error
citem.price_setting = citem.price
citem.weight_admin = 0
citem.price_admin = 0
citem.weight_error_admin = 0
return citem
})
})
return {
...state,
data,
custom_print_id,
sale_order_id,
custom_order_total,
admin_data: null,
init_state: true,
}
}
// 后端所需数据
const onUpdateData = (state, action) => {
const { data } = action
const updateData = {
adjust_type: parseInt(state.adjust_type),
purchaser_form_title_id: 0,
custom_print_product: [],
price: 0,
weight: 0,
weight_error: 0,
custom_print_id: parseInt(state.custom_print_id!),
sale_order_id: parseInt(state.sale_order_id!),
}
updateData.weight = data?.weight_admin || 0
updateData.price = data?.price_admin || 0
updateData.weight_error = data?.weight_error_admin || 0
data?.product_details?.map((item) => {
const product_item = {
price: item.price_admin || 0,
weight: item.weight_admin || 0,
weight_error: item.weight_error_admin || 0,
product_id: item.product_id,
product_name: item.product_name,
custom_print_product_color: [],
}
item?.product_color_details?.map((citem) => {
product_item.custom_print_product_color.push({
price: citem.price_admin || 0,
weight: citem.weight_admin || 0,
weight_error: citem.weight_error_admin || 0,
product_color_id: citem.product_color_id,
product_color_name: citem.product_color_name,
})
})
updateData.custom_print_product.push(product_item)
})
return { ...state, admin_data: updateData, data: { ...data } }
}
const [productData, dispatch] = useReducer(reducer, initialState)
return (
<CurrentUserProvider value={{ productData, dispatch }} children={props.children}></CurrentUserProvider>
)
}

View File

@ -1,20 +1,17 @@
import React, { useContext, useReducer } from 'react'
import { useDispatch } from 'react-redux'
import { CustomPrintCalculationApi } from '@/api/codeManage'
import type { CodeParam } from '@/reducers/codeData'
import { useSelector } from '@/reducers/hooks'
interface params {
productData?: any
dispatch?: any
productData: CodeParam
dispatch: any
}
interface PropsType {
children: React.ReactNode
}
type ACTIONTYPE =
| { type: 'setInitData'; data: any }
| { type: 'updateData'; data: any }
| { type: 'changeAdjustType'; data: number }
| { type: 'changeSaveStatus'; data: boolean }
function createCtx<A extends {} | null>() {
const ctx = React.createContext<A | undefined>(undefined)
function useCtx() {
@ -27,108 +24,8 @@ function createCtx<A extends {} | null>() {
export const [useCurrenCode, CurrentUserProvider] = createCtx<params>()
export default (props: PropsType) => {
const initialState = {
data: null, // 码单数据
adjust_type: 1, // 码单调整类型
custom_print_id: 0, // 自定义码单id
sale_order_id: 0, // 销售码单id
admin_data: null, // 需要传给后端的数据
save_status: false, // 是否保存了数据
}
function reducer(state: typeof initialState, action: ACTIONTYPE) {
switch (action.type) {
case 'setInitData':
return onInitData(state, action)
case 'updateData':
return onUpdateData(state, action)
case 'changeAdjustType':
return { ...state, adjust_type: action.data }
case 'changeSaveStatus':
return { ...state, save_status: action.data }
default:
throw new Error('reducer没找到对应的type')
}
}
// 初始化数据
const onInitData = (state, action) => {
const { data, custom_print_id, sale_order_id } = action
const custom_order_total = {
total_weight_error: data?.total_weight_error,
total_sale_weight: data?.total_sale_weight,
total_amount: data?.total_amount,
}
data.weight_admin = 0
data.price_admin = 0
data.weight_error_admin = 0
data?.product_details?.map((item, index) => {
item.weight_admin = 0
item.price_admin = 0
item.weight_error_admin = 0
item.index_str = index.toString()
return item?.product_color_details?.map((citem, cindex) => {
citem.index_str = `${item.index_str}_${cindex}` // 通过这个可以快速定位数组位置
citem.weight_setting = citem.weight
citem.weight_error_setting = citem.weight_error
citem.price_setting = citem.price
citem.weight_admin = 0
citem.price_admin = 0
citem.weight_error_admin = 0
return citem
})
})
return {
...state,
data,
custom_print_id,
sale_order_id,
custom_order_total,
admin_data: null,
init_state: true,
}
}
// 后端所需数据
const onUpdateData = (state, action) => {
const { data } = action
const updateData = {
adjust_type: parseInt(state.adjust_type),
purchaser_form_title_id: 0,
custom_print_product: [],
price: 0,
weight: 0,
weight_error: 0,
custom_print_id: parseInt(state.custom_print_id!),
sale_order_id: parseInt(state.sale_order_id!),
}
updateData.weight = data?.weight_admin || 0
updateData.price = data?.price_admin || 0
updateData.weight_error = data?.weight_error_admin || 0
data?.product_details?.map((item) => {
const product_item = {
price: item.price_admin || 0,
weight: item.weight_admin || 0,
weight_error: item.weight_error_admin || 0,
product_id: item.product_id,
product_name: item.product_name,
custom_print_product_color: [],
}
item?.product_color_details?.map((citem) => {
product_item.custom_print_product_color.push({
price: citem.price_admin || 0,
weight: citem.weight_admin || 0,
weight_error: citem.weight_error_admin || 0,
product_color_id: citem.product_color_id,
product_color_name: citem.product_color_name,
})
})
updateData.custom_print_product.push(product_item)
})
return { ...state, admin_data: updateData, data: { ...data } }
}
const [productData, dispatch] = useReducer(reducer, initialState)
const productData = useSelector(state => state.codeData)
const dispatch = useDispatch()
return (
<CurrentUserProvider value={{ productData, dispatch }} children={props.children}></CurrentUserProvider>
)

View File

@ -0,0 +1,38 @@
.main {
padding: 24px;
background-color: #f7f7f7ff;
padding-bottom: 200px;
min-height: 100vh;
box-sizing: border-box;
.bottom_btn {
display: flex;
justify-content: space-between;
padding: 16px 48px;
position: fixed;
width: 100%;
bottom: 0;
left: 0;
box-sizing: border-box;
background-color: #fff;
height: 160px;
z-index: 999;
box-shadow: 6px 0px 12px 0px rgba(0, 0, 0, 0.16);
text {
display: block;
width: 311px;
height: 80px;
border-radius: 44px;
text-align: center;
line-height: 80px;
&:nth-child(2) {
background: #337fff;
color: #fff;
}
&:nth-child(1) {
border: 1px solid #087eff;
color: #337fffff;
box-sizing: border-box;
}
}
}
}

View File

@ -0,0 +1,34 @@
import { Text, View } from '@tarojs/components'
import Taro, { getCurrentPages, useDidHide } from '@tarojs/taro'
import { useEffect } from 'react'
import ColorItemSetting from '../../../components/colorItemSetting'
import styles from './index.module.scss'
import { useCurrenCode } from '@/context/ContextCodeSetting'
export default () => {
const { dispatch, productData } = useCurrenCode()
const cancel = () => {
Taro.navigateBack()
}
const submit = () => {
const index = productData.color_item_data.index_str.split(',')[0]
productData.data.product_details[index] = productData.color_item_data
dispatch({ type: 'updateData', data: { ...productData.data } })
Taro.navigateBack()
}
useEffect(() => {
return () => {
dispatch({ type: 'updateColorData', data: null })
}
}, [])
return <View className={styles.main}>
<ColorItemSetting />
<View >
<View className={styles.bottom_btn}>
<Text onClick={cancel}></Text>
<Text onClick={submit}></Text>
</View>
<View className="common_safe_area_y"></View>
</View>
</View>
}

View File

@ -1,35 +0,0 @@
.main {
padding: 24px;
background-color: #f7f7f7ff;
padding-bottom: 200px;
.bottom_btn {
display: flex;
justify-content: space-between;
padding: 16px 48px;
position: fixed;
width: 100%;
bottom: 0;
left: 0;
box-sizing: border-box;
background-color: #fff;
height: 160px;
z-index: 999;
text {
display: block;
width: 311px;
height: 80px;
border-radius: 44px;
text-align: center;
line-height: 80px;
&:nth-child(2) {
background: #337fff;
color: #fff;
}
&:nth-child(1) {
border: 1px solid #087eff;
color: #337fffff;
box-sizing: border-box;
}
}
}
}

View File

@ -1,17 +1,11 @@
import { CoverView, Text, View } from '@tarojs/components'
import ColorItemSetting from '../components/colorItemSetting'
import Main from './components/main'
import styles from './index.module.scss'
import ContextCodeSetting from '@/context/ContextCodeSetting'
export default () => {
return <View className={styles.main}>
<ColorItemSetting />
<View >
<View className={styles.bottom_btn}>
<Text></Text>
<Text></Text>
</View>
<View className="common_safe_area_y"></View>
</View>
</View>
return <ContextCodeSetting>
<Main />
</ContextCodeSetting>
}

View File

@ -8,6 +8,7 @@
justify-content: flex-end;
padding: 24px 32px;
box-sizing: border-box;
box-shadow: 6px 0px 12px 0px rgba(0, 0, 0, 0.16);
.bottom_btn_item {
width: 160px;
height: 72px;

View File

@ -0,0 +1,6 @@
.product_list__item--con {
background-color: #fff;
padding: 24px 32px 18px 32px;
box-sizing: border-box;
margin-bottom: 8px;
}

View File

@ -0,0 +1,79 @@
import { View } from '@tarojs/components'
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react'
import Big from 'big.js'
import ProductItem from '../../productItem'
import type { NumberParam } from '../../settingNumber'
import SettingNumber from '../../settingNumber'
import styles from './index.module.scss'
import { useCurrenCode } from '@/context/ContextCodeSetting'
interface Param {
colorInfo: any
}
type IndexParam = {
onChangeNumber: NumberParam
} & Param
export default memo((props: Param) => {
const { dispatch, productData } = useCurrenCode()
const { colorInfo } = props
const index = colorInfo.index_str.split('_')
const changeNumber: NumberParam = useCallback((num, type) => {
// 更新整体数据
const updateData = {
price: colorInfo?.price_admin,
weight: colorInfo?.weight_admin,
weight_error: colorInfo?.weight_error_admin,
}
if (type === 'weight') {
updateData.weight = num * 1000
}
else if (type === 'sale_price') {
updateData.price = num * 100
}
else {
updateData.weight_error = num * 1000
}
if (colorInfo.sale_mode === 0) {
colorInfo.weight_setting = Big(updateData.weight).times(colorInfo.roll).add(colorInfo.weight).toNumber()
colorInfo.weight_error_setting = Big(updateData.weight_error).times(colorInfo.roll).add(colorInfo.weight_error).toNumber()
}
else {
colorInfo.weight_setting = Big(updateData.weight).add(colorInfo.weight).toNumber()
colorInfo.weight_error_setting = Big(updateData.weight_error).add(colorInfo.weight_error).toNumber()
}
colorInfo.price_setting = Big(updateData.price).add(colorInfo.price).toNumber()
colorInfo.weight_admin = updateData.weight
colorInfo.price_admin = updateData.price
colorInfo.weight_error_admin = updateData.weight_error
productData.color_item_data.product_color_details[index[1]] = { ...colorInfo }
dispatch({ type: 'updateColorData', data: { ...productData.color_item_data }, update_status: 1 })
}, [productData.color_item_data])
return <Index colorInfo={productData.color_item_data.product_color_details[index[1]]} onChangeNumber={changeNumber} />
})
const Index = memo((props: IndexParam) => {
const { colorInfo } = props
const getNumber: NumberParam = (num, type) => {
props.onChangeNumber?.(num, type)
}
useEffect(() => {
console.log('colorInfo777:::', colorInfo)
}, [colorInfo])
const defaultNum = useMemo(() => {
return {
weight: Big(colorInfo.weight_admin || 0).div(Big(1000)).toNumber(),
sale_price: Big(colorInfo.price_admin || 0).div(Big(100)).toNumber(),
weight_error: Big(colorInfo.weight_error_admin || 0).div(Big(1000)).toNumber(),
}
}, [colorInfo])
return <View className={styles['product_list__item--con']}>
<ProductItem codeItem={colorInfo} />
<SettingNumber sale_mode={colorInfo.sale_mode} onNumber={getNumber} defaultValue={defaultNum} />
</View>
})

View File

@ -1,24 +1,57 @@
import { Text, View } from '@tarojs/components'
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react'
import Big from 'big.js'
import type { NumberParam } from '../settingNumber'
import SettingNumber from '../settingNumber'
import ProductItem from '../productItem'
import styles from './index.module.scss'
import ColorBlock from './colorBlock'
import IconFont from '@/components/iconfont/iconfont'
import LabAndImg from '@/components/LabAndImg'
import { useCurrenCode } from '@/context/ContextCodeSetting'
import PopupModal from '@/components/popupModal'
export default () => {
interface IndexParam {
productInfo: any
onChangeName: (val: string) => void
}
export default memo(() => {
const { dispatch, productData } = useCurrenCode()
const getNewName = useCallback((name) => {
productData.color_item_data = {
...productData.color_item_data,
product_name: name,
}
dispatch({ type: 'updateColorData', data: { ...productData.color_item_data }, update_status: 2 })
}, [productData.color_item_data])
return <>
<Index productInfo={productData.color_item_data} onChangeName={getNewName} />
</>
})
const Index = memo((props: IndexParam) => {
const { productInfo } = props
const [showEdit, setShowEdit] = useState(false)
const [title, setTitle] = useState('')
const onUpdate = () => {
setTitle(productInfo.product_name)
setShowEdit(true)
}
const onConfirm = (item) => {
props.onChangeName?.(item)
}
return <>
<View className={styles.product_list}>
<View className={styles.product_list__item}>
<View className={styles['product_list__item--title']}>
<Text className={styles.product_title}>5215# 26S双纱亲水滑爽棉</Text>
<View className={styles['product_list__item--title']} onClick={onUpdate}>
<Text className={styles.product_title}>{productInfo.product_name}</Text>
<IconFont name="icon-shuru" size={50} />
<Text className={styles.mode_status}></Text>
<Text className={styles.mode_status}>{productInfo.sale_mode_name}</Text>
</View>
{new Array(5).fill('').map((item, index) => <View key={index} className={styles['product_list__item--con']}>
<ProductItem codeItem={{}} />
{/* <SettingNumber /> */}
</View>)}
{productInfo?.product_color_details?.map(item => <ColorBlock key={item.product_color_id} colorInfo={item} ></ColorBlock>)}
</View>
</View>
<PopupModal show={showEdit} title="修改面料名称" defaultValue={title} onClose={() => setShowEdit(false)} onConfirm={onConfirm} />
</>
}
})

View File

@ -5,4 +5,39 @@
margin-top: 24px;
padding: 0 32px 32px 32px;
box-sizing: border-box;
.product_list__item {
.product_list__item--title {
height: 82px;
font-size: 28px;
display: flex;
justify-content: space-between;
color: #000000;
align-items: center;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
.product_title {
margin-right: 8px;
}
.mode_status {
width: 60px;
height: 30px;
font-size: 20px;
background: #337fff;
border-radius: 8px;
text-align: center;
line-height: 30px;
color: #fff;
margin-left: 8px;
}
.con {
display: flex;
align-items: center;
}
.update {
display: flex;
align-items: center;
color: #337fffff;
font-size: 28px;
}
}
}
}

View File

@ -1,4 +1,5 @@
import { Text, View } from '@tarojs/components'
import Taro from '@tarojs/taro'
import { memo, useCallback, useContext, useState } from 'react'
import classNames from 'classnames'
import ProductItem from '../../productItem'
@ -15,30 +16,36 @@ interface Parma {
type IndexParam = {
onChange: (val: string) => void
onSetColorData: () => void
} & Parma
export default memo((props: Parma) => {
const { productInfo } = props
const { dispatch, productData } = useCurrenCode()
const index = productInfo.index_str.split('_')[0]
const getNewName = useCallback((name) => {
const index = productInfo.index_str.split('_')[0]
productData.data.product_details[index] = {
...productData.data.product_details[index],
product_name: name,
}
dispatch({ type: 'updateData', data: { ...productData.data } })
}, [productInfo])
const toSetColorData = useCallback(() => {
dispatch({ type: 'setColorData', data: productInfo })
goLink('/pages/codeSetting/codeColorList/index')
}, [productInfo])
return <>
<Index {...props} onChange={getNewName} />
<Index {...props} onChange={getNewName} onSetColorData={toSetColorData} />
</>
})
const Index = memo((props: IndexParam) => {
const { productInfo, sale_mode_name } = props
const { productInfo, sale_mode_name, onSetColorData } = props
const [showEdit, setShowEdit] = useState(false)
const [upStatus, setStatus] = useState(false)
const [title, setTitle] = useState('')
console.log('productInfo内容', productInfo)
console.log('productInfo内容33', productInfo)
const onUpdate = () => {
setTitle(productInfo.product_name)
setShowEdit(true)
@ -54,7 +61,7 @@ const Index = memo((props: IndexParam) => {
<IconFont name="icon-shuru" size={50} />
<Text className={styles.mode_status}>{sale_mode_name}</Text>
</View>
<View className={styles.update} onClick={() => goLink('/pages/codeSetting/codeColorList/index')}>
<View className={styles.update} onClick={onSetColorData}>
<Text></Text>
<IconFont name="icon-rukou" size={35} />
</View>
@ -62,7 +69,7 @@ const Index = memo((props: IndexParam) => {
<View style={{ height: upStatus ? '0rpx' : `${194 * productInfo?.product_color_details?.length}rpx` }} className={classNames(styles['product_list__item--con'])}>
{productInfo?.product_color_details?.map(citem => <View key={citem?.product_color_id}><ProductItem codeItem={citem} /></View>)}
</View>
<View className={styles.up_btn} onClick={() => setStatus(!upStatus)}>{upStatus ? '展开' : '收起'}<View className={classNames(styles.up_icon, upStatus ? styles.open_up_icon : styles.close_up_icon)}><IconFont name="icon-shangla" size={35} /></View></View>
<View className={styles.up_btn} onClick={() => setStatus(!upStatus)}>{upStatus ? '查看更多' : '收起'}<View className={classNames(styles.up_icon, upStatus ? styles.open_up_icon : styles.close_up_icon)}><IconFont name="icon-shangla" size={35} /></View></View>
</View>
<PopupModal show={showEdit} title="修改面料名称" defaultValue={title} onClose={() => setShowEdit(false)} onConfirm={onConfirm} />
</>

View File

@ -1,5 +1,5 @@
import { Text, View } from '@tarojs/components'
import { useRouter } from '@tarojs/taro'
import { useDidShow, useRouter } from '@tarojs/taro'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import PayeeHead from '../payeeHead'
import type { CompanyItem } from '../payeeHead'
@ -18,37 +18,40 @@ import { alert } from '@/common/common'
export default () => {
const { productData, dispatch } = useCurrenCode()
const { custom_print_id, sale_order_id } = useRouter().params
const submit_ids = useRef({
custom_print_id,
sale_order_id,
})
const selectList = [
{ value: 1, label: '按整单' },
{ value: 2, label: '按面料' },
{ value: 3, label: '按颜色' },
]
const [modeIndex, setModeIndex] = useState(1)
const modelIndex = useRef(1)
const getTypeSelect = useCallback((index) => {
setModeIndex(index)
dispatch({ type: 'changeAdjustType', data: index })
modelIndex.current = index
// dispatch({ type: 'changeAdjustType', data: index })
getDataInit()
}, [])
const companyId = useRef<number>(0)
const [codeData, setCodeData] = useState<any>(null)
// 获取新增码单详情
const { fetchData: getCustomCodeInit } = GetCustomCodeInitApi()
const onCustomCodeInit = async() => {
const res = await getCustomCodeInit({ id: sale_order_id })
const res = await getCustomCodeInit({ id: submit_ids.current.sale_order_id })
setCodeData(() => res?.data)
}
// 获取码单编辑详情
const { fetchData: getCustomCodeDetail } = GetCustomCodeDetailApi()
const onGetCustomCodeDetail = async() => {
const res = await getCustomCodeDetail({ id: custom_print_id })
const res = await getCustomCodeDetail({ id: submit_ids.current.custom_print_id })
setCodeData(() => res?.data)
}
const getDataInit = async() => {
if (custom_print_id) {
if (submit_ids.current.custom_print_id) {
await onGetCustomCodeDetail()
}
else {
@ -63,12 +66,12 @@ export default () => {
useEffect(() => {
if (codeData) {
companyId.current = codeData?.default_title_id
codeData && dispatch({
type: 'setInitData',
data: codeData,
sale_order_id: sale_order_id || 0,
custom_print_id: custom_print_id || 0,
sale_order_id: submit_ids.current.sale_order_id || 0,
custom_print_id: submit_ids.current.custom_print_id || 0,
adjust_type: modelIndex.current,
})
setCustomTotal(() => ({
total_weight_error: codeData.total_weight_error,
@ -80,12 +83,10 @@ export default () => {
// 默认抬头
const company = useMemo(() => {
console.log('productData默认抬头:::', productData)
return {
title: productData?.data?.title_name,
purchaser_name: productData?.data?.purchaser_name,
phone: productData?.data?.purchaser_phone,
is_default: true,
title: productData?.purchaser_form_title?.title,
purchaser_name: productData?.purchaser_form_title?.purchaser_name,
phone: productData?.purchaser_form_title?.phone,
}
}, [productData])
@ -95,24 +96,25 @@ export default () => {
// 获取码单抬头
const getCompany = useCallback((val: CompanyItem) => {
companyId.current = val?.id || 0
dispatch({ type: 'setPurchaserFormTitle', data: val })
}, [])
// 按钮事件
const onBottomClick = useCallback((type: BottomItem) => {
const onBottomClick = (type: BottomItem) => {
(async() => {
if (type === 'save') {
const res = custom_print_id
? await updateCustomCodeApi({ ...productData.admin_data })
: await createCustomCodeApi({ ...productData.admin_data })
? await updateCustomCodeApi({ ...productData?.admin_data })
: await createCustomCodeApi({ ...productData?.admin_data })
if (res.success) {
submit_ids.current.custom_print_id = res.data.id
getDataInit()
dispatch({ type: 'changeSaveStatus', data: true })
alert.success('保存成功!')
}
}
})()
}, [productData])
}
// 自定义码单合计数据
const [customTotal, setCustomTotal] = useState({
@ -120,11 +122,13 @@ export default () => {
total_sale_weight: 0,
total_amount: 0,
})
useEffect(() => {
if (productData.admin_data) {
console.log('productData合计数据:::', productData)
if (productData?.admin_data && productData?.update_status === 1) {
updateCustomOrderTotal(productData.admin_data)
}
}, [productData.admin_data])
}, [productData?.admin_data])
// 更新合计数据
const { fetchData: customPrintCalculationApi } = CustomPrintCalculationApi()
@ -146,20 +150,20 @@ export default () => {
<SelectList onSelect={getTypeSelect} list={selectList} defaultIndex={1} />
<View className={styles.code_list_con}>
<View>
{modeIndex == 1 && <WholeOrderSetting orderData={productData?.data} />}
{productData?.adjust_type == 1 && <WholeOrderSetting orderData={productData?.data} />}
</View>
<View>
{modeIndex == 2 && <ProductSetting orderData={productData?.data} />}
{productData?.adjust_type == 2 && <ProductSetting orderData={productData?.data} />}
</View>
<View>
{modeIndex == 3 && <ColorSetting orderData={productData?.data} />}
{productData?.adjust_type == 3 && <ColorSetting orderData={productData?.data} />}
</View>
<View className={styles.code_des}>
<View className={styles.code_des_title}></View>
<View className={styles.code_des_item}>
{codeData?.sale_mode === 0 && <View className={styles.code_des_item}>
<Text></Text>
<Text>{formatWeightDiv(customTotal.total_weight_error)}kg</Text>
</View>
</View>}
<View className={styles.code_des_item}>
<Text></Text>
<Text className={styles.code_des_weight}>{formatWeightDiv(customTotal.total_sale_weight)}kg</Text>
@ -171,10 +175,10 @@ export default () => {
</View>
<View className={styles.code_des}>
<View className={styles.code_des_title}></View>
<View className={styles.code_des_item}>
{codeData?.sale_mode === 0 && <View className={styles.code_des_item}>
<Text></Text>
<Text>{formatWeightDiv(productData?.data?.original_total_weight_error)}kg</Text>
</View>
</View>}
<View className={styles.code_des_item}>
<Text></Text>
<Text className={styles.code_des_weight}>{formatWeightDiv(productData?.data?.original_total_sale_weight)}kg</Text>

View File

@ -34,7 +34,7 @@ export default (props: CompanyParam) => {
<View className={styles.payee_head__desc}>
<View className={styles.payee_head__desc__company}>
<Text>{data?.title}</Text>
{data?.is_default && <Text></Text>}
{/* {data?.is_default && <Text>默认抬头</Text>} */}
</View>
<View className={styles.payee_head__desc__name}>
<Text>{data?.purchaser_name}</Text>

View File

@ -2,9 +2,7 @@
display: flex;
padding: 24px 0;
box-sizing: border-box;
&:nth-last-child(n + 2) {
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
height: 194px;
.item_image {
width: 90px;
height: 90px;
@ -41,3 +39,9 @@
}
}
}
.product_list__item__bottom {
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
.product_list_item_height {
height: 150px !important;
}

View File

@ -1,11 +1,13 @@
import { Text, View } from '@tarojs/components'
import { memo, useCallback, useEffect, useMemo, useState } from 'react'
import classNames from 'classnames'
import styles from './index.module.scss'
import LabAndImg from '@/components/LabAndImg'
import IconFont from '@/components/iconfont/iconfont'
import { formatPriceDiv, formatWeightDiv } from '@/common/fotmat'
import PopupModal from '@/components/popupModal'
import { useCurrenCode } from '@/context/ContextCodeSetting'
import type { adjustType } from '@/common/enum'
interface Param {
codeItem: any
@ -13,34 +15,44 @@ interface Param {
type IndexParam = {
onChange: (val: string) => void
adjust_type: adjustType
settingColorStatus: boolean
} & Param
export default (props: Param) => {
const { codeItem } = props
const { dispatch, productData } = useCurrenCode()
const index = codeItem.index_str.split('_')
const productInfo = productData.data.product_details[index[0]]
const codeInfo = productInfo.product_color_details[index[1]]
const getNewName = useCallback((name) => {
productData.data.product_details[index[0]].product_color_details[index[1]] = { ...codeInfo, product_color_name: name }
productData.data.product_details[index[0]] = { ...productData.data.product_details[index[0]] }
dispatch({ type: 'updateData', data: { ...productData.data } })
if (!productData.color_item_data) {
const productInfo = productData.data.product_details[index[0]]
const codeInfo = productInfo.product_color_details[index[1]]
productData.data.product_details[index[0]].product_color_details[index[1]] = { ...codeInfo, product_color_name: name }
productData.data.product_details[index[0]] = { ...productData.data.product_details[index[0]] }
dispatch({ type: 'updateData', data: { ...productData.data }, update_status: 2 })
}
else {
productData.color_item_data.product_color_details[index[1]] = { ...codeItem, product_color_name: name }
dispatch({ type: 'updateColorData', data: { ...productData.color_item_data } })
}
}, [codeItem])
const settingColorStatus = useMemo(() => {
return !!productData.color_item_data
}, [productData.color_item_data])
return <>
<Index {...props} onChange={getNewName} />
<Index codeItem={codeItem} onChange={getNewName} adjust_type={productData.adjust_type} settingColorStatus={settingColorStatus} />
</>
}
const Index = memo((props: IndexParam) => {
const { codeItem } = props
const { codeItem, adjust_type, settingColorStatus } = props
const [showEdit, setShowEdit] = useState(false)
const [title, setTitle] = useState('')
console.log('codeItem内容', codeItem)
const countData = useMemo(() => {
console.log('codeItem内容', codeItem)
return {
old: `重量:${formatWeightDiv(codeItem?.weight_setting)}kg|空差: ${formatWeightDiv(codeItem?.weight_error_setting)}k|单价:¥${formatPriceDiv(codeItem?.price_setting)}/kg`,
new: `重量:${formatWeightDiv(codeItem?.original_weight)}kg|空差: ${formatWeightDiv(codeItem?.original_weight_error)}k|单价:¥${formatWeightDiv(codeItem?.original_price)}/kg`,
old: `重量:${formatWeightDiv(codeItem?.weight_setting)}kg` + `${codeItem.sale_mode === 0 ? `|空差: ${formatWeightDiv(codeItem?.weight_error_setting)}kg` : ''}` + `|单价:¥${formatPriceDiv(codeItem?.price_setting)}/kg`,
new: `重量:${formatWeightDiv(codeItem?.original_weight)}kg` + `${codeItem.sale_mode === 0 ? `|空差: ${formatWeightDiv(codeItem?.original_weight_error)}kg` : ''}` + `|单价:¥${formatWeightDiv(codeItem?.original_price)}/kg`,
}
}, [codeItem])
const onUpdate = () => {
@ -51,9 +63,16 @@ const Index = memo((props: IndexParam) => {
const onConfirm = (item) => {
props.onChange?.(item)
}
return <View className={styles['product_list__item--con']}>
const labAndImgData = useMemo(() => {
return { lab: codeItem.lab, rgb: codeItem.rgb, texture_url: codeItem.texture_url }
}, [codeItem])
const number = useMemo(() => {
return codeItem.sale_mode == 0 ? `${codeItem?.roll}` : `${codeItem?.length / 100}`
}, [codeItem])
return <View className={classNames(styles['product_list__item--con'], !settingColorStatus ? styles.product_list__item__bottom : styles.product_list_item_height)}>
<View className={styles.item_image} >
<LabAndImg value={{}} />
<LabAndImg value={labAndImgData} />
</View>
<View className={styles.item_desc}>
<View className={styles.item_name_count}>
@ -61,10 +80,10 @@ const Index = memo((props: IndexParam) => {
<Text>{codeItem?.product_color_name}</Text>
<IconFont name="icon-shuru" size={50} />
</View>
<View className={styles.number}>x{codeItem?.roll}</View>
<View className={styles.number}>x{number}</View>
</View>
<View className={styles.item_specs_new}>{countData.old}</View>
<View className={styles.item_specs_old}>{countData.new}</View>
{!settingColorStatus && <View className={styles.item_specs_old}>{countData.new}</View>}
</View>
<View className="common_ellipsis"></View>
<PopupModal show={showEdit} title="修改面料名称" defaultValue={title} onClose={() => setShowEdit(false)} onConfirm={onConfirm} />

View File

@ -1,5 +1,5 @@
import { Text, View } from '@tarojs/components'
import { memo, useCallback, useContext, useRef, useState } from 'react'
import { memo, useCallback, useContext, useMemo, useRef, useState } from 'react'
import classNames from 'classnames'
import Big from 'big.js'
import ProductItem from '../../productItem'
@ -9,6 +9,7 @@ import styles from './index.module.scss'
import IconFont from '@/components/iconfont/iconfont'
import PopupModal from '@/components/popupModal'
import { useCurrenCode } from '@/context/ContextCodeSetting'
import colorItem from '@/pages/codeList/components/colorItem'
interface Parma {
productInfo: any
@ -29,39 +30,44 @@ export default memo((props: Parma) => {
...productData.data.product_details[index],
product_name: name,
}
dispatch({ type: 'updateData', data: { ...productData.data } })
dispatch({ type: 'updateData', data: { ...productData.data }, update_status: 2 })
}, [productInfo])
// 更新整体数据
const updateData = useRef({
price: 0,
weight: 0,
weight_error: 0,
adjust_type: 1,
})
const changeNumber: NumberParam = useCallback((num, type) => {
// 更新整体数据
const updateData = {
price: productInfo?.price_admin,
weight: productInfo?.weight_admin,
weight_error: productInfo?.weight_error_admin,
}
if (type === 'weight') {
updateData.current.weight = num * 1000
updateData.weight = num * 1000
}
else if (type === 'sale_price') {
updateData.current.price = num * 100
updateData.price = num * 100
}
else {
updateData.current.weight_error = num * 1000
updateData.weight_error = num * 1000
}
// 需要传给后端
productData.data.product_details[index].weight_admin = updateData.current.weight
productData.data.product_details[index].price_admin = updateData.current.price
productData.data.product_details[index].weight_error_admin = updateData.current.weight_error
productData.data.product_details[index].weight_admin = updateData.weight
productData.data.product_details[index].price_admin = updateData.price
productData.data.product_details[index].weight_error_admin = updateData.weight_error
// 更新原始数组
productData.data.product_details[index]?.product_color_details?.map((item) => {
item.weight_setting = Big(updateData.current.weight).times(item.roll).add(item.weight).toNumber()
item.weight_error_setting = Big(updateData.current.weight_error).times(item.roll).add(item.weight_error).toNumber()
item.price_setting = Big(updateData.current.price).add(item.price).toNumber()
if (item.sale_mode === 0) {
item.weight_setting = Big(updateData.weight).times(item.roll).add(item.weight).toNumber()
item.weight_error_setting = Big(updateData.weight_error).times(item.roll).add(item.weight_error).toNumber()
}
else {
item.weight_setting = Big(updateData.weight).add(item.weight).toNumber()
item.weight_error_setting = Big(updateData.weight_error).add(item.weight_error).toNumber()
}
item.price_setting = Big(updateData.price).add(item.price).toNumber()
})
productData.data.product_details[index] = JSON.parse(JSON.stringify(productData.data.product_details[index]))
dispatch({ type: 'updateData', data: { ...productData.data } })
dispatch({ type: 'updateData', data: { ...productData.data }, update_status: 1 })
}, [productInfo])
return <>
@ -87,6 +93,13 @@ const Index = memo((props: IndexParam) => {
props.onChangeNumber?.(num, type)
}
const defaultNum = useMemo(() => {
return {
weight: Big(productInfo.weight_admin || 0).div(Big(1000)).toNumber(),
sale_price: Big(productInfo.price_admin || 0).div(Big(100)).toNumber(),
weight_error: Big(productInfo.weight_error_admin || 0).div(Big(1000)).toNumber(),
}
}, [productInfo])
return <>
<View className={styles.product_list__item}>
<View className={styles['product_list__item--title']} onClick={onUpdate}>
@ -94,11 +107,11 @@ const Index = memo((props: IndexParam) => {
<IconFont name="icon-shuru" size={50} />
<Text className={styles.mode_status}>{sale_mode_name}</Text>
</View>
<SettingNumber onNumber={getNumber} />
<SettingNumber sale_mode={productInfo?.sale_mode} onNumber={getNumber} defaultValue={defaultNum} />
<View style={{ height: upStatus ? '0rpx' : `${194 * productInfo?.product_color_details?.length}rpx` }} className={classNames(styles['product_list__item--con'])}>
{productInfo?.product_color_details?.map(citem => <View key={citem?.product_color_id}><ProductItem codeItem={citem} /></View>)}
</View>
<View className={styles.up_btn} onClick={() => setStatus(!upStatus)}>{upStatus ? '展开' : '收起'}<View className={classNames(styles.up_icon, upStatus ? styles.open_up_icon : styles.close_up_icon)}><IconFont name="icon-shangla" size={35} /></View></View>
<View className={styles.up_btn} onClick={() => setStatus(!upStatus)}>{upStatus ? '查看更多' : '收起'}<View className={classNames(styles.up_icon, upStatus ? styles.open_up_icon : styles.close_up_icon)}><IconFont name="icon-shangla" size={35} /></View></View>
</View>
<PopupModal show={showEdit} title="修改面料名称" defaultValue={title} onClose={() => setShowEdit(false)} onConfirm={onConfirm} />
</>

View File

@ -3,31 +3,29 @@ import { useContext, useEffect, useState } from 'react'
import Counter from '../counter'
import styles from './index.module.scss'
import { debounce } from '@/common/util'
import { useCurrenCode } from '@/context/ContextCodeSetting'
import type { saleModeType } from '@/common/enum'
export type Mode = 'weight'|'weight_error'|'sale_price'
export type NumberParam = (num: number, type: Mode) => void
interface Props {
onNumber?: NumberParam
sale_mode: saleModeType
defaultValue?: {
weight: number
weight_error: number
sale_price: number
}
}
export default (props: Props) => {
const { productData } = useCurrenCode()
const { onNumber } = props
const { onNumber, defaultValue, sale_mode } = props
const [defaultNum, setDefaultNum] = useState({
weight: 0,
weight_error: 0,
sale_price: 0,
})
useEffect(() => {
if (productData.save_status) {
console.log('重置数据:::', productData.save_status)
setDefaultNum(() => ({
weight: 0,
weight_error: 0,
sale_price: 0,
}))
}
}, [productData.save_status])
defaultValue && setDefaultNum(() => defaultValue)
}, [defaultValue])
const getNumber: NumberParam = debounce((num, type) => {
onNumber?.(num, type)
if (type === 'weight') {
@ -46,10 +44,10 @@ export default (props: Props) => {
<View className={styles['change_count__item--title']}></View>
<Counter defaultNum={defaultNum.weight} minNum={-1000} digits={2} onChange={num => getNumber(num, 'weight')} onBlue={num => getNumber(num, 'weight')} />
</View>
<View className={styles.change_count__item}>
{sale_mode === 0 && <View className={styles.change_count__item}>
<View className={styles['change_count__item--title']}></View>
<Counter defaultNum={defaultNum.weight_error} minNum={-1000} digits={2} onChange={num => getNumber(num, 'weight_error')} onBlue={num => getNumber(num, 'weight_error')} />
</View>
</View>}
<View className={styles.change_count__item}>
<View className={styles['change_count__item--title']}></View>
<Counter defaultNum={defaultNum.sale_price} minNum={-1000} digits={2} onChange={num => getNumber(num, 'sale_price')} onBlue={num => getNumber(num, 'sale_price')} />

View File

@ -21,46 +21,53 @@ export default memo((props: Parma) => {
return orderData?.product_details
}, [orderData])
const { updateCustomOrderTotal } = useCommon()
// 更新整体数据
const updateData = useRef({
price: 0,
weight: 0,
weight_error: 0,
adjust_type: 1,
})
const getNumber: NumberParam = useCallback((num, type) => {
// 更新整体数据
const updateData = {
price: orderData?.price_admin,
weight: orderData?.weight_admin,
weight_error: orderData?.weight_error_admin,
}
if (type === 'weight') {
updateData.current.weight = num * 1000
updateData.weight = num * 1000
}
else if (type === 'sale_price') {
updateData.current.price = num * 100
updateData.price = num * 100
}
else {
updateData.current.weight_error = num * 1000
updateData.weight_error = num * 1000
}
console.log(`aa${type}`, num)
// 需要传给后端
productData.data.weight_admin = updateData.current.weight
productData.data.price_admin = updateData.current.price
productData.data.weight_error_admin = updateData.current.weight_error
orderData.weight_admin = updateData.weight
orderData.price_admin = updateData.price
orderData.weight_error_admin = updateData.weight_error
console.log('orderData123::', updateData.price)
// 更新原始数组
productList?.map((item) => {
item?.product_color_details?.map((citem) => {
citem.weight_setting = Big(updateData.current.weight).times(citem.roll).add(citem.weight).toNumber()
citem.weight_error_setting = Big(updateData.current.weight_error).times(citem.roll).add(citem.weight_error).toNumber()
citem.price_setting = Big(updateData.current.price).add(citem.price).toNumber()
if (citem.sale_mode === 0) {
citem.weight_setting = Big(updateData.weight).times(citem.roll).add(citem.weight).toNumber()
citem.weight_error_setting = Big(updateData.weight_error).times(citem.roll).add(citem.weight_error).toNumber()
}
else {
citem.weight_setting = Big(updateData.weight).add(citem.weight).toNumber()
citem.weight_error_setting = Big(updateData.weight_error).add(citem.weight_error).toNumber()
}
citem.price_setting = Big(updateData.price).add(citem.price).toNumber()
})
})
orderData.product_details = productList
console.log('orderData::', orderData)
dispatch(updateCustomOrderTotal(orderData))
dispatch({ type: 'updateData', data: JSON.parse(JSON.stringify(orderData)) })
dispatch({ type: 'updateData', data: JSON.parse(JSON.stringify(orderData)), update_status: 1 })
}, [productList])
const defaultNum = useMemo(() => {
console.log('orderData::默认', orderData)
return {
weight: Big(orderData?.weight_admin || 0).div(Big(1000)).toNumber(),
sale_price: Big(orderData?.price_admin || 0).div(Big(100)).toNumber(),
@ -69,7 +76,7 @@ export default memo((props: Parma) => {
}, [orderData])
return <>
<SettingNumber onNumber={getNumber} defaultValue={defaultNum} />
<SettingNumber sale_mode={orderData?.sale_mode} onNumber={getNumber} defaultValue={defaultNum} />
<View className={styles.product_list}>
{productList?.map((item) => {
return <ProductBlock key={item.id} productInfo={item} sale_mode_name={orderData?.sale_mode_name} />

View File

@ -25,7 +25,7 @@ export default memo((props: Parma) => {
...productData.data.product_details[index],
product_name: name,
}
dispatch({ type: 'updateData', data: { ...productData.data } })
dispatch({ type: 'updateData', data: { ...productData.data }, update_status: 2 })
}, [productInfo])
return <>
<Index {...props} onChange={getNewName} />
@ -55,7 +55,7 @@ const Index = memo((props: IndexParam) => {
<View style={{ height: upStatus ? '0rpx' : `${194 * productInfo?.product_color_details?.length}rpx` }} className={classNames(styles['product_list__item--con'])}>
{productInfo?.product_color_details?.map(citem => <View key={citem?.product_color_id}><ProductItem codeItem={citem} /></View>)}
</View>
<View className={styles.up_btn} onClick={() => setStatus(!upStatus)}>{upStatus ? '展开' : '收起'}<View className={classNames(styles.up_icon, upStatus ? styles.open_up_icon : styles.close_up_icon)}><IconFont name="icon-shangla" size={35} /></View></View>
<View className={styles.up_btn} onClick={() => setStatus(!upStatus)}>{upStatus ? '查看更多' : '收起'}<View className={classNames(styles.up_icon, upStatus ? styles.open_up_icon : styles.close_up_icon)}><IconFont name="icon-shangla" size={35} /></View></View>
</View>
<PopupModal show={showEdit} title="修改面料名称" defaultValue={title} onClose={() => setShowEdit(false)} onConfirm={onConfirm} />
</>

View File

@ -0,0 +1,24 @@
import { CustomPrintCalculationApi } from '@/api/codeManage'
export default () => {
const { fetchData: customPrintCalculationApi } = CustomPrintCalculationApi()
// 更新合计数据
const updateCustomOrderTotal = (updateData) => {
return async(dispatch) => {
const res = await customPrintCalculationApi(updateData)
if (res.success) {
dispatch({
type: 'setCustomTotal',
data: {
total_weight_error: res?.data?.total_weight_error,
otal_sale_weight: res?.data?.total_sale_weight,
total_amount: res?.data?.total_amount,
},
})
}
}
}
return {
updateCustomOrderTotal,
}
}

206
src/reducers/codeData.ts Normal file
View File

@ -0,0 +1,206 @@
// 自定义码单
import type { adjustType } from '@/common/enum'
import type { CompanyItem } from '@/pages/codeSetting/components/payeeHead'
export interface customPrintProductColor {
price: number
product_color_id: number
product_color_name: string
weight: number
weight_error: number
}
export interface customPrintProduct {
custom_print_product_color: customPrintProductColor[]
price: number
product_id: number
product_name: string
weight: number
weight_error: number
}
export interface adminParam {
adjust_type: number
custom_print_id: number
sale_order_id: number
custom_print_product: customPrintProduct[]
price: number
purchaser_form_title_id: number
weight: number
weight_error: number
}
export interface CodeParam {
data: any // 码单数据
adjust_type: adjustType// 码单调整类型
custom_print_id: number // 自定义码单id
sale_order_id: number // 销售码单id
admin_data: adminParam|null // 需要传给后端的数据
save_status: boolean // 是否保存了数据
color_item_data: any // 当前编辑的颜色数据
update_status: 0|1|2
purchaser_form_title: CompanyItem // 码单抬头
}
type Action = {
type: string
}&CodeParam
const INIT_USER: CodeParam = {
data: null, // 码单数据
adjust_type: 1, // 码单调整类型
custom_print_id: 0, // 自定义码单id
sale_order_id: 0, // 销售码单id
admin_data: null, // 需要传给后端的数据
color_item_data: null,
update_status: 0, // 1代表修改了数量2代表修改了名称
purchaser_form_title: {
title: '',
purchaser_name: '',
phone: '',
id: 0,
},
}
export default function counter(state = INIT_USER, action: Action) {
const { type, data, admin_data } = action
switch (type) {
case 'setInitData':
return onInitData(state, action)
case 'updateData':
return onUpdateData(state, action)
case 'changeAdjustType':
return { ...state, adjust_type: data }
case 'setColorData':
return { ...state, color_item_data: JSON.parse(JSON.stringify(data)) }
case 'updateColorData':
return { ...state, color_item_data: data }
case 'setPurchaserFormTitle':
return onUpdatePurchaserFormTitle(state, action)
default:
return state
}
}
// 初始化数据
const onInitData = (state, action: Action) => {
const { data = {}, custom_print_id, sale_order_id, adjust_type } = action
const updateData: adminParam = {
adjust_type: parseInt(adjust_type.toString()),
custom_print_product: [],
price: data?.price_admin || 0,
weight: data?.weight_admin || 0,
weight_error: data?.weight_error_admin || 0,
custom_print_id: parseInt(custom_print_id.toString()),
sale_order_id: parseInt(custom_print_id.toString()),
purchaser_form_title_id: data?.default_title_id,
}
const custom_order_total = {
total_weight_error: data?.total_weight_error,
total_sale_weight: data?.total_sale_weight,
total_amount: data?.total_amount,
}
data.weight_admin = 0
data.price_admin = 0
data.weight_error_admin = 0
data?.product_details?.map((item, index) => {
item.weight_admin = 0
item.price_admin = 0
item.weight_error_admin = 0
item.index_str = index.toString()
item.sale_mode_name = data.sale_mode_name
item.sale_mode = data.sale_mode
const product_item: customPrintProduct = {
price: item.price_admin || 0,
weight: item.weight_admin || 0,
weight_error: item.weight_error_admin || 0,
product_id: item.product_id,
product_name: item.product_name,
custom_print_product_color: [],
}
item?.product_color_details?.map((citem, cindex) => {
citem.index_str = `${item.index_str}_${cindex}` // 通过这个可以快速定位数组位置
citem.weight_setting = citem.weight
citem.weight_error_setting = citem.weight_error
citem.price_setting = citem.price
citem.weight_admin = 0
citem.price_admin = 0
citem.weight_error_admin = 0
citem.sale_mode_name = data.sale_mode_name
citem.sale_mode = data.sale_mode
product_item.custom_print_product_color.push({
price: citem.price_admin || 0,
weight: citem.weight_admin || 0,
weight_error: citem.weight_error_admin || 0,
product_color_id: citem.product_color_id,
product_color_name: citem.product_color_name,
})
})
updateData.custom_print_product.push(product_item)
})
// 抬头
const purchaser_form_title = {
id: data?.default_title_id,
title: data?.title_name,
purchaser_name: data?.purchaser_name,
phone: data?.purchaser_phone,
}
return {
...state,
data,
custom_print_id,
sale_order_id,
custom_order_total,
admin_data: updateData,
init_state: true,
update_status: 0,
color_item_data: null,
purchaser_form_title,
adjust_type,
}
}
// 后端所需数据
const onUpdateData = (state, action) => {
const { data, update_status } = action
const updateData: adminParam = {
adjust_type: parseInt(state.adjust_type),
custom_print_product: [],
price: 0,
weight: 0,
weight_error: 0,
custom_print_id: parseInt(state.custom_print_id!),
sale_order_id: parseInt(state.sale_order_id!),
purchaser_form_title_id: parseInt(state.purchaser_form_title.id),
}
updateData.weight = data?.weight_admin || 0
updateData.price = data?.price_admin || 0
updateData.weight_error = data?.weight_error_admin || 0
data?.product_details?.map((item) => {
const product_item: customPrintProduct = {
price: item.price_admin || 0,
weight: item.weight_admin || 0,
weight_error: item.weight_error_admin || 0,
product_id: item.product_id,
product_name: item.product_name,
custom_print_product_color: [],
}
item?.product_color_details?.map((citem) => {
product_item.custom_print_product_color.push({
price: citem.price_admin || 0,
weight: citem.weight_admin || 0,
weight_error: citem.weight_error_admin || 0,
product_color_id: citem.product_color_id,
product_color_name: citem.product_color_name,
})
})
updateData.custom_print_product.push(product_item)
})
return { ...state, admin_data: updateData, data: { ...data }, update_status }
}
// 更新码单抬头
const onUpdatePurchaserFormTitle = (state, action) => {
const { data } = action
state.admin_data.purchaser_form_title_id = data.id
return { ...state, purchaser_form_title: data }
}

View File

@ -1,12 +1,14 @@
// 该方法纯粹只是个Ts类型定义文件
import type { TypedUseSelectorHook } from 'react-redux'
import type { TypedUseSelectorHook } from 'react-redux'
import { useSelector as useReduxSelector } from 'react-redux'
import type { DataParam } from './userInfo'
import type { DataParam as commonDataParam } from './commonData'
import type { DataParam as commonDataParam } from './commonData'
import type { CodeParam } from './codeData'
interface Params {
userInfo: DataParam
commonData: commonDataParam
codeData: CodeParam
}
export const useSelector: TypedUseSelectorHook<Params> = useReduxSelector
export const useSelector: TypedUseSelectorHook<Params> = useReduxSelector

View File

@ -1,8 +1,10 @@
import { combineReducers } from 'redux'
import userInfo from './userInfo'
import commonData from './commonData'
import codeData from './codeData'
export default combineReducers({
userInfo,
commonData,
})
codeData,
})