Commit a51fe745 authored by renjintao's avatar renjintao

changeExcel

parent 51a0cf28
...@@ -27,6 +27,8 @@ export default { ...@@ -27,6 +27,8 @@ export default {
rows: 10, rows: 10,
placeholder: "请从Excel复制一段表格数据,粘贴在这里", placeholder: "请从Excel复制一段表格数据,粘贴在这里",
}, },
columnsImport: [],
excelData: []
}; };
}, },
...@@ -77,6 +79,39 @@ export default { ...@@ -77,6 +79,39 @@ export default {
} }
} }
}, },
//粘贴excel成功
handleSuccess(tableData) {
//初始化数据
this.excelData = [];
this.excelDataBack = [];
this.columnsImport = [];
this.sheetNames = [];
this.pageType = undefined;
//处理colum和data
let tabColum = tableData.columns
let tabData = tableData.data
let arrData = []
tabData.forEach(ele => {
let objData = {}
tabColum.forEach(el => {
objData[el.title] = ele[el.key]
})
arrData.push(objData)
})
//处理title和key一致
tabColum.forEach(el => {
el.key = el.title
})
this.columnsImport = tabColum;
this.excelData = arrData;
this.excelDataBack = arrData;
},
//粘贴excel失败
handleError(tableData, errorIndex) {
//console.log(tableData, errorIndex);
this.$Message.error("表格数据有误");
},
//粘贴excel相关end
l(key) { l(key) {
key = "import_center" + "." + key; key = "import_center" + "." + key;
return this.$t(key); return this.$t(key);
......
<template> <template>
<div class="table-content"> <div class="table-content">
<TablePaste hide-table :input-props="inputProps" @on-success="handleSuccess" @on-error="handleError" v-show="showTablePaste" />
<div class="table-tools"> <div class="table-tools">
<div class="table-search"> <div class="table-search">
<Form inline> <Form inline>
...@@ -14,7 +13,7 @@ ...@@ -14,7 +13,7 @@
<div class="tip mr20">{{excelData.length}}条数据</div> <div class="tip mr20">{{excelData.length}}条数据</div>
</FormItem> </FormItem>
<FormItem> <FormItem>
<Button type="primary" @click="openInfoModal">导入</Button> <Button type="primary" @click="openInfoModal" :disabled="btnIm">导入</Button>
</FormItem> </FormItem>
<FormItem> <FormItem>
<div style="height:34px;overflow: hidden;padding:0"> <div style="height:34px;overflow: hidden;padding:0">
...@@ -38,11 +37,8 @@ ...@@ -38,11 +37,8 @@
<Icon type="md-eye" />预览 <Icon type="md-eye" />预览
</a> </a>
</FormItem> </FormItem>
<FormItem v-if="show">
<Button @click="openPaste" :type="btnType" :ghost="ghostStatus">{{btnTxt}}</Button>
</FormItem>
<FormItem> <FormItem>
<RadioGroup value="0" type="button" @on-change="changeExcel"> <RadioGroup v-model="excelType" type="button" @on-change="changeExcel">
<Radio label="0"> <Radio label="0">
<Icon type="md-list" />列表 <Icon type="md-list" />列表
</Radio> </Radio>
...@@ -55,10 +51,9 @@ ...@@ -55,10 +51,9 @@
</div> </div>
</div> </div>
<div class="table-main" ref="main"> <div class="table-main" ref="main">
<Table border="true" :columns="columnsImport" :data="excelData" :height="tdHeightExcel" ref="table" class="tableCommon" v-if="tableImport"></Table> <Table :border="true" :columns="columnsImport" :data="excelData" :height="tdHeightExcel" ref="table" class="tableCommon" v-if="tableImport"></Table>
<component :is="detailExcel" /> <component :is="detailExcel" ref="comExcel" />
</div> </div>
<FooterToolbar v-if="sheetNames.length>1&&tableImport"> <FooterToolbar v-if="sheetNames.length>1&&tableImport">
<Form inline> <Form inline>
<FormItem> <FormItem>
...@@ -68,8 +63,12 @@ ...@@ -68,8 +63,12 @@
</FormItem> </FormItem>
</Form> </Form>
</FooterToolbar> </FooterToolbar>
<Modal v-model="infoModal" title="提示信息" @on-ok="importOk"> <Modal v-model="infoModal" title="确定批量导入" fullscreen>
<p>确定批量导入数据到<span class="red f16 fwBold ml10 mr10">用户管理</span>模块下?</p> <DataGrid :tool="false" :page="false" :columns="colsIm" :data="dataIm" :height="tdHeightExcel+30" ref="dataImport"></DataGrid>
<div slot="footer">
<Button @click="infoModal=false">关闭</Button>
<Button type="primary" @click="importOk">确定导入</Button>
</div>
</Modal> </Modal>
</div> </div>
</template> </template>
...@@ -334,15 +333,11 @@ export default { ...@@ -334,15 +333,11 @@ export default {
workBook: {}, workBook: {},
openDatas: [], openDatas: [],
dataType: 0, dataType: 0,
//粘贴excel内容start //new
btnType: "default", colsIm: [],
ghostStatus: false, dataIm: [],
btnTxt: "打开粘贴Excel", excelType: '0',
showTablePaste: false, btnIm: true,
inputProps: {
rows: 10,
placeholder: "请从Excel复制一段表格数据,粘贴在这里",
},
}; };
}, },
props: { props: {
...@@ -365,11 +360,7 @@ export default { ...@@ -365,11 +360,7 @@ export default {
///浏览器窗口大小变化 ///浏览器窗口大小变化
return (() => { return (() => {
window.screenHeight = window.innerHeight; window.screenHeight = window.innerHeight;
if (this.showTablePaste) {
this.tdHeightExcel = window.screenHeight - 180 - 220;
} else {
this.tdHeightExcel = window.screenHeight - 180; this.tdHeightExcel = window.screenHeight - 180;
}
})(); })();
}; };
...@@ -423,11 +414,17 @@ export default { ...@@ -423,11 +414,17 @@ export default {
ele.hide = true; ele.hide = true;
} }
}); });
this.columnsImport = tempCol; this.colsIm = tempCol;
//处理原始数据和表头进行对应 //处理原始数据和表头进行对应
let temCol = this.$u.clone(this.columnsImport); //原始数据表头 let temCol = this.$u.clone(this.colsIm); //原始数据表头
let temColPage = this.$u.clone(columns); //需要显示的页面的表头 let temColPage = this.$u.clone(columns); //需要显示的页面的表头
let temData = this.$u.clone(this.excelDataBack); //原始数据 //let temData = this.$u.clone(this.excelDataBack); //原始数据
let temData = []; //原始数据
if (this.excelType == "0") {
temData = this.$u.clone(this.excelDataBack)
} else {
temData = this.$u.clone(this.$refs.comExcel.excelData)
}
let arrTitleUse = []; ////使用数据字典的字段 let arrTitleUse = []; ////使用数据字典的字段
temColPage.forEach((elCode) => { temColPage.forEach((elCode) => {
if (elCode.code) { if (elCode.code) {
...@@ -482,7 +479,7 @@ export default { ...@@ -482,7 +479,7 @@ export default {
} }
}); });
}) })
this.excelData = useData; this.dataIm = useData;
}, },
//下载原excel文件 //下载原excel文件
downFile() { downFile() {
...@@ -503,10 +500,6 @@ export default { ...@@ -503,10 +500,6 @@ export default {
//打开传时初始化 //打开传时初始化
resetParms() { resetParms() {
this.pageType = undefined; this.pageType = undefined;
this.btnTxt = "打开粘贴Excel";
this.showTablePaste = false;
this.btnType = "default";
this.ghostStatus = false;
this.tdHeightExcel = window.innerHeight - 180; this.tdHeightExcel = window.innerHeight - 180;
}, },
async beforeUpload(file) { async beforeUpload(file) {
...@@ -556,6 +549,7 @@ export default { ...@@ -556,6 +549,7 @@ export default {
} }
this.excelData = result; this.excelData = result;
this.excelDataBack = result; this.excelDataBack = result;
this.changeExcel(0)
}, },
//切换sheet表重新加载 //切换sheet表重新加载
sheetClick(val) { sheetClick(val) {
...@@ -571,23 +565,13 @@ export default { ...@@ -571,23 +565,13 @@ export default {
}, },
//选择导入的模块 0:用户管理 //选择导入的模块 0:用户管理
pageChange(val) { pageChange(val) {
switch (val) { this.btnIm = false
case 0: if (val == undefined) {
//this.loadColum(this.columns0); this.btnIm = true
break;
case 1:
//this.loadColum(this.columns1);
break;
case undefined:
if (this.dataType == 0) {
this.load(this.eid);
} else { } else {
this.dealSheet(this.tabVal); this.btnIm = false
}
break;
default:
//this.loadColum(this.columns1);
} }
}, },
handleClose() { handleClose() {
this.$emit("on-close"); this.$emit("on-close");
...@@ -608,67 +592,28 @@ export default { ...@@ -608,67 +592,28 @@ export default {
}) })
this.$emit("on-close"); this.$emit("on-close");
}, },
//粘贴excel相关start
openPaste() {
if (this.btnTxt == "打开粘贴Excel") {
this.btnType = "primary";
this.ghostStatus = true;
this.showTablePaste = true;
this.btnTxt = "关闭粘贴Excel";
this.tdHeightExcel = window.innerHeight - 180 - 220;
} else {
this.btnType = "default";
this.ghostStatus = false;
this.showTablePaste = false;
this.btnTxt = "打开粘贴Excel";
this.tdHeightExcel = window.innerHeight - 180;
}
},
//粘贴excel成功
handleSuccess(tableData) {
//初始化数据
this.excelData = [];
this.excelDataBack = [];
this.columnsImport = [];
this.sheetNames = [];
this.pageType = undefined;
//处理colum和data
let tabColum = tableData.columns
let tabData = tableData.data
let arrData = []
tabData.forEach(ele => {
let objData = {}
tabColum.forEach(el => {
objData[el.title] = ele[el.key]
})
arrData.push(objData)
})
//处理title和key一致
tabColum.forEach(el => {
el.key = el.title
})
this.columnsImport = tabColum;
this.excelData = arrData;
this.excelDataBack = arrData;
},
//粘贴excel失败
handleError(tableData, errorIndex) {
//console.log(tableData, errorIndex);
this.$Message.error("表格数据有误");
},
//粘贴excel相关end
//重新加载excel //重新加载excel
resetTable() { resetTable() {
this.pageType = undefined; this.pageType = undefined;
this.btnTxt = "打开粘贴Excel";
this.showTablePaste = false;
this.btnType = "default";
this.ghostStatus = false;
this.load(this.eid); this.load(this.eid);
this.tdHeightExcel = window.innerHeight - 180; this.tdHeightExcel = window.innerHeight - 180;
if (this.excelType == 1) {
this.changeExcel(0)
}
}, },
openInfoModal() { openInfoModal() {
if (this.excelData.length > 0 && this.pageType != undefined) { if (this.excelData.length > 0 && this.pageType != undefined) {
switch (this.pageType) {
case 0:
this.loadColum(this.columns0);
break;
case 1:
this.loadColum(this.columns1);
break;
default:
this.loadColum(this.columns0);
}
this.infoModal = true this.infoModal = true
} else { } else {
if (this.excelData.length == 0) { if (this.excelData.length == 0) {
...@@ -685,15 +630,15 @@ export default { ...@@ -685,15 +630,15 @@ export default {
this.importUser(); this.importUser();
break; break;
case 1: case 1:
this.loadColum(this.columns1); //this.loadColum(this.columns1);
break; break;
default: default:
this.loadColum(this.columns1); //this.loadColum(this.columns1);
} }
}, },
//批量导入用户 //批量导入用户
importUser() { importUser() {
let tempData = this.$u.clone(this.excelData); let tempData = this.$u.clone(this.dataIm);
let tempList = []; let tempList = [];
tempData.forEach((ele) => { tempData.forEach((ele) => {
let obj = { let obj = {
...@@ -711,30 +656,41 @@ export default { ...@@ -711,30 +656,41 @@ export default {
titleId: ele.titleId, titleId: ele.titleId,
departmentTitle: ele.departmentTitle, departmentTitle: ele.departmentTitle,
}; };
if (ele.userName && ele.userName != '' && ele.cardNo && ele.cardNo != '' && ele.departmentId && ele.departmentId != '' && ele.phone && ele.phone != '') {
tempList.push(obj); tempList.push(obj);
}
}); });
if (tempList.length == 0) {
this.$Message.error("所有导入的数据均不合法!");
} else {
let parms = { let parms = {
list: tempList, list: tempList,
}; };
Api.importUser(parms).then((res) => { Api.importUser(parms).then((res) => {
if (res.success) { if (res.success) {
this.$Message.success("批量导入用户管理成功!"); this.$Message.success("成功批量导入用户管理成功模块 " + tempList.length + " 条数据");
this.cancelExcel(); this.cancelExcel();
} else { } else {
this.$Message.error("批量导入用户管理失败!"); this.$Message.error("批量导入用户管理失败!");
} }
}); });
}
}, },
changeExcel(val) { changeExcel(val) {
if (val == 1) { if (val == 1) {
this.tableImport = false this.tableImport = false
this.detailExcel = () => import("./detailExcel"); this.detailExcel = () => import("./detailExcel");
this.pageType = undefined
this.excelType = '1';
} else { } else {
this.detailExcel = null; this.detailExcel = null;
this.tableImport = true this.tableImport = true;
this.pageType = undefined
this.excelType = '0';
} }
}, },
l(key) { l(key) {
key = "user" + "." + key; key = "user" + "." + key;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment