import {
  getBusinessConditionDatas,
  getAllTypeBusinessConditionDatas,
  getAllTypeBusinessConditionDetailByDay,
  getBusinessConditionDataByMonth,
  getAllTypeBusinessConditionDatasByMonth,
  getAllTypeBusinessConditionDetailByMonth,
  getBusinessConditionDatasByYear,
  getAllTypeBusinessConditionDatasByYear,
  getAllTypeBusinessConditionDetailByYear
} from "../../api/apiList";
import {calc_hb_str, calc_tb_str, conver_amont} from "../../utils/numUtil";
import moment from 'moment'
//天维度数据转换
export const getTrunOver = async function (dimension, type, cur_day) {
  let pageData = new Object();
  pageData.head = await getHead(dimension, type, cur_day)
  pageData.detail = await getDetail(dimension, type, cur_day)
  return pageData;
};

/**
 * @param cur_day
 */
export const getHead = async function (dimension, type, cur_day) {
  let typeName = new Object({"yye": "营业额", "cb": "成本", "ml": "毛利"});
  let pageName = typeName[type]
  let truck = "汽运" + pageName;
  let ship = "水运" + pageName;
  let tran = "铁运" + pageName;
  let headData = new Object();
  let transportData;
  let res = await reqDaySumData(dimension, cur_day);
  headData[pageName] = adapterSumData(dimension, type, res);
  transportData = await reqDayTransportData(dimension, cur_day)
  headData[truck] = initSumDataDay();
  headData[ship] = initSumDataDay();
  headData[tran] = initSumDataDay();
  if (transportData[10]) {
    headData[truck] = adapterSumData(dimension, type, transportData[10]);
  }
  if (transportData[30]) {
    headData[ship] = adapterSumData(dimension, type, transportData[30]);
  }
  if (transportData[20]) {
    headData[tran] = adapterSumData(dimension, type, transportData[20]);
  }
  return headData;
};
//获取折线图明细
export const getDetail = async function (dimension, type, cur_day) {
  let data;
  if (dimension == 'day') {
    data = {"2023-11-01":[{"cur_gross_profit_amount":70082.523823,"cur_sell_settle_amount":703063.741043,"cur_transport_type":"10","cur_buy_settle_amount":632981.21722,"cur_day":"2023-11-01"},{"cur_gross_profit_amount":25375.7484,"cur_sell_settle_amount":95674.02,"cur_transport_type":"30","cur_buy_settle_amount":70298.2716,"cur_day":"2023-11-01"}],"2023-11-02":[{"cur_gross_profit_amount":41925.480805,"cur_sell_settle_amount":440038.57384,"cur_transport_type":"10","cur_buy_settle_amount":398113.093035,"cur_day":"2023-11-02"},{"cur_gross_profit_amount":74376.117446,"cur_sell_settle_amount":507004.049946,"cur_transport_type":"30","cur_buy_settle_amount":432627.9325,"cur_day":"2023-11-02"}],"2023-11-03":[{"cur_gross_profit_amount":287604.872168,"cur_sell_settle_amount":799348.274278,"cur_transport_type":"10","cur_buy_settle_amount":511743.40211,"cur_day":"2023-11-03"},{"cur_gross_profit_amount":316273.680993,"cur_sell_settle_amount":1132012.320996,"cur_transport_type":"30","cur_buy_settle_amount":815738.640001,"cur_day":"2023-11-03"}],"2023-11-04":[{"cur_gross_profit_amount":266415.247293,"cur_sell_settle_amount":443246.774403,"cur_transport_type":"10","cur_buy_settle_amount":176831.52711,"cur_day":"2023-11-04"},{"cur_gross_profit_amount":223359.972,"cur_sell_settle_amount":248204.529993,"cur_transport_type":"30","cur_buy_settle_amount":24844.557994,"cur_day":"2023-11-04"}],"2023-11-05":[{"cur_gross_profit_amount":35551.916038,"cur_sell_settle_amount":278584.572298,"cur_transport_type":"10","cur_buy_settle_amount":243032.65626,"cur_day":"2023-11-05"},{"cur_gross_profit_amount":69522.316999,"cur_sell_settle_amount":991071.918003,"cur_transport_type":"30","cur_buy_settle_amount":921549.601,"cur_day":"2023-11-05"}],"2023-11-06":[{"cur_gross_profit_amount":19011.162147,"cur_sell_settle_amount":388910.647517,"cur_transport_type":"10","cur_buy_settle_amount":369899.48537,"cur_day":"2023-11-06"},{"cur_gross_profit_amount":91924.958996,"cur_sell_settle_amount":295085.989996,"cur_transport_type":"30","cur_buy_settle_amount":203161.031,"cur_day":"2023-11-06"}],"2023-11-07":[{"cur_gross_profit_amount":127421.729747,"cur_sell_settle_amount":604575.918557,"cur_transport_type":"10","cur_buy_settle_amount":477154.18881,"cur_day":"2023-11-07"},{"cur_gross_profit_amount":154839.369006,"cur_sell_settle_amount":406379.538006,"cur_transport_type":"30","cur_buy_settle_amount":251540.169,"cur_day":"2023-11-07"}],"2023-11-08":[{"cur_gross_profit_amount":93013.797215,"cur_sell_settle_amount":451126.650715,"cur_transport_type":"10","cur_buy_settle_amount":358112.8535,"cur_day":"2023-11-08"},{"cur_gross_profit_amount":270980.954899,"cur_sell_settle_amount":456219.540002,"cur_transport_type":"30","cur_buy_settle_amount":185238.585104,"cur_day":"2023-11-08"}],"2023-11-09":[{"cur_gross_profit_amount":149226.570849,"cur_sell_settle_amount":691733.774299,"cur_transport_type":"10","cur_buy_settle_amount":542507.20345,"cur_day":"2023-11-09"},{"cur_gross_profit_amount":259640.239988,"cur_sell_settle_amount":764082.284996,"cur_transport_type":"30","cur_buy_settle_amount":504442.045009,"cur_day":"2023-11-09"}],"2023-11-10":[{"cur_gross_profit_amount":111458.467546,"cur_sell_settle_amount":412478.139906,"cur_transport_type":"10","cur_buy_settle_amount":301019.67236,"cur_day":"2023-11-10"},{"cur_gross_profit_amount":43916.144771,"cur_sell_settle_amount":491861.039771,"cur_transport_type":"30","cur_buy_settle_amount":447944.895,"cur_day":"2023-11-10"}],"2023-11-11":[{"cur_gross_profit_amount":68137.248363,"cur_sell_settle_amount":221786.959793,"cur_transport_type":"10","cur_buy_settle_amount":153649.71143,"cur_day":"2023-11-11"},{"cur_gross_profit_amount":147090.853004,"cur_sell_settle_amount":201166.320004,"cur_transport_type":"30","cur_buy_settle_amount":54075.467,"cur_day":"2023-11-11"}],"2023-11-12":[{"cur_gross_profit_amount":530689.876952,"cur_sell_settle_amount":684774.877702,"cur_transport_type":"10","cur_buy_settle_amount":154085.00075,"cur_day":"2023-11-12"},{"cur_gross_profit_amount":21763.825503,"cur_sell_settle_amount":491827.563003,"cur_transport_type":"30","cur_buy_settle_amount":470063.7375,"cur_day":"2023-11-12"}],"2023-11-13":[{"cur_gross_profit_amount":201188.821843,"cur_sell_settle_amount":615101.835913,"cur_transport_type":"10","cur_buy_settle_amount":413913.01407,"cur_day":"2023-11-13"},{"cur_gross_profit_amount":70520.7535,"cur_sell_settle_amount":110916.21,"cur_transport_type":"30","cur_buy_settle_amount":40395.4565,"cur_day":"2023-11-13"}],"2023-11-14":[{"cur_gross_profit_amount":123120.210139,"cur_sell_settle_amount":524819.703099,"cur_transport_type":"10","cur_buy_settle_amount":401699.49296,"cur_day":"2023-11-14"},{"cur_gross_profit_amount":75932.832488,"cur_sell_settle_amount":455821.738988,"cur_transport_type":"30","cur_buy_settle_amount":379888.9065,"cur_day":"2023-11-14"}],"2023-11-15":[{"cur_gross_profit_amount":180095.801101,"cur_sell_settle_amount":684506.742981,"cur_transport_type":"10","cur_buy_settle_amount":504410.94188,"cur_day":"2023-11-15"},{"cur_gross_profit_amount":258339.618997,"cur_sell_settle_amount":617923.644997,"cur_transport_type":"30","cur_buy_settle_amount":359584.026,"cur_day":"2023-11-15"}],"2023-11-16":[{"cur_gross_profit_amount":106751.30058,"cur_sell_settle_amount":633242.769468,"cur_transport_type":"10","cur_buy_settle_amount":526491.468893,"cur_day":"2023-11-16"},{"cur_gross_profit_amount":74687.287999,"cur_sell_settle_amount":298274.089999,"cur_transport_type":"30","cur_buy_settle_amount":223586.802,"cur_day":"2023-11-16"}],"2023-11-17":[{"cur_gross_profit_amount":154268.04136,"cur_sell_settle_amount":362953.76239,"cur_transport_type":"10","cur_buy_settle_amount":208685.72103,"cur_day":"2023-11-17"},{"cur_gross_profit_amount":22827.661399,"cur_sell_settle_amount":102587.439999,"cur_transport_type":"30","cur_buy_settle_amount":79759.7786,"cur_day":"2023-11-17"}],"2023-11-18":[{"cur_gross_profit_amount":111852.36541,"cur_sell_settle_amount":364995.5018,"cur_transport_type":"10","cur_buy_settle_amount":253143.13639,"cur_day":"2023-11-18"},{"cur_gross_profit_amount":30924.737997,"cur_sell_settle_amount":140895.749997,"cur_transport_type":"30","cur_buy_settle_amount":109971.012,"cur_day":"2023-11-18"}],"2023-11-19":[{"cur_gross_profit_amount":517353.74873,"cur_sell_settle_amount":647192.8212,"cur_transport_type":"10","cur_buy_settle_amount":129839.07247,"cur_day":"2023-11-19"},{"cur_gross_profit_amount":348230.23551,"cur_sell_settle_amount":611401.63301,"cur_transport_type":"30","cur_buy_settle_amount":263171.3975,"cur_day":"2023-11-19"}],"2023-11-20":[{"cur_gross_profit_amount":184584.59267,"cur_sell_settle_amount":361261.45128,"cur_transport_type":"10","cur_buy_settle_amount":176676.85861,"cur_day":"2023-11-20"},{"cur_gross_profit_amount":373168.7117,"cur_sell_settle_amount":695554.9694,"cur_transport_type":"30","cur_buy_settle_amount":322386.2577,"cur_day":"2023-11-20"}],"2023-11-21":[{"cur_gross_profit_amount":369161.17037,"cur_sell_settle_amount":532818.92124,"cur_transport_type":"10","cur_buy_settle_amount":163657.75087,"cur_day":"2023-11-21"},{"cur_gross_profit_amount":16782.9225,"cur_sell_settle_amount":66089.673,"cur_transport_type":"30","cur_buy_settle_amount":49306.7505,"cur_day":"2023-11-21"}],"2023-11-22":[{"cur_gross_profit_amount":778616.21739,"cur_sell_settle_amount":947153.95138,"cur_transport_type":"10","cur_buy_settle_amount":168537.73399,"cur_day":"2023-11-22"},{"cur_gross_profit_amount":119512.5309,"cur_sell_settle_amount":165140.1423,"cur_transport_type":"30","cur_buy_settle_amount":45627.6114,"cur_day":"2023-11-22"}],"2023-11-23":[{"cur_gross_profit_amount":101674.84894,"cur_sell_settle_amount":166593.02355,"cur_transport_type":"10","cur_buy_settle_amount":64918.17461,"cur_day":"2023-11-23"},{"cur_gross_profit_amount":-25654.24,"cur_sell_settle_amount":48353.725,"cur_transport_type":"30","cur_buy_settle_amount":74007.965,"cur_day":"2023-11-23"}]};
  }
  if (dimension == 'month') {
    data = {"2023-10":[{"cur_gross_profit_amount":2371455.56141,"cur_sell_settle_amount":14411928.065146,"cur_month":"2023-10","cur_transport_type":"10","cur_buy_settle_amount":12040472.503739},{"cur_gross_profit_amount":2743626.653688,"cur_sell_settle_amount":16227670.151025,"cur_month":"2023-10","cur_transport_type":"30","cur_buy_settle_amount":13484043.497485}],"2023-11":[{"cur_gross_profit_amount":4629206.011479,"cur_sell_settle_amount":11960309.388652,"cur_month":"2023-11","cur_transport_type":"10","cur_buy_settle_amount":7331103.377178},{"cur_gross_profit_amount":3064337.234995,"cur_sell_settle_amount":9393548.131406,"cur_month":"2023-11","cur_transport_type":"30","cur_buy_settle_amount":6329210.896408}],"2023-01":[{"cur_gross_profit_amount":963056.382398,"cur_sell_settle_amount":10015901.747851,"cur_month":"2023-01","cur_transport_type":"10","cur_buy_settle_amount":9052845.365444},{"cur_gross_profit_amount":1470739.289382,"cur_sell_settle_amount":14369794.398776,"cur_month":"2023-01","cur_transport_type":"30","cur_buy_settle_amount":12899055.109572}],"2023-02":[{"cur_gross_profit_amount":1111950.378322,"cur_sell_settle_amount":11498376.985437,"cur_month":"2023-02","cur_transport_type":"10","cur_buy_settle_amount":10386426.607118},{"cur_gross_profit_amount":1822576.974592,"cur_sell_settle_amount":16455239.814466,"cur_month":"2023-02","cur_transport_type":"30","cur_buy_settle_amount":14632662.839973}],"2023-03":[{"cur_gross_profit_amount":916912.95362,"cur_sell_settle_amount":11871971.328282,"cur_month":"2023-03","cur_transport_type":"10","cur_buy_settle_amount":10955058.374648},{"cur_gross_profit_amount":1902918.682052,"cur_sell_settle_amount":18409202.355704,"cur_month":"2023-03","cur_transport_type":"30","cur_buy_settle_amount":16506283.673167}],"2023-04":[{"cur_gross_profit_amount":933930.975026,"cur_sell_settle_amount":12164871.64552,"cur_month":"2023-04","cur_transport_type":"10","cur_buy_settle_amount":11230940.670501},{"cur_gross_profit_amount":40289.59,"cur_sell_settle_amount":40289.59,"cur_month":"2023-04","cur_transport_type":"20","cur_buy_settle_amount":0},{"cur_gross_profit_amount":1768346.381106,"cur_sell_settle_amount":17107996.223209,"cur_month":"2023-04","cur_transport_type":"30","cur_buy_settle_amount":15339649.842343}],"2023-05":[{"cur_gross_profit_amount":1027834.475232,"cur_sell_settle_amount":13398462.694501,"cur_month":"2023-05","cur_transport_type":"10","cur_buy_settle_amount":12370628.219258},{"cur_gross_profit_amount":7274.96,"cur_sell_settle_amount":7274.96,"cur_month":"2023-05","cur_transport_type":"20","cur_buy_settle_amount":0},{"cur_gross_profit_amount":1938052.25009,"cur_sell_settle_amount":18487024.576067,"cur_month":"2023-05","cur_transport_type":"30","cur_buy_settle_amount":16548972.326434}],"2023-06":[{"cur_gross_profit_amount":926783.649524,"cur_sell_settle_amount":11677306.246429,"cur_month":"2023-06","cur_transport_type":"10","cur_buy_settle_amount":10750522.596905},{"cur_gross_profit_amount":1679257.899074,"cur_sell_settle_amount":13293432.776273,"cur_month":"2023-06","cur_transport_type":"30","cur_buy_settle_amount":11614174.877305}],"2023-07":[{"cur_gross_profit_amount":538218.812622,"cur_sell_settle_amount":11321404.463061,"cur_month":"2023-07","cur_transport_type":"10","cur_buy_settle_amount":10783185.650427},{"cur_gross_profit_amount":1620396.182778,"cur_sell_settle_amount":15798110.546585,"cur_month":"2023-07","cur_transport_type":"30","cur_buy_settle_amount":14177714.363797}],"2023-08":[{"cur_gross_profit_amount":659122.713145,"cur_sell_settle_amount":12563604.766923,"cur_month":"2023-08","cur_transport_type":"10","cur_buy_settle_amount":11904482.053764},{"cur_gross_profit_amount":2075817.900885,"cur_sell_settle_amount":16466178.361762,"cur_month":"2023-08","cur_transport_type":"30","cur_buy_settle_amount":14390360.460873}],"2023-09":[{"cur_gross_profit_amount":2230060.618783,"cur_sell_settle_amount":12106561.290177,"cur_month":"2023-09","cur_transport_type":"10","cur_buy_settle_amount":9876500.671403},{"cur_gross_profit_amount":2036921.332193,"cur_sell_settle_amount":14559762.115248,"cur_month":"2023-09","cur_transport_type":"30","cur_buy_settle_amount":12522840.783157}]};
  }
  if (dimension == 'year') {
    data = {"2021":[{"cur_gross_profit_amount":265827.958096,"cur_sell_settle_amount":355324.123887,"annual":2021,"cur_transport_type":"30","cur_buy_settle_amount":89496.165791},{"cur_gross_profit_amount":272921.715591,"cur_sell_settle_amount":360907.980242,"annual":2021,"cur_transport_type":"10","cur_buy_settle_amount":87986.264651}],"2022":[{"cur_gross_profit_amount":12664983.198857,"cur_sell_settle_amount":230228467.765424,"annual":2022,"cur_transport_type":"30","cur_buy_settle_amount":217563484.566954},{"cur_gross_profit_amount":22586.841891,"cur_sell_settle_amount":998792.355,"annual":2022,"cur_transport_type":"20","cur_buy_settle_amount":976205.513109},{"cur_gross_profit_amount":8460125.980709,"cur_sell_settle_amount":139091852.082745,"annual":2022,"cur_transport_type":"10","cur_buy_settle_amount":130631726.102089}],"2023":[{"cur_gross_profit_amount":16308532.531561,"cur_sell_settle_amount":132990698.621979,"annual":2023,"cur_transport_type":"10","cur_buy_settle_amount":116682166.090385},{"cur_gross_profit_amount":22122990.780835,"cur_sell_settle_amount":170567959.450521,"annual":2023,"cur_transport_type":"30","cur_buy_settle_amount":148444968.670514},{"cur_gross_profit_amount":47564.55,"cur_sell_settle_amount":47564.55,"annual":2023,"cur_transport_type":"20","cur_buy_settle_amount":0}]};
  }
  return adapterDetailData(dimension, type, data)
};

