行政区域批量导入
This commit is contained in:
parent
f7d14af8a2
commit
4b47213d65
BIN
public/static/tpl/import_countryArea.xlsx
Normal file
BIN
public/static/tpl/import_countryArea.xlsx
Normal file
Binary file not shown.
BIN
public/static/tpl/import_region.xlsx
Normal file
BIN
public/static/tpl/import_region.xlsx
Normal file
Binary file not shown.
@ -42,3 +42,12 @@ export function delEmisCountryArea(id) {
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
|
||||
// 批量导入国家大区表
|
||||
export function draftSubmitCountryArea(data) {
|
||||
return request({
|
||||
url: '/emisCountryArea/draftSubmitCountryArea',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
@ -52,3 +52,11 @@ export function delEmisRegion(id) {
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
// 批量导入四级省市区镇表
|
||||
export function draftSubmitRegion(data) {
|
||||
return request({
|
||||
url: '/emis/emisRegion/draftSubmitRegion',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
392
src/views/emis/emisCountryArea/batchImportCountryArea.vue
Normal file
392
src/views/emis/emisCountryArea/batchImportCountryArea.vue
Normal file
@ -0,0 +1,392 @@
|
||||
<template>
|
||||
<XdPageContainer >
|
||||
<div slot="pageHeader"></div>
|
||||
<XdTable
|
||||
slot="pageContent"
|
||||
slot-scope="slotProps"
|
||||
:height="(slotProps.contentHeight)+'px'"
|
||||
storageName="batchSiteBatchRecord_main_9"
|
||||
|
||||
ref="multipleTable"
|
||||
:row-class-name="tableRowClassName"
|
||||
v-loading="loading"
|
||||
border
|
||||
size="mini"
|
||||
:data="orderList"
|
||||
:showSearch.sync="showSearch"
|
||||
:queryParams="queryParams"
|
||||
:total="total"
|
||||
@queryTable="getList"
|
||||
@selection-change="handleSelectionChange"
|
||||
@sort-change="handleSortChange"
|
||||
|
||||
>
|
||||
|
||||
<div slot="toolbar">
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-upload
|
||||
action=""
|
||||
name="file"
|
||||
accept="application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||
:show-file-list="true"
|
||||
:limit="1"
|
||||
:file-list="fileList"
|
||||
:tooltip="fileName"
|
||||
:on-change="fileChange"
|
||||
:before-upload="beforeUpload">
|
||||
<el-button slot="trigger" plain class="filter-item" size="mini" type="primary" >选择文件</el-button>
|
||||
<el-link type="primary" style="line-height: 28px;font-size:13px;color:blue" href="/static/tpl/import_countryArea.xlsx">下载导入Excel模板</el-link>
|
||||
</el-upload>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
size="mini"
|
||||
@click="handleRealUploadAll"
|
||||
>批量发送</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="danger"
|
||||
plain
|
||||
icon="el-icon-delete"
|
||||
size="mini"
|
||||
:disabled="multiple"
|
||||
@click="handleDelete"
|
||||
>删除</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column :label="$t('状态')" align="center" prop="uploadStatus" min-width="80" :show-overflow-tooltip="true" >
|
||||
<template slot-scope="scope">
|
||||
<el-tag v-if="scope.row.uploadStatus==1" type="success">发送成功</el-tag>
|
||||
<el-tag v-if="scope.row.uploadStatus==0" type="info">待发送</el-tag>
|
||||
<el-tag v-if="scope.row.uploadStatus==-1" type="danger">发送异常</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('异常信息')" align="center" prop="errorInfo" min-width="300" :show-overflow-tooltip="true" >
|
||||
<template slot-scope="scope">
|
||||
<span v-if="scope.row.uploadStatus==-1" style="color:red">{{ scope.row.errorInfo }}</span>
|
||||
<span v-if="scope.row.uploadStatus==1">发送成功</span>
|
||||
<span v-if="scope.row.uploadStatus==0">待发送</span>
|
||||
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column :label="$t('片区名称')" align="center" prop="name" min-width="120" :show-overflow-tooltip="true" />
|
||||
<el-table-column :label="$t('英文名称')" align="center" prop="nameEn" min-width="120" :show-overflow-tooltip="true"/>
|
||||
<el-table-column :label="$t('所属国家')" align="center" prop="countryCode" min-width="100" :show-overflow-tooltip="true"/>
|
||||
<el-table-column :label="$t('服务网点')" align="center" prop="siteCode" min-width="100" :show-overflow-tooltip="true"/>
|
||||
<el-table-column :label="$t('备注')" align="center" prop="remark" min-width="100" :show-overflow-tooltip="true"/>
|
||||
</XdTable>
|
||||
</XdPageContainer>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { draftSubmitCountryArea } from "@/api/emis/emisCountryArea";
|
||||
import {timeDiffTime} from '@/utils/dateUtils'
|
||||
import XLSX from 'xlsx'
|
||||
|
||||
export default {
|
||||
name: "BatchImportCountryArea",
|
||||
components: {
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
resetRefreshId:null,
|
||||
// 遮罩层
|
||||
loading: false,
|
||||
// 选中数组
|
||||
ids: [],
|
||||
// 非单个禁用
|
||||
single: true,
|
||||
// 非多个禁用
|
||||
multiple: true,
|
||||
// 显示搜索条件
|
||||
showSearch: true,
|
||||
|
||||
// 总条数
|
||||
total: 0,
|
||||
// 运单列表表格数据
|
||||
orderList: [],
|
||||
tmpDataList: [],
|
||||
selectionList:[],
|
||||
selectionIndexList: [],
|
||||
|
||||
form:{},
|
||||
rules:{},
|
||||
|
||||
openUploadForm:false,
|
||||
uploadMsg:"",
|
||||
uploadExcelDataInfo:"",
|
||||
fileName:"",
|
||||
fileList:[],
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 20,
|
||||
queryKey:null,
|
||||
},
|
||||
};
|
||||
},
|
||||
created() {
|
||||
|
||||
},
|
||||
mounted() {
|
||||
|
||||
},
|
||||
methods: {
|
||||
getUUID() {
|
||||
return Math.random().toString(36).substring(3,10);
|
||||
},
|
||||
handleBatchImport(){
|
||||
this.resetRefreshId="importForm-"+this.getUUID();
|
||||
|
||||
this.openUploadForm=true;
|
||||
this.fileList=[];
|
||||
this.uploadExcelDataInfo="";
|
||||
this.fileName="";
|
||||
|
||||
},
|
||||
calcDeliveryTime(startData,endDate){
|
||||
return timeDiffTime(startData,endDate)
|
||||
},
|
||||
//标红table指定行
|
||||
tableRowClassName(row, index) {
|
||||
row.row.index = row.rowIndex;
|
||||
if (row.uploadStatus=='1') {
|
||||
return 'success-row';
|
||||
}
|
||||
else if (row.uploadStatus=='-1') {
|
||||
return 'warning-row';
|
||||
}
|
||||
return '';
|
||||
},
|
||||
/** 查询运单列表列表 */
|
||||
getList() {
|
||||
this.loading = true;
|
||||
},
|
||||
fileChange(file, fileList) {
|
||||
this.fileList = fileList;
|
||||
},
|
||||
beforeUpload(file) {
|
||||
this.fileName = file.name;
|
||||
this.form.batchName = file.name;
|
||||
this.readerData(file)
|
||||
return false
|
||||
},
|
||||
readerData(rawFile) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader()
|
||||
reader.onload = e => {
|
||||
const data = e.target.result
|
||||
const workbook = XLSX.read(data, { type: 'array' ,cellDates: true})
|
||||
const firstSheetName = workbook.SheetNames[0] // firstSheetName
|
||||
// if (!excelTypes.includes(firstSheetName)) {
|
||||
// reject('无法识别当前Excel模板')
|
||||
// this.$modal.msgError('无法识别当前Excel模板')
|
||||
// return
|
||||
// }
|
||||
const worksheet = workbook.Sheets[firstSheetName]
|
||||
// const header = this.getHeaderRow(worksheet) // 标题
|
||||
const results = XLSX.utils.sheet_to_json(worksheet)
|
||||
|
||||
console.log(results);
|
||||
|
||||
this.batchImportData(results);
|
||||
|
||||
resolve()
|
||||
}
|
||||
reader.readAsArrayBuffer(rawFile)
|
||||
})
|
||||
},
|
||||
getHeaderRow(sheet) {
|
||||
const headers = []
|
||||
const range = XLSX.utils.decode_range(sheet['!ref'])
|
||||
let C
|
||||
const R = range.s.r
|
||||
/* start in the first row */
|
||||
for (C = range.s.c; C <= range.e.c; ++C) { /* walk every column in the range */
|
||||
const cell = sheet[XLSX.utils.encode_cell({ c: C, r: R })]
|
||||
/* find the cell in the first row */
|
||||
let hdr = 'UNKNOWN ' + C // <-- replace with your desired default
|
||||
if (cell && cell.t) hdr = XLSX.utils.format_cell(cell)
|
||||
headers.push(hdr)
|
||||
}
|
||||
return headers
|
||||
},
|
||||
async batchImportData(results) {
|
||||
const _index = 1
|
||||
let loadingInstance = this.$loading({
|
||||
text: '正在解析 ' + _index + ' 数据...'
|
||||
})
|
||||
|
||||
this.orderList = [];
|
||||
|
||||
// 组装提交的数据
|
||||
for (let index = 0; index < results.length; index++) {
|
||||
const element = results[index]
|
||||
let orderData={
|
||||
name: element['片区名称'],
|
||||
nameEn: element['英文名称'],
|
||||
countryCode: element['所属国家'],
|
||||
siteCode: element['服务网点'],
|
||||
remark: element['备注'],
|
||||
uploadStatus: 0,
|
||||
errorInfo:'',
|
||||
}
|
||||
//数据转换
|
||||
this.tmpDataList.push(orderData);
|
||||
}
|
||||
|
||||
// 判断是否有数据
|
||||
this.orderList=[];
|
||||
if(this.tmpDataList.length==0){
|
||||
this.$modal.msgError('表格中没有数据');
|
||||
loadingInstance.close()
|
||||
return;
|
||||
}
|
||||
this.tmpDataList=this.tmpDataList.map(item=>this.transformData(item));
|
||||
this.orderList = this.orderList.concat(this.tmpDataList);
|
||||
this.tmpDataList=[];
|
||||
loadingInstance.close()
|
||||
|
||||
},
|
||||
// 数据转换
|
||||
transformData(orderData){
|
||||
return orderData;
|
||||
},
|
||||
handleRealUploadAll(){
|
||||
if (this.ids && this.ids.length>0) {
|
||||
this.$confirm("确认发送吗?", "提示", {
|
||||
cancelButtonText: "取消",
|
||||
confirmButtonText: "确认",
|
||||
type: "warning",
|
||||
distinguishCancelAndClose: true,
|
||||
closeOnClickModal: false
|
||||
}).then(async () => {
|
||||
|
||||
if(this.selectionList&&this.selectionList.length>0){
|
||||
for(let i=0;i<this.selectionList.length;i++){
|
||||
let orderItem=this.selectionList[i];
|
||||
|
||||
// 检查数据后发送
|
||||
let res=await draftSubmitCountryArea(orderItem)
|
||||
let rstData=res.data;
|
||||
if(rstData.result=='success'){
|
||||
orderItem.uploadStatus=1;
|
||||
orderItem.errorInfo="发送成功";
|
||||
orderItem.batchNo=rstData.batchNo;
|
||||
}
|
||||
else{
|
||||
orderItem.uploadStatus=-1;
|
||||
orderItem.errorInfo=rstData.msg;
|
||||
}
|
||||
|
||||
}
|
||||
this.$modal.msgSuccess("上传成功");
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
},
|
||||
/** 搜索按钮操作 */
|
||||
handleQuery() {
|
||||
// this.queryParams.pageNum = 1;
|
||||
// this.getList();
|
||||
},
|
||||
/** 重置按钮操作 */
|
||||
resetQuery() {
|
||||
// this.resetForm("queryForm");
|
||||
// this.handleQuery();
|
||||
},
|
||||
// 多选框选中数据
|
||||
handleSelectionChange(selection) {
|
||||
|
||||
this.selectionList=selection;
|
||||
this.ids = selection.map(item => item.id)
|
||||
this.single = selection.length!==1
|
||||
this.multiple = !selection.length
|
||||
},
|
||||
// 排序 查询字段是表格中字段名字 动态取值排序顺序
|
||||
handleSortChange(column) {
|
||||
this.queryParams.orderByColumn = column.prop;
|
||||
this.queryParams.isAsc = column.order;
|
||||
this.getList();
|
||||
},
|
||||
|
||||
cancel(){
|
||||
this.openUploadForm = false;
|
||||
},
|
||||
/** 删除按钮操作 */
|
||||
handleDelete(row) {
|
||||
const ids = row.id || this.ids;
|
||||
let that=this;
|
||||
this.$modal.confirm('是否确认删除').then(function() {
|
||||
that.selectionList.forEach((item,index) =>{
|
||||
that.orderList.forEach((v,i)=>{
|
||||
if(item.index === v.index){
|
||||
that.orderList.splice(i,1)
|
||||
}
|
||||
})
|
||||
})
|
||||
that.$refs.multipleTable.clearSelection();
|
||||
}).then(() => {
|
||||
this.$modal.msgSuccess("删除成功");
|
||||
}).catch(() => {});
|
||||
},
|
||||
|
||||
/** 列索引函数 */
|
||||
getIndex($index) {
|
||||
return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + $index + 1
|
||||
},
|
||||
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
:deep .el-form-item__label-wrap {
|
||||
margin-left: 0 !important;
|
||||
}
|
||||
.el-divider{
|
||||
margin-top: 0px;
|
||||
background: 0 0;
|
||||
border-top: 1px solid #E6EBF5;
|
||||
}
|
||||
.el-divider__text {
|
||||
color: #0955ee;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
|
||||
.query-label {
|
||||
.el-radio{
|
||||
display: block;
|
||||
line-height: 23px;
|
||||
white-space: normal;
|
||||
margin-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.queryForm .el-form-item {
|
||||
margin-bottom: 0px !important;
|
||||
}
|
||||
|
||||
:deep .el-table .success-row {
|
||||
color: rgb(21, 174, 31) !important;
|
||||
}
|
||||
|
||||
:deep .el-table .warning-row {
|
||||
color: #f51f1f !important;
|
||||
}
|
||||
|
||||
:deep .el-form-item__label {
|
||||
text-align: left;
|
||||
}
|
||||
</style>
|
||||
@ -80,6 +80,16 @@
|
||||
v-hasPermi="['emis:emisCountryArea:export']"
|
||||
>导出</el-button>
|
||||
</el-col> -->
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
icon="el-icon-upload"
|
||||
size="mini"
|
||||
@click="handleBatchAdd"
|
||||
v-hasPermi="['emis:emisCountryArea:draftSubmitCountryArea']"
|
||||
>批量导入</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
|
||||
@ -109,8 +119,10 @@
|
||||
<el-dialog :title="titleForm" :visible.sync="openForm" width="500px" :destroy-on-close="true" v-dialogDrag append-to-body>
|
||||
<emisCountryAreaForm :id="currentId" @on-changed="handleFormChanged" @on-cancel="cancelForm"></EmisCountryAreaForm>
|
||||
</el-dialog>
|
||||
|
||||
|
||||
<!-- 批量导入弹窗 -->
|
||||
<el-dialog :title="batchAddTitleForm" :visible.sync="openBatchAdd" width="45%" :close-on-click-modal="false" v-dialogDrag append-to-body>
|
||||
<batchImportCountryArea></batchImportCountryArea>
|
||||
</el-dialog>
|
||||
</XdPageContainer>
|
||||
</template>
|
||||
|
||||
@ -118,9 +130,10 @@
|
||||
import { listEmisCountryArea, getEmisCountryArea, delEmisCountryArea, addEmisCountryArea, updateEmisCountryArea } from "@/api/emis/emisCountryArea";
|
||||
import emisCountryAreaForm from '@/views/emis/emisCountryArea/emisCountryAreaForm';
|
||||
import CountryPicker from '@/views/emis/EmisBaseTools/CountryPicker.vue';
|
||||
import batchImportCountryArea from '@/views/emis/emisCountryArea/batchImportCountryArea.vue';
|
||||
export default {
|
||||
name: "emisCountryArea",
|
||||
components: { emisCountryAreaForm,CountryPicker },
|
||||
components: { emisCountryAreaForm,CountryPicker,batchImportCountryArea },
|
||||
dicts: [
|
||||
],
|
||||
props: {
|
||||
@ -170,6 +183,8 @@ export default {
|
||||
daterangeCreateTime: [],
|
||||
// 删除标志(0代表存在时间范围
|
||||
daterangeUpdateTime: [],
|
||||
openBatchAdd: false,
|
||||
batchAddTitleForm: "",
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
@ -393,6 +408,10 @@ export default {
|
||||
dateTimeChange(value){
|
||||
this.dateTimeRange=value;
|
||||
},
|
||||
handleBatchAdd(){
|
||||
this.openBatchAdd= true;
|
||||
this.batchAddTitleForm = "批量导入";
|
||||
},
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
@ -99,6 +99,16 @@
|
||||
<span><CountryAreaPicker size="mini" :placeholder="$t('所属片区')" :countryCode="queryParams.countryCode" v-model="queryParams.areaId" @onChange="handleQuery"></CountryAreaPicker></span>
|
||||
</div>
|
||||
</el-col> -->
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
icon="el-icon-upload"
|
||||
size="mini"
|
||||
@click="handleBatchAdd"
|
||||
v-hasPermi="['emis:emisRegion:draftSubmitRegion']"
|
||||
>批量导入</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
|
||||
@ -153,7 +163,10 @@
|
||||
<el-dialog :title="titleForm" :visible.sync="openForm" :destroy-on-close="true" width="50%" v-dialogDrag append-to-body>
|
||||
<emisRegionForm :id="currentId" :regionType="regionType" :countryCode="currentCountryCode" :parentCode="parentCode" @on-changed="handleFormChanged" @on-cancel="cancelForm"></EmisRegionForm>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 批量导入弹出层 -->
|
||||
<el-dialog :title="batchAddTitleForm" :visible.sync="openBatchAdd" :destroy-on-close="true" width="50%" v-dialogDrag append-to-body>
|
||||
<batchImportRegion></batchImportRegion>
|
||||
</el-dialog>
|
||||
</XdPageContainer>
|
||||
</template>
|
||||
|
||||
@ -162,10 +175,11 @@ import { listEmisRegion, delEmisRegion} from "@/api/emis/emisRegion";
|
||||
import emisRegionForm from '@/views/emis/emisRegion/emisRegionForm';
|
||||
import CountryPicker from '@/views/emis/EmisBaseTools/CountryPicker.vue';
|
||||
import CountryAreaPicker from '@/views/emis/EmisBaseTools/CountryAreaPicker.vue';
|
||||
import batchImportRegion from '@/views/emis/emisRegion/batchImportRegion.vue';
|
||||
|
||||
export default {
|
||||
name: "emisRegion",
|
||||
components: { emisRegionForm,CountryPicker,CountryAreaPicker },
|
||||
components: { emisRegionForm,CountryPicker,CountryAreaPicker,batchImportRegion,batchImportRegion },
|
||||
props: {
|
||||
countryCode: {
|
||||
type: String,
|
||||
@ -222,6 +236,9 @@ export default {
|
||||
daterangeCreateTime: [],
|
||||
// 删除标志(0代表存在时间范围
|
||||
daterangeUpdateTime: [],
|
||||
// 批量导入弹出层
|
||||
openBatchAdd: false,
|
||||
batchAddTitleForm: "",
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
@ -422,6 +439,10 @@ export default {
|
||||
dateTimeChange(value){
|
||||
this.dateTimeRange=value;
|
||||
},
|
||||
handleBatchAdd(){
|
||||
this.openBatchAdd= true;
|
||||
this.batchAddTitleForm = "批量导入";
|
||||
},
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
396
src/views/emis/emisRegion/batchImportRegion.vue
Normal file
396
src/views/emis/emisRegion/batchImportRegion.vue
Normal file
@ -0,0 +1,396 @@
|
||||
<template>
|
||||
<XdPageContainer >
|
||||
<div slot="pageHeader"></div>
|
||||
<XdTable
|
||||
slot="pageContent"
|
||||
slot-scope="slotProps"
|
||||
:height="(slotProps.contentHeight)+'px'"
|
||||
storageName="batchSiteBatchRecord_main_9"
|
||||
|
||||
ref="multipleTable"
|
||||
:row-class-name="tableRowClassName"
|
||||
v-loading="loading"
|
||||
border
|
||||
size="mini"
|
||||
:data="orderList"
|
||||
:showSearch.sync="showSearch"
|
||||
:queryParams="queryParams"
|
||||
:total="total"
|
||||
@queryTable="getList"
|
||||
@selection-change="handleSelectionChange"
|
||||
@sort-change="handleSortChange"
|
||||
|
||||
>
|
||||
|
||||
<div slot="toolbar">
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-upload
|
||||
action=""
|
||||
name="file"
|
||||
accept="application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||
:show-file-list="true"
|
||||
:limit="1"
|
||||
:file-list="fileList"
|
||||
:tooltip="fileName"
|
||||
:on-change="fileChange"
|
||||
:before-upload="beforeUpload">
|
||||
<el-button slot="trigger" plain class="filter-item" size="mini" type="primary" >选择文件</el-button>
|
||||
<el-link type="primary" style="line-height: 28px;font-size:13px;color:blue" href="/static/tpl/import_region.xlsx">下载导入Excel模板</el-link>
|
||||
</el-upload>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
size="mini"
|
||||
@click="handleRealUploadAll"
|
||||
>批量发送</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="danger"
|
||||
plain
|
||||
icon="el-icon-delete"
|
||||
size="mini"
|
||||
:disabled="multiple"
|
||||
@click="handleDelete"
|
||||
>删除</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column :label="$t('状态')" align="center" prop="uploadStatus" min-width="80" :show-overflow-tooltip="true" >
|
||||
<template slot-scope="scope">
|
||||
<el-tag v-if="scope.row.uploadStatus==1" type="success">发送成功</el-tag>
|
||||
<el-tag v-if="scope.row.uploadStatus==0" type="info">待发送</el-tag>
|
||||
<el-tag v-if="scope.row.uploadStatus==-1" type="danger">发送异常</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('异常信息')" align="center" prop="errorInfo" min-width="300" :show-overflow-tooltip="true" >
|
||||
<template slot-scope="scope">
|
||||
<span v-if="scope.row.uploadStatus==-1" style="color:red">{{ scope.row.errorInfo }}</span>
|
||||
<span v-if="scope.row.uploadStatus==1">发送成功</span>
|
||||
<span v-if="scope.row.uploadStatus==0">待发送</span>
|
||||
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column :label="$t('省份名称')" align="center" prop="regionName" min-width="120" :show-overflow-tooltip="true" />
|
||||
<el-table-column :label="$t('英文名称')" align="center" prop="regionNameEn" min-width="120" :show-overflow-tooltip="true"/>
|
||||
<el-table-column :label="$t('省份编码')" align="center" prop="regionCode" min-width="100" :show-overflow-tooltip="true"/>
|
||||
<el-table-column :label="$t('所属国家')" align="center" prop="countryCode" min-width="100" :show-overflow-tooltip="true"/>
|
||||
<el-table-column :label="$t('寄件片区')" align="center" prop="sendAreaId" min-width="100" :show-overflow-tooltip="true"/>
|
||||
<el-table-column :label="$t('派件片区')" align="center" prop="areaId" min-width="100" :show-overflow-tooltip="true"/>
|
||||
<el-table-column :label="$t('备注')" align="center" prop="remark" min-width="100" :show-overflow-tooltip="true"/>
|
||||
</XdTable>
|
||||
</XdPageContainer>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { draftSubmitRegion } from "@/api/emis/emisRegion";
|
||||
import {timeDiffTime} from '@/utils/dateUtils'
|
||||
import XLSX from 'xlsx'
|
||||
|
||||
export default {
|
||||
name: "BatchImportRegion",
|
||||
components: {
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
resetRefreshId:null,
|
||||
// 遮罩层
|
||||
loading: false,
|
||||
// 选中数组
|
||||
ids: [],
|
||||
// 非单个禁用
|
||||
single: true,
|
||||
// 非多个禁用
|
||||
multiple: true,
|
||||
// 显示搜索条件
|
||||
showSearch: true,
|
||||
|
||||
// 总条数
|
||||
total: 0,
|
||||
// 运单列表表格数据
|
||||
orderList: [],
|
||||
tmpDataList: [],
|
||||
selectionList:[],
|
||||
selectionIndexList: [],
|
||||
|
||||
form:{},
|
||||
rules:{},
|
||||
|
||||
openUploadForm:false,
|
||||
uploadMsg:"",
|
||||
uploadExcelDataInfo:"",
|
||||
fileName:"",
|
||||
fileList:[],
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 20,
|
||||
queryKey:null,
|
||||
},
|
||||
};
|
||||
},
|
||||
created() {
|
||||
|
||||
},
|
||||
mounted() {
|
||||
|
||||
},
|
||||
methods: {
|
||||
getUUID() {
|
||||
return Math.random().toString(36).substring(3,10);
|
||||
},
|
||||
handleBatchImport(){
|
||||
this.resetRefreshId="importForm-"+this.getUUID();
|
||||
|
||||
this.openUploadForm=true;
|
||||
this.fileList=[];
|
||||
this.uploadExcelDataInfo="";
|
||||
this.fileName="";
|
||||
|
||||
},
|
||||
calcDeliveryTime(startData,endDate){
|
||||
return timeDiffTime(startData,endDate)
|
||||
},
|
||||
//标红table指定行
|
||||
tableRowClassName(row, index) {
|
||||
row.row.index = row.rowIndex;
|
||||
if (row.uploadStatus=='1') {
|
||||
return 'success-row';
|
||||
}
|
||||
else if (row.uploadStatus=='-1') {
|
||||
return 'warning-row';
|
||||
}
|
||||
return '';
|
||||
},
|
||||
/** 查询运单列表列表 */
|
||||
getList() {
|
||||
this.loading = true;
|
||||
},
|
||||
fileChange(file, fileList) {
|
||||
this.fileList = fileList;
|
||||
},
|
||||
beforeUpload(file) {
|
||||
this.fileName = file.name;
|
||||
this.form.batchName = file.name;
|
||||
this.readerData(file)
|
||||
return false
|
||||
},
|
||||
readerData(rawFile) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader()
|
||||
reader.onload = e => {
|
||||
const data = e.target.result
|
||||
const workbook = XLSX.read(data, { type: 'array' ,cellDates: true})
|
||||
const firstSheetName = workbook.SheetNames[0] // firstSheetName
|
||||
// if (!excelTypes.includes(firstSheetName)) {
|
||||
// reject('无法识别当前Excel模板')
|
||||
// this.$modal.msgError('无法识别当前Excel模板')
|
||||
// return
|
||||
// }
|
||||
const worksheet = workbook.Sheets[firstSheetName]
|
||||
// const header = this.getHeaderRow(worksheet) // 标题
|
||||
const results = XLSX.utils.sheet_to_json(worksheet)
|
||||
|
||||
console.log(results);
|
||||
|
||||
this.batchImportData(results);
|
||||
|
||||
resolve()
|
||||
}
|
||||
reader.readAsArrayBuffer(rawFile)
|
||||
})
|
||||
},
|
||||
getHeaderRow(sheet) {
|
||||
const headers = []
|
||||
const range = XLSX.utils.decode_range(sheet['!ref'])
|
||||
let C
|
||||
const R = range.s.r
|
||||
/* start in the first row */
|
||||
for (C = range.s.c; C <= range.e.c; ++C) { /* walk every column in the range */
|
||||
const cell = sheet[XLSX.utils.encode_cell({ c: C, r: R })]
|
||||
/* find the cell in the first row */
|
||||
let hdr = 'UNKNOWN ' + C // <-- replace with your desired default
|
||||
if (cell && cell.t) hdr = XLSX.utils.format_cell(cell)
|
||||
headers.push(hdr)
|
||||
}
|
||||
return headers
|
||||
},
|
||||
async batchImportData(results) {
|
||||
const _index = 1
|
||||
let loadingInstance = this.$loading({
|
||||
text: '正在解析 ' + _index + ' 数据...'
|
||||
})
|
||||
|
||||
this.orderList = [];
|
||||
|
||||
// 组装提交的数据
|
||||
for (let index = 0; index < results.length; index++) {
|
||||
const element = results[index]
|
||||
let orderData={
|
||||
regionName: element['省份名称'],
|
||||
regionNameEn: element['英文名称'],
|
||||
regionCode: element['省份编码'],
|
||||
countryCode: element['所属国家'],
|
||||
sendAreaId: element['寄件片区'],
|
||||
areaId: element['派件片区'],
|
||||
remark: element['备注'],
|
||||
uploadStatus: 0,
|
||||
errorInfo:'',
|
||||
}
|
||||
//数据转换
|
||||
this.tmpDataList.push(orderData);
|
||||
}
|
||||
|
||||
// 判断是否有数据
|
||||
this.orderList=[];
|
||||
if(this.tmpDataList.length==0){
|
||||
this.$modal.msgError('表格中没有数据');
|
||||
loadingInstance.close()
|
||||
return;
|
||||
}
|
||||
this.tmpDataList=this.tmpDataList.map(item=>this.transformData(item));
|
||||
this.orderList = this.orderList.concat(this.tmpDataList);
|
||||
this.tmpDataList=[];
|
||||
loadingInstance.close()
|
||||
|
||||
},
|
||||
// 数据转换
|
||||
transformData(orderData){
|
||||
return orderData;
|
||||
},
|
||||
handleRealUploadAll(){
|
||||
if (this.ids && this.ids.length>0) {
|
||||
this.$confirm("确认发送吗?", "提示", {
|
||||
cancelButtonText: "取消",
|
||||
confirmButtonText: "确认",
|
||||
type: "warning",
|
||||
distinguishCancelAndClose: true,
|
||||
closeOnClickModal: false
|
||||
}).then(async () => {
|
||||
|
||||
if(this.selectionList&&this.selectionList.length>0){
|
||||
for(let i=0;i<this.selectionList.length;i++){
|
||||
let orderItem=this.selectionList[i];
|
||||
|
||||
// 检查数据后发送
|
||||
let res=await draftSubmitRegion(orderItem)
|
||||
let rstData=res.data;
|
||||
if(rstData.result=='success'){
|
||||
orderItem.uploadStatus=1;
|
||||
orderItem.errorInfo="发送成功";
|
||||
orderItem.batchNo=rstData.batchNo;
|
||||
}
|
||||
else{
|
||||
orderItem.uploadStatus=-1;
|
||||
orderItem.errorInfo=rstData.msg;
|
||||
}
|
||||
|
||||
}
|
||||
this.$modal.msgSuccess("上传成功");
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
},
|
||||
/** 搜索按钮操作 */
|
||||
handleQuery() {
|
||||
// this.queryParams.pageNum = 1;
|
||||
// this.getList();
|
||||
},
|
||||
/** 重置按钮操作 */
|
||||
resetQuery() {
|
||||
// this.resetForm("queryForm");
|
||||
// this.handleQuery();
|
||||
},
|
||||
// 多选框选中数据
|
||||
handleSelectionChange(selection) {
|
||||
|
||||
this.selectionList=selection;
|
||||
this.ids = selection.map(item => item.id)
|
||||
this.single = selection.length!==1
|
||||
this.multiple = !selection.length
|
||||
},
|
||||
// 排序 查询字段是表格中字段名字 动态取值排序顺序
|
||||
handleSortChange(column) {
|
||||
this.queryParams.orderByColumn = column.prop;
|
||||
this.queryParams.isAsc = column.order;
|
||||
this.getList();
|
||||
},
|
||||
|
||||
cancel(){
|
||||
this.openUploadForm = false;
|
||||
},
|
||||
/** 删除按钮操作 */
|
||||
handleDelete(row) {
|
||||
const ids = row.id || this.ids;
|
||||
let that=this;
|
||||
this.$modal.confirm('是否确认删除').then(function() {
|
||||
that.selectionList.forEach((item,index) =>{
|
||||
that.orderList.forEach((v,i)=>{
|
||||
if(item.index === v.index){
|
||||
that.orderList.splice(i,1)
|
||||
}
|
||||
})
|
||||
})
|
||||
that.$refs.multipleTable.clearSelection();
|
||||
}).then(() => {
|
||||
this.$modal.msgSuccess("删除成功");
|
||||
}).catch(() => {});
|
||||
},
|
||||
|
||||
/** 列索引函数 */
|
||||
getIndex($index) {
|
||||
return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + $index + 1
|
||||
},
|
||||
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
:deep .el-form-item__label-wrap {
|
||||
margin-left: 0 !important;
|
||||
}
|
||||
.el-divider{
|
||||
margin-top: 0px;
|
||||
background: 0 0;
|
||||
border-top: 1px solid #E6EBF5;
|
||||
}
|
||||
.el-divider__text {
|
||||
color: #0955ee;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
|
||||
.query-label {
|
||||
.el-radio{
|
||||
display: block;
|
||||
line-height: 23px;
|
||||
white-space: normal;
|
||||
margin-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.queryForm .el-form-item {
|
||||
margin-bottom: 0px !important;
|
||||
}
|
||||
|
||||
:deep .el-table .success-row {
|
||||
color: rgb(21, 174, 31) !important;
|
||||
}
|
||||
|
||||
:deep .el-table .warning-row {
|
||||
color: #f51f1f !important;
|
||||
}
|
||||
|
||||
:deep .el-form-item__label {
|
||||
text-align: left;
|
||||
}
|
||||
</style>
|
||||
Loading…
Reference in New Issue
Block a user