From 7f101dabd36ad244679ac4f217af26b3c511f4ec Mon Sep 17 00:00:00 2001 From: czm <2192718639@qq.com> Date: Wed, 28 Dec 2022 19:52:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E8=B4=A7=E7=A0=81=E5=8D=95=E5=AF=B9?= =?UTF-8?q?=E6=8E=A5=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc | 3 +- src/context/ContextCodeSetting/index copy.tsx | 135 ++++++++++++ src/context/ContextCodeSetting/index.tsx | 117 +--------- .../components/main/index.module.scss | 38 ++++ .../codeColorList/components/main/index.tsx | 34 +++ .../codeColorList/index.module.scss | 35 --- src/pages/codeSetting/codeColorList/index.tsx | 16 +- .../components/bottomBtn/index.module.scss | 1 + .../colorBlock/index.module.scss | 6 + .../colorItemSetting/colorBlock/index.tsx | 79 +++++++ .../components/colorItemSetting/index.tsx | 53 ++++- .../components/colorSetting/index.module.scss | 35 +++ .../colorSetting/productBlock/index.tsx | 19 +- .../codeSetting/components/main/index.tsx | 64 +++--- .../components/payeeHead/index.tsx | 2 +- .../components/productItem/index.module.scss | 10 +- .../components/productItem/index.tsx | 49 +++-- .../productSetting/productBlock/index.tsx | 55 +++-- .../components/settingNumber/index.tsx | 26 +-- .../components/wholeOrderSetting/index.tsx | 51 +++-- .../wholeOrderSetting/productBlock/index.tsx | 4 +- src/pages/codeSetting/useHook/useCommon.ts | 24 ++ src/reducers/codeData.ts | 206 ++++++++++++++++++ src/reducers/hooks.ts | 8 +- src/reducers/index.ts | 4 +- 25 files changed, 789 insertions(+), 285 deletions(-) create mode 100644 src/context/ContextCodeSetting/index copy.tsx create mode 100644 src/pages/codeSetting/codeColorList/components/main/index.module.scss create mode 100644 src/pages/codeSetting/codeColorList/components/main/index.tsx create mode 100644 src/pages/codeSetting/components/colorItemSetting/colorBlock/index.module.scss create mode 100644 src/pages/codeSetting/components/colorItemSetting/colorBlock/index.tsx create mode 100644 src/pages/codeSetting/useHook/useCommon.ts create mode 100644 src/reducers/codeData.ts diff --git a/.eslintrc b/.eslintrc index 14f6bd7..b9c8964 100644 --- a/.eslintrc +++ b/.eslintrc @@ -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 } } \ No newline at end of file diff --git a/src/context/ContextCodeSetting/index copy.tsx b/src/context/ContextCodeSetting/index copy.tsx new file mode 100644 index 0000000..b4b204b --- /dev/null +++ b/src/context/ContextCodeSetting/index copy.tsx @@ -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() { + const ctx = React.createContext(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() + +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 ( + + ) +} diff --git a/src/context/ContextCodeSetting/index.tsx b/src/context/ContextCodeSetting/index.tsx index b4b204b..f58fb8c 100644 --- a/src/context/ContextCodeSetting/index.tsx +++ b/src/context/ContextCodeSetting/index.tsx @@ -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() { const ctx = React.createContext(undefined) function useCtx() { @@ -27,108 +24,8 @@ function createCtx() { export const [useCurrenCode, CurrentUserProvider] = createCtx() 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 ( ) diff --git a/src/pages/codeSetting/codeColorList/components/main/index.module.scss b/src/pages/codeSetting/codeColorList/components/main/index.module.scss new file mode 100644 index 0000000..50e077e --- /dev/null +++ b/src/pages/codeSetting/codeColorList/components/main/index.module.scss @@ -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; + } + } + } +} diff --git a/src/pages/codeSetting/codeColorList/components/main/index.tsx b/src/pages/codeSetting/codeColorList/components/main/index.tsx new file mode 100644 index 0000000..76aecad --- /dev/null +++ b/src/pages/codeSetting/codeColorList/components/main/index.tsx @@ -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 + + + + 取消 + 确认 + + + + +} diff --git a/src/pages/codeSetting/codeColorList/index.module.scss b/src/pages/codeSetting/codeColorList/index.module.scss index b9b6d54..e69de29 100644 --- a/src/pages/codeSetting/codeColorList/index.module.scss +++ b/src/pages/codeSetting/codeColorList/index.module.scss @@ -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; - } - } - } -} diff --git a/src/pages/codeSetting/codeColorList/index.tsx b/src/pages/codeSetting/codeColorList/index.tsx index d6f188b..7189403 100644 --- a/src/pages/codeSetting/codeColorList/index.tsx +++ b/src/pages/codeSetting/codeColorList/index.tsx @@ -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 - - - - 取消 - 确认 - - - - - + return +
+ } diff --git a/src/pages/codeSetting/components/bottomBtn/index.module.scss b/src/pages/codeSetting/components/bottomBtn/index.module.scss index 16e2636..5b64847 100644 --- a/src/pages/codeSetting/components/bottomBtn/index.module.scss +++ b/src/pages/codeSetting/components/bottomBtn/index.module.scss @@ -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; diff --git a/src/pages/codeSetting/components/colorItemSetting/colorBlock/index.module.scss b/src/pages/codeSetting/components/colorItemSetting/colorBlock/index.module.scss new file mode 100644 index 0000000..1ce604b --- /dev/null +++ b/src/pages/codeSetting/components/colorItemSetting/colorBlock/index.module.scss @@ -0,0 +1,6 @@ +.product_list__item--con { + background-color: #fff; + padding: 24px 32px 18px 32px; + box-sizing: border-box; + margin-bottom: 8px; +} diff --git a/src/pages/codeSetting/components/colorItemSetting/colorBlock/index.tsx b/src/pages/codeSetting/components/colorItemSetting/colorBlock/index.tsx new file mode 100644 index 0000000..56fedd6 --- /dev/null +++ b/src/pages/codeSetting/components/colorItemSetting/colorBlock/index.tsx @@ -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 +}) + +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 + + + +}) diff --git a/src/pages/codeSetting/components/colorItemSetting/index.tsx b/src/pages/codeSetting/components/colorItemSetting/index.tsx index 5b6d4b6..7730ab8 100644 --- a/src/pages/codeSetting/components/colorItemSetting/index.tsx +++ b/src/pages/codeSetting/components/colorItemSetting/index.tsx @@ -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 <> + + +}) + +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 <> - - 5215# 26S双纱亲水滑爽棉 + + {productInfo.product_name} - 大货 + {productInfo.sale_mode_name} - {new Array(5).fill('').map((item, index) => - - {/* */} - )} + {productInfo?.product_color_details?.map(item => )} + setShowEdit(false)} onConfirm={onConfirm} /> -} +}) diff --git a/src/pages/codeSetting/components/colorSetting/index.module.scss b/src/pages/codeSetting/components/colorSetting/index.module.scss index e3b5813..a66a67f 100644 --- a/src/pages/codeSetting/components/colorSetting/index.module.scss +++ b/src/pages/codeSetting/components/colorSetting/index.module.scss @@ -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; + } + } + } } diff --git a/src/pages/codeSetting/components/colorSetting/productBlock/index.tsx b/src/pages/codeSetting/components/colorSetting/productBlock/index.tsx index 46c05b8..879658d 100644 --- a/src/pages/codeSetting/components/colorSetting/productBlock/index.tsx +++ b/src/pages/codeSetting/components/colorSetting/productBlock/index.tsx @@ -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 <> - + }) 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) => { {sale_mode_name} - goLink('/pages/codeSetting/codeColorList/index')}> + 编辑 @@ -62,7 +69,7 @@ const Index = memo((props: IndexParam) => { {productInfo?.product_color_details?.map(citem => )} - setStatus(!upStatus)}>{upStatus ? '展开' : '收起'} + setStatus(!upStatus)}>{upStatus ? '查看更多' : '收起'} setShowEdit(false)} onConfirm={onConfirm} /> diff --git a/src/pages/codeSetting/components/main/index.tsx b/src/pages/codeSetting/components/main/index.tsx index 425c989..41a4ef3 100644 --- a/src/pages/codeSetting/components/main/index.tsx +++ b/src/pages/codeSetting/components/main/index.tsx @@ -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(0) const [codeData, setCodeData] = useState(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 () => { - {modeIndex == 1 && } + {productData?.adjust_type == 1 && } - {modeIndex == 2 && } + {productData?.adjust_type == 2 && } - {modeIndex == 3 && } + {productData?.adjust_type == 3 && } 自定义单据信息 - + {codeData?.sale_mode === 0 && 合计空差 {formatWeightDiv(customTotal.total_weight_error)}kg - + } 合计重量 {formatWeightDiv(customTotal.total_sale_weight)}kg @@ -171,10 +175,10 @@ export default () => { 原始单据信息 - + {codeData?.sale_mode === 0 && 合计空差 {formatWeightDiv(productData?.data?.original_total_weight_error)}kg - + } 合计重量 {formatWeightDiv(productData?.data?.original_total_sale_weight)}kg diff --git a/src/pages/codeSetting/components/payeeHead/index.tsx b/src/pages/codeSetting/components/payeeHead/index.tsx index 35ee971..bd7c706 100644 --- a/src/pages/codeSetting/components/payeeHead/index.tsx +++ b/src/pages/codeSetting/components/payeeHead/index.tsx @@ -34,7 +34,7 @@ export default (props: CompanyParam) => { {data?.title} - {data?.is_default && 默认抬头} + {/* {data?.is_default && 默认抬头} */} {data?.purchaser_name} diff --git a/src/pages/codeSetting/components/productItem/index.module.scss b/src/pages/codeSetting/components/productItem/index.module.scss index 1ebe988..2355556 100644 --- a/src/pages/codeSetting/components/productItem/index.module.scss +++ b/src/pages/codeSetting/components/productItem/index.module.scss @@ -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; +} diff --git a/src/pages/codeSetting/components/productItem/index.tsx b/src/pages/codeSetting/components/productItem/index.tsx index d0f1c9a..d5a603c 100644 --- a/src/pages/codeSetting/components/productItem/index.tsx +++ b/src/pages/codeSetting/components/productItem/index.tsx @@ -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 <> - + } 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 + 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 - + @@ -61,10 +80,10 @@ const Index = memo((props: IndexParam) => { {codeItem?.product_color_name} - x{codeItem?.roll}条 + x{number} {countData.old} - {countData.new} + {!settingColorStatus && {countData.new}} setShowEdit(false)} onConfirm={onConfirm} /> diff --git a/src/pages/codeSetting/components/productSetting/productBlock/index.tsx b/src/pages/codeSetting/components/productSetting/productBlock/index.tsx index 52f3c15..91031dd 100644 --- a/src/pages/codeSetting/components/productSetting/productBlock/index.tsx +++ b/src/pages/codeSetting/components/productSetting/productBlock/index.tsx @@ -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 <> @@ -94,11 +107,11 @@ const Index = memo((props: IndexParam) => { {sale_mode_name} - + {productInfo?.product_color_details?.map(citem => )} - setStatus(!upStatus)}>{upStatus ? '展开' : '收起'} + setStatus(!upStatus)}>{upStatus ? '查看更多' : '收起'} setShowEdit(false)} onConfirm={onConfirm} /> diff --git a/src/pages/codeSetting/components/settingNumber/index.tsx b/src/pages/codeSetting/components/settingNumber/index.tsx index 637fa8d..e2a7f7d 100644 --- a/src/pages/codeSetting/components/settingNumber/index.tsx +++ b/src/pages/codeSetting/components/settingNumber/index.tsx @@ -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) => { 重量 getNumber(num, 'weight')} onBlue={num => getNumber(num, 'weight')} /> - + {sale_mode === 0 && 空差 getNumber(num, 'weight_error')} onBlue={num => getNumber(num, 'weight_error')} /> - + } 单价 getNumber(num, 'sale_price')} onBlue={num => getNumber(num, 'sale_price')} /> diff --git a/src/pages/codeSetting/components/wholeOrderSetting/index.tsx b/src/pages/codeSetting/components/wholeOrderSetting/index.tsx index 90d864d..77c6052 100644 --- a/src/pages/codeSetting/components/wholeOrderSetting/index.tsx +++ b/src/pages/codeSetting/components/wholeOrderSetting/index.tsx @@ -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 <> - + {productList?.map((item) => { return diff --git a/src/pages/codeSetting/components/wholeOrderSetting/productBlock/index.tsx b/src/pages/codeSetting/components/wholeOrderSetting/productBlock/index.tsx index 2b9bb51..991398c 100644 --- a/src/pages/codeSetting/components/wholeOrderSetting/productBlock/index.tsx +++ b/src/pages/codeSetting/components/wholeOrderSetting/productBlock/index.tsx @@ -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 <> @@ -55,7 +55,7 @@ const Index = memo((props: IndexParam) => { {productInfo?.product_color_details?.map(citem => )} - setStatus(!upStatus)}>{upStatus ? '展开' : '收起'} + setStatus(!upStatus)}>{upStatus ? '查看更多' : '收起'} setShowEdit(false)} onConfirm={onConfirm} /> diff --git a/src/pages/codeSetting/useHook/useCommon.ts b/src/pages/codeSetting/useHook/useCommon.ts new file mode 100644 index 0000000..099389b --- /dev/null +++ b/src/pages/codeSetting/useHook/useCommon.ts @@ -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, + } +} diff --git a/src/reducers/codeData.ts b/src/reducers/codeData.ts new file mode 100644 index 0000000..05a9238 --- /dev/null +++ b/src/reducers/codeData.ts @@ -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 } +} diff --git a/src/reducers/hooks.ts b/src/reducers/hooks.ts index 58d11c9..e488cd5 100644 --- a/src/reducers/hooks.ts +++ b/src/reducers/hooks.ts @@ -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 = useReduxSelector +export const useSelector: TypedUseSelectorHook = useReduxSelector diff --git a/src/reducers/index.ts b/src/reducers/index.ts index 7958463..d8f0829 100644 --- a/src/reducers/index.ts +++ b/src/reducers/index.ts @@ -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, +})