diff --git a/src/pages/activity/activityStart/components/CouponDelivery/index.jsx b/src/pages/activity/activityStart/components/CouponDelivery/index.jsx index b8bc76d..8182e83 100644 --- a/src/pages/activity/activityStart/components/CouponDelivery/index.jsx +++ b/src/pages/activity/activityStart/components/CouponDelivery/index.jsx @@ -1,16 +1,71 @@ import React, { useState, useEffect } from "react"; -import { Form, Button, Input, Select, InputNumber, DatePicker, Upload, message } from 'antd'; +import { Form, Button, Input, Select, InputNumber, DatePicker, Upload, message, Modal, Checkbox, Row, Col } from 'antd'; import styles from "../../index.less"; import { MinusCircleOutlined, PlusOutlined, UploadOutlined, PlusCircleOutlined } from '@ant-design/icons'; import startAPI from "../../service"; import axios from 'axios'; +import moment from "moment"; -const CouponDelivery = () => { +/** + * (送券)活动 + * @returns + */ +const key = 'coupon'; +const activityConfigArray = [ + { + "configId": null, + "operator": null, + "value1": [], + "value2": null, + "activity_Id": null, + "configuration_Id": "3718AB6C-F4ED-4FAD-8462-6608FF87799C", + "configurationName": "新人注册", + "configurationRule": "没有领取过优惠券", + "valueType": 1, + "configurationValueCount": 0 + }, + { + "configId": null, + "operator": null, + "value1": [], + "value2": null, + "activity_Id": null, + "configuration_Id": "58cbe72f-5022-48bd-8ed0-7ebb091e884a", + "configurationName": "限制领券", + "configurationRule": "不存在此优惠券", + "valueType": 1, + "configurationValueCount": 0 + }, + { + "configId": null, + "operator": null, + "value1": [], + "value2": null, + "activity_Id": null, + "configuration_Id": "E432268C-7140-4519-B29F-892764486232", + "configurationName": "每日领券", + "configurationRule": "每日只可领取一次", + "valueType": 1, + "configurationValueCount": 0 + }, +] +const CouponDelivery = () => { + const [form] = Form.useForm(); const [couponInfo, SetCouponInfo] = useState([]); const [couponForm] = Form.useForm(); const [imgurl, setimgUrl] = useState(null); const [canUseCount, setCanUseCount] = useState([]); + /** 新建/更新窗口的弹窗 */ + const [createModalVisible, handleModalVisible] = useState(false); + /** 优惠券类型 */ + const [couponType, setcouponType] = useState([]); + /** 适用门店范围 */ + const [applicableStore, setApplicableStore] = useState([]); + /** 适用商品类型范围 */ + const [applyGoodType, setApplyGoodType] = useState([]); + /** 适用商品范围 */ + const [applyGood, setApplyGood] = useState([]); /** * 获取优惠券列表 @@ -81,8 +136,163 @@ const CouponDelivery = () => { }, }; + const formItemLayout = { + labelCol: { + sm: { span: 4 }, + }, + wrapperCol: {}, + }; + + const tailFormItemLayout = { + wrapperCol: { + sm: { + span: 500, + offset: 1, + }, + }, + }; + + /** + * 获取消费券类型 + */ + const GetCouponStatusOrType = async () => { + await startAPI.GetCouponStatusOrType(2).then((r) => { + if (r.succeeded) { + setcouponType(r.data); + } + }); + } + + /** + * 获取适用店铺 + */ + const GetStores = async () => { + const response = await startAPI.GetStores(); + if (response.statusCode === 200) { + setApplicableStore(response.data); + } + } + + /** + * 适用商品范围 + */ + const onFetchGoodsType = async () => { + const response = await startAPI.GetGoodsType(); + if (response.statusCode === 200) { + const array = []; + Object.keys(response.data).forEach(item => { + array.push({ + id: item, + name: response.data[item] + }) + }) + setApplyGoodType(array); + } + } + + /** + * 获取商品 + */ + const onFetchGoods = async (goodsType = -1) => { + const response = await startAPI.GetGoodsById(goodsType); + if (response.statusCode === 200) { + const array = []; + Object.keys(response.data).forEach(item => { + array.push({ + id: item, + name: response.data[item] + }) + }); + setApplyGood(array) + } + } + + + //新增 + const handleAddCoupon = async (fields) => { + fields.RangeType = 1; + message.loading('正在添加...', key); + try { + if (fields.validEndTime < fields.validStartTime) { + message.error('开始时间不能大于结束时间'); + } + await startAPI.Addcoupon(JSON.stringify(fields)).then((r) => { + message.destroy(key); + if (r.data) { + message.success('添加成功'); + onFetchCouponList(); + handleModalVisible(false); + } else { + message.error('添加失败请重试!'); + } + }); + } catch (error) { + message.destroy(key); + message.error('添加失败请重试!'); + } + }; + + const hander = async (value) => { + var res = (await startAPI.GetSelectedConfig(value)).data; + var arr = []; + for (let k in res) { + arr.push({ + id: k.toString(), + name: res[k.toString()], + }); + } + setApplicableStore(data); + form.setFieldsValue({ Relation: [] }); + }; + + /** + * 提交活动 + */ + const onSubmitActivity = async (values) => { + if (!values.activityRewards) { + message.error('请至少添加一种优惠券'); + return; + } + values.activityType = 1; + values.activityRewards.forEach(item => { + item.id = ""; + item.activityInfo_Id = ""; + }) + values.activityStartTime = moment(values.activityStartAndEndTime[0]).format('YYYY-MM-DD'); + values.activityEndTime = moment(values.activityStartAndEndTime[1]).format('YYYY-MM-DD'); + values.status = 0; + values.isShow = 1; + values.isDeleted = 0; + values.consumptionType = 0; + values.isGiftGoodsParticipate = 0; + const activityConfiguration = []; + values.activityConfig.forEach(valueItem => { + const findConfig = activityConfigArray.find(item => item.configuration_Id === valueItem); + if (findConfig) { + activityConfiguration.push({ + ...findConfig, + configId: [valueItem] + }); + } + }); + delete values.activityConfig; + delete values.activityStartAndEndTime; + values.activityConfiguration = activityConfiguration; + const response = await startAPI.FastAddActivity(values); + if (response.statusCode === 200) { + message.success('新建活动成功!'); + couponForm.resetFields(); + } else { + message.error(response.errors || '创建失败 请重试!'); + } + } + useEffect(() => { onFetchCouponList(); + GetCouponStatusOrType(); + GetStores(); + onFetchGoodsType(); + onFetchGoods(); }, []); return
@@ -96,11 +306,7 @@ const CouponDelivery = () => { remember: true, }} onFinish={(values) => { - console.log('values>>>', values); - if (!values.activityRewards) { - message.error('请至少添加一种优惠券'); - return; - } + onSubmitActivity(values); }} layout="vertical" autoComplete="off" @@ -159,7 +365,7 @@ const CouponDelivery = () => { - + handleModalVisible(true)} style={{ margin: '0 10px', flexShrink: 0, marginBottom: '24px', fontSize: '25px', color: '#F84352' }} />
可领取数量: {canUseCount[key]?.canUseCount}
@@ -201,7 +407,7 @@ const CouponDelivery = () => { @@ -226,6 +432,29 @@ const CouponDelivery = () => { + + + + + + + + { + activityConfigArray.map((config, index) => { + return + {config.configurationName}:{config.configurationRule}! + + }) + } + + + + - + + { + handleModalVisible(false); + }} + //关闭时销毁 Modal 里的子元素 + destroyOnClose + > +
{ + handleAddCoupon(values) + }} + > + + + + + + + + + + + + + + + + + + + + + + + 0 为不限制 + + + + + + + prevValues.timeType !== currentValues.timeType + } + > + {({ getFieldValue }) => + getFieldValue('timeType') == '2' ? ( + + + + + + ) : ( + + + + + + + + + ) + } + + + + + + + + + + + 注: 多条规则请用  ;  隔开。    如:1.xxxxxx; 2.xxxxxx + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
} diff --git a/src/pages/activity/activityStart/service.js b/src/pages/activity/activityStart/service.js index ad58cb2..d7ce54d 100644 --- a/src/pages/activity/activityStart/service.js +++ b/src/pages/activity/activityStart/service.js @@ -13,5 +13,56 @@ export default { return request(`/kitchen/api/coupon-helper/coupon-can-use-count-and-limit`, { method: 'get', }); + }, + + /** 获取优惠卷状态或类型 */ + GetCouponStatusOrType(data) { + return request(`/kitchen/api/coupon/getCouponStatusOrType`, { + method: 'POST', + data: data + }); + }, + + /** 新增优惠卷 POST */ + Addcoupon(data) { + return request('/kitchen/api/activity-info/fast-coupon', { + method: 'POST', + data: data + }); + }, + + //获取店铺 + GetStores(data) { + return request('/kitchen/api/sysOrg/listbytype', { + method: 'get', + data: data, + }); + }, + + //获取商品类型 + GetGoodsType(data) { + return request(`/kitchen/api/select/goodstype`, { + method: 'get' + }); + }, + + //获取商品类型 + GetGoodsById(data) { + return request(`/kitchen/api/select/goods/${data}`, { + method: 'get' + }); + }, + + GetSelectedConfig(data) { + return request(`/kitchen/api/select/selectedconfig/${data}`, { + method: 'get' + }); + }, + + FastAddActivity(data) { + return request('/kitchen/api/activity-info/fast-activity', { + method: 'POST', + data + }); } } \ No newline at end of file