feat: 用接口
This commit is contained in:
@ -43,4 +43,5 @@ export enum AdminAPI {
|
||||
GIVE_VIP = '/api/bo/giveVip/give',
|
||||
// 产品列表
|
||||
PRODUCT_LIST = '/api/bo/product/listByType/{productType}',
|
||||
GET_PRODUCT_SPEC = '/api/bo/product/getBySpecId/{productSpecId}'
|
||||
}
|
||||
|
||||
@ -19,7 +19,13 @@ import React, { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { CITY_OPTIONS } from '@/constants/city';
|
||||
import { TIME_FORMAT } from '@/constants/global';
|
||||
import { uploadFileWx } from '@/services/file';
|
||||
import { deleteCityOperator, getAllStaffList, getCityOpratorList, updateCityOperator } from '@/services/list';
|
||||
import {
|
||||
deleteCityOperator,
|
||||
getAllStaffList,
|
||||
getCityOpratorList,
|
||||
getProductList,
|
||||
updateCityOperator,
|
||||
} from '@/services/list';
|
||||
|
||||
const useStyles = createStyles(({ token }) => {
|
||||
return {
|
||||
@ -36,53 +42,14 @@ const useStyles = createStyles(({ token }) => {
|
||||
};
|
||||
});
|
||||
|
||||
const MIN_GROUP_SIZE = 20;
|
||||
export enum ProductSpecId {
|
||||
GroupBatchPublish20 = 'GROUP_BATCH_PUSH_20',
|
||||
GroupBatchPublish50 = 'GROUP_BATCH_PUSH_50',
|
||||
GroupBatchPublish60 = 'GROUP_BATCH_PUSH_60',
|
||||
GroupBatchPublish80 = 'GROUP_BATCH_PUSH_80',
|
||||
GroupBatchPublish100 = 'GROUP_BATCH_PUSH_100',
|
||||
GroupBatchPublish120 = 'GROUP_BATCH_PUSH_120',
|
||||
GroupBatchPublish150 = 'GROUP_BATCH_PUSH_150',
|
||||
GroupBatchPublish200 = 'GROUP_BATCH_PUSH_200',
|
||||
GroupBatchPublish250 = 'GROUP_BATCH_PUSH_250',
|
||||
GroupBatchPublish300 = 'GROUP_BATCH_PUSH_300',
|
||||
GroupBatchPublish500 = 'GROUP_BATCH_PUSH_500',
|
||||
GroupBatchPublish750 = 'GROUP_BATCH_PUSH_750',
|
||||
GroupBatchPublish800 = 'GROUP_BATCH_PUSH_800',
|
||||
GroupBatchPublish1000 = 'GROUP_BATCH_PUSH_1000',
|
||||
}
|
||||
const GROUP_OPTIONS = [
|
||||
{
|
||||
value: MIN_GROUP_SIZE,
|
||||
productSpecId: ProductSpecId.GroupBatchPublish20,
|
||||
label: '20',
|
||||
price: 38,
|
||||
originalPrice: 40,
|
||||
},
|
||||
{ value: 50, productSpecId: ProductSpecId.GroupBatchPublish50, label: '50', price: 68, originalPrice: 100 },
|
||||
{ value: 60, productSpecId: ProductSpecId.GroupBatchPublish60, label: '60', price: 78, originalPrice: 120 },
|
||||
{ value: 80, productSpecId: ProductSpecId.GroupBatchPublish80, label: '80', price: 88, originalPrice: 160 },
|
||||
{ value: 100, productSpecId: ProductSpecId.GroupBatchPublish100, label: '100', price: 98, originalPrice: 200 },
|
||||
{ value: 120, productSpecId: ProductSpecId.GroupBatchPublish120, label: '120', price: 108, originalPrice: 240 },
|
||||
{ value: 150, productSpecId: ProductSpecId.GroupBatchPublish150, label: '150', price: 128, originalPrice: 300 },
|
||||
{ value: 200, productSpecId: ProductSpecId.GroupBatchPublish200, label: '200', price: 148, originalPrice: 200 },
|
||||
{ value: 250, productSpecId: ProductSpecId.GroupBatchPublish250, label: '250', price: 168, originalPrice: 250 },
|
||||
{ value: 300, productSpecId: ProductSpecId.GroupBatchPublish300, label: '300', price: 168, originalPrice: 300 },
|
||||
{ value: 500, productSpecId: ProductSpecId.GroupBatchPublish500, label: '500', price: 168, originalPrice: 500 },
|
||||
{ value: 750, productSpecId: ProductSpecId.GroupBatchPublish750, label: '750', price: 168, originalPrice: 750 },
|
||||
{ value: 800, productSpecId: ProductSpecId.GroupBatchPublish800, label: '800', price: 168, originalPrice: 800 },
|
||||
{ value: 1000, productSpecId: ProductSpecId.GroupBatchPublish1000, label: '1000', price: 168, originalPrice: 1000 },
|
||||
];
|
||||
|
||||
const calcPrice = (sendCount: number) => {
|
||||
const price = GROUP_OPTIONS.find(o => o.value === sendCount)?.price || 18;
|
||||
const originalPrice = GROUP_OPTIONS.find(o => o.value === sendCount)?.originalPrice || sendCount;
|
||||
const calcPrice = (sendCount: number, specList: API.ProductSpecListItem[]) => {
|
||||
const price = specList.find(o => o.count === sendCount)?.showPrice || sendCount;
|
||||
const originalPrice = specList.find(o => o.count === sendCount)?.originalPrice || sendCount;
|
||||
return { price, originalPrice };
|
||||
};
|
||||
const TableList: React.FC = () => {
|
||||
const [updateModalOpen, handleUpdateModalOpen] = useState<boolean>(false);
|
||||
const [specList, setSpecList] = useState<API.ProductSpecListItem[]>([]);
|
||||
const [currentRow, setCurrentRow] = useState<API.CityOperatorListItem>();
|
||||
const actionRef = useRef<ActionType>();
|
||||
const formRef = useRef<ProFormInstance>();
|
||||
@ -91,6 +58,14 @@ const TableList: React.FC = () => {
|
||||
return staffOptions.find(it => it.isDefault) || staffOptions[0];
|
||||
}, [staffOptions]);
|
||||
const { styles } = useStyles();
|
||||
const specOptions = useMemo(
|
||||
() =>
|
||||
specList.map(it => ({
|
||||
value: it.count,
|
||||
label: it.title,
|
||||
})),
|
||||
[specList],
|
||||
);
|
||||
|
||||
const getAllStaffOptions = async () => {
|
||||
try {
|
||||
@ -107,6 +82,11 @@ const TableList: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const getAllSpectList = async () => {
|
||||
const list = await getProductList('GROUP_BATCH_PUSH');
|
||||
setSpecList(list);
|
||||
};
|
||||
|
||||
const handleDelete = async (id: number) => {
|
||||
await deleteCityOperator(id);
|
||||
message.success('操作成功');
|
||||
@ -118,6 +98,7 @@ const TableList: React.FC = () => {
|
||||
};
|
||||
useEffect(() => {
|
||||
getAllStaffOptions();
|
||||
getAllSpectList();
|
||||
}, []);
|
||||
|
||||
const columns: ProColumns<API.CityOperatorListItem>[] = [
|
||||
@ -272,7 +253,7 @@ const TableList: React.FC = () => {
|
||||
groupLink: formData.groupLink,
|
||||
sendCount: formData.sendCount,
|
||||
groupQrCode: formData.qrCode[0].xhr ? formData.qrCode[0].xhr.responseURL : formData.qrCode[0].url,
|
||||
price: calcPrice(formData.sendCount).price,
|
||||
price: calcPrice(formData.sendCount, specList).price,
|
||||
};
|
||||
console.log('update confirm', formData, params);
|
||||
try {
|
||||
@ -314,14 +295,14 @@ const TableList: React.FC = () => {
|
||||
mode="single"
|
||||
name="sendCount"
|
||||
label="可群发数量"
|
||||
options={GROUP_OPTIONS}
|
||||
options={specOptions}
|
||||
rules={[{ required: true, message: '必填项' }]}
|
||||
/>
|
||||
<ProFormDependency name={['sendCount']}>
|
||||
{({ sendCount }) =>
|
||||
sendCount ? (
|
||||
<div>
|
||||
价格:{calcPrice(sendCount).price}(原价:{calcPrice(sendCount).originalPrice})
|
||||
价格:{calcPrice(sendCount, specList).price}(原价:{calcPrice(sendCount, specList).originalPrice})
|
||||
</div>
|
||||
) : null
|
||||
}
|
||||
|
||||
@ -327,3 +327,9 @@ export async function getProductList(productType: API.ProductType) {
|
||||
method: 'GET',
|
||||
});
|
||||
}
|
||||
|
||||
export async function getProductSpec(productSpecId: API.ProductType) {
|
||||
return request<API.ProductSpecListItem>(buildUrl(AdminAPI.GET_PRODUCT_SPEC, {productSpecId}), {
|
||||
method: 'GET',
|
||||
})
|
||||
}
|
||||
|
||||
1
src/services/typings.d.ts
vendored
1
src/services/typings.d.ts
vendored
@ -411,6 +411,7 @@ declare namespace API {
|
||||
productSpecId: string;
|
||||
productType: ProductType;
|
||||
productName: string;
|
||||
count: number;
|
||||
title: string;
|
||||
priceText: string;
|
||||
payPrice: number;
|
||||
|
||||
Reference in New Issue
Block a user