|
@@ -3,6 +3,12 @@
|
|
|
<div>
|
|
|
<BaseHeaderLayout :leftSpan="12">
|
|
|
<template slot="left">
|
|
|
+ <el-upload style="margin-left: 8px;" class="upload-demo inline-block margin-right-10" action=""
|
|
|
+ :on-change="importClick" :show-file-list="false"
|
|
|
+ accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
|
|
|
+ :auto-upload="false">
|
|
|
+ <ws-button type="primary">导入</ws-button>
|
|
|
+ </el-upload>
|
|
|
</template>
|
|
|
<!-- <template slot="left"> </template> -->
|
|
|
<template slot="right">
|
|
@@ -134,6 +140,7 @@
|
|
|
delelteWeighing,
|
|
|
getweighing,
|
|
|
changeNo,
|
|
|
+ importWordSale,
|
|
|
goBack
|
|
|
} from '@/model/outboundManagement/index'
|
|
|
import {
|
|
@@ -185,6 +192,124 @@
|
|
|
this.showType = this.isShow
|
|
|
},
|
|
|
methods: {
|
|
|
+ importClick(file, fileList) {
|
|
|
+ this.fileTemp = file.raw
|
|
|
+ let fileName = file.raw.name
|
|
|
+ let fileType = fileName.substring(fileName.lastIndexOf('.') + 1)
|
|
|
+ // 判断上传文件格式
|
|
|
+ if (this.fileTemp) {
|
|
|
+ if (fileType == 'xlsx' || fileType == 'xls') {
|
|
|
+ this.importf(this.fileTemp)
|
|
|
+ } else {
|
|
|
+ this.$message({
|
|
|
+ type: 'warning',
|
|
|
+ message: '附件格式错误,请删除后重新上传!',
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.$message({
|
|
|
+ type: 'warning',
|
|
|
+ message: '请上传附件!',
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ importf(obj) {
|
|
|
+ this.excelFreightspace = []
|
|
|
+ // this.dialogVisible = true;
|
|
|
+ let _this = this;
|
|
|
+ let inputDOM = this.$refs.inputer; // 通过DOM取文件数据
|
|
|
+ this.file = event.currentTarget.files[0];
|
|
|
+ var rABS = false; //是否将文件读取为二进制字符串
|
|
|
+ var f = this.file;
|
|
|
+ var reader = new FileReader();
|
|
|
+ //if (!FileReader.prototype.readAsBinaryString) {
|
|
|
+ FileReader.prototype.readAsBinaryString = function(f) {
|
|
|
+ var binary = '';
|
|
|
+ var rABS = false; //是否将文件读取为二进制字符串
|
|
|
+ var pt = this;
|
|
|
+ var wb; //读取完成的数据
|
|
|
+ var outdata;
|
|
|
+ var reader = new FileReader();
|
|
|
+ reader.onload = function(e) {
|
|
|
+ var bytes = new Uint8Array(reader.result);
|
|
|
+ var length = bytes.byteLength;
|
|
|
+ for (var i = 0; i < length; i++) {
|
|
|
+ binary += String.fromCharCode(bytes[i]);
|
|
|
+ }
|
|
|
+ var XLSX = require('xlsx');
|
|
|
+ if (rABS) {
|
|
|
+ wb = XLSX.read(btoa(fixdata(binary)), { //手动转化
|
|
|
+ type: 'base64',
|
|
|
+ cellDates: true
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ wb = XLSX.read(binary, {
|
|
|
+ type: 'binary'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // outdata就是你想要的东西 excel导入的数据
|
|
|
+ outdata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]);
|
|
|
+ // excel 数据再处理
|
|
|
+ let arr = []
|
|
|
+ outdata.map(v => {
|
|
|
+ // let jsonString = JSON.stringify(v).replace(/\*/g, '').replace(/\s/ig,'');
|
|
|
+ let jsonString = JSON.stringify(v).replace(/\//g, '').replace(/\s/ig, '');
|
|
|
+ v = JSON.parse(jsonString);
|
|
|
+ let obj = {}
|
|
|
+ //xxx代表列名
|
|
|
+ obj.number = v.业务编号
|
|
|
+ obj.inOutTaskNo = v.出库任务编号
|
|
|
+ obj.outType = v.运输方式
|
|
|
+ obj.carNumber = v.车牌号
|
|
|
+ obj.grossWeight = v.毛重
|
|
|
+ obj.tare = v.皮重
|
|
|
+ obj.netWeight = v.净重
|
|
|
+ obj.contractNo = v.销售合同号
|
|
|
+ obj.contractPrice = v.销售合同单价
|
|
|
+ obj.grossDate = _this.formatDate(v.出库日期, '-')
|
|
|
+ obj.settleWeight = v.结算数量
|
|
|
+ obj.settlePrice = v.结算单价
|
|
|
+ obj.settleDate = v.结算日期
|
|
|
+ obj.settleMoney = v.结算金额
|
|
|
+ _this.excelFreightspace.push(obj)
|
|
|
+ })
|
|
|
+ if (_this.excelFreightspace) {
|
|
|
+ importWordSale({
|
|
|
+ warehouseName: _this.warehouseName,
|
|
|
+ weighingManagementList: _this.excelFreightspace
|
|
|
+ }).toPromise()
|
|
|
+ .then((response) => {
|
|
|
+ if (response == 'ok') {
|
|
|
+ this.$notify({
|
|
|
+ title: '成功',
|
|
|
+ message: '导入成功',
|
|
|
+ type: 'success'
|
|
|
+ });
|
|
|
+ _this.getList()
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ reader.readAsArrayBuffer(f);
|
|
|
+ }
|
|
|
+ if (rABS) {
|
|
|
+ reader.readAsArrayBuffer(f);
|
|
|
+ } else {
|
|
|
+ reader.readAsBinaryString(f);
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+ formatDate(numb, format) {
|
|
|
+ const old = numb - 1;
|
|
|
+ const t = Math.round((old - Math.floor(old)) * 24 * 60 * 60);
|
|
|
+ const time = new Date(1900, 0, old, 0, 0, t)
|
|
|
+ const year = time.getFullYear();
|
|
|
+ const month = time.getMonth() + 1;
|
|
|
+ const date = time.getDate();
|
|
|
+ return year + format + (month < 10 ? '0' + month : month) + format + (date < 10 ? '0' + date : date) +
|
|
|
+ ' 00:00:00'
|
|
|
+ },
|
|
|
returnBack(item){
|
|
|
goBack({id:item.id}).toPromise()
|
|
|
.then((response) => {
|