//获取全部汇总数据
export const reqDaySumData = async function (dimension, cur_day) {
  if (dimension == 'day') {
    return {"pre_buy_settle_amount":214165.34539,"cur_gross_profit_amount":76020.60894,"cur_sell_settle_amount":214946.74855,"pre_sell_settle_amount":1112294.09368,"pre_month_sell_settle_amount":1208466.39419,"pre_month_buy_settle_amount":1085500.24183,"cur_buy_settle_amount":138926.13961,"pre_gross_profit_amount":898128.74829,"pre_month_gross_profit_amount":122966.15236};
  }
  if (dimension == 'month') {
    return {"pre_year_sell_settle_amount":328471828.014936,"pre_year_buy_settle_amount":310648662.166894,"cur_month_buy_settle_amount":13660314.273586,"cur_month_sell_settle_amount":21353857.520058,"pre_month_sell_settle_amount":20863796.334218,"pre_month_buy_settle_amount":17284347.818552,"pre_year_gross_profit_amount":17823165.848097,"cur_month_gross_profit_amount":7693543.246474,"pre_month_gross_profit_amount":3579448.515737};
  }
  if (dimension == 'year') {
    return {"pre_year_sell_settle_amount":328471828.014936,"pre_year_buy_settle_amount":310648662.166894,"cur_year_sell_settle_amount":303606222.6225,"cur_year_buy_settle_amount":265127134.760899,"cur_year_gross_profit_amount":38479087.862396,"pre_year_gross_profit_amount":17823165.848097};
  }
}

//获取每个运输方式汇总数据
export const reqDayTransportData = async function (dimension, cur_day) {
  let data;
  if (dimension == 'day') {
    data = {"10":{"pre_buy_settle_amount":168537.73399,"cur_gross_profit_amount":101674.84894,"cur_sell_settle_amount":166593.02355,"pre_sell_settle_amount":947153.95138,"pre_month_sell_settle_amount":911861.814214,"pre_month_buy_settle_amount":855066.25033,"cur_buy_settle_amount":64918.17461,"pre_gross_profit_amount":778616.21739,"pre_month_gross_profit_amount":56795.563884},"20":{"pre_buy_settle_amount":0,"cur_gross_profit_amount":0,"cur_sell_settle_amount":0,"pre_sell_settle_amount":0,"pre_month_sell_settle_amount":0,"pre_month_buy_settle_amount":0,"cur_buy_settle_amount":0,"pre_gross_profit_amount":0,"pre_month_gross_profit_amount":0},"30":{"pre_buy_settle_amount":45627.6114,"cur_gross_profit_amount":-25654.24,"cur_sell_settle_amount":48353.725,"pre_sell_settle_amount":165140.1423,"pre_month_sell_settle_amount":296604.579976,"pre_month_buy_settle_amount":230433.9915,"cur_buy_settle_amount":74007.965,"pre_gross_profit_amount":119512.5309,"pre_month_gross_profit_amount":66170.588476},"40":{"pre_buy_settle_amount":0,"cur_gross_profit_amount":0,"cur_sell_settle_amount":0,"pre_sell_settle_amount":0,"pre_month_sell_settle_amount":0,"pre_month_buy_settle_amount":0,"cur_buy_settle_amount":0,"pre_gross_profit_amount":0,"pre_month_gross_profit_amount":0}};
  }
  if (dimension == 'month') {
    data = {"10":{"pre_year_sell_settle_amount":122661347.044853,"pre_year_buy_settle_amount":115074390.699944,"cur_month_buy_settle_amount":7330742.611278,"cur_month_sell_settle_amount":11960309.388652,"pre_month_sell_settle_amount":9739589.919675,"pre_month_buy_settle_amount":7916723.162187,"pre_year_gross_profit_amount":7586956.344956,"cur_month_gross_profit_amount":4629566.777379,"pre_month_gross_profit_amount":1822866.757492},"20":{"pre_year_sell_settle_amount":998792.355,"pre_year_buy_settle_amount":976205.513109,"cur_month_buy_settle_amount":0,"cur_month_sell_settle_amount":0,"pre_month_sell_settle_amount":0,"pre_month_buy_settle_amount":0,"pre_year_gross_profit_amount":22586.841891,"cur_month_gross_profit_amount":0,"pre_month_gross_profit_amount":0},"30":{"pre_year_sell_settle_amount":204811688.615083,"pre_year_buy_settle_amount":194598065.953841,"cur_month_buy_settle_amount":6329210.896408,"cur_month_sell_settle_amount":9393548.131406,"pre_month_sell_settle_amount":11124206.414543,"pre_month_buy_settle_amount":9367624.656365,"pre_year_gross_profit_amount":10213622.66125,"cur_month_gross_profit_amount":3064337.234995,"pre_month_gross_profit_amount":1756581.758245},"40":{"pre_year_sell_settle_amount":0,"pre_year_buy_settle_amount":0,"cur_month_buy_settle_amount":0,"cur_month_sell_settle_amount":0,"pre_month_sell_settle_amount":0,"pre_month_buy_settle_amount":0,"pre_year_gross_profit_amount":0,"cur_month_gross_profit_amount":0,"pre_month_gross_profit_amount":0}};
  }
  if (dimension == 'year') {
    data = {"10":{"pre_year_sell_settle_amount":122661347.044853,"pre_year_buy_settle_amount":115074390.699944,"cur_year_sell_settle_amount":132990698.621979,"cur_year_buy_settle_amount":116682166.090385,"cur_year_gross_profit_amount":16308532.531561,"pre_year_gross_profit_amount":7586956.344956},"20":{"pre_year_sell_settle_amount":998792.355,"pre_year_buy_settle_amount":976205.513109,"cur_year_sell_settle_amount":47564.55,"cur_year_buy_settle_amount":0,"cur_year_gross_profit_amount":47564.55,"pre_year_gross_profit_amount":22586.841891},"30":{"pre_year_sell_settle_amount":204811688.615083,"pre_year_buy_settle_amount":194598065.953841,"cur_year_sell_settle_amount":170567959.450521,"cur_year_buy_settle_amount":148444968.670514,"cur_year_gross_profit_amount":22122990.780835,"pre_year_gross_profit_amount":10213622.66125},"40":{"pre_year_sell_settle_amount":0,"pre_year_buy_settle_amount":0,"cur_year_sell_settle_amount":0,"cur_year_buy_settle_amount":0,"cur_year_gross_profit_amount":0,"pre_year_gross_profit_amount":0}};
  }
  return data;
}


//获取明细数据数据
export const reqTransportDetailDayData = async function (cur_day) {
  let res = await getAllTypeBusinessConditionDetailByDay(moment(cur_day).format('YYYY-MM'));
  let data = res.data
  return data;
}


/**
 * 数据匹配
 * @param type
 * @param data
 */
export const adapterSumData = function (dimension, type, data) {
  let res;
  if (dimension == 'day') {
    res = adapterSumDataDay(type, data);
  }
  if (dimension == 'month') {
    res = adapterSumDataMonth(type, data);
  }
  if (dimension == 'year') {
    res = adapterSumDataYear(type, data);
  }
  return res;
}


/**
 *日维度汇总
 * @param type yye:营业额、cb:成本、ml:毛利
 * @param data
 */
export const adapterSumDataDay = function (type, data) {
  let turnOver = initSumDataDay();
  let hb = new Array()
  if (type == 'yye') {
    turnOver.title = '营业额'
    turnOver.amount = conver_amont(data.cur_sell_settle_amount);
    //昨日环比
    let yesterday = initRate('昨日', conver_amont(data.pre_sell_settle_amount), calc_hb_str(data.cur_sell_settle_amount, data.pre_sell_settle_amount))
    hb.push(yesterday)
    //昨日环比
    let premonth = initRate('上月', conver_amont(data.pre_month_sell_settle_amount), calc_tb_str(data.cur_sell_settle_amount, data.pre_month_sell_settle_amount))
    hb.push(premonth)
  }
  if (type == 'cb') {
    turnOver.title = '成本'
    turnOver.amount = conver_amont(data.cur_buy_settle_amount);
    //昨日环比
    let yesterday = initRate('昨日', conver_amont(data.pre_buy_settle_amount), calc_hb_str(data.cur_buy_settle_amount, data.pre_buy_settle_amount))
    hb.push(yesterday)
    //昨日环比
    let premonth = initRate('上月', conver_amont(data.pre_month_buy_settle_amount), calc_tb_str(data.cur_buy_settle_amount, data.pre_month_buy_settle_amount))
    hb.push(premonth)
  }
  if (type == 'ml') {
    turnOver.title = '毛利'
    turnOver.amount = conver_amont(data.cur_gross_profit_amount);
    //昨日环比
    let yesterday = initRate('昨日', conver_amont(data.pre_gross_profit_amount), calc_hb_str(data.cur_gross_profit_amount, data.pre_gross_profit_amount))
    hb.push(yesterday)
    //昨日环比
    let premonth = initRate('上月', conver_amont(data.pre_month_gross_profit_amount), calc_tb_str(data.cur_gross_profit_amount, data.pre_month_gross_profit_amount))
    hb.push(premonth)
  }
  turnOver['hb'] = hb
  return turnOver;
}

/**
 * 初始化汇总数据
 * @returns {Object}
 */
export const initSumDataDay = function () {
  let turnOver = new Object()
  turnOver.title = '营业额'
  turnOver.amount = "0.0"
  let hb = new Array()
  let yesterday = initRate('昨日')
  hb.push(yesterday)
  yesterday = initRate('上月')
  hb.push(yesterday)
  turnOver.hb = hb
  return turnOver;
}

export const initRate = function (title, amount, rate) {
  let rateVo = new Object()
  rateVo.title = title
  rateVo.amount = amount ? amount : "0.0"
  rateVo.rate = rate ? rate : "0%"
  return rateVo;
}


/**
 * 月维度汇总
 * @param type
 * @param data
 */
export const adapterSumDataMonth = function (type, data) {
  let turnOver = initSumDataDay()
  let hb = new Array()
  if (type == 'yye') {
    turnOver.title = '营业额'
    turnOver.amount = conver_amont(data.cur_month_sell_settle_amount);
    //昨日环比
    let yesterday = initRate('上月', conver_amont(data.pre_month_sell_settle_amount), calc_hb_str(data.cur_month_sell_settle_amount, data.pre_month_sell_settle_amount))
    hb.push(yesterday)
    //昨日环比
    let premonth = initRate('去年', conver_amont(data.pre_year_sell_settle_amount), calc_tb_str(data.cur_month_sell_settle_amount, data.pre_year_sell_settle_amount))
    hb.push(premonth)
  }
  if (type == 'cb') {
    turnOver.title = '成本'
    turnOver.amount = conver_amont(data.cur_month_buy_settle_amount);
    //上月环比
    let yesterday = initRate('上月', conver_amont(data.pre_month_buy_settle_amount), calc_hb_str(data.cur_month_buy_settle_amount, data.pre_month_buy_settle_amount))
    hb.push(yesterday)
    //去年环比
    let premonth = initRate('去年', conver_amont(data.pre_year_buy_settle_amount), calc_tb_str(data.cur_month_buy_settle_amount, data.pre_year_buy_settle_amount))
    hb.push(premonth)
  }
  if (type == 'ml') {
    turnOver.title = '毛利'
    turnOver.amount = conver_amont(data.cur_month_gross_profit_amount);
    //昨日环比
    let yesterday = initRate('上月', conver_amont(data.pre_month_gross_profit_amount), calc_hb_str(data.cur_month_gross_profit_amount, data.pre_month_gross_profit_amount))
    hb.push(yesterday)
    //昨日环比
    let premonth = initRate('去年', conver_amont(data.pre_year_gross_profit_amount), calc_tb_str(data.cur_month_gross_profit_amount, data.pre_year_gross_profit_amount))
    hb.push(premonth)
  }
  turnOver['hb'] = hb
  return turnOver;
}

/**
 * 月维度汇总
 * @param type
 * @param data
 */
export const adapterSumDataYear = function (type, data) {
  let turnOver = initSumDataDay()
  let hb = new Array()
  if (type == 'yye') {
    turnOver.title = '营业额'
    turnOver.amount = conver_amont(data.cur_year_sell_settle_amount);
    //昨日环比
    let yesterday = initRate('去年', conver_amont(data.pre_year_sell_settle_amount), calc_hb_str(data.cur_year_sell_settle_amount, data.pre_year_sell_settle_amount))
    hb.push(yesterday)
  }
  if (type == 'cb') {
    turnOver.title = '成本'
    turnOver.amount = conver_amont(data.cur_year_buy_settle_amount);
    //上月环比
    let yesterday = initRate('去年', conver_amont(data.pre_year_buy_settle_amount), calc_hb_str(data.cur_year_buy_settle_amount, data.pre_year_buy_settle_amount))
    hb.push(yesterday)
  }
  if (type == 'ml') {
    turnOver.title = '毛利'
    turnOver.amount = conver_amont(data.cur_year_gross_profit_amount);
    //昨日环比
    let yesterday = initRate('去年', conver_amont(data.pre_year_gross_profit_amount), calc_hb_str(data.cur_year_gross_profit_amount, data.pre_year_gross_profit_amount))
    hb.push(yesterday)
  }
  turnOver['hb'] = hb
  return turnOver;
}


