fix:光芯辅料库添加导出
This commit is contained in:
parent
1c61925eac
commit
9ce4971ec7
|
@ -2,6 +2,12 @@
|
||||||
<el-container>
|
<el-container>
|
||||||
<el-header>
|
<el-header>
|
||||||
<div class="left-panel">
|
<div class="left-panel">
|
||||||
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
:disabled = 'dLoading'
|
||||||
|
icon="el-icon-download"
|
||||||
|
@click="exportList"
|
||||||
|
>导出</el-button>
|
||||||
</div>
|
</div>
|
||||||
<div class="right-panel">
|
<div class="right-panel">
|
||||||
<el-input
|
<el-input
|
||||||
|
@ -120,6 +126,9 @@
|
||||||
</el-container>
|
</el-container>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
import * as XLSX2 from "xlsx";
|
||||||
|
import * as XLSX from "xlsx-style";
|
||||||
import printDialog from "./../template/printmaterial.vue";
|
import printDialog from "./../template/printmaterial.vue";
|
||||||
export default {
|
export default {
|
||||||
name: "materials",
|
name: "materials",
|
||||||
|
@ -135,6 +144,8 @@ export default {
|
||||||
query: {},
|
query: {},
|
||||||
warehouseOptions: [],
|
warehouseOptions: [],
|
||||||
wmtype:0,
|
wmtype:0,
|
||||||
|
ElLoading:null,
|
||||||
|
dLoading:false,
|
||||||
print_m:false,
|
print_m:false,
|
||||||
materialsVisible:false,
|
materialsVisible:false,
|
||||||
apiObjPrint:this.$API.cm.labelmat.fromMb,
|
apiObjPrint:this.$API.cm.labelmat.fromMb,
|
||||||
|
@ -183,6 +194,78 @@ export default {
|
||||||
this.$refs.printmaterial.open();
|
this.$refs.printmaterial.open();
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
exportList(){
|
||||||
|
let that = this;
|
||||||
|
that.dLoading = true;
|
||||||
|
let chartName = '辅料表';
|
||||||
|
let titleData = ['辅料表'];
|
||||||
|
let tipsData = ['日期','物料编号','物料名称','货位号','规格','品牌型号','单位','安全库存','数量','单价','总金额'];
|
||||||
|
let tableData = [];
|
||||||
|
tableData.push(titleData)
|
||||||
|
tableData.push(tipsData)
|
||||||
|
that.ElLoading = this.$loading({
|
||||||
|
lock: true,
|
||||||
|
text: '数据请求中,请稍后...',
|
||||||
|
background: 'rgba(0, 0, 0, 0)',
|
||||||
|
})
|
||||||
|
that.$API.inm.warehouse.batch.req({ page: 0, count__gte: 1, material__type__in: "40" }).then((res) => {
|
||||||
|
res.forEach(item => {
|
||||||
|
let data0 = [];
|
||||||
|
let total = Number(item.material_.unit_price)*Number(item.count);
|
||||||
|
data0.push(item.update_time);
|
||||||
|
data0.push(item.material_.number);
|
||||||
|
data0.push(item.material_.name);
|
||||||
|
data0.push(item.material_.bin_number_main);
|
||||||
|
data0.push(item.material_.specification);
|
||||||
|
data0.push(item.material_.model);
|
||||||
|
data0.push(item.material_.unit);
|
||||||
|
data0.push(item.material_.count_safe);
|
||||||
|
data0.push(item.count);
|
||||||
|
data0.push(item.material_.unit_price);
|
||||||
|
data0.push(total);
|
||||||
|
tableData.push(data0);
|
||||||
|
})
|
||||||
|
let ws = XLSX2.utils.aoa_to_sheet(tableData);
|
||||||
|
let wb = XLSX2.utils.book_new();
|
||||||
|
XLSX2.utils.book_append_sheet(wb, ws, chartName);
|
||||||
|
var wopts = {
|
||||||
|
bookType: 'xlsx',
|
||||||
|
bookSST: false,
|
||||||
|
type: 'binary'
|
||||||
|
};
|
||||||
|
var wbout = XLSX.write(wb, wopts);
|
||||||
|
var blob = new Blob([this.s2ab(wbout)], {
|
||||||
|
type: "application/octet-stream"
|
||||||
|
});
|
||||||
|
this.openDownloadDialog(blob, chartName+`.xlsx`);
|
||||||
|
that.dLoading = false;
|
||||||
|
that.ElLoading.close();
|
||||||
|
}).catch(res=>{
|
||||||
|
that.dLoading = false;
|
||||||
|
that.ElLoading.close();
|
||||||
|
})
|
||||||
|
},
|
||||||
|
s2ab(s) {
|
||||||
|
var buf = new ArrayBuffer(s.length);
|
||||||
|
var view = new Uint8Array(buf);
|
||||||
|
for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
|
||||||
|
return buf;
|
||||||
|
},
|
||||||
|
openDownloadDialog(url, saveName) {
|
||||||
|
if (typeof url == 'object' && url instanceof Blob) {
|
||||||
|
url = URL.createObjectURL(url); // 创建blob地址
|
||||||
|
}
|
||||||
|
var aLink = document.createElement('a');
|
||||||
|
aLink.href = url;
|
||||||
|
aLink.download = saveName || ''; // HTML5新增的属性,指定保存文件名,可以不要后缀,注意,file:///模式下不会生效
|
||||||
|
var event;
|
||||||
|
if (window.MouseEvent) event = new MouseEvent('click');
|
||||||
|
else {
|
||||||
|
event = document.createEvent('MouseEvents');
|
||||||
|
event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
||||||
|
}
|
||||||
|
aLink.dispatchEvent(event);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue