Commit a838cbd1 authored by 许佳敏's avatar 许佳敏

Merge branch '220518-feat' into 'v2-220518'

feat: 完善请购单流程规则 See merge request linkseeks-design/pro-admin!53
parents bf85dc0e 2716b393
......@@ -3,8 +3,8 @@ import { ColumnType } from 'antd/lib/table/interface';
/** 流程规则ID */
export const id: ColumnType<any> = {
title: 'ID',
key: 'id',
dataIndex: 'id',
key: 'processId',
dataIndex: 'processId',
}
/** 流程规则名称 */
......
import React, { useState, useRef } from 'react';
import React, { useState, useRef, useEffect } from 'react';
import PeripheralLayout from '@/components/DetailLayout';
import FormProgress, { HandleType } from '@/components/FormProgress'
import { Button, Form } from 'antd';
......@@ -8,6 +8,8 @@ import ProcessSelectLayout from '../ProcessSelect';
import ApplyMemberLayout from '../ApplyMember';
import usePrompt from '@/hooks/usePrompt';
import { VISIT_TYPE } from '@/constants';
import { history } from 'umi';
import { getPurchaseRequisitionWebProcessBaseList, getPurchaseRequisitionWebProcessGet, postPurchaseRequisitionWebProcessSave, postPurchaseRequisitionWebProcessUpdate } from '@/services/PurchaseV2Api'
type PropsType = {
type: 'add' | 'edit' | 'view'
......@@ -22,18 +24,69 @@ export const layout: any = {
labelAlign: "left"
};
const AddInvoiceProcessEng: React.FC<PropsType> = ({ id, title, type }) => {
const AddInvoiceProcessEng: React.FC<PropsType> = ({ id: processId, title, type }) => {
const [form] = Form.useForm();
const { renderPrompt, handleLeave } = usePrompt()
const [loading, setLoading] = useState<boolean>(false)
const [processBaseList, setProcessBaseList] = useState<any[]>([])
const progressRef = useRef<HandleType>()
const handleSubmit = () => {
form.validateFields().then((values) => {
form.validateFields().then(values => {
setLoading(true)
const params = {
processId,
...values,
allMembers: values.allMembers === 1 ? true : false,
members: values.allMembers === 2 ? values.members?.map(_item => {
return {
memberId: _item.memberId,
roleId: _item.roleId,
}
})
: undefined
}
const fetchApi = processId ? postPurchaseRequisitionWebProcessUpdate : postPurchaseRequisitionWebProcessSave
fetchApi({ ...params }).then(res => {
if (res.code !== 1000) {
setLoading(false)
return
}
handleLeave(false)
history.goBack()
})
})
}
const getProcessBaseList = async () => {
const { code, data } = await getPurchaseRequisitionWebProcessBaseList();
if (code === 1000) {
setProcessBaseList(data)
}
}
const getDetail = async () => {
if (processId) {
const { code, data } = await getPurchaseRequisitionWebProcessGet({ processId });
if (code === 1000) {
form.setFieldsValue({
name: data.name,
baseProcessId: data.baseProcessId,
allMembers: data.allMembers ? 1 : 2,
})
}
}
}
useEffect(() => {
const getData = async () => {
await getProcessBaseList()
getDetail()
}
getData()
}, [])
return (
<>
<PeripheralLayout
......@@ -64,8 +117,8 @@ const AddInvoiceProcessEng: React.FC<PropsType> = ({ id, title, type }) => {
onFieldsChange={() => { progressRef?.current?.render(form) }}
>
<ProcessEngLayout type={type} />
<ProcessSelectLayout type={type} />
<ApplyMemberLayout type={type} />
<ProcessSelectLayout type={type} optionsData={processBaseList} />
<ApplyMemberLayout form={form} type={type} processId={processId} />
</Form>
}
/>
......
import React, { useCallback, useState } from 'react';
import { Button, Form, Radio, Space, Table } from 'antd';
import React, { useCallback, useEffect, useState } from 'react';
import { Button, Form, Popconfirm, Radio, Space, Table } from 'antd';
import { FormInstance } from 'antd/es/form/Form';
import { ColumnType } from 'antd/lib/table/interface';
import { PlusOutlined } from '@ant-design/icons';
......@@ -9,18 +9,20 @@ import { operation } from '../../columns';
import { FORM_FILTER_PATH } from '@/formSchema/const';
import { useStateFilterSearchLinkageEffect } from '@/formSchema/effects/useFilterSearch';
import TableModal from '@/components/TableModal';
import { getMemberManageAllProviderPage } from '@/services/MemberV2Api';
import { getPurchaseRequisitionWebProcessMemberPage } from '@/services/PurchaseV2Api';
import { getMemberManageAllConsumerPage } from '@/services/MemberV2Api';
import { VISIT_TYPE } from '@/constants';
interface InvoiceTypeProps {
form?: FormInstance
type: 'add' | 'edit' | 'view'
processId?: string
}
const InvoiceTypeLayout: React.FC<InvoiceTypeProps> = (props: any) => {
const { form, type } = props;
const { form, type, processId } = props;
const [visible, setVisible] = useState<boolean>(false);
const [member, setMember] = useState<any>({})
const [member, setMember] = useState<any>([])
const mock = [
{ value: 1, label: '所有会员(默认)' },
{ value: 2, label: '指定会员' },
......@@ -29,8 +31,8 @@ const InvoiceTypeLayout: React.FC<InvoiceTypeProps> = (props: any) => {
const columns: ColumnType<any>[] = [
{
title: 'ID',
dataIndex: 'id',
key: 'id',
dataIndex: 'memberId',
key: 'memberId',
},
{
title: '会员名称',
......@@ -56,7 +58,7 @@ const InvoiceTypeLayout: React.FC<InvoiceTypeProps> = (props: any) => {
const handleFetchData = useCallback((params: any) => {
return new Promise(resolve => {
getMemberManageAllProviderPage({ ...params }).then(res => {
getMemberManageAllConsumerPage({ ...params }).then(res => {
if (res.code !== 1000) {
return
}
......@@ -67,15 +69,52 @@ const InvoiceTypeLayout: React.FC<InvoiceTypeProps> = (props: any) => {
})
}, [])
const toggle = (flag: boolean) => {
setVisible(flag)
const confirm = (records) => {
const newMember = member.filter(_item => _item.id !== records.id);
console.log(newMember)
setMember(newMember)
form.setFieldsValue({ 'members': newMember })
}
const handleConfirm = (selectRow: number[] | string[], selectedRows: { [key: string]: any }[]) => {
console.log(selectRow, 'selectRow');
console.log(selectedRows, 'selectedRows');
console.log('selectedRows', selectedRows)
setMember(selectedRows)
form.setFieldsValue({
'members': selectedRows
})
setVisible(false)
}
const columnFunc = useCallback(() => {
const params = [...columns];
!(type === VISIT_TYPE.VIEW) && params.push({
...operation,
render: (_text, record) => <>{(
<Popconfirm
title="确认要删除吗?"
onConfirm={() => confirm(record)}
okText="是"
cancelText="否"
>
<Button type="link">删除</Button>
</Popconfirm>
)}</>
})
return params
}, [member])
useEffect(() => {
if (processId) {
getPurchaseRequisitionWebProcessMemberPage({ processId } as any).then(({ code, data }) => {
if (code === 1000) {
setMember(data);
form.setFieldsValue({ 'members': data })
}
})
}
}, [processId])
return (
<CardLayout
id="applyMember"
......@@ -85,7 +124,7 @@ const InvoiceTypeLayout: React.FC<InvoiceTypeProps> = (props: any) => {
classNames={styles['invoice-type']}
>
<Form.Item
name='invoiceType'
name='allMembers'
initialValue={1}
rules={[
{ required: true, message: '请选择适用会员' },
......@@ -99,20 +138,17 @@ const InvoiceTypeLayout: React.FC<InvoiceTypeProps> = (props: any) => {
</Form.Item>
<Form.Item
noStyle
shouldUpdate={(prevValues, currentValues) => (prevValues.invoiceType !== currentValues.invoiceType)}
shouldUpdate={(prevValues, currentValues) => (prevValues.allMembers !== currentValues.allMembers)}
>
{({ getFieldValue }) =>
getFieldValue('invoiceType') === 2 ? (
getFieldValue('allMembers') === 2 ? (
<Space direction='vertical'>
<Button block type='dashed' icon={<PlusOutlined />} onClick={() => toggle(true)}>选择</Button>
<Form.Item name="memberId" rules={[{ required: true, message: '请选择适用会员' }]}>
<Button block type='dashed' icon={<PlusOutlined />} onClick={() => setVisible(true)}>选择</Button>
<Form.Item name="members" rules={[{ required: true, message: '请选择适用会员' }]}>
<Table
columns={[
...columns,
{
...operation
}
]}
rowKey='id'
columns={columnFunc()}
dataSource={member}
/>
</Form.Item>
</Space>
......@@ -129,7 +165,7 @@ const InvoiceTypeLayout: React.FC<InvoiceTypeProps> = (props: any) => {
}}
customKey='id'
fetchData={handleFetchData}
onClose={() => toggle(false)}
onClose={() => setVisible(false)}
onOk={handleConfirm}
columns={columns}
effects={($, actions) => {
......@@ -170,7 +206,7 @@ const InvoiceTypeLayout: React.FC<InvoiceTypeProps> = (props: any) => {
}
}
}}
value={[member]}
value={member}
/>
</CardLayout>
)
......
......@@ -9,18 +9,12 @@ interface ProcessSelectProps {
/** FormInstance */
form?: FormInstance
type: 'add' | 'edit' | 'view'
optionsData: any[]
}
const ProcessSelectLayout: React.FC<ProcessSelectProps> = (props: any) => {
const { form, type } = props;
const mock = [
{ id: 1, name: '请购单流程--0级', value: '-', tag: '请购单流程' },
{ id: 2, name: '请购单流程--1级', value: '1-待提交请购单', tag: '请购单流程' },
{ id: 3, name: '请购单流程--2级', value: '1-待审核请购单(一级) —>2-待提交请购单', tag: '请购单流程' },
{ id: 4, name: '请购单流程--3级', value: '1-待审核请购单(一级) —>2-审核请购单(二级)—>3-待提交请购单', tag: '请购单流程' },
]
const { form, type, optionsData } = props;
return (
<CardLayout
......@@ -31,20 +25,20 @@ const ProcessSelectLayout: React.FC<ProcessSelectProps> = (props: any) => {
classNames={styles['select-box']}
>
<Form.Item
name='processSelect'
name='baseProcessId'
rules={[
{ required: true, message: '请选择流程' },
]}
>
<Radio.Group disabled={type === VISIT_TYPE.VIEW}>
{mock.map(_item => (
<Radio key={_item.id} value={_item.id}>
{optionsData.map(_item => (
<Radio key={_item.baseProcessId} value={_item.baseProcessId}>
<div className={styles['box']}>
<div className={styles['box-clerk']}>
<div className={styles['box-clerk-name']}>{_item.name}</div>
<div className={styles['box-clerk-value']}>{_item.value}</div>
<div className={styles['box-clerk-name']}>{_item.processName}</div>
<div className={styles['box-clerk-value']}>{_item.description}</div>
</div>
<div className={styles['box-tag']}>{_item.tag}</div>
<div className={styles['box-tag']}>{_item.processTypeName}</div>
</div>
</Radio>
))}
......
import React from 'react';
import React, { useRef } from 'react';
import { history, Link } from 'umi';
import { Button, Space, Switch } from 'antd';
import { Button, Popconfirm, Space, Switch } from 'antd';
import moment from 'moment';
import { PlusOutlined } from '@ant-design/icons';
import TableLayout from '@/components/TableLayout';
import { ColumnType } from 'antd/lib/table/interface';
import { createTime, id, name, operation, processName, status } from './columns';
import { getPurchaseRequisitionWebProcessPage, postPurchaseRequisitionWebProcessStatusUpdate, getPurchaseRequisitionWebProcessDelete } from '@/services/PurchaseV2Api'
const InvoiceProcessEng: React.FC<{}> = () => {
const ref = useRef<any>()
const format = (text, fmt?: string) => {
return <>{moment(text).format(fmt || "YYYY-MM-DD HH:mm:ss")}</>
}
const mock = [
{
id: 1,
name: '物料对账单请购流程',
processName: '请购单流程-2级',
createTime: 1650614111890,
status: 1,
const handleStatus = async ({ processId }, status: number) => {
const res = await postPurchaseRequisitionWebProcessStatusUpdate({
processId,
status
})
if (res.code === 1000) {
ref.current.reload()
}
]
}
const fetchDeleteBatch = (processId) => {
getPurchaseRequisitionWebProcessDelete({ processId }).then(res => {
if (res.code === 1000) {
ref.current.reload()
}
})
}
const columns: ColumnType<any>[] = [
{
......@@ -29,10 +39,7 @@ const InvoiceProcessEng: React.FC<{}> = () => {
},
{
...name,
render: (_text) => <Link to='#'>{_text}</Link>
},
{
...processName,
render: (_text, record) => <Link to={`/system/ruleSettingManager/buyingRequisitionProcess/view?id=${record.processId}`}>{_text}</Link>
},
{
...createTime,
......@@ -40,22 +47,36 @@ const InvoiceProcessEng: React.FC<{}> = () => {
},
{
...status,
render: (_text) => <Switch checked={!!_text} />
render: (_text, record) => <Switch checked={!!_text} onChange={() => handleStatus(record, !!_text ? 0 : 1)} />
},
{
...operation,
render: (_text) => <Space size={16}>
<a>查看</a>
<a>编辑</a>
<a>删除</a>
</Space>
render: (_text, record) => (
<Space size={16}>
<a onClick={() => { history.push(`/system/ruleSettingManager/buyingRequisitionProcess/view?id=${record.processId}`) }}>查看</a>
{ !record.status && (
<>
<a onClick={() => { history.push(`/system/ruleSettingManager/buyingRequisitionProcess/edit?id=${record.processId}`) }}>编辑</a>
<Popconfirm
title='确定删除么?'
okText='是'
cancelText='否'
onConfirm={() => fetchDeleteBatch(record.processId)}
>
<a >删除</a>
</Popconfirm>
</>
)}
</Space>
)
},
]
return (
<TableLayout
reload={ref}
columns={columns}
fetch={mock}
fetch={getPurchaseRequisitionWebProcessPage}
schema={{
type: "object",
properties: {
......
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