Commit 124df178 authored by TZW's avatar TZW

1129

parent 7f8afc0d
/* 扩展字段内容
* @Author: Li Hanlin
* @Date: 2022-11-29 14:03:07
* @Last Modified by: Li Hanlin
* @Last Modified time: 2022-11-29 16:28:29
*/
import { doFetch } from '@/utils/doFetch';
import { useRequest } from 'ahooks';
import { useState, useEffect } from 'react';
import InitForm from '../InitForm';
export default ({ formId }) => {
const [columns, setcolumns] = useState([]);
const selectValueType = (type, options) => {
switch (type) {
case 1:
return {
valueType: 'input',
};
case 2:
return {
valueType: 'select',
options,
};
case 3:
return {
valueType: 'radio',
options,
};
case 4:
return {
valueType: 'select',
options,
};
default:
break;
}
};
useEffect(() => {
const fn = async () => {
let res = await doFetch({
url: '/base/paFormField/queryList',
params: {
formId,
},
});
if (res?.data?.dataList) {
let column = [];
res?.data?.dataList?.forEach((el) => {
column.push({
...selectValueType(el.fieldChar, el.valueType),
title: el.fieldName,
dataIndex: 'title',
key: el.id,
});
});
console.log('11111', column);
setcolumns(column);
}
};
fn();
}, []);
return (
<>
<InitForm fields={columns} />
</>
);
};
......@@ -12,6 +12,7 @@ import moment from 'moment';
import { doFetch } from '@/utils/doFetch';
import styles from './index.less';
import FormItems from './FormItems';
import ExtendField from '@/components/ExtendField';
function upperCase(str) {
const newStr = str.slice(0, 1).toUpperCase() + str.slice(1);
......@@ -93,6 +94,7 @@ function InitForm({
defaultFormValue = {},
submitter,
fields,
extendField = '',
colProps = { xs: 24, sm: 24, md: 12, lg: 12, xl: 12, xxl: 12 },
}) {
let proformRef = useRef();
......@@ -117,6 +119,18 @@ function InitForm({
...(res?.data?.data ?? {}),
...defaultFormValue,
});
if (extendField) {
let obj = {};
res?.data?.data[extendField]?.forEach((it) => {
obj[it?.fieldId] = it?.fieldRealValue;
});
console.log('extendField:', obj);
return {
...(res?.data?.data ?? {}),
...obj,
...defaultFormValue,
};
}
return {
...(res?.data?.data ?? {}),
...defaultFormValue,
......
......@@ -2,11 +2,11 @@
* @Author: Li Hanlin
* @Date: 2022-11-09 14:44:44
* @Last Modified by: Li Hanlin
* @Last Modified time: 2022-11-24 15:02:31
* @Last Modified time: 2022-11-29 18:04:45
*/
import * as React from 'react';
import { useState, useMemo, useRef, useCallback } from 'react';
import { useState, useMemo, useRef, useEffect, useCallback } from 'react';
import DrawerPro from '@/components/DrawerPro';
import AutoTable from '@/components/AutoTable';
import PremButton from '@/components/PremButton';
......@@ -61,11 +61,10 @@ function User(props) {
setDrawer((s) => ({
...s,
visible: true,
// item: row,
detailpath: urlParams.detail,
params: { id: row.id },
item: row,
type: 'add',
title: '编辑',
val: 'edit',
val: 'only',
onFinish: async (vals) => {
console.log(1);
let params = {
......@@ -123,55 +122,115 @@ function User(props) {
);
};
// const Adduser = () => {
// const [value, setValue] = useState('');
// const [options, setOptions] = useState([]);
// const debounce = lodash.debounce;
// const serchHandle = useCallback(
// debounce(async (val) => {
// console.log(val + '!!');
// if (val) {
// let res = await doFetch({
// url: '/auth/sysUser/queryLikeIotUsername',
// params: { username: val },
// });
// console.log(res);
// }
// }, 800),
// [],
// );
// const onSearch = (val) => {
// serchHandle(val);
// };
// const onSelect = (data) => {
// console.log('onSelect', data);
// };
// const onChange = (data) => {
// setValue(data);
// };
// return (
// <>
// <div style={{ marginBottom: 22 }}>
// <div style={{ marginBottom: 8 }}>用户名</div>
// <AutoComplete
// options={options}
// style={{
// width: '50%',
// }}
// onSelect={onSelect}
// onSearch={onSearch}
// placeholder="请输入用户名"
// />
// </div>
// <InitForm
// fields={columns}
// onFinish={() => {
// console.log(1);
// }}
// />
// </>
// );
// };
const Adduser = () => {
const [value, setValue] = useState('');
const [options, setOptions] = useState([]);
const [fieldscolumns, setfieldscolumns] = useState(columns);
const selectValueType = (type, options) => {
switch (type) {
case 1:
return {
valueType: 'input',
};
case 2:
return {
valueType: 'select',
options,
};
case 3:
return {
valueType: 'radio',
options,
};
case 4:
return {
valueType: 'select',
options,
};
default:
break;
}
};
useEffect(() => {
const fn = async () => {
let res = await doFetch({
url: '/base/paFormField/queryList',
params: {
formId: '1',
},
});
if (res?.data?.dataList) {
let column = [
{
title: '扩展字段',
valueType: 'split',
},
];
res?.data?.dataList?.forEach((el) => {
column.push({
...selectValueType(el.fieldChar, el.valueType),
title: el.fieldName,
dataIndex: el.fieldName,
key: el.id,
});
});
console.log('11111', column);
setfieldscolumns(fieldscolumns.concat(column));
}
};
fn();
}, []);
return (
<>
<InitForm
extendField="userCharList"
detailpath={urlParams.detail}
params={{ id: drawer?.item?.id }}
fields={fieldscolumns}
onFinish={async (vals) => {
let userCharReqList = [];
for (let i in vals) {
if (!isNaN(Number(i))) {
userCharReqList.push({
fieldId: i,
fieldRealValue: vals[i],
});
delete vals[i];
}
}
let params = {
...vals,
factoryIdList: vals.factoryNames,
shopIdList: vals.shopId,
sectionIdList: vals.sectionId,
productionLineIdList: vals.productLineName,
roleIdList: vals.roleNames,
userCharReqList,
};
delete params.factoryNames;
delete params.shopId;
delete params.sectionId;
delete params.productLineName;
delete params.roleNames;
console.log(params, '!!!!');
let res = await doFetch({
url: urlParams.save,
params,
});
if (res.code === '0000') {
message.success('新增成功!');
setDrawer((s) => ({
...s,
visible: false,
}));
actionRef.current.reload();
}
}}
/>
</>
);
};
const columns = useMemo(() => {
let defcolumn = getcolumns(setDrawer);
......@@ -204,40 +263,11 @@ function User(props) {
item: {
status: 1,
},
detailpath: null,
detailpath: '',
params: {},
title: '新增',
// type: 'add',
val: 'add',
onFinish: async (vals) => {
console.log(vals);
let params = {
...vals,
factoryIdList: vals.factoryNames,
shopIdList: vals.shopId,
sectionIdList: vals.sectionId,
productionLineIdList: vals.productLineName,
roleIdList: vals.roleNames,
userCharReqList: [],
};
delete params.factoryNames;
delete params.shopId;
delete params.sectionId;
delete params.productLineName;
delete params.roleNames;
console.log(params, '!!!!');
let res = await doFetch({
url: urlParams.save,
params,
});
if (res.code === '0000') {
message.success('新增成功!');
setDrawer((s) => ({
...s,
visible: false,
}));
actionRef.current.reload();
}
},
type: 'add',
val: 'only',
}));
},
},
......@@ -259,7 +289,7 @@ function User(props) {
}}
{...drawer}
>
{/* {drawer?.type == 'add' ? <Adduser /> : null} */}
{drawer?.type == 'add' ? <Adduser /> : null}
</DrawerPro>
</div>
);
......
function getcolumns(setdrawer) {
return [
{ title: '单号类型', dataIndex: 'noTypeName', key: 'noTypeId' },
{
title: '单号类型',
dataIndex: 'noTypeName',
key: 'noTypeId',
valueType: 'select',
options: { path: '/base/bmNoType/queryAllSelect', params: {} },
formItemProps: {
rules: [
{
required: false,
message: '此项为必填项',
},
],
},
},
{
title: '预览',
dataIndex: 'ruleNames',
......
......@@ -2,7 +2,7 @@
* @Author: Li Hanlin
* @Date: 2022-11-09 14:44:44
* @Last Modified by: Li Hanlin
* @Last Modified time: 2022-11-28 17:56:41
* @Last Modified time: 2022-11-29 10:02:24
*/
import * as React from 'react';
......@@ -33,7 +33,6 @@ function Rules(props) {
<PremButton
btn={{
size: 'small',
type: 'link',
onClick: () => {
setDrawer((s) => ({
...s,
......@@ -135,6 +134,7 @@ function Rules(props) {
<AutoTable
pagetitle={<h3 className="page-title">编号规则</h3>}
columns={columns}
pagination={false}
path={urlParams.list}
actionRef={actionRef}
pageextra={'add'}
......
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