Commit a33add65 authored by XieZhiXiong's avatar XieZhiXiong

feat: 待提交审核商家优惠劵

parent 5e8725eb
......@@ -2,7 +2,7 @@
* @Author: XieZhiXiong
* @Date: 2021-06-22 11:08:16
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-06-28 10:27:45
* @LastEditTime: 2021-07-02 15:19:32
* @Description: 待提交审核商家优惠劵
*/
import React, { useState, useRef } from 'react';
......@@ -11,123 +11,127 @@ import {
Card,
Space,
Button,
message,
Modal,
} from 'antd';
import {
PlusOutlined,
QuestionCircleOutlined,
} from '@ant-design/icons';
import { StandardTable } from 'god';
import { ColumnType } from 'antd/lib/table/interface';
import { createFormActions } from '@formily/antd';
import { DatePicker } from '@formily/antd-components';
import moment from 'moment';
import { useStateFilterSearchLinkageEffect } from '@/formSchema/effects/useFilterSearch';
import { useAsyncInitSelect } from '@/formSchema/effects/useAsyncInitSelect';
import { FORM_FILTER_PATH } from '@/formSchema/const';
import EyePreview from '@/components/EyePreview';
import NiceForm from '@/components/NiceForm';
import { PublicApi } from '@/services/api';
import { GetMarketingCouponWaitAuditPageResponseDetail } from '@/services/MarketingApi';
import useSpliceArray from '@/hooks/useSpliceArray';
import { querySchema } from './schema';
import commonColumn from '../common/columns/coupon';
const { confirm } = Modal;
const formActions = createFormActions();
type fetchParams = {
name: string,
id: number,
effectiveTimeStart: string | number,
effectiveTimeEnd: string | number,
type: number,
}
const MerchantCouponUnsubmitted: React.FC = () => {
const ref = useRef<any>({});
const [selectedRowKeys, setSelectedRowKeys] = useState<number[]>([]);
const fetchData = async (params: any) => {
let res = await PublicApi.getMemberAbilityMaintenancePage(params);
const fetchData = async (params: fetchParams) => {
const { effectiveTimeStart = null, effectiveTimeEnd = null } = params;
const newParams: fetchParams = { ...params };
if (effectiveTimeStart) {
newParams.effectiveTimeStart = moment(effectiveTimeStart).valueOf();
}
if (effectiveTimeEnd) {
newParams.effectiveTimeEnd = moment(effectiveTimeEnd).valueOf();
}
let res = await PublicApi.getMarketingCouponWaitAuditPage(newParams as any);
return res.data;
};
const defaultColumns: ColumnType<any>[] = [
{
title: 'ID',
dataIndex: 'id',
align: 'center',
},
{
title: '优惠劵名称',
dataIndex: 'name',
align: 'center',
render: (text, record) => (
<EyePreview
url={`/memberCenter/marketingAbility/merchantCoupon/unsubmitted/detail?id=${record.validateId}`}
>
{text}
</EyePreview>
),
},
{
title: '优惠劵类型',
dataIndex: 'memberTypeName',
align: 'center',
},
{
title: '领(发)劵起始时间',
dataIndex: 'registerTime',
align: 'center',
},
{
title: '领(发)劵截止时间',
dataIndex: 'registerTime',
align: 'center',
},
{
title: '劵有效期起始时间',
dataIndex: 'registerTime',
align: 'center',
},
{
title: '劵有效期截止时间',
dataIndex: 'registerTime',
align: 'center',
},
{
title: '领劵方式',
dataIndex: 'depositTime',
align: 'center',
},
{
title: '劵面额',
dataIndex: 'statusName',
},
{
title: '发劵数量',
dataIndex: 'statusName',
},
{
title: '内部状态',
dataIndex: 'statusName',
},
const handleCommit = (ids: number[]) => {
const mesInstance = message.loading({
content: '正在提交',
duration: 0,
});
PublicApi.postMarketingCouponWaitAuditSubmitBatch({
ids,
}).then(res => {
if (res.code !== 1000) {
return;
}
ref.current.reload();
}).finally(() => {
mesInstance();
});
};
const handleDelete = (ids: number[]) => {
const mesInstance = message.loading({
content: '正在删除',
duration: 0,
});
PublicApi.postMarketingCouponWaitAuditDelete({
ids,
}).then(res => {
if (res.code !== 1000) {
return;
}
ref.current.reload();
}).finally(() => {
mesInstance();
});
};
const defaultColumns: ColumnType<GetMarketingCouponWaitAuditPageResponseDetail>[] = commonColumn().concat([
{
title: '操作',
dataIndex: 'option',
align: 'center',
render: (_, record) => (
<>
{record.submit && (
<Button
type="link"
onClick={() => {}}
onClick={() => handleCommit([record.id])}
>
提交
</Button>
)}
{record.update && (
<Button
type="link"
onClick={() => history.push(`/memberCenter/marketingAbility/merchantCoupon/unsubmitted/edit`)}
onClick={() => history.push(`/memberCenter/marketingAbility/merchantCoupon/unsubmitted/edit?id=${record.id}`)}
>
修改
</Button>
)}
{record.delete && (
<Button
type="link"
onClick={() => {}}
onClick={() => handleDelete([record.id])}
>
删除
</Button>
)}
</>
),
},
];
]);
const [columns, columnsHandle] = useSpliceArray<ColumnType<any>>(defaultColumns);
const rowSelection = {
......@@ -138,31 +142,79 @@ const MerchantCouponUnsubmitted: React.FC = () => {
};
// 初始化高级筛选选项
const fetchSelectOptions = async () => {
const res = await PublicApi.getMemberAbilityInfoPageitems();
const fetchTypeEnums = async () => {
const res = await PublicApi.getMarketingCouponTypeList();
if (res.code === 1000) {
const { data = {} }: any = res;
const {
outerStatus = [],
} = data;
const outerIndex = columns.findIndex((item) => item.dataIndex === 'memberTypeName');
if (outerIndex) {
columnsHandle.replace(outerIndex, {
...columns[outerIndex],
filters: outerStatus.map(item => ({ text: item.text, value: item.id })).filter(item => item.value !== 0),
});
}
const { data = [] } = res;
return {
innerStatus: outerStatus.map(item => ({ label: item.text, value: item.id })),
type: data.map(item => ({ label: item.name, value: item.value })),
};
}
return {};
};
const handleBatchCommit = () => {
if (!selectedRowKeys.length) {
message.warning('未选择任何优惠券');
return;
}
confirm({
title: '提示',
icon: <QuestionCircleOutlined />,
content: '确定要提交选中的优惠券吗?',
onOk() {
return new Promise<void>((resolve, reject) => {
PublicApi.postMarketingCouponWaitAuditSubmitBatch({
ids: selectedRowKeys,
})
.then(res => {
if (res.code === 1000) {
ref.current.reload();
setSelectedRowKeys([]);
resolve();
}
reject();
})
.catch(() => {
reject();
});
});
},
});
};
const handleBatchDelete = () => {
if (!selectedRowKeys.length) {
message.warning('未选择任何优惠券');
return;
}
confirm({
title: '提示',
icon: <QuestionCircleOutlined />,
content: '确定要删除选中的优惠券吗?',
onOk() {
return new Promise<void>((resolve, reject) => {
PublicApi.postMarketingCouponWaitAuditDelete({
ids: selectedRowKeys,
})
.then(res => {
if (res.code === 1000) {
ref.current.reload();
setSelectedRowKeys([]);
resolve();
}
reject();
})
.catch(() => {
reject();
});
});
},
});
};
const ControllerBtns = () => (
<Space size={16}>
<Button
......@@ -173,12 +225,12 @@ const MerchantCouponUnsubmitted: React.FC = () => {
新增优惠券
</Button>
<Button
onClick={() => {}}
onClick={handleBatchCommit}
>
批量提交
</Button>
<Button
onClick={() => {}}
onClick={handleBatchDelete}
>
批量删除
</Button>
......@@ -189,7 +241,7 @@ const MerchantCouponUnsubmitted: React.FC = () => {
<Card>
<StandardTable
tableProps={{
rowKey: 'validateId',
rowKey: 'id',
}}
columns={columns}
currentRef={ref}
......@@ -211,8 +263,8 @@ const MerchantCouponUnsubmitted: React.FC = () => {
FORM_FILTER_PATH,
);
useAsyncInitSelect(
['outerStatus'],
fetchSelectOptions,
['type'],
fetchTypeEnums,
);
}}
schema={querySchema}
......
......@@ -50,12 +50,9 @@ export const querySchema: ISchema = {
'x-component-props': {
placeholder: '优惠劵ID',
allowClear: true,
style: {
width: 160,
},
},
},
'[startTime2, endTime2]': {
'[effectiveTimeStart, effectiveTimeEnd]': {
type: 'object',
'x-component': 'RangePicker',
'x-component-props': {
......
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