Commit eca1f22c authored by 前端-钟卫鹏's avatar 前端-钟卫鹏

Merge branch 'featStrategies' into dev

parents 90f2c422 cd4421e9
......@@ -35,9 +35,9 @@ export const columnsSetMember: any[] = [
export const columnsSetProduct: any[] = [
{
title: '商品ID',
dataIndex: 'commodityId',
dataIndex: 'id',
align: 'center',
key: 'commodityId',
key: 'id',
},
{
title: '商品名称',
......@@ -49,15 +49,15 @@ export const columnsSetProduct: any[] = [
},
{
title: '品类',
dataIndex: 'customerCategoryName',
dataIndex: ['customerCategory', 'name'],
align: 'center',
key: 'customerCategoryName',
key: 'customerCategory',
},
{
title: '品牌',
dataIndex: 'brandName',
dataIndex: ['brand', 'name'],
align: 'center',
key: 'brandName',
key: 'brand',
},
{
title: '单位',
......@@ -65,6 +65,13 @@ export const columnsSetProduct: any[] = [
align: 'center',
key: 'unitName',
},
{
title: '商品定价',
dataIndex: 'priceType',
align: 'center',
key: 'priceType',
render: (t, r) => t===1 ? '现货价格' : '价格需要询问'
},
]
// 和商品规格
......@@ -139,11 +146,11 @@ export const memberColumns: any[] = [
title: '角色',
align: 'center'
},
{
dataIndex: 'levelTag',
title: '等级',
align: 'center'
},
// {
// dataIndex: 'levelTag',
// title: '等级',
// align: 'center'
// },
{
dataIndex: 'ctl',
title: '操作',
......
......@@ -3,9 +3,9 @@ import { ISchemaFormActions, FormEffectHooks, IFormActions, ISchemaFormAsyncActi
import { PublicApi } from '@/services/api';
import { useAsyncSelect } from '@/formSchema/effects/useAsyncSelect';
import { columnsUnitProduct } from '../constant';
import { GlobalConfig } from '@/global/config';
const { onFieldValueChange$ } = FormEffectHooks
// 高级筛选schema中用于输入搜索品牌的Effect
export const searchBrandOptionEffect = (context: any, fieldName: string) => {
......@@ -30,6 +30,8 @@ export const searchCustomerCategoryOptionEffect = (context: any, fieldName: stri
})
}
// 构建设置价格 table 所需要的data和columns
export const constructTableData = (data: any, ctx: ISchemaFormActions | ISchemaFormAsyncActions) => {
// 预先对阶梯价格排序
data = data.map(item => {
......@@ -43,8 +45,6 @@ export const constructTableData = (data: any, ctx: ISchemaFormActions | ISchemaF
}
})
console.log(data, 'structureTableData')
let col: any = [...columnsUnitProduct]
let temp: any = []
......@@ -96,7 +96,68 @@ export const constructTableData = (data: any, ctx: ISchemaFormActions | ISchemaF
}
}
// 生成 Api 所需要的参数
export const transformParamsForApi = (data: any, ctx: ISchemaFormActions | ISchemaFormAsyncActions) => {
let _params: any = {}
_params["name"] = data.name
_params["priceType"] = data.priceType
let shopInfo = ctx.getFieldState("shopId").dataSource[0]
// _params["shopName"] = ctx.getFieldState("shopId").dataSource[0]["name"]
_params["type"] = shopInfo["type"]
_params["environment"] = shopInfo["environment"]
_params["commodity"] = { id: data.productId }
_params["commodityMemberList"] = data.commodityMemberList.map(item => ({
memberId: item.memberId,
memberName: item.name,
memberTypeName: item.memberTypeName,
memberRoleId: item.roleId,
memberRoleName: item.roleName,
}))
_params["memberUnitPriceList"] = data.memberUnitPriceList.map(item => ({
commodityUnitPrice: { id: item.id },
unitPrice: item["单价"]
}))
return {
params: _params
}
}
export const transformParamsForApi = () => {
// 生成前端Form所需要的参数
export const transformDataForNiceForm = (value: any, ctx: ISchemaFormActions | ISchemaFormAsyncActions) => {
if(value && JSON.stringify(value) !== '{}') {
let initValue: any = {};
initValue["name"] = value.name
initValue["priceType"] = value.priceType
initValue["productId"] = value.commodity.id
initValue["productName"] = value.commodity.name
initValue["commodityMemberList"] = value.commodityMemberList.map(item => ({
memberId: item.memberId,
name: item.memberName,
memberTypeName: item.memberTypeName,
roleId: item.memberRoleId,
roleName: item.memberRoleName,
}))
let shopInfo = GlobalConfig.web.shopInfo.filter(item => item["type"] === value["type"] && item["environment"] === value["environment"])
initValue["shopId"] = shopInfo[0]["id"]
return {
initValue
}
// const { tableUnitData, columsUnit } = constructTableData(value.memberUnitPriceList, ctx)
// initValue["memberUnitPriceList"] = constructTableData(value.memberUnitPriceList, ctx)["tableUnitData"]
// ctx.setFieldState("memberUnitPriceList", state => {
// columsUnit.push({
// dataIndex: 'ctl',
// title: '操作',
// align: 'center',
// render: (_i, _r) => <Button type='link' onClick={() => handleSetProductPrice(_r)}>设置价格</Button>
// })
// state.props["x-component-props"].columns = columsUnit
// })
}
}
......@@ -9,6 +9,7 @@ import { useStateFilterSearchLinkageEffect } from '@/formSchema/effects/useFilte
import { FORM_FILTER_PATH } from '@/formSchema/const'
import ModalSearch from '@/components/NiceForm/components/Search'
import Submit from '@/components/NiceForm/components/Submit'
import { PageStatus, usePageStatus } from '@/hooks/usePageStatus'
export interface MemberModalProps {
type?: 'radio' | 'checkbox',
......@@ -24,7 +25,13 @@ const MemberModal:React.FC<MemberModalProps> = (props) => {
setVisible,
rowSelection,
rowSelectionCtl,
} = useModalTable({type})
} = useModalTable({type, customKey: "memberId"})
const {
id,
preview,
pageStatus
} = usePageStatus()
useEffect(() => {
if (currentRef) {
......@@ -40,18 +47,44 @@ const MemberModal:React.FC<MemberModalProps> = (props) => {
// 添加会员
const handleOkAddMember = () => {
setVisible(false)
console.log(rowSelectionCtl.selectRow, 'row')
schemaAction.setFieldValue('commodityMemberList', rowSelectionCtl.selectRow)
// let hasMember: any = schemaAction.setFieldValue('commodityMemberList') || []
// // schemaAction.setFieldValue('commodityMemberList', hasMember.concat(rowSelectionCtl.selectRow))
// schemaAction.setFieldValue('commodityMemberList', rowSelectionCtl.selectRow)
// // rowSelectionCtl.setSelectedRowKeys([])
if(pageStatus === PageStatus.EDIT) {
schemaAction.setFieldState('commodityMemberList', state => {
state.isDelete = true
})
let hasMember: any = schemaAction.getFieldValue('commodityMemberList') || []
schemaAction.setFieldValue('commodityMemberList', hasMember.concat(rowSelectionCtl.selectRow))
rowSelectionCtl.setSelectedRowKeys([])
rowSelectionCtl.setSelectRow([])
console.log(hasMember, rowSelectionCtl.selectRow)
} else {
schemaAction.setFieldValue('commodityMemberList', rowSelectionCtl.selectRow)
}
}
const fetchMemberList = async (params) => {
const excludeIds = await PublicApi.getProductCommodityGetStrategyMemberByCommodityId({commodityId: schemaAction.getFieldValue("productId")}, {ctlType: 'none'})
params.excludeList = excludeIds.data
let checkedMember = schemaAction.getFieldValue('commodityMemberList')
console.log(schemaAction.getFieldState('commodityMemberList'), 'state')
if(schemaAction.getFieldState('commodityMemberList').isDelete) {
params.excludeList = checkedMember.map(item => ({
memberId: item.memberId,
roleId: item.roleId,
}))
} else {
params.excludeList = excludeIds.data.map(item => ({
memberId: item.memberId,
roleId: item.memberRoleId,
}))
}
const res = await PublicApi.postMemberManageLowerConsumerPage(params, {ctlType: 'none'});
return res.data
}
return (
<ModalTable
modalTitle='选择会员'
......@@ -85,7 +118,7 @@ const MemberModal:React.FC<MemberModalProps> = (props) => {
destroyOnClose: true
}}
tableProps={{
rowKey: 'id'
rowKey: 'memberId'
}}
/>
)
......
......@@ -49,12 +49,10 @@ const PriceModal:React.FC<PriceModalProps> = (props) => {
}, [])
useEffect(() => {
console.log(curretSetPriceRow, 'curretSetPriceRow')
let record = {...curretSetPriceRow}
if(record && JSON.stringify(record)!=="{}" && record.id) {
setVisible(true)
console.log(schemaAction.getFieldState("memberUnitPriceList"))
setIsBatchSetting(false)
setPriceForm.resetFields()
// 0-0为 非阶梯
......
......@@ -12,7 +12,7 @@ import { Button, message, Select, Input } from 'antd'
import NiceForm from '@/components/NiceForm'
import { GlobalConfig } from '@/global/config'
import { columnsUnitProduct, memberColumns } from '../../constant'
import { constructTableData } from '../../effect'
import { constructTableData, transformDataForNiceForm } from '../../effect'
import PriceModal from './priceModal'
import ProductModal from './ProductModal'
import MemberModal from './MemberModal'
......@@ -31,9 +31,11 @@ const PriceSetting:React.FC<PriceSettingProps> = (props) => {
const priceRef = useRef<any>({})
const productRef = useRef<any>({})
const memberRef = useRef<any>({})
const [formLoading, setFormLoading] = useState(false)
const [visibleMember, setVisibleMember] = useState(false)
const [memberRowSelection, memberRowCtl] = useRowSelectionTable({ customKey: 'memberId' })
const [initValue, setInitialValue] = useState({});
const [initFormValue, setInitialFormValue] = useState({});
const [membersLength, setMembersLength] = useState(0);
const {
......@@ -42,12 +44,28 @@ const PriceSetting:React.FC<PriceSettingProps> = (props) => {
pageStatus
} = usePageStatus()
useEffect(() => {
if(id) {
PublicApi.getProductCommodityGetUnitPriceStrategy({id}).then(res => {
const { initValue } = transformDataForNiceForm(res.data, addSchemaAction)
setInitialFormValue(initValue)
})
}
}, [])
// 会员选择后的表格
const handleDeleteMemberTable = (id) => {
// 删除会员
const handleDeleteMemberTable = (reocrd) => {
const value = addSchemaAction.getFieldValue('commodityMemberList')
const res = value.filter((item) => item.id != id);
const res = value.filter(item => item.memberId != reocrd.memberId);
addSchemaAction.setFieldValue('commodityMemberList', res)
addSchemaAction.setFieldState('commodityMemberList', state => {
state.isDelete = true
})
if(pageStatus === PageStatus.EDIT) {
let hasMember = memberRef.current.rowSelectionCtl.selectRow
memberRef.current.rowSelectionCtl.setSelectRow(hasMember.filter(item => item.memberId != reocrd.memberId))
}
}
const handleAddMemberBtn = () => {
......@@ -58,16 +76,16 @@ const PriceSetting:React.FC<PriceSettingProps> = (props) => {
return;
}
const checkBoxs = addSchemaAction.getFieldValue('commodityMemberList')
if(checkBoxs?.length) {
memberRowCtl.setSelectedRowKeys(checkBoxs.map(v => v.memberId))
memberRowCtl.setSelectRow(checkBoxs)
}
// const checkBoxs = addSchemaAction.getFieldValue('commodityMemberList')
// if(checkBoxs?.length) {
// memberRowCtl.setSelectedRowKeys(checkBoxs.map(v => v.memberId))
// memberRowCtl.setSelectRow(checkBoxs)
// }
memberRef.current.setVisible(true)
}
const handleSetProductPrice = (record: any) => {
console.log(record, 'rrr')
if(record?.id) {
priceRef.current.setVisible(true)
priceRef.current.setCurrentSetPriceRow(record)
......@@ -81,8 +99,8 @@ const PriceSetting:React.FC<PriceSettingProps> = (props) => {
message.error('请先选择适用商城')
return false
}
productRef.current.setVisible(true)
productRef.current.rowSelectionCtl.setSelectedRowKeys([addSchemaAction.getFieldValue('productId')])
}
// 价格策略设置表单提交
......@@ -100,6 +118,12 @@ const PriceSetting:React.FC<PriceSettingProps> = (props) => {
}
}
const searchMember = (value) => {
let commodityMemberList = addSchemaAction.getFieldValue("commodityMemberList").filter(item => item.name === value)
addSchemaAction.setFieldValue("commodityMemberList", commodityMemberList)
}
// const paginationChange = async (page: number, size: number) => {
// if(id !== '') {
......@@ -116,29 +140,30 @@ const PriceSetting:React.FC<PriceSettingProps> = (props) => {
// 新增会员
const tableAddMemberButton = (<>
const tableAddMemberButton = pageStatus !== PageStatus.PREVIEW && <>
<p style={{display: 'flex', justifyContent: 'flex-end', flexWrap: 'wrap'}}>
<Search
placeholder="会员名称"
onSearch={value => console.log(value)}
onSearch={value => searchMember(value)}
style={{ width: 256 }}
/>
</p>
<Button style={{marginBottom: 16}} block icon={<PlusOutlined/>} onClick={handleAddMemberBtn} type='dashed'>选择指定会员</Button>
</>)
</>
// 批量设置价格按钮
const batchPriceButton = <Button type="text" onClick={clickBatchSetPrice} style={{marginBottom: 12, float: "right"}}><SettingOutlined /> 批量设置价格</Button>
const batchPriceButton = pageStatus !== PageStatus.PREVIEW && <Button type="text" onClick={clickBatchSetPrice} style={{marginBottom: 12, float: "right"}}><SettingOutlined /> 批量设置价格</Button>
// 选择商品
const connectProduct = <div className='connectBtn' onClick={handleAddProductBtn}><LinkOutlined style={{marginRight: 4}}/>选择</div>
const connectProduct = pageStatus !== PageStatus.PREVIEW && <div className='connectBtn' onClick={handleAddProductBtn}><LinkOutlined style={{marginRight: 4}}/>选择</div>
return (
<>
<NiceForm
loading={formLoading}
previewPlaceholder=' '
editable={pageStatus !== PageStatus.PREVIEW}
value={initValue}
value={initFormValue}
expressionScope={{
connectProduct,
batchPriceButton,
......@@ -156,10 +181,14 @@ const PriceSetting:React.FC<PriceSettingProps> = (props) => {
$('onFieldValueChange', 'shopId').subscribe(parentState => {
if (parentState.value) {
ctx.setFieldState('shopId', state => {
state.dataSource = pageStatus === PageStatus.PREVIEW ?
GlobalConfig.web.shopInfo.filter(v => v.id === parentState.value && state.value.includes(v.id))
:
GlobalConfig.web.shopInfo.filter(v => v.id === parentState.value)
// state.dataSource = pageStatus === PageStatus.PREVIEW ?
// GlobalConfig.web.shopInfo.filter(v => v.id === parentState.value && state.value.includes(v.id))
// :
state.dataSource = GlobalConfig.web.shopInfo.filter(v => v.id === parentState.value)
if(pageStatus === PageStatus.EDIT) {
state.props['x-component-props'].disabled = true;
}
});
}
})
......@@ -178,7 +207,7 @@ const PriceSetting:React.FC<PriceSettingProps> = (props) => {
dataIndex: 'ctl',
title: '操作',
align: 'center',
render: (_i, _r) => <Button type='link' onClick={() => handleSetProductPrice(_r)}>设置价格</Button>
render: (_i, _r) => <Button disabled={pageStatus === PageStatus.PREVIEW} type='link' onClick={() => handleSetProductPrice(_r)}>设置价格</Button>
})
state.props["x-component-props"].columns = columsUnit
})
......@@ -187,7 +216,9 @@ const PriceSetting:React.FC<PriceSettingProps> = (props) => {
// 填充适用会员table
ctx.setFieldState("commodityMemberList", state => {
memberColumns[memberColumns.length -1].render = (_, _r) => <Button type='link' onClick={() => handleDeleteMemberTable(_r.id)}>删除</Button>
memberColumns[memberColumns.length -1].render = (text, record) => {
return <Button disabled={pageStatus === PageStatus.PREVIEW} type='link' onClick={() => handleDeleteMemberTable(record)}>删除</Button>
}
state.props["x-component-props"].columns = memberColumns
})
}
......
......@@ -42,12 +42,12 @@ const ProductModal:React.FC<ProductModalProps> = (props) => {
const fetchProductList = async (params) => {
const shopId = schemaAction.getFieldValue('shopId')
let shopInfo: any = GlobalConfig.web.shopInfo.filter(item => item.id === shopId)
console.log(shopInfo, 'shopInfo')
const res = await PublicApi.getProductCommodityCommonGetCommodityListBySeller({
const res = await PublicApi.getProductCommodityGetStrategyCommodityList({
...params,
shopType: shopInfo[0]["type"],
type: shopInfo[0]["type"],
environment: shopInfo[0].environment,
priceTypeList: [1, 2],
// priceTypeList: [1, 2],
})
return res.data
}
......@@ -61,7 +61,7 @@ const ProductModal:React.FC<ProductModalProps> = (props) => {
}
schemaAction.setFieldValue('productName', selectResult.name)
schemaAction.setFieldValue('productId', selectResult.commodityId)
schemaAction.setFieldValue('productId', selectResult.id)
}
return (
......@@ -94,7 +94,7 @@ const ProductModal:React.FC<ProductModalProps> = (props) => {
}
}
resetModal={{
destroyOnClose: true
destroyOnClose: true,
}}
tableProps={{
rowKey: 'id',
......
import React, { useState, useEffect, useRef, ReactNode } from 'react'
import { Button, Form, Card, Space} from 'antd'
import React, { useRef } from 'react'
import { Button, Popconfirm, Card, Space} from 'antd'
import { PageHeaderWrapper } from '@ant-design/pro-layout'
import { StandardTable } from 'god'
import { ColumnType } from 'antd/lib/table/interface'
import moment from 'moment'
import { PublicApi } from '@/services/api'
import EyePreview from '@/components/EyePreview'
import NiceForm from '@/components/NiceForm'
......@@ -40,13 +39,13 @@ const PriceManage: React.FC<{}> = () => {
},
{
title: '商品ID',
dataIndex: 'id',
key: 'id',
dataIndex: ["commodity", "id"],
key: 'commodity',
},
{
title: '商品名称',
dataIndex: 'name',
key: 'name',
dataIndex: ["commodity", "name"],
key: "commodity",
},
{
title: '品类',
......@@ -129,7 +128,9 @@ const PriceManage: React.FC<{}> = () => {
return (
<>
<Button type='link' className="padLeft0" onClick={() => handleModify(record)}>修改</Button>
<Button type='link' className="padLeft0" onClick={() => handleDelete(record)}>删除</Button>
<Popconfirm title="确定要执行该操作?" okText="确定" cancelText="取消" onConfirm={() => handleDelete(record)}>
<Button type='link' className="padLeft0">删除</Button>
</Popconfirm>
</>
)
}
......@@ -154,7 +155,13 @@ const PriceManage: React.FC<{}> = () => {
}
const handleDelete = (record: any) => {
PublicApi.postProductCommodityDeleteUnitPriceStrategy({ id: record.id }).then(res => {
if(res.code === 1000) {
setTimeout(() => {
ref.current.reload()
}, 1000)
}
})
}
const controllerBtns = (
......
import React, { useState } from 'react'
import React, { useEffect, useState } from 'react'
import { Button, message, Card, } from 'antd'
import { PageHeaderWrapper } from '@ant-design/pro-layout'
import { history } from "umi"
......@@ -11,6 +11,7 @@ import './index.less'
import { usePageStatus, PageStatus } from '@/hooks/usePageStatus'
import { PublicApi } from '@/services/api'
import { omit } from '@/utils'
import { transformParamsForApi } from '../effect'
const addSchemaAction = createFormActions()
......@@ -23,36 +24,25 @@ const SetStrategy: React.FC<{}> = () => {
const [btnLoading, setBtnLoading] = useState<boolean>(false)
// 整体表单提交
const formSubmit = async (params) => {
console.log(params, '原始参数', addSchemaAction.getFieldState("shopId").dataSource)
const formSubmit = async (values) => {
setBtnLoading(true)
// console.log(values, '原始参数', addSchemaAction.getFieldState("shopId").dataSource)
if(!params['commodityMemberList'] && !params['commodityMemberList']?.length) {
if(!values['commodityMemberList'] && !values['commodityMemberList']?.length) {
message.error('请选择指定适用会员')
} else {
let _params: any = {}
_params["name"] = params.name
_params["priceType"] = params.priceType
_params["shopName"] = addSchemaAction.getFieldState("shopId").dataSource[0]["name"]
_params["commodity"] = { id: params.productId }
_params["commodityMemberList"] = params.commodityMemberList.map(item => ({
memberId: item.memberId,
memberName: item.name,
memberTypeName: item.memberTypeName,
memberRoleId: item.roleId,
memberRoleName: item.roleName,
}))
_params["memberUnitPriceList"] = params.memberUnitPriceList.map(item => ({
commodityUnitPrice: { id: item.id },
unitPrice: item["单价"]
}))
console.log(_params, '传输参数')
const { params } = transformParamsForApi(values, addSchemaAction)
await PublicApi.postProductCommoditySaveOrUpdateUnitPriceStrategy(_params)
let _params = {}
if(id) {
_params["id"] = Number(id)
}
await PublicApi.postProductCommoditySaveOrUpdateUnitPriceStrategy({...params, ..._params})
setTimeout(() => {
setBtnLoading(false)
history.goBack(-1)
}, 1000)
}
......@@ -63,8 +53,7 @@ const SetStrategy: React.FC<{}> = () => {
onBack={() => history.goBack()}
backIcon={<ReutrnEle description="返回" />}
className="setStrategy"
title={pageStatus === PageStatus.PREVIEW ? '查看商品价格策略' : '新建商品价格策略'}
title={pageStatus === PageStatus.PREVIEW ? '查看商品价格策略' : ( pageStatus === PageStatus.ADD ? '新建商品价格策略' : '编辑商品价格策略')}
extra={(
pageStatus !== PageStatus.PREVIEW
? (
......
......@@ -3,6 +3,11 @@ import { FORM_FILTER_PATH } from '@/formSchema/const';
import { GlobalConfig } from '@/global/config';
import { SHOP_TYPE } from '@/constants';
import { PublicApi } from '@/services/api';
import { PageStatus, usePageStatus } from '@/hooks/usePageStatus';
const {
pageStatus
} = usePageStatus()
// 将获取的商城转化为可用类型
const getShopTypeMap = (() => {
......@@ -208,7 +213,10 @@ export const setPriceSchema: ISchema = {
type: 'number',
enum: getShopTypeMap,
title: '适用商城',
required: true
required: true,
"x-component-props": {
disabled: false,
},
},
productName: {
type: 'string',
......
......@@ -6,7 +6,7 @@ import './index.less'
import { PublicApi } from '@/services/api'
export interface InvoiceModalProps {
mode: 'add' | 'edit' | 'preview' | 'default',
mode: 'add' | 'edit' | 'preview' | 'default' | 'delete',
currentRef?: any,
formInitValue?: any,
reload?()
......@@ -48,6 +48,7 @@ const InvoiceModal:React.FC<InvoiceModalProps> = (props) => {
await fn(params)
resetForm()
props.currentRef.current.setVisible(false)
// @tofix bug 添加发票后 重载了列表导致选中失效
props.reload && props.reload()
}
return (
......
import React, { useState, useRef, useEffect, useCallback } from 'react'
import styled from 'styled-components'
import { ISchemaFormProps, ISchemaFieldProps, ISchemaFieldComponentProps, createFormActions, useFieldState, FormEffectHooks, useFormEffects } from '@formily/antd'
import { Button, Space, Row, Col, Tag, Radio } from 'antd'
import { PlusOutlined, DeleteColumnOutlined, EditOutlined, DeleteOutlined, CaretUpOutlined, CaretDownOutlined } from '@ant-design/icons'
import React, { useState, useRef, useMemo } from 'react'
import { ISchemaFieldComponentProps, useFieldState, FormEffectHooks, createFormActions } from '@formily/antd'
import { Button, Radio } from 'antd'
import { PlusOutlined, CaretUpOutlined, CaretDownOutlined } from '@ant-design/icons'
import cx from 'classnames'
import { fetchOrderApi } from '../../apis'
import { PublicApi } from '@/services/api'
import InvoiceModal from '../invoiceModal'
import styles from './index.less'
const { onFieldChange$ } = FormEffectHooks
import { PageStatus, usePageStatus } from '@/hooks/usePageStatus'
const TheInvoiceList = (props: ISchemaFieldComponentProps) => {
const [formInitValue, setFormInitValue] = useState<any>(null)
const [mode, setMode] = useState<'add' | 'edit' | 'default'>('default')
const [mode, setMode] = useState<'add' | 'edit' | 'default' | 'preview' | 'delete'>('default')
const modalRef = useRef<any>({})
let { value, mutators, form, editable } = props
const [state, setFieldState] = useFieldState({
dataSource: [],
showMore: false
showMore: false,
useValue: null
})
const modalRef = useRef<any>({})
const { dataSource, showMore } = state
let { value, mutators, form, editable } = props
let useValue = typeof value === 'object' ? value : dataSource.find(v => v.id === value)
const { dataSource, showMore, useValue } = state
if (!useValue && dataSource.length > 0) {
useValue = dataSource[0]
}
// 载入 默认使用值
if(useValue && JSON.stringify(useValue) !== "{}") {
mutators.change(useValue)
const { pageStatus, id } = usePageStatus()
// const [useValue, setUseValue] = useState(() => typeof value === 'object' ? value : dataSource.find(v => v.id === value))
// let useValue = typeof value === 'object' ? value : dataSource.find(v => v.id === value)
if(pageStatus === PageStatus.ADD) {
if(typeof value === 'object') {
setFieldState({
dataSource,
showMore,
useValue: value
})
}
} else if(pageStatus === PageStatus.EDIT){
// console.log(value, mode, dataSource, 'vvv')
if(typeof value === 'object') {
// console.log('o')
let target = (mode === 'add' || mode === 'delete') ? dataSource[0] : value
setFieldState({
dataSource,
showMore,
useValue: target
})
mutators.change(target)
} else {
let target = dataSource.find(v => v.id === value)
// console.log(target, 'target')
setFieldState({
dataSource,
showMore,
useValue: target
})
mutators.change(target)
}
}
const transformDefaultData = (data: any[]) => {
if (data.length === 0) return data
......@@ -58,26 +88,41 @@ const TheInvoiceList = (props: ISchemaFieldComponentProps) => {
if(!data.length) {
form.setFieldValue("needTheInvoice", 0)
}
setFieldState({
dataSource: data,
showMore
})
// 订单新增 重载全部置为第一个
// console.log(value, '-2')
if(pageStatus === PageStatus.ADD) {
// console.log(value, '-1')
setFieldState({
dataSource: data,
showMore,
useValue: data[0],
})
mutators.change(data[0])
} else if(pageStatus === PageStatus.EDIT) {
setFieldState({
dataSource: data,
showMore,
useValue,
})
}
})
}
const toogleMore = () => {
setFieldState({
dataSource,
showMore: !showMore
showMore: !showMore,
useValue,
})
}
const handleDelete = async (id, e) => {
const handleDelete = async (id, e) => { // 选中当前的删除
e.stopPropagation()
try {
const result = await PublicApi.postSettleAccountsInvoiceMessageDelete({id})
if(result.code === 1000) {
reload()
setMode('delete')
}
} catch (error) {
......@@ -98,6 +143,10 @@ const TheInvoiceList = (props: ISchemaFieldComponentProps) => {
reload()
}
// @tofix bug 添加或删除发票后 useValue Radio默认值是操作的数据 导致无法选中
// console.log(useValue, 'useValue', dataSource, 'dataSource', mode, value, 'value')
return (
<div style={{width: '100%'}} className={styles.invoice}>
{ editable && <Button block onClick={handleAdd} icon={<PlusOutlined/>}>新增发票</Button> }
......@@ -105,7 +154,7 @@ const TheInvoiceList = (props: ISchemaFieldComponentProps) => {
<div className={styles.invoice_list}>
{
showDataSource.map((item, index) => (
<Radio className={styles.list_radio} value={item} key={`address_list_radio_${item.id}`}>
<Radio className={styles.list_radio} value={item} key={`address_list_radio_${item?.id}`}>
<div className={styles.invoice_list_item} key={`invoice_list_item_${index}`}>
<div className={styles.invoice_list_item_content}>
<div className={cx(styles.invoice_list_item_content_tag, item.kind !== 1 ? styles.special : '')}>{item.kind === 1 ? '增值税普通发票' : '增值税专用发票'}</div>
......@@ -119,11 +168,11 @@ const TheInvoiceList = (props: ISchemaFieldComponentProps) => {
</div>
</div>
{
useValue.id === item.id && (
useValue?.id === item?.id && (
editable ?
<div className={styles.invoice_list_item_btn_group}>
<div className={styles.invoice_list_item_btn} onClick={(e) => handleEdit(item, e)}>编辑</div>
<div className={styles.invoice_list_item_btn} onClick={(e) => handleDelete(item.id, e)}>删除</div>
<div className={styles.invoice_list_item_btn} onClick={(e) => handleDelete(item?.id, e)}>删除</div>
</div>
:
<div className={styles.invoice_list_item_btn_group}>
......@@ -143,7 +192,9 @@ const TheInvoiceList = (props: ISchemaFieldComponentProps) => {
显示更多{showMore ? <CaretDownOutlined /> : <CaretUpOutlined/>}
</div>
}
<InvoiceModal mode={mode} formInitValue={formInitValue} currentRef={modalRef} reload={reload}/>
</div>
)
}
......
......@@ -259,8 +259,8 @@ export const useInvoiceList = (ctx: ISchemaFormActions | ISchemaFormAsyncActions
// 查询工作流获取电子合同
export const useElectronicContract = (ctx: ISchemaFormActions | ISchemaFormAsyncActions) => {
let params: any = {};
// 商品数据有commodityId为手动下单 不存在为询价等下单
params['productId'] = ctx.getFieldValue('orderProductRequests')[0]['commodityId'] ? ctx.getFieldValue('orderProductRequests')[0]['id'] : ctx.getFieldValue('orderProductRequests')[0]['productId']
// 通过下单模式 判断是手工还是询需报价
params['productId'] = ctx.getFieldValue("orderModel") === OrderModalType["HAND_ORDER"] ? ctx.getFieldValue('orderProductRequests')[0]['id'] : ctx.getFieldValue('orderProductRequests')[0]['productId']
params['orderModelId'] = ctx.getFieldValue('orderModel')
params['memberId'] = ctx.getFieldValue('supplyMembersId')
params['memberRoleId'] = ctx.getFieldValue('supplyMembersRoleId')
......@@ -281,23 +281,23 @@ export const useElectronicContract = (ctx: ISchemaFormActions | ISchemaFormAsync
}
}
// 编辑订单 地址和发票变动 触发订单更新
// // 编辑订单 地址和发票变动 触发订单更新
export const useOrderUpdateChangeOther = (ctx: ISchemaFormActions | ISchemaFormAsyncActions) => {
const { pageStatus, id } = usePageStatus()
FormEffectHooks.onFieldValueChange$('NO_SUBMIT_TABS.*.*.*(theInvoiceId, needTheInvoice, deliveryAddresId)').subscribe(state => {
FormEffectHooks.onFieldValueChange$('theInvoiceId').subscribe(state => {
const { value, path } = state
if(pageStatus === PageStatus.EDIT){
if(state.loading) {
if(state?.dataSource?.length && state.loading) {
ctx.submit((values) => {
console.log(values, value, path, '发票id')
if(values){
PublicApi.postOrderProcurementOrderUpdate({
...values,
deliveryTime: moment(values.deliveryTime).valueOf(),
theInvoiceId: value.id,
needTheInvoice: Number(values.needTheInvoice),
deliveryAddresId: value.id,
// needTheInvoice: Number(values.needTheInvoice),
deliveryAddresId: values.deliveryAddresId,
id,
}, { ctlType: "none" })
}
......@@ -306,5 +306,52 @@ export const useOrderUpdateChangeOther = (ctx: ISchemaFormActions | ISchemaFormA
ctx.setFieldState(path, _state => _state.loading = true)
}
}
})
})
FormEffectHooks.onFieldValueChange$('deliveryAddresId').subscribe(state => {
const { value, path } = state
if(pageStatus === PageStatus.EDIT){
if(state?.dataSource?.length && state.loading) {
ctx.submit((values) => {
console.log(values, value, path, '发货地址id')
if(values){
PublicApi.postOrderProcurementOrderUpdate({
...values,
deliveryTime: moment(values.deliveryTime).valueOf(),
theInvoiceId: values.theInvoiceId,
// needTheInvoice: Number(values.needTheInvoice),
deliveryAddresId: value?.id ? value.id : value,
id,
}, { ctlType: "none" })
}
})
} else {
ctx.setFieldState(path, _state => _state.loading = true)
}
}
})
// FormEffectHooks.onFieldValueChange$('needTheInvoice').subscribe(state => {
// const { value, path } = state
// if(pageStatus === PageStatus.EDIT){
// if(state?.dataSource?.length && state.loading) {
// ctx.submit((values) => {
// console.log(values, value, path, '是否需要发票')
// if(values){
// // PublicApi.postOrderProcurementOrderUpdate({
// // ...values,
// // deliveryTime: moment(values.deliveryTime).valueOf(),
// // theInvoiceId: value.id,
// // needTheInvoice: Number(values.needTheInvoice),
// // deliveryAddresId: path.indexOf("deliveryAddresId") !== -1 ? ( value?.id ? value.id : value ) : values.deliveryAddresId,
// // id,
// // }, { ctlType: "none" })
// }
// })
// } else {
// ctx.setFieldState(path, _state => _state.loading = true)
// }
// }
// })
}
......@@ -192,6 +192,7 @@ const PurchaseOrderDetail:React.FC<PurchaseOrderDetailProps> = (props) => {
}, [])
const handleSubmit = async (value) => {
// console.log(value, 'value')
let _orderProductRequests = JSON.parse(JSON.stringify(value.orderProductRequests))
let processEnum = value['processEnum']
let usingElectronicContracts = value['usingElectronicContracts']
......@@ -270,7 +271,7 @@ const PurchaseOrderDetail:React.FC<PurchaseOrderDetailProps> = (props) => {
}),
needTheInvoice: Number(value.needTheInvoice),
// 冗余交付信息
deliveryAddresId: value.deliveryAddresId.id,
deliveryAddresId: value.deliveryAddresId.id || value.deliveryAddresId,
...omit(value.deliveryAddresId, ['id']),
// 冗余发票信息
theInvoiceId: value.theInvoiceId ? value.theInvoiceId.id : undefined,
......@@ -544,6 +545,30 @@ const PurchaseOrderDetail:React.FC<PurchaseOrderDetailProps> = (props) => {
//编辑 地址和发票信息变动 触发订单更新
useOrderUpdateChangeOther(ctx)
// address初始下只有id change后为object
// $('onFieldValueChange', 'NO_SUBMIT_TABS.*.*.*(theInvoiceId, needTheInvoice, deliveryAddresId)').subscribe(state => {
// const { value, path } = state
// if(pageStatus === PageStatus.EDIT){
// if(state?.dataSource?.length && state.loading) {
// ctx.submit((values) => {
// console.log(value, path)
// if(values){
// PublicApi.postOrderProcurementOrderUpdate({
// ...values,
// deliveryTime: moment(values.deliveryTime).valueOf(),
// theInvoiceId: value.id,
// needTheInvoice: Number(values.needTheInvoice),
// deliveryAddresId: path.indexOf("deliveryAddresId") !== -1 ? ( value?.id ? value.id : value ) : values.deliveryAddresId,
// id,
// }, { ctlType: "none" })
// }
// })
// } else {
// ctx.setFieldState(path, _state => _state.loading = true)
// }
// }
// })
}}
expressionScope={{
orderNoPrice,
......
......@@ -5,6 +5,7 @@ import { productInfoColumns } from '../constant';
import ProductTableCell, { ProductEditableRow } from '../components/productTableCell';
import { useModalTable } from './useModalTable';
import { usePageStatus, PageStatus } from '@/hooks/usePageStatus';
import { OrderModalType } from '@/constants';
// 对象按key排序(运用于商城传过来的阶梯价格排序)
export const sortByKey = (params) => {
......@@ -122,8 +123,8 @@ export const useProductTable = (ctx: ISchemaFormActions | ISchemaFormAsyncAction
const index = newData.findIndex(item => row.id === item.id);
const item = newData[index];
row['money'] = getUnitPriceTotal(row)
// 新增的时候接口字段id,commodityId 编辑的时候id,productId
row['productId'] = row?.commodityId ? row.id : row.productId
// 通过下单模式判断 是否是询需报价下单
row['productId'] = ctx.getFieldValue("orderModel") === OrderModalType["HAND_ORDER"] ? row.id : row.productId
newData.splice(index, 1, {
...item,
...row,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment