?//?導(dǎo)出表格數(shù)據(jù)處理
????????exportExcl(){
???????????let?exportJsonData?=?{
????????????????tHeader:?[],?//表頭中文例如?["時(shí)間"鸳劳,“名稱(chēng)”思喊,?“金額”]
????????????????filterVal:?[],?//表頭key例如?["time",?"name",?"money"]
????????????????list:?[],?//表格數(shù)據(jù)
????????????????total_info:?''?//總計(jì)信息數(shù)據(jù),可以沒(méi)有為空奴紧,表格頂部做統(tǒng)計(jì)使用
????????????}
????????????//處理數(shù)據(jù)
????????????this.columns.map(colunm=>{
????????????colunm.label&&exportJsonData.tHeader.push(colunm.label)
????????????colunm.prop&&exportJsonData.filterVal.push(colunm.prop)
??????})
????????????//?執(zhí)行導(dǎo)出方法
????????????this.exportPathMethod(exportJsonData,?"賬單報(bào)表");
????????},
????????//導(dǎo)出數(shù)據(jù)組合
????????exportPathMethod(data,?setName)?{
????????????/*
????????????*注:csv文件:","逗號(hào)換列,\n換行,\t防止excel將長(zhǎng)數(shù)字變科學(xué)計(jì)算法等樣式
????????????*/
????????????//要導(dǎo)出的json數(shù)據(jù)
????????????let?mainLists?=?data;?//主表
????????????//##?數(shù)據(jù)處理
????????????//一級(jí)表
????????????let?mainTitle?=?mainLists.tHeader;?//一級(jí)標(biāo)題
????????????let?mainTitleForKey?=?mainLists.filterVal;?//一級(jí)過(guò)濾
????????????let?mainList?=?this.tableDatas;?//一級(jí)數(shù)據(jù)
????????????let?mainStr?=?[];
????????????mainStr.push(mainTitle.join(",")?+?"\n");?//標(biāo)題添加上換列轉(zhuǎn)成字符串并存進(jìn)數(shù)組
????????????mainList.forEach(e?=>?{
????????????????let?temp?=?[];
????????????????mainTitleForKey.forEach(f?=>?{
??????????????????console.log(f,e);
???????????????if?(f=='sendType')?{?//當(dāng)是數(shù)字時(shí)
????????????????????let?s?=??e[f];
????????????????????let?c=?this.dict.type.notice_type.find(item=>item.value==e[f])//字典類(lèi)型根據(jù)查詢(xún)值查詢(xún)到相應(yīng)的lable
????????????????????temp.push(c.label);?//根據(jù)過(guò)濾器拿出對(duì)應(yīng)的值
????????????????}?else?{
????????????????????temp.push(e[f]);?//根據(jù)過(guò)濾器拿出對(duì)應(yīng)的值
????????????????}
????????????????})
????????????????mainStr.push(temp.join(",")?+?"\n");?//取出來(lái)的值加上逗號(hào)換列轉(zhuǎn)字符串存數(shù)組
????????????})
????????????//兩個(gè)表數(shù)組轉(zhuǎn)成字符串合并
????????????let?merged?=?mainStr.join("");
????????????//##?導(dǎo)出操作
????????????//?encodeURIComponent解決中文亂碼
????????????const?uri?=
????????????????"data:text/csv;charset=utf-8,\ufeff"?+
????????????????encodeURIComponent(merged);
????????????//?通過(guò)創(chuàng)建a標(biāo)簽實(shí)現(xiàn)
????????????let?link?=?document.createElement("a");
????????????link.href?=?uri;
????????????//?對(duì)下載的文件命名
????????????link.download?=?setName?+?`.csv`;
????????????document.body.appendChild(link);
????????????link.click();
????????},