/*
|
* @Company: hugeInfo
|
* @Author: lwh
|
* @Date: 2022-03-11 17:01:10
|
* @LastEditTime: 2022-04-21 11:50:53
|
* @LastEditors: lwh
|
* @Version: 1.0.0
|
* @Description:客户管理-新增增强包
|
*/
|
import React, { useState, useEffect } from 'react';
|
import { useNavigate, useParams } from 'react-router-dom';
|
import PageHead from '../../../components/PageHead';
|
import { Card, Input, message, Button, Form, Select, Spin } from 'antd';
|
import * as $$ from '../../../utils/utility';
|
import './index.less';
|
const { Option } = Select;
|
// 查询列表 增强包
|
function listQueryRsMeal() {
|
return $$.ax.request({ url: 'v1/rsMeal/listQuery', type: 'get', data: { status: '1' }, service: 'oper' });
|
}
|
// 保存修改版本和增强包
|
function saveSeCustomVer(data) {
|
return $$.ax.request({ url: 'v1/seCustom/saveSeCustomVer', type: 'POST', data, service: 'oper' });
|
}
|
|
// 详情
|
function getByIdSeCustom(id) {
|
return $$.ax.request({ url: 'v1/seCustom/getById', type: 'get', data: { id }, service: 'oper' });
|
}
|
|
const AddMeal = () => {
|
const [form] = Form.useForm();
|
const [mealList, setMealList] = useState([]);
|
const [formData, setFormData] = useState({});
|
const [loading, setLoading] = useState(false);
|
const navigate = useNavigate();
|
const params = useParams();
|
//初始化组件回显
|
useEffect(() => {
|
getOrganization();
|
}, []);
|
|
const getOrganization = async () => {
|
const requestObj = await getByIdSeCustom(params.id);
|
setFormData(requestObj.data);
|
const list = await listQueryRsMeal();
|
let mealIds = params.mealIds !== 'null' ? params.mealIds.split(',') : [];
|
console.log('mealIds', mealIds);
|
console.log('list.data', list.data);
|
console.log(
|
'1111',
|
list.data.filter((item) => !mealIds.includes(item.id))
|
);
|
let newList = list.data.filter((item) => !mealIds.includes(item.id));
|
console.log('newList', newList);
|
setMealList(newList);
|
};
|
|
const reset = () => {
|
form.resetFields();
|
};
|
|
const back = () => {
|
navigate(-1);
|
};
|
|
const save = async () => {
|
setLoading(true);
|
const row = await form.validateFields();
|
const tableData = form.getFieldValue();
|
const res = await saveSeCustomVer({ ...formData, seCustom: '', ...formData.seCustom, ...tableData, id: params.id });
|
setLoading(false);
|
if (res.data) {
|
message.success('提交成功!');
|
navigate(-1);
|
}
|
};
|
|
// 增强包选择
|
const selectMealOnChange = (name, e, data) => {
|
const tableData = form.getFieldValue();
|
const version = mealList.find((i) => i.id == e);
|
//
|
form.setFieldsValue({
|
...tableData,
|
[name + 'Ids']: data.value,
|
[name + 'Names']: data.key,
|
planPrice: version.price,
|
});
|
};
|
|
return (
|
<>
|
<PageHead
|
breadcrumbData={[{ title: '客户管理', url: '/operation/customer' }, { title: '订购版本' }]}
|
title={params.title ? params.title : '订购版本'}
|
/>
|
<Spin spinning={loading}>
|
<Card style={{ margin: '24px', display: 'flex', justifyContent: 'center' }}>
|
<Form form={form} labelCol={{ style: { width: '100%', textAlign: 'left' } }} layout="vertical" component={false}>
|
<Form.Item label="增强包" name="mealId" rules={[{ required: false, message: `请选择增强包` }]}>
|
<Select placeholder="请选择增强包" onChange={(e, data) => selectMealOnChange('meal', e, data)} style={{ width: '320px' }} allowClear>
|
{mealList.map((item, index) => (
|
<Option key={item.name} value={item.id}>
|
{item.name}
|
</Option>
|
))}
|
</Select>
|
</Form.Item>
|
|
<Form.Item label="价格" name="planPrice" rules={[{ required: false, message: `请输入价格` }]}>
|
<Input type={'number'} prefix={'¥'} suffix={'元'} placeholder={`请输入价格`} style={{ width: '320px' }} />
|
</Form.Item>
|
</Form>
|
<div className="add-meal-foot-buttton">
|
<Button onClick={save} type="primary">
|
提交
|
</Button>
|
<Button onClick={reset}>重置</Button>
|
<Button onClick={back}>返回</Button>
|
</div>
|
</Card>
|
</Spin>
|
</>
|
);
|
};
|
|
export default AddMeal;
|