Commit 47411217 authored by 武广's avatar 武广

Merge branch 'feature/package-upgrade' into 'master'

Feature/package upgrade

See merge request !74
parents d50542cd c9195344
import React, { useState, forwardRef, useEffect, useImperativeHandle } from 'react'; import React, { useState, forwardRef, useEffect, useImperativeHandle } from 'react';
import { Form, Button, Row, Col, Input, Select, Modal, notification } from 'antd'; import { Form, Button, Row, Col, Input, Select, Modal, notification, Popover } from 'antd';
import { PlusOutlined } from '@ant-design/icons'; import { PlusOutlined } from '@ant-design/icons';
import styles from '../common.less'; import styles from '../common.less';
import { isIntegerNotZero, isCheckPriceOneDecimal } from '@/utils/validator'; import { isIntegerNotZero, isCheckPriceOneDecimal } from '@/utils/validator';
...@@ -15,19 +15,29 @@ const getCaiJson = gname => ({ ...@@ -15,19 +15,29 @@ const getCaiJson = gname => ({
gName: gname, gName: gname,
quantity: '', quantity: '',
dishName: '', dishName: '',
subtitle: '',
unit: '', unit: '',
price: '', price: '',
skuId: '', skuId: '',
}); });
const FormCai = forwardRef((props, ref) => { const FormCai = forwardRef((props, ref) => {
const { gitem, groupName, groupkey, packageIndex } = props; const { gitem, groupName, groupkey, packageIndex, form, groupIndex } = props;
const lists = form.getFieldValue('lists');
const subTitles = lists[packageIndex].children[groupIndex].dishes.map(item => item.subtitle);
const [subTitle, setSubTitle] = useState(subTitles);
const onDel = (callback, name, key) => { const onDel = (callback, name, key) => {
// callback(name); // callback(name);
props.onDelCai(packageIndex, groupkey, key); props.onDelCai(packageIndex, groupkey, key);
}; };
const onChange = (e, i) => {
const { value } = e.target;
const arr = [...subTitle];
arr[i] = value;
setSubTitle(arr);
};
const onAdd = (callback, key) => { const onAdd = (callback, key) => {
if (props.onAddCai(packageIndex, groupkey)) { if (props.onAddCai(packageIndex, groupkey)) {
callback(getCaiJson(groupName)); callback(getCaiJson(groupName));
...@@ -40,7 +50,7 @@ const FormCai = forwardRef((props, ref) => { ...@@ -40,7 +50,7 @@ const FormCai = forwardRef((props, ref) => {
<> <>
{items.map(({ key, name }, caiIndex) => ( {items.map(({ key, name }, caiIndex) => (
<Row gutter={24} key={`cai_${key}`} className={styles.caiRow}> <Row gutter={24} key={`cai_${key}`} className={styles.caiRow}>
<Col span={5}> <Col span={3}>
<Form.Item name={[name, 'gName']}> <Form.Item name={[name, 'gName']}>
<Input readOnly hidden /> <Input readOnly hidden />
<span>{groupName}</span> <span>{groupName}</span>
...@@ -80,7 +90,7 @@ const FormCai = forwardRef((props, ref) => { ...@@ -80,7 +90,7 @@ const FormCai = forwardRef((props, ref) => {
</Select> </Select>
</Form.Item> </Form.Item>
</Col> </Col>
<Col span={4}> <Col span={3}>
<Form.Item <Form.Item
name={[name, 'price']} name={[name, 'price']}
rules={[ rules={[
...@@ -91,7 +101,18 @@ const FormCai = forwardRef((props, ref) => { ...@@ -91,7 +101,18 @@ const FormCai = forwardRef((props, ref) => {
<Input maxLength={10} /> <Input maxLength={10} />
</Form.Item> </Form.Item>
</Col> </Col>
<Col span={3}> <Col span={4}>
<Popover content={() => subTitle[caiIndex]} trigger="hover">
<Form.Item
name={[name, 'subtitle']}
onChange={e => onChange(e, caiIndex)}
// rules={[{ required: true, message: '请输入副标题' }]}
>
<Input maxLength={100} placeholder="最多100个字" />
</Form.Item>
</Popover>
</Col>
<Col span={2}>
<Button type="link" onClick={() => onDel(remove, name, key)}> <Button type="link" onClick={() => onDel(remove, name, key)}>
删除 删除
</Button> </Button>
...@@ -118,15 +139,16 @@ const FormGroup = forwardRef((props, ref) => { ...@@ -118,15 +139,16 @@ const FormGroup = forwardRef((props, ref) => {
<Form.List name={item}> <Form.List name={item}>
{(items, { add, remove }) => ( {(items, { add, remove }) => (
<> <>
{items.map(({ key, name }) => ( {items.map(({ key, name }, index) => (
<div className={styles.groupMargin} key={`group_${key}`}> <div className={styles.groupMargin} key={`group_${key}`}>
<Row gutter={24} className={styles.groupHeader}> <Row gutter={24} className={styles.groupHeader}>
<Col span={5}>组名</Col> <Col span={3}>组名</Col>
<Col span={3}>数量</Col> <Col span={3}>数量</Col>
<Col span={4}>菜名</Col> <Col span={4}>标题</Col>
<Col span={2}>单位</Col> <Col span={2}>单位</Col>
<Col span={4}>价格</Col> <Col span={3}>价格</Col>
<Col span={3}>操作</Col> <Col span={4}>副标题</Col>
<Col span={2}>操作</Col>
<Col span={3}> <Col span={3}>
<div> <div>
<Form.Item name={[name, 'groupName']}> <Form.Item name={[name, 'groupName']}>
...@@ -138,6 +160,8 @@ const FormGroup = forwardRef((props, ref) => { ...@@ -138,6 +160,8 @@ const FormGroup = forwardRef((props, ref) => {
<FormCai <FormCai
gitem={[name, 'dishes']} gitem={[name, 'dishes']}
packageIndex={packageIndex} packageIndex={packageIndex}
groupIndex={index}
form={form}
groupkey={key} groupkey={key}
onAddCai={onAddCai} onAddCai={onAddCai}
onDelCai={onDelCai} onDelCai={onDelCai}
......
...@@ -92,6 +92,7 @@ const ServiceGoods = options => { ...@@ -92,6 +92,7 @@ const ServiceGoods = options => {
setPageLoading(true); setPageLoading(true);
setCategoryIds([]); setCategoryIds([]);
setVisibleCacheEdit(false); setVisibleCacheEdit(false);
resetForm();
const timer = setTimeout(() => { const timer = setTimeout(() => {
setPageLoading(false); setPageLoading(false);
resetForm(); resetForm();
......
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