/**
 * 详细数据匹配
 * @param type
 * @param data
 * @returns {any[]}
 */
export const adapterDetailData = function (dimension, type, data) {
  let list = new Array()
  let detail = null
  for (let key in data) {
    detail = detailConver(type, data[key])
    let date;
    if (dimension == 'day') {
      date = moment(key).format('MM月DD日')
    }
    if (dimension == 'month') {
      date = moment(key).format('MM月')
    }
    if (dimension == 'year') {
      date = moment(key).format('YYYY年')
    }
    detail.date = date;
    list.push(detail);
  }
  return list;
}

/**
 * 详细数据转换
 * @param type
 * @param detailList
 * @returns {Object}
 */
export const detailConver = function (type, detailList) {
  let detail = initDetail();
  for (let det in detailList) {
    let data = detailList[det]
    //初始化
    if (type == 'yye') {
      if (data.cur_transport_type == '10') {
        detail['汽运(万元)'] = data.cur_sell_settle_amount;
      }
      if (data.cur_transport_type == '30') {
        detail['水运(万元)'] = data.cur_sell_settle_amount
      }
      if (data.cur_transport_type == '20') {
        detail['铁运(万元)'] = data.cur_sell_settle_amount
      }
    }
    if (type == 'cb') {
      if (data.cur_transport_type == '10') {
        detail['汽运(万元)'] = data.cur_buy_settle_amount
      }
      if (data.cur_transport_type == '30') {
        detail['水运(万元)'] = data.cur_buy_settle_amount
      }
      if (data.cur_transport_type == '20') {
        detail['铁运(万元)'] = data.cur_buy_settle_amount
      }
    }
    if (type == 'ml') {
      if (data.cur_transport_type == '10') {
        detail['汽运(万元)'] = data.cur_gross_profit_amount
      }
      if (data.cur_transport_type == '30') {
        detail['水运(万元)'] = data.cur_gross_profit_amount
      }
      if (data.cur_transport_type == '20') {
        detail['铁运(万元)'] = data.cur_gross_profit_amount
      }
    }
  }
  return detail;
}
/**
 * @returns {{}}
 */
export const initDetail = function () {
  let detail = {};
  detail['汽运(万元)'] = 0
  detail['水运(万元)'] = 0
  detail['铁运(万元)'] = 0
  return detail;
}

