todo: KPI 设置和查看
parent
31481fd301
commit
a816e9a9de
@ -0,0 +1,106 @@
|
||||
import { makeAutoObservable, runInAction, toJS } from 'mobx';
|
||||
import * as req from '../utils/request';
|
||||
import { isEmpty, sortBy, groupBy } from '../utils/commons';
|
||||
import moment from 'moment';
|
||||
|
||||
const currentYear = moment().year();
|
||||
|
||||
class KPI {
|
||||
constructor(appStore) {
|
||||
this.appStore = appStore;
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
saveOrUpdate() {
|
||||
console.log('ssssssssssss');
|
||||
console.log(this.pageData);
|
||||
const tableData = this.pageData.reduce((r, curObj) => {
|
||||
const allMonth = new Array(12).fill(1).map((_, index) => {
|
||||
const mIndex = index+1;
|
||||
const startM = moment([this.settingYear, index, 1]);
|
||||
const pick = (({
|
||||
object, object_name, object_id, subject,date_type,
|
||||
}) => ({
|
||||
object, object_name, object_id, subject,date_type,
|
||||
}))(curObj);
|
||||
return {
|
||||
...pick,
|
||||
start_date: startM.format('YYYY-MM-DD'),
|
||||
end_date: startM.endOf('M').format('YYYY-MM-DD HH:mm:ss'),
|
||||
value: curObj[`M${mIndex}`],
|
||||
// ...(curObj[`M${mIndex}_id`] ? { kpi_id: curObj[`M${mIndex}_id`] } : {}),
|
||||
kpi_id: curObj[`M${mIndex}_id`] || undefined,
|
||||
key: undefined,
|
||||
};
|
||||
});
|
||||
console.log('cccccccccc', allMonth);
|
||||
return r.concat(allMonth);
|
||||
}, []);
|
||||
console.log('ppppp', tableData);
|
||||
const data = {
|
||||
'kpis': tableData
|
||||
// [
|
||||
// {
|
||||
// 'kpi_id': '1',
|
||||
// 'object': 'sales',
|
||||
// 'subject': 'orderCount',
|
||||
// 'object_name': '刘莎',
|
||||
// 'object_id': '15',
|
||||
// 'date_type': 'confirmDate',
|
||||
// 'start_date': '2024-01-01',
|
||||
// 'end_date': '2024-03-31 23:59',
|
||||
// 'value': '10000',
|
||||
// },
|
||||
// ],
|
||||
};
|
||||
// req.postJSON('/service-Analyse2/setkpi_multi/test', data).then((json) => {
|
||||
req.postJSON('/service-Analyse2/setkpi_multi', data).then((json) => {
|
||||
if (json.errcode === 0) {
|
||||
runInAction(() => {
|
||||
console.log({ loading: false, ...json }, 'post kpi');
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getList() {
|
||||
const param = {
|
||||
date_type: 'confirmDate',
|
||||
start_date: '2024-01-01',
|
||||
end_date: '2024-12-01',
|
||||
};
|
||||
// req.fetchJSON('/service-Analyse2/getkpi/test', param).then((json) => {
|
||||
req.fetchJSON('/service-Analyse2/getkpi', param).then((json) => {
|
||||
if (json.errcode === 0) {
|
||||
runInAction(() => {
|
||||
const result = json.result.map((row) => ({ ...row, yearIndex: moment(row.start_date).year(), monthIndex: moment(row.start_date).month() + 1 }));
|
||||
const byYear = groupBy(result, (ele) => ele.yearIndex);
|
||||
const yearData = {};
|
||||
Object.keys(byYear).map((_yearVal) => {
|
||||
const _objRet = groupBy(byYear[_yearVal], (ele) => `${ele.object_id}`);
|
||||
Object.keys(_objRet).map((_obj) => {
|
||||
_objRet[_obj] = _objRet[_obj].reduce((r, v) => ({ ...r, ...v, [`M${v.monthIndex}`]: v.value, [`M${v.monthIndex}_id`]: v.kpi_id }), {});
|
||||
return _obj;
|
||||
});
|
||||
Object.assign(yearData, { [_yearVal]: Object.values(_objRet) });
|
||||
return _yearVal;
|
||||
});
|
||||
console.log(111, yearData);
|
||||
this.pageData = yearData[this.settingYear];
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
handleTableEdit(data) {
|
||||
console.log('handle change ', data);
|
||||
this.pageData = data;
|
||||
}
|
||||
|
||||
settingYear = 2024;
|
||||
data = [];
|
||||
objectData = [];
|
||||
|
||||
pageData = [];
|
||||
}
|
||||
export default KPI;
|
Loading…
Reference in New Issue