|
@@ -12,6 +12,7 @@ import moment from "moment";
|
|
|
import TableData from "@/pages/launchSystemNew/components/TableData";
|
|
|
import FilterQuery from "./components/FilterQuery";
|
|
|
import RuleAccountLog from "@/components/EarlyWarning/ruleAccountLog";
|
|
|
+import { LineField } from "./config";
|
|
|
interface newListType extends ListType {
|
|
|
totalTimeUnit: 'total' | 'minute' | 'hour' | 'day',
|
|
|
planTimeUnit: 'minute' | 'hour' | 'day'
|
|
@@ -43,6 +44,7 @@ function Monitor(props: { onChange: () => void }) {
|
|
|
const [adgroupId, setAdgroupId] = useState<string>('')
|
|
|
const [adgroupName, setAdgroupName] = useState<string>('')
|
|
|
const [accountIdRule, setAccountIdRule] = useState<string>('')
|
|
|
+ const [trendColumns, setTrendColumns] = useState<string[]>(['cost'])
|
|
|
|
|
|
const { totalTimeUnit, planTimeUnit, adgroup, accountId, sysUserId, groupAccountIds } = queryForm
|
|
|
const configName = '起量广告排行明细New'
|
|
@@ -136,20 +138,24 @@ function Monitor(props: { onChange: () => void }) {
|
|
|
// 获取今日计划总消耗图谱,折线
|
|
|
useEffect(() => {
|
|
|
getTootalCostList()
|
|
|
- }, [planTimeUnit, adgroup, accountId, sysUserId, groupAccountIds])
|
|
|
+ }, [planTimeUnit, adgroup, accountId, sysUserId, groupAccountIds, trendColumns])
|
|
|
|
|
|
/** 获取折线图 */
|
|
|
const getTootalCostList = useCallback(async () => {
|
|
|
let { totalTimeUnit, planTimeUnit, pageNum, pageSize, adgroup, sysUserId, accountId, ...newQueryForm } = queryForm
|
|
|
let params = adgroup ? { ...newQueryForm, adgroupId: adgroup } : newQueryForm
|
|
|
- let res = await getCostTrendList.run({ ...params, timeUnit: planTimeUnit, sysUserIds: sysUserId, accountId: accountId?.join() })
|
|
|
- let data: any[] = [{ legendName: '消耗' }]
|
|
|
- res?.data?.forEach((item: any) => {
|
|
|
- data[0][item.trendUnit] = item.costOfUnit
|
|
|
+ let res = await getCostTrendList.run({ ...params, timeUnit: planTimeUnit, sysUserIds: sysUserId, accountId: accountId?.join(), trendColumns })
|
|
|
+ let data = trendColumns.map((field) => {
|
|
|
+ let value: any = {}
|
|
|
+ res?.data?.forEach((item: any, index: number) => {
|
|
|
+ if (index === 0) value.legendName = LineField[field];
|
|
|
+ value[item?.trend_unit] = item?.[field]
|
|
|
+ });
|
|
|
+ return value
|
|
|
})
|
|
|
setLineDis(() => data)
|
|
|
- setLineTitle(() => res?.data?.adName ? res?.data?.adName + '_消耗趋势' : '广告总消耗趋势')
|
|
|
- }, [queryForm, lineDis])
|
|
|
+ setLineTitle(() => `广告总${LineField[trendColumns[0]]}趋势`)
|
|
|
+ }, [queryForm, lineDis, trendColumns])
|
|
|
|
|
|
/** 获取柱状图 */
|
|
|
const getPlanCostList = useCallback(async () => {
|
|
@@ -202,32 +208,41 @@ function Monitor(props: { onChange: () => void }) {
|
|
|
setPx(b)
|
|
|
getCostTrendList.refresh()
|
|
|
getCostTopList.refresh()
|
|
|
- }, [getCostTopList, getCostTrendList])
|
|
|
+ }, [getCostTopList, getCostTrendList, trendColumns])
|
|
|
|
|
|
// 处理折线图数据
|
|
|
const timePickerHandle = async (values: any, formatString: [string, string]) => {
|
|
|
let res = await getCostTrendList.data
|
|
|
- let data: any[] = [{ legendName: '消耗' }]
|
|
|
- res?.data?.forEach((item: any) => {
|
|
|
- data[0][item.trendUnit] = item.costOfUnit
|
|
|
+ let data = trendColumns.map((field) => {
|
|
|
+ let value: any = {}
|
|
|
+ res?.data?.forEach((item: any, index: number) => {
|
|
|
+ if (index === 0) value.legendName = LineField[field];
|
|
|
+ value[item?.trend_unit] = item?.[field]
|
|
|
+ });
|
|
|
+ return value
|
|
|
})
|
|
|
+
|
|
|
if (values) {
|
|
|
let date = moment().format('YYYY-MM-DD')
|
|
|
let strTime = formatString[0]
|
|
|
let endTime = formatString[1]
|
|
|
let dateTimeStr = `${date} ${strTime}:00`
|
|
|
let dateTimeEnd = `${date} ${endTime}:00`
|
|
|
- let { legendName, ...otherData } = data[0]
|
|
|
- let newData: any = { legendName }
|
|
|
- for (const key in otherData) {
|
|
|
- if (Object.prototype.hasOwnProperty.call(otherData, key)) {
|
|
|
- const value = otherData[key];
|
|
|
- if (moment(dateTimeStr) <= moment(key) && moment(key) <= moment(dateTimeEnd)) {
|
|
|
- newData[key] = value
|
|
|
+
|
|
|
+ let newData: any[] = data.map(item => {
|
|
|
+ let { legendName, ...otherData } = item
|
|
|
+ let newItem: any = { legendName }
|
|
|
+ for (const key in otherData) {
|
|
|
+ if (Object.prototype.hasOwnProperty.call(otherData, key)) {
|
|
|
+ const value = otherData[key];
|
|
|
+ if (moment(dateTimeStr) <= moment(key) && moment(key) <= moment(dateTimeEnd)) {
|
|
|
+ newItem[key] = value
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- setLineDis(() => [newData])
|
|
|
+ return newItem
|
|
|
+ })
|
|
|
+ setLineDis(() => newData)
|
|
|
} else {
|
|
|
setLineDis(() => data)
|
|
|
}
|
|
@@ -369,9 +384,26 @@ function Monitor(props: { onChange: () => void }) {
|
|
|
minuteStep={5}
|
|
|
onChange={timePickerHandle}
|
|
|
/>}
|
|
|
+ <Select
|
|
|
+ showSearch
|
|
|
+ mode='multiple'
|
|
|
+ maxTagCount={1}
|
|
|
+ value={trendColumns}
|
|
|
+ style={{ minWidth: 130 }}
|
|
|
+ allowClear
|
|
|
+ placeholder="请选择图表字段"
|
|
|
+ onChange={(value: string[]) => {
|
|
|
+ setTrendColumns(value?.length ? value : ['cost'])
|
|
|
+ }}
|
|
|
+ size="small"
|
|
|
+ >
|
|
|
+ {Object.keys(LineField).map((key) => <Select.Option value={key} key={key}>
|
|
|
+ {LineField[key]}
|
|
|
+ </Select.Option>)}
|
|
|
+ </Select>
|
|
|
</Space>
|
|
|
</div>
|
|
|
- {getCostTrendList?.loading ? <Spin /> : <LineMonitor style={{ width: '100%', height: '100%' }} series smooth data={lineDis} title={lineTitle} />}
|
|
|
+ {getCostTrendList?.loading ? <Spin /> : <LineMonitor style={{ width: '100%', height: '100%' }} series smooth data={lineDis} title={trendColumns?.length > 1 ? undefined : lineTitle} />}
|
|
|
</div>
|
|
|
</div>
|
|
|
</Card>}
|
|
@@ -431,7 +463,7 @@ function Monitor(props: { onChange: () => void }) {
|
|
|
|
|
|
{visible && <Details visible={visible} onClose={() => { setVisible(false) }} data={aId} />}
|
|
|
|
|
|
- {logVisible && <RuleAccountLog accountId={accountIdRule} adgroupName={adgroupName} adgroupId={adgroupId} visible={logVisible} onClose={() => setLogVisible(false)}/>}
|
|
|
+ {logVisible && <RuleAccountLog accountId={accountIdRule} adgroupName={adgroupName} adgroupId={adgroupId} visible={logVisible} onClose={() => setLogVisible(false)} />}
|
|
|
</Space>
|
|
|
}
|
|
|
|