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

fix:处理仓位中获取仓位货品数量异常,处理采购询价下单删除商品运费变动异常和支付比例不为0的问题

parent b93d4c2d
import React, {useState, useEffect, useRef} from 'react'
import { usePageStatus, PageStatus } from '@/hooks/usePageStatus'
import { useInitValue } from '@/formSchema/effects/useInitValue'
import EyePreview from '@/components/EyePreview'
import { findItemAndDelete } from '@/utils'
import { ISchemaFormActions, ISchema, FormEffectHooks, createAsyncFormActions } from '@formily/antd'
import { useRowSelectionTable } from '@/hooks/useRowSelectionTable'
import { createAddRepositoryEffect, useUnitPreview } from '../effects'
import { PublicApi } from '@/services/api'
import {
PlusOutlined,
LinkOutlined,
} from '@ant-design/icons'
import { Button, message, Select } from 'antd'
import NiceForm from '@/components/NiceForm'
import ModalTable from '@/components/ModalTable'
import { GlobalConfig } from '@/global/config'
import { FORM_FILTER_PATH } from '@/formSchema/const'
import SearchSelect from '@/components/NiceForm/components/SearchSelect'
import Search from '@/components/NiceForm/components/Search'
import { useStateFilterSearchLinkageEffect } from '@/formSchema/effects/useFilterSearch'
import Submit from '@/components/NiceForm/components/Submit'
import { SHOP_TYPES, MALL_TYPE } from '@/constants';
import { useAsyncInitSelect } from '@/formSchema/effects/useAsyncInitSelect';
export interface PositionSettingProps {
addSchemaAction: ISchemaFormActions,
schema: ISchema,
onFieldChange?(),
formSubmit?(values)
}
const priceTypeMaps = {
[MALL_TYPE[0]]: [1,2],
[MALL_TYPE[1]]: [3],
[MALL_TYPE[2]]: [1],
[MALL_TYPE[3]]: [1],
[MALL_TYPE[4]]: [3]
}
const all = [{
label: '所有',
value: 0
}];
const transferLabelToValue = (list: any[], label: string, value: string) => {
return list.map((item) => {
return {
label: item[label],
value: item[value]
}
})
}
const BUSINESS_INTEGRATE = [1, 2]; // 企业商城, 积分商城
const CANAL = [3, 4, 5]; // 渠道商城
const PositionSetting:React.FC<PositionSettingProps> = (props) => {
const { addSchemaAction, schema, formSubmit, onFieldChange = () => {} } = props
const [visibleChannelMember, setVisibleChannelMember] = useState(false)
const [visibleChannelRroduct, setVisibleChannelRroduct] = useState(false)
const [memberRowSelection, memberRowCtl] = useRowSelectionTable({ customKey: 'memberId' })
const [productRowSelection, productRowCtl] = useRowSelectionTable({type: 'radio'})
const {
id,
preview,
pageStatus
} = usePageStatus()
// const initValue = useInitValue(PublicApi.getWarehouseFreightSpaceDetails)
const [shopTypeState, setShopType] = useState(0);
const [productState, setProductState] = useState<any>({})
const [membersFilterState, setMemberFilter] = useState({level: [], role: [], type: []});
const [initValue, setInitialValue] = useState({});
const [membersLength, setMembersLength] = useState(0);
// const [channelMemberState, setChannelMemberState] = useState({channelMemberRoleId: '', channelMemberIdList: []})
// useUnitPreview(initValue, addSchemaAction)
useEffect(() => {
// 拿到所有的角色等级, 根据shopType, 商品的类容重新拿
async function getMemberLevel() {
const response = await PublicApi.getMemberManagePageitems({roleTypeEnum: '2'});
const { levels = [], memberTypes = [], roles = [] } = response.data;
const allLevels = all.concat(transferLabelToValue(levels, "levelTag", "level"));
const allMemberTypes = all.concat(transferLabelToValue(memberTypes, "memberTypeName", "memberTypeId"))
const allRoles = all.concat(transferLabelToValue(roles, "roleName", "roleId"))
setMemberFilter((state) => {
return {
...state,
level: allLevels,
role: allRoles,
type: allMemberTypes
}
})
}
if(preview !== '1') {
getMemberLevel();
}
}, []);
useEffect(() => {
async function getInitValue() {
const { data } = await PublicApi.getWarehouseFreightSpaceDetails({id: id});
if(data.isAllMemberShare === 0) {
const res = await getBindingMember({id: id.toString(), current: '1', pageSize: '10'});
setInitialValue({...data, applyMember: res.data});
} else {
setInitialValue(data)
}
}
if(id != '') {
getInitValue();
}
}, [id])
// 拿到绑定会员
const getBindingMember = async ({id = '1', current = '1', pageSize = '10'}) => {
const res = await PublicApi.getWarehouseFreightSpaceMamberList({id, current, pageSize});
return res.data
}
const fetchProductList = async (params) => {
const shopType = addSchemaAction.getFieldValue('shopType')
const res = await PublicApi.getProductCommodityCommonGetCommodityListByStock({
...params,
shopType,
environment: 1,
// 根据商城类型手动传输定价类型
priceTypeList: priceTypeMaps[shopType] ? priceTypeMaps[shopType] : undefined
})
return res.data
}
// 会员选择后的表格
const handleDeleteTable = (id) => {
const value = addSchemaAction.getFieldValue('applyMember')
const res = value.filter((item) => item.memberId != id);
addSchemaAction.setFieldValue('applyMember', res)
}
const handleAddMemberBtn = () => {
const shopType = addSchemaAction.getFieldValue('shopType');
const itemNo = addSchemaAction.getFieldValue('productId');
if (!shopType) {
message.error('请先选择商城类型');
return;
}
if(CANAL.includes(shopType) && !itemNo) {
message.error('请先选择商品');
return;
}
const checkBoxs = addSchemaAction.getFieldValue('applyMember')
memberRowCtl.setSelectedRowKeys(checkBoxs.map(v => v.memberId))
memberRowCtl.setSelectRow(checkBoxs)
setVisibleChannelMember(true)
}
// 弹出商品选择
const handleAddProductBtn = () => {
const shopType = addSchemaAction.getFieldValue('shopType')
if (!shopType) {
message.error('请先选择商城类型')
return false
}
// fix: 选中后无法回显
// productRowCtl.setSelectedRowKeys([])
// productRowCtl.setSelectRow([])
setVisibleChannelRroduct(true)
}
// 新增会员
const tableAddButton =
preview !== '1'
? <Button style={{marginBottom: 16}} block icon={<PlusOutlined/>} onClick={handleAddMemberBtn} type='dashed'>选择指定会员</Button>
: null
const tableColumns = [
{ dataIndex: 'memberId', title: 'ID', align: 'center' },
{ dataIndex: 'name', align: 'center', title: '会员名称' },
{ dataIndex: 'memberTypeName', title: '会员类型', align: 'center' },
{ dataIndex: 'ctl', title: '操作', align: 'center', render: (_, record) => <Button type='link' onClick={() => handleDeleteTable(record.memberId)}>删除</Button> }
]
const connectProduct = pageStatus !== PageStatus.PREVIEW && <div className='connectBtn' onClick={handleAddProductBtn}><LinkOutlined style={{marginRight: 4}}/>选择</div>
// 仓位设置表单提交
const handleSubmit = async (values) => {
formSubmit && formSubmit(values)
}
// 会员添加弹窗控制
const handleOkAddMember = () => {
setVisibleChannelMember(false)
setMembersLength(memberRowCtl.selectRow.length);
addSchemaAction.setFieldValue('applyMember', memberRowCtl.selectRow)
}
const handleCancelAddMember = () => {
setVisibleChannelMember(false)
}
// 商品添加弹窗控制
const handleOkAddProduct = async () => {
setVisibleChannelRroduct(false)
const selectResult = productRowCtl.selectRow[0]
if (!selectResult) {
return null
}
const goodsId = selectResult.goodsId
setProductState(selectResult)
addSchemaAction.setFieldValue('productName', selectResult.name)
addSchemaAction.setFieldValue('category', selectResult.customerCategoryName)
addSchemaAction.setFieldValue('brand', selectResult.brandName)
addSchemaAction.setFieldValue('unit', selectResult.unitName)
addSchemaAction.setFieldValue('productId', selectResult.id)
addSchemaAction.setFieldState('inventory', state => {
state.props["x-props"] = {
addonAfter: <div style={{marginLeft: 4}}>{selectResult.unitName}</div>
}
})
// 商品有可能没有货品, 没有货品时不请求
if (goodsId) {
// 查询到的货品id
const { data } = await PublicApi.getProductGoodsGetGoods({
id: goodsId
})
// 设置货品名称
addSchemaAction.setFieldValue('goodsName', data?.name || '')
addSchemaAction.setFieldValue('goodsId', goodsId)
addSchemaAction.setFieldValue('itemNo', data?.code || '')
}
}
const fetchMemberList = async (params) => {
const shopType = addSchemaAction.getFieldValue('shopType');
// 当商城类型为 渠道商城、渠道自由商城和渠道积分商城时,需要带上下面两个参数
const { members } = productState;
const data = {
...params,
shopType: shopType,
members: members
}
const res = await PublicApi.postMemberManageAllPageByshoptype(data, {ctlType: 'none'});
return res.data
}
const handleCancelAddProduct = () => {
setVisibleChannelRroduct(false)
}
const columnsSetMember: any[] = [
{
title: 'ID',
dataIndex: 'memberId',
align: 'center',
key: 'memberId',
},
{
title: '会员名称',
dataIndex: 'name',
align: 'center',
key: 'name',
},
{
title: '会员类型',
dataIndex: 'memberTypeName',
align: 'center',
key: 'memberTypeName',
},
{
title: '会员角色',
dataIndex: 'roleName',
align: 'center',
key: 'roleName',
},
{
title: '会员等级',
dataIndex: 'levelTag',
align: 'center',
key: 'levelTag',
}
]
const columnsSetProduct: any[] = [
{
title: '商品ID',
dataIndex: 'id',
align: 'center',
key: 'id',
},
{
title: '商品名称',
dataIndex: 'name',
align: 'center',
key: 'name',
width: 210,
ellipsis: true,
},
{
title: '品类',
dataIndex: 'customerCategoryName',
align: 'center',
key: 'customerCategoryName',
},
{
title: '品牌',
dataIndex: 'brandName',
align: 'center',
key: 'brandName',
},
{
title: '单位',
dataIndex: 'unitName',
align: 'center',
key: 'unitName',
},
]
const formSearch: ISchema = {
type: 'object',
properties: {
name: {
type: 'string',
'x-component': 'ModalSearch',
'x-component-props': {
placeholder: '请输入会员名字',
align: 'flex-left',
},
},
[FORM_FILTER_PATH]: {
type: 'object',
'x-component': 'flex-layout',
'x-component-props': {
rowStyle: {
flexWrap: 'nowrap',
style: {
marginRight: 0
}
},
colStyle: {
marginTop: 20,
},
},
properties: {
memberTypeId: {
type: 'string',
"x-component": 'Select',
"x-component-props": {
options: membersFilterState.type,
style: {width: '180px'},
placeholder: '请选择会员类型'
}
},
level: {
type: 'string',
"x-component": 'Select',
"x-component-props": {
options: membersFilterState.level,
style: {width: '180px'},
placeholder: '请选择会员等级'
}
},
roleId: {
type: 'string',
"x-component": 'Select',
"x-component-props": {
options: membersFilterState.role,
style: {width: '180px'},
placeholder: '请选择会员角色'
}
},
submit: {
"x-component": 'Submit',
"x-mega-props": {
span: 1
},
"x-component-props": {
children: '查询'
}
}
}
}
}
}
const formProduct: ISchema = {
type: 'object',
properties: {
name: {
type: 'string',
'x-component': 'ModalSearch',
'x-component-props': {
placeholder: '请输入商品名称',
align: 'flex-left',
},
},
[FORM_FILTER_PATH]: {
type: 'object',
'x-component': 'flex-layout',
'x-component-props': {
rowStyle: {
flexWrap: 'nowrap',
style: {
marginRight: 0
}
},
colStyle: {
marginTop: 20,
},
},
properties: {
customerCategoryId: {
type: 'string',
"x-component": 'SearchSelect',
"x-component-props": {
placeholder: '请选择品类',
className: 'fixed-ant-selected-down', // 该类强制将显示的下拉框出现在select下, 只有这里出现问题, ??
fetchSearch: PublicApi.getProductSelectGetSelectCustomerCategory,
style: {
width: 160
}
}
},
brandId: {
type: 'string',
"x-component": 'SearchSelect',
"x-component-props": {
placeholder: '请选择品牌',
fetchSearch: PublicApi.getProductSelectGetSelectBrand,
style: {
width: 160
}
}
},
submit: {
"x-component": 'Submit',
"x-mega-props": {
span: 1
},
"x-component-props": {
children: '查询'
}
}
}
}
}
}
const paginationChange = async (page: number, size: number) => {
if(id !== '') {
const result = await getBindingMember({id, current: page.toString(), pageSize: size.toString()});
addSchemaAction.setFieldValue('applyMember', result.data);
}
}
return (
<>
<NiceForm
previewPlaceholder=' '
editable={pageStatus !== PageStatus.PREVIEW}
value={initValue}
expressionScope={{
tableColumns,
tableAddButton,
connectProduct,
paginationChange,
membersLength
}}
effects={($, { setFieldState }) => {
FormEffectHooks.onFormInputChange$().subscribe(() => {
onFieldChange()
})
createAddRepositoryEffect(addSchemaAction)
$('onFieldValueChange', 'shopType').subscribe(parentState => {
if (parentState.value) {
console.log('review')
setFieldState('shopIds', state => {
state.props["x-component-props"].dataSource = pageStatus === PageStatus.PREVIEW ?
GlobalConfig.web.shopInfo.filter(v => v.type === parentState.value && state.value.includes(v.id))
:
GlobalConfig.web.shopInfo.filter(v => v.type === parentState.value)
});
// 切换商城的时候,指定的会员需要重置
setShopType((prev) => {
if(
(BUSINESS_INTEGRATE.includes(prev) && CANAL.includes(parentState.value))
|| (CANAL.includes(prev) && BUSINESS_INTEGRATE.includes(parentState.value))
) {
setFieldState('applyMember', (state) => {
console.log("applyMember")
state.value = []
})
}
return parentState.value
});
// 商城类型修改的时候,就清空商品
if(!id) {
addSchemaAction.setFieldValue('productId', "");
addSchemaAction.setFieldValue('productName', "");
}
}
})
// FormEffectHooks.
}}
onSubmit={handleSubmit}
actions={addSchemaAction}
schema={schema}
/>
<ModalTable
modalTitle='选择会员'
confirm={handleOkAddMember}
cancel={handleCancelAddMember}
visible={visibleChannelMember}
columns={columnsSetMember}
rowSelection={memberRowSelection}
fetchTableData={params => fetchMemberList(params)}
formilyProps={
{
ctx: {
schema: formSearch,
components: { ModalSearch: Search, SearchSelect, Submit, Select } ,
effects: ($, actions) => {
actions.reset()
useStateFilterSearchLinkageEffect(
$,
actions,
'name',
FORM_FILTER_PATH,
);
}
}
}
}
resetModal={{
destroyOnClose: true
}}
tableProps={{
rowKey: 'memberId'
}}
/>
<ModalTable
modalTitle='选择商品'
confirm={handleOkAddProduct}
cancel={handleCancelAddProduct}
visible={visibleChannelRroduct}
columns={columnsSetProduct}
rowSelection={productRowSelection}
fetchTableData={params => fetchProductList(params)}
formilyProps={
{
ctx: {
schema: formProduct,
components: { ModalSearch: Search, SearchSelect, Submit } ,
effects: ($, actions) => {
actions.reset()
useStateFilterSearchLinkageEffect(
$,
actions,
'name',
FORM_FILTER_PATH,
);
}
}
}
}
resetModal={{
destroyOnClose: true
}}
tableProps={{
rowKey: 'id',
onRow: (record) => ({
onClick: () => {
productRowCtl.setSelectRow([record]);
productRowCtl.setSelectedRowKeys([record.id]);
},
})
}}
/>
</>
)
}
PositionSetting.defaultProps = {}
export default PositionSetting
\ No newline at end of file
import React, {useState, useEffect, useRef} from 'react'
import { usePageStatus, PageStatus } from '@/hooks/usePageStatus'
import { useInitValue } from '@/formSchema/effects/useInitValue'
import EyePreview from '@/components/EyePreview'
import { findItemAndDelete } from '@/utils'
import { ISchemaFormActions, ISchema, FormEffectHooks, createAsyncFormActions } from '@formily/antd'
import { useRowSelectionTable } from '@/hooks/useRowSelectionTable'
import { createAddRepositoryEffect, useUnitPreview } from '../effects'
import { PublicApi } from '@/services/api'
import {
PlusOutlined,
LinkOutlined,
} from '@ant-design/icons'
import { Button, message, Select } from 'antd'
import NiceForm from '@/components/NiceForm'
import ModalTable from '@/components/ModalTable'
import { GlobalConfig } from '@/global/config'
import { FORM_FILTER_PATH } from '@/formSchema/const'
import SearchSelect from '@/components/NiceForm/components/SearchSelect'
import Search from '@/components/NiceForm/components/Search'
import { useStateFilterSearchLinkageEffect } from '@/formSchema/effects/useFilterSearch'
import Submit from '@/components/NiceForm/components/Submit'
import { SHOP_TYPES, MALL_TYPE } from '@/constants';
import { useAsyncInitSelect } from '@/formSchema/effects/useAsyncInitSelect';
export interface PositionSettingProps {
addSchemaAction: ISchemaFormActions,
schema: ISchema,
onFieldChange?(),
formSubmit?(values)
}
const priceTypeMaps = {
[MALL_TYPE[0]]: [1,2],
[MALL_TYPE[1]]: [3],
[MALL_TYPE[2]]: [1],
[MALL_TYPE[3]]: [1],
[MALL_TYPE[4]]: [3]
}
const all = [{
label: '所有',
value: 0
}];
const transferLabelToValue = (list: any[], label: string, value: string) => {
return list.map((item) => {
return {
label: item[label],
value: item[value]
}
})
}
const BUSINESS_INTEGRATE = [1, 2]; // 企业商城, 积分商城
const CANAL = [3, 4, 5]; // 渠道商城
const PositionSetting:React.FC<PositionSettingProps> = (props) => {
const { addSchemaAction, schema, formSubmit, onFieldChange = () => {} } = props
const [visibleChannelMember, setVisibleChannelMember] = useState(false)
const [visibleChannelRroduct, setVisibleChannelRroduct] = useState(false)
const [memberRowSelection, memberRowCtl] = useRowSelectionTable({ customKey: 'memberId' })
const [productRowSelection, productRowCtl] = useRowSelectionTable({type: 'radio'})
const {
id,
preview,
pageStatus
} = usePageStatus()
// const initValue = useInitValue(PublicApi.getWarehouseFreightSpaceDetails)
const [shopTypeState, setShopType] = useState(0);
const [productState, setProductState] = useState<any>({})
const [membersFilterState, setMemberFilter] = useState({level: [], role: [], type: []});
const [initValue, setInitialValue] = useState({});
const [membersLength, setMembersLength] = useState(0);
// const [channelMemberState, setChannelMemberState] = useState({channelMemberRoleId: '', channelMemberIdList: []})
// useUnitPreview(initValue, addSchemaAction)
useEffect(() => {
// 拿到所有的角色等级, 根据shopType, 商品的类容重新拿
async function getMemberLevel() {
const response = await PublicApi.getMemberManagePageitems({roleTypeEnum: '2'});
const { levels = [], memberTypes = [], roles = [] } = response.data;
const allLevels = all.concat(transferLabelToValue(levels, "levelTag", "level"));
const allMemberTypes = all.concat(transferLabelToValue(memberTypes, "memberTypeName", "memberTypeId"))
const allRoles = all.concat(transferLabelToValue(roles, "roleName", "roleId"))
setMemberFilter((state) => {
return {
...state,
level: allLevels,
role: allRoles,
type: allMemberTypes
}
})
}
if(preview !== '1') {
getMemberLevel();
}
}, []);
useEffect(() => {
async function getInitValue() {
const { data } = await PublicApi.getWarehouseFreightSpaceDetails({id: id});
if(data.isAllMemberShare === 0) {
const res = await getBindingMember({id: id.toString(), current: '1', pageSize: '10'});
setInitialValue({...data, applyMember: res.data});
} else {
setInitialValue(data)
}
}
if(id != '') {
getInitValue();
}
}, [id])
// 拿到绑定会员
const getBindingMember = async ({id = '1', current = '1', pageSize = '10'}) => {
const res = await PublicApi.getWarehouseFreightSpaceMamberList({id, current, pageSize});
return res.data
}
const fetchProductList = async (params) => {
const shopType = addSchemaAction.getFieldValue('shopType')
const res = await PublicApi.getProductCommodityCommonGetCommodityListByStock({
...params,
shopType,
environment: 1,
// 根据商城类型手动传输定价类型
priceTypeList: priceTypeMaps[shopType] ? priceTypeMaps[shopType] : undefined
})
return res.data
}
// 会员选择后的表格
const handleDeleteTable = (id) => {
const value = addSchemaAction.getFieldValue('applyMember')
const res = value.filter((item) => item.memberId != id);
addSchemaAction.setFieldValue('applyMember', res)
}
const handleAddMemberBtn = () => {
const shopType = addSchemaAction.getFieldValue('shopType');
const itemNo = addSchemaAction.getFieldValue('productId');
if (!shopType) {
message.error('请先选择商城类型');
return;
}
if(CANAL.includes(shopType) && !itemNo) {
message.error('请先选择商品');
return;
}
const checkBoxs = addSchemaAction.getFieldValue('applyMember')
memberRowCtl.setSelectedRowKeys(checkBoxs.map(v => v.memberId))
memberRowCtl.setSelectRow(checkBoxs)
setVisibleChannelMember(true)
}
// 弹出商品选择
const handleAddProductBtn = () => {
const shopType = addSchemaAction.getFieldValue('shopType')
if (!shopType) {
message.error('请先选择商城类型')
return false
}
// fix: 选中后无法回显
// productRowCtl.setSelectedRowKeys([])
// productRowCtl.setSelectRow([])
setVisibleChannelRroduct(true)
}
// 新增会员
const tableAddButton =
preview !== '1'
? <Button style={{marginBottom: 16}} block icon={<PlusOutlined/>} onClick={handleAddMemberBtn} type='dashed'>选择指定会员</Button>
: null
const tableColumns = [
{ dataIndex: 'memberId', title: 'ID', align: 'center' },
{ dataIndex: 'name', align: 'center', title: '会员名称' },
{ dataIndex: 'memberTypeName', title: '会员类型', align: 'center' },
{ dataIndex: 'ctl', title: '操作', align: 'center', render: (_, record) => <Button type='link' onClick={() => handleDeleteTable(record.memberId)}>删除</Button> }
]
const connectProduct = pageStatus !== PageStatus.PREVIEW && <div className='connectBtn' onClick={handleAddProductBtn}><LinkOutlined style={{marginRight: 4}}/>选择</div>
// 仓位设置表单提交
const handleSubmit = async (values) => {
formSubmit && formSubmit(values)
}
// 会员添加弹窗控制
const handleOkAddMember = () => {
setVisibleChannelMember(false)
setMembersLength(memberRowCtl.selectRow.length);
addSchemaAction.setFieldValue('applyMember', memberRowCtl.selectRow)
}
const handleCancelAddMember = () => {
setVisibleChannelMember(false)
}
// 商品添加弹窗控制
const handleOkAddProduct = async () => {
setVisibleChannelRroduct(false)
const selectResult = productRowCtl.selectRow[0]
if (!selectResult) {
return null
}
const goodsId = selectResult.goodsId
setProductState(selectResult)
addSchemaAction.setFieldValue('productName', selectResult.name)
addSchemaAction.setFieldValue('category', selectResult.customerCategoryName)
addSchemaAction.setFieldValue('brand', selectResult.brandName)
addSchemaAction.setFieldValue('unit', selectResult.unitName)
addSchemaAction.setFieldValue('productId', selectResult.id)
addSchemaAction.setFieldState('inventory', state => {
state.props["x-props"] = {
addonAfter: <div style={{marginLeft: 4}}>{selectResult.unitName}</div>
}
})
// 商品有可能没有货品, 没有货品时不请求
if (goodsId) {
// 查询到的货品id
const { data } = await PublicApi.getProductGoodsGetGoods({
id: goodsId
})
// 设置货品名称
addSchemaAction.setFieldValue('goodsName', data?.name || '')
addSchemaAction.setFieldValue('goodsId', goodsId)
addSchemaAction.setFieldValue('itemNo', data?.code || '')
}
}
const fetchMemberList = async (params) => {
const shopType = addSchemaAction.getFieldValue('shopType');
// 当商城类型为 渠道商城、渠道自由商城和渠道积分商城时,需要带上下面两个参数
const { members } = productState;
const data = {
...params,
shopType: shopType,
members: members
}
const res = await PublicApi.postMemberManageAllPageByshoptype(data, {ctlType: 'none'});
return res.data
}
const handleCancelAddProduct = () => {
setVisibleChannelRroduct(false)
}
const columnsSetMember: any[] = [
{
title: 'ID',
dataIndex: 'memberId',
align: 'center',
key: 'memberId',
},
{
title: '会员名称',
dataIndex: 'name',
align: 'center',
key: 'name',
},
{
title: '会员类型',
dataIndex: 'memberTypeName',
align: 'center',
key: 'memberTypeName',
},
{
title: '会员角色',
dataIndex: 'roleName',
align: 'center',
key: 'roleName',
},
{
title: '会员等级',
dataIndex: 'levelTag',
align: 'center',
key: 'levelTag',
}
]
const columnsSetProduct: any[] = [
{
title: '商品ID',
dataIndex: 'id',
align: 'center',
key: 'id',
},
{
title: '商品名称',
dataIndex: 'name',
align: 'center',
key: 'name',
width: 210,
ellipsis: true,
},
{
title: '品类',
dataIndex: 'customerCategoryName',
align: 'center',
key: 'customerCategoryName',
},
{
title: '品牌',
dataIndex: 'brandName',
align: 'center',
key: 'brandName',
},
{
title: '单位',
dataIndex: 'unitName',
align: 'center',
key: 'unitName',
},
]
const formSearch: ISchema = {
type: 'object',
properties: {
name: {
type: 'string',
'x-component': 'ModalSearch',
'x-component-props': {
placeholder: '请输入会员名字',
align: 'flex-left',
},
},
[FORM_FILTER_PATH]: {
type: 'object',
'x-component': 'flex-layout',
'x-component-props': {
rowStyle: {
flexWrap: 'nowrap',
style: {
marginRight: 0
}
},
colStyle: {
marginTop: 20,
},
},
properties: {
memberTypeId: {
type: 'string',
"x-component": 'Select',
"x-component-props": {
options: membersFilterState.type,
style: {width: '180px'},
placeholder: '请选择会员类型'
}
},
level: {
type: 'string',
"x-component": 'Select',
"x-component-props": {
options: membersFilterState.level,
style: {width: '180px'},
placeholder: '请选择会员等级'
}
},
roleId: {
type: 'string',
"x-component": 'Select',
"x-component-props": {
options: membersFilterState.role,
style: {width: '180px'},
placeholder: '请选择会员角色'
}
},
submit: {
"x-component": 'Submit',
"x-mega-props": {
span: 1
},
"x-component-props": {
children: '查询'
}
}
}
}
}
}
const formProduct: ISchema = {
type: 'object',
properties: {
name: {
type: 'string',
'x-component': 'ModalSearch',
'x-component-props': {
placeholder: '请输入商品名称',
align: 'flex-left',
},
},
[FORM_FILTER_PATH]: {
type: 'object',
'x-component': 'flex-layout',
'x-component-props': {
rowStyle: {
flexWrap: 'nowrap',
style: {
marginRight: 0
}
},
colStyle: {
marginTop: 20,
},
},
properties: {
customerCategoryId: {
type: 'string',
"x-component": 'SearchSelect',
"x-component-props": {
placeholder: '请选择品类',
className: 'fixed-ant-selected-down', // 该类强制将显示的下拉框出现在select下, 只有这里出现问题, ??
fetchSearch: PublicApi.getProductSelectGetSelectCustomerCategory,
style: {
width: 160
}
}
},
brandId: {
type: 'string',
"x-component": 'SearchSelect',
"x-component-props": {
placeholder: '请选择品牌',
fetchSearch: PublicApi.getProductSelectGetSelectBrand,
style: {
width: 160
}
}
},
submit: {
"x-component": 'Submit',
"x-mega-props": {
span: 1
},
"x-component-props": {
children: '查询'
}
}
}
}
}
}
const paginationChange = async (page: number, size: number) => {
if(id !== '') {
const result = await getBindingMember({id, current: page.toString(), pageSize: size.toString()});
addSchemaAction.setFieldValue('applyMember', result.data);
}
}
return (
<>
<NiceForm
previewPlaceholder=' '
editable={pageStatus !== PageStatus.PREVIEW}
value={initValue}
expressionScope={{
tableColumns,
tableAddButton,
connectProduct,
paginationChange,
membersLength
}}
effects={($, { setFieldState }) => {
FormEffectHooks.onFormInputChange$().subscribe(() => {
onFieldChange()
})
createAddRepositoryEffect(addSchemaAction)
$('onFieldValueChange', 'shopType').subscribe(parentState => {
if (parentState.value) {
console.log('review')
setFieldState('shopIds', state => {
state.props["x-component-props"].dataSource = pageStatus === PageStatus.PREVIEW ?
GlobalConfig.web.shopInfo.filter(v => v.type === parentState.value && state.value.includes(v.id))
:
GlobalConfig.web.shopInfo.filter(v => v.type === parentState.value)
});
// 切换商城的时候,指定的会员需要重置
setShopType((prev) => {
if(
(BUSINESS_INTEGRATE.includes(prev) && CANAL.includes(parentState.value))
|| (CANAL.includes(prev) && BUSINESS_INTEGRATE.includes(parentState.value))
) {
setFieldState('applyMember', (state) => {
console.log("applyMember")
state.value = []
})
}
return parentState.value
});
// 商城类型修改的时候,就清空商品
if(!id) {
addSchemaAction.setFieldValue('productId', "");
addSchemaAction.setFieldValue('productName', "");
}
}
})
// FormEffectHooks.
}}
onSubmit={handleSubmit}
actions={addSchemaAction}
schema={schema}
/>
<ModalTable
modalTitle='选择会员'
confirm={handleOkAddMember}
cancel={handleCancelAddMember}
visible={visibleChannelMember}
columns={columnsSetMember}
rowSelection={memberRowSelection}
fetchTableData={params => fetchMemberList(params)}
formilyProps={
{
ctx: {
schema: formSearch,
components: { ModalSearch: Search, SearchSelect, Submit, Select } ,
effects: ($, actions) => {
actions.reset()
useStateFilterSearchLinkageEffect(
$,
actions,
'name',
FORM_FILTER_PATH,
);
}
}
}
}
resetModal={{
destroyOnClose: true
}}
tableProps={{
rowKey: 'memberId'
}}
/>
<ModalTable
modalTitle='选择商品'
confirm={handleOkAddProduct}
cancel={handleCancelAddProduct}
visible={visibleChannelRroduct}
columns={columnsSetProduct}
rowSelection={productRowSelection}
fetchTableData={params => fetchProductList(params)}
formilyProps={
{
ctx: {
schema: formProduct,
components: { ModalSearch: Search, SearchSelect, Submit } ,
effects: ($, actions) => {
actions.reset()
useStateFilterSearchLinkageEffect(
$,
actions,
'name',
FORM_FILTER_PATH,
);
}
}
}
}
resetModal={{
destroyOnClose: true
}}
tableProps={{
rowKey: 'id',
onRow: (record) => ({
onClick: () => {
productRowCtl.setSelectRow([record]);
productRowCtl.setSelectedRowKeys([record.id]);
},
})
}}
/>
</>
)
}
PositionSetting.defaultProps = {}
export default PositionSetting
import React, { useEffect } from 'react'
import { ISchemaFormActions, FormEffectHooks, IFormActions } from '@formily/antd';
import { PublicApi } from '@/services/api';
import { useAsyncSelect } from '@/formSchema/effects/useAsyncSelect';
const { onFieldValueChange$ } = FormEffectHooks
export const useWarehouseSelect = (context: ISchemaFormActions) => {
onFieldValueChange$('warehouseId').subscribe(state => {
// 货品ID
const goodsId = context.getFieldValue('productId')
const warehouseId = state.value
PublicApi.getWarehouseInventoryByItemNo({
warehouseId,
itemId: goodsId
}).then(res => {
const { data } = res
context.setFieldValue('NO_SUBMIT3', data.inventory)
})
})
}
export const createAddRepositoryEffect = (context: ISchemaFormActions) => {
const fetchWarehouseAll = async () => {
const { data } = await PublicApi.getWarehouseWarehouseAll()
context.setFieldState('warehouseId', state => {
state.warehouseLists = data
})
return data.map(v => ({
value: v.id,
label: v.name
}))
}
useAsyncSelect('warehouseId', fetchWarehouseAll)
useWarehouseSelect(context)
}
export const useUnitPreview = (initValue, context) => {
useEffect(() => {
if (initValue) {
context.setFieldState('inventory', state => {
if (!state.props['x-props']) {
state.props['x-props'] = {}
}
state.props['x-props'].addonAfter = <div style={{marginLeft: 4}}>{initValue.unit}</div>
})
context.setFieldValue('itemNo', initValue.itemNo)
}
}, [initValue])
}
// 高级筛选schema中用于输入搜索品牌的Effect
export const searchBrandOptionEffect = (context: any, fieldName: string) => {
context.getFieldState(fieldName, state => {
PublicApi.getProductSelectGetSelectBrand({ name: state.props['x-component-props'].searchValue }).then(res => {
context.setFieldState(fieldName, state => {
state.props['x-component-props'].dataoption = res.data
})
})
})
}
// 高级筛选schema中用于输入搜索商品品类的Effect
export const searchCustomerCategoryOptionEffect = (context: any, fieldName: string) => {
context.getFieldState(fieldName, state => {
PublicApi.getProductSelectGetSelectCustomerCategory({ name: state.props['x-component-props'].searchValue }).then(res => {
context.setFieldState(fieldName, state => {
state.props['x-component-props'].dataoption = res.data
})
})
})
}
\ No newline at end of file
import React, { useEffect } from 'react'
import { ISchemaFormActions, FormEffectHooks, IFormActions } from '@formily/antd';
import { PublicApi } from '@/services/api';
import { useAsyncSelect } from '@/formSchema/effects/useAsyncSelect';
const { onFieldValueChange$ } = FormEffectHooks
export const useWarehouseSelect = (context: ISchemaFormActions) => {
onFieldValueChange$('warehouseId').subscribe(state => {
// 货品ID
const goodsId = context.getFieldValue('goodsId')
const warehouseId = state.value
PublicApi.getWarehouseInventoryByItemNo({
warehouseId,
itemId: goodsId
}).then(res => {
const { data } = res
context.setFieldValue('NO_SUBMIT3', data.inventory)
})
})
}
export const createAddRepositoryEffect = (context: ISchemaFormActions) => {
const fetchWarehouseAll = async () => {
const { data } = await PublicApi.getWarehouseWarehouseAll()
context.setFieldState('warehouseId', state => {
state.warehouseLists = data
})
return data.map(v => ({
value: v.id,
label: v.name
}))
}
useAsyncSelect('warehouseId', fetchWarehouseAll)
useWarehouseSelect(context)
}
export const useUnitPreview = (initValue, context) => {
useEffect(() => {
if (initValue) {
context.setFieldState('inventory', state => {
if (!state.props['x-props']) {
state.props['x-props'] = {}
}
state.props['x-props'].addonAfter = <div style={{marginLeft: 4}}>{initValue.unit}</div>
})
context.setFieldValue('itemNo', initValue.itemNo)
}
}, [initValue])
}
// 高级筛选schema中用于输入搜索品牌的Effect
export const searchBrandOptionEffect = (context: any, fieldName: string) => {
context.getFieldState(fieldName, state => {
PublicApi.getProductSelectGetSelectBrand({ name: state.props['x-component-props'].searchValue }).then(res => {
context.setFieldState(fieldName, state => {
state.props['x-component-props'].dataoption = res.data
})
})
})
}
// 高级筛选schema中用于输入搜索商品品类的Effect
export const searchCustomerCategoryOptionEffect = (context: any, fieldName: string) => {
context.getFieldState(fieldName, state => {
PublicApi.getProductSelectGetSelectCustomerCategory({ name: state.props['x-component-props'].searchValue }).then(res => {
context.setFieldState(fieldName, state => {
state.props['x-component-props'].dataoption = res.data
})
})
})
}
import React, { useState, useRef, useContext, useEffect } from 'react'
import { Form, Input, Select } from 'antd';
export interface PayInfoCellProps {
title: React.ReactNode;
editable: boolean;
children: React.ReactNode;
dataIndex: string;
record: any;
colIndex: number,
handleChange(record: any, value: any)
handleSave: (record: any) => Promise<any>;
forceEdit: boolean,
formItem: string,
formItemProps: any
}
const EditableContext = React.createContext<any>({});
export const EditableRow: React.FC<any> = (props) => {
const [form] = Form.useForm();
// form.setFieldsValue()
const { options = [] } = props?.children[5]?.props.additionalProps.formItemProps || {}
const [childOptions, setChildOptions] = useState<any[]>(() => {
const { payWay } = props?.children[5]?.props.record || {}
if (payWay) {
return options.find(v => v.payType === payWay)?.payList.map(v => ({
label: v.way,
value: v.id
})) || []
} else {
return []
}
})
const ctx = {
form,
childOptions,
setChildOptions,
originOptions: options
}
return (
<Form form={form} component={false}>
<EditableContext.Provider value={ctx}>
<tr {...props} />
</EditableContext.Provider>
</Form>
);
};
export const PayInfoCell:React.FC<PayInfoCellProps> = ({
title,
editable,
children,
dataIndex,
record,
colIndex,
handleChange,
handleSave,
forceEdit,
formItem,
formItemProps={},
...restProps
}) => {
const formItemRef = useRef<any>();
const { form, childOptions, setChildOptions, originOptions } = useContext(EditableContext);
const save = async e => {
try {
const values = await form.validateFields();
handleSave({ ...record, ...values });
} catch (errInfo) {
console.log('Save failed:', errInfo);
}
};
const handleInputChange = (e) => {
handleChange(record, e.target.value)
}
const chooseFormItem = (type) => {
const formId = dataIndex + colIndex
switch(type) {
case 'input': {
return <Input ref={formItemRef} onPressEnter={save} onBlur={save} onChange={handleInputChange} {...formItemProps} id={formId}/>
}
case 'select': {
const { options, ...rest } = formItemProps
// 支付方式
if (dataIndex === 'payWay') {
return <Select ref={formItemRef}
options={originOptions.map(v => ({label: v.payVal, value: v.payType, disabled: v?.disabled}))} // ?? 仅限线下支付下面只有一种方式
onChange={e => {
const result = originOptions.find(v => e === v.payType)
setChildOptions(result.payList.map(v => ({label: v.way, value: v.id})))
form.setFieldsValue({channel: ''})
save(e)
}}
{...rest}
id={formId}
/>
}
// 需联动的内容
if (dataIndex === 'channel') {
return <Select
ref={formItemRef}
onChange={save}
options={childOptions}
{...rest}
id={formId}
/>
}
}
}
}
let childNode = children;
if (editable) {
childNode = (forceEdit) ? (
<Form.Item
style={{ margin: 0 }}
name={dataIndex}
initialValue={record[dataIndex] || ''}
rules={[
{
required: true,
message: `${title}必须填写`,
},
]}
>
{chooseFormItem(formItem)}
</Form.Item>
) : (
null
);
}
return <td {...restProps}>{childNode}</td>;
}
PayInfoCell.defaultProps = {}
export default PayInfoCell
import React, { useState, useRef, useContext, useEffect } from 'react'
import { Form, Input, Select } from 'antd';
export interface PayInfoCellProps {
title: React.ReactNode;
editable: boolean;
children: React.ReactNode;
dataIndex: string;
record: any;
colIndex: number,
handleChange(record: any, value: any)
handleSave: (record: any) => Promise<any>;
forceEdit: boolean,
formItem: string,
formItemProps: any
}
const EditableContext = React.createContext<any>({});
export const EditableRow: React.FC<any> = (props) => {
const [form] = Form.useForm();
// form.setFieldsValue()
const { options = [] } = props?.children[5]?.props.additionalProps.formItemProps || {}
const [childOptions, setChildOptions] = useState<any[]>(() => {
const { payWay } = props?.children[5]?.props.record || {}
if (payWay) {
return options.find(v => v.payType === payWay)?.payList.map(v => ({
label: v.way,
value: v.id
})) || []
} else {
return []
}
})
const ctx = {
form,
childOptions,
setChildOptions,
originOptions: options
}
return (
<Form form={form} component={false}>
<EditableContext.Provider value={ctx}>
<tr {...props} />
</EditableContext.Provider>
</Form>
);
};
export const PayInfoCell:React.FC<PayInfoCellProps> = ({
title,
editable,
children,
dataIndex,
record,
colIndex,
handleChange,
handleSave,
forceEdit,
formItem,
formItemProps={},
...restProps
}) => {
const formItemRef = useRef<any>();
const { form, childOptions, setChildOptions, originOptions } = useContext(EditableContext);
const save = async e => {
try {
const values = await form.validateFields();
handleSave({ ...record, ...values });
} catch (errInfo) {
console.log('Save failed:', errInfo);
}
};
const handleInputChange = (e) => {
handleChange(record, e.target.value)
}
const chooseFormItem = (type) => {
const formId = dataIndex + colIndex
switch(type) {
case 'input': {
return <Input ref={formItemRef} onPressEnter={save} onBlur={save} onChange={handleInputChange} {...formItemProps} id={formId}/>
}
case 'select': {
const { options, ...rest } = formItemProps
// 支付方式
if (dataIndex === 'payWay') {
return <Select ref={formItemRef}
options={originOptions.map(v => ({label: v.payVal, value: v.payType, disabled: v?.disabled}))} // ?? 仅限线下支付下面只有一种方式
onChange={e => {
const result = originOptions.find(v => e === v.payType)
setChildOptions(result.payList.map(v => ({label: v.way, value: v.id})))
form.setFieldsValue({channel: ''})
save(e)
}}
{...rest}
id={formId}
/>
}
// 需联动的内容
if (dataIndex === 'channel') {
return <Select
ref={formItemRef}
onChange={save}
options={childOptions}
{...rest}
id={formId}
/>
}
}
}
}
let childNode = children;
if (editable) {
childNode = (forceEdit) ? (
<Form.Item
style={{ margin: 0 }}
name={dataIndex}
initialValue={record[dataIndex] || ''}
rules={[
{
required: true,
message: `${title}必须填写`,
},
]}
>
{chooseFormItem(formItem)}
</Form.Item>
) : (
null
);
}
return <td {...restProps}>{childNode}</td>;
}
PayInfoCell.defaultProps = {}
export default PayInfoCell
......@@ -79,6 +79,8 @@ export const MoneyTotalBox = registerVirtualBox('moneyTotalBox', props => {
setFreePrice(res.data)
}
})
} else {
setFreePrice(0)
}
}
}, [data])
......@@ -211,14 +213,14 @@ const PurchaseOrderDetail:React.FC<PurchaseOrderDetailProps> = (props) => {
}
// 校验是否选择支付渠道
let judgementByPay = params.paymentInformationResponses.map(item => {
if(item.channel && item.payWay){
if(item.channel && item.payWay && Number(item.payRatio)){
return true
} else {
return false
}
})
if(judgementByPay.includes(false)){
throw new Error('请选择支付方式或者支付渠道')
throw new Error('请正确填写支付信息')
}
// 校验采购数量
let judgementByCount = params.orderProductRequests.map(item => {
......
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