factory_web/src/views/ungrouped/costing.vue

328 lines
13 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!-- 成本分析 -->
<template>
<div class="app-container">
<el-header>
<div class="left-panel">
<el-select
v-model="query.mgroup"
placeholder="工段"
clearable
@change="mgroupChange"
style="margin-left: 2px; width: 200px"
>
<el-option
v-for="item in mgroupOptions"
:key="item.id"
:label="item.name"
:value="item.id"
></el-option>
</el-select>
<el-select
v-model="query.type"
placeholder="查询类型"
clearable
@change="typeCange"
>
<el-option
v-for="item in options"
:key="item.id"
:label="item.name"
:value="item.id"
></el-option>
</el-select>
<el-date-picker
v-model="query.day"
type="date"
value-format="YYYY-MM-DD"
format="YYYY-MM-DD"
placeholder="日"
v-if="query.type==0"
/>
<!-- 选择班次 -->
<el-select
v-if="query.type==0"
v-model="query.shift"
placeholder="班次"
clearable
style="margin-left: 2px; width: 120px"
>
<el-option
v-for="item in optionsShift"
:key="item.id"
:label="item.name"
:value="item.id"
></el-option>
</el-select>
<el-date-picker
v-model="query.month"
type="month"
value-format="YYYY-MM"
format="YYYY-MM"
placeholder="月份"
v-if="query.type==1"
/>
<el-date-picker
v-model="query.year"
type="year"
value-format="YYYY"
format="YYYY"
placeholder="年份"
v-if="query.type==2"
/>
<el-button
type="primary"
icon="el-icon-search"
@click="getTableData"
></el-button>
<el-button
type="primary"
@click="exportExcel()"
:loading = "exportLoading"
>导出xlsx
</el-button>
<el-button
type="primary"
@click="handlePrint"
>打印
</el-button>
</div>
</el-header>
<el-card style="margin-top:5px">
<div ref="print" id="myReport" class="printContainer">
<table border="1" cellspacing="0" :key="timeStamp" id="myTable" class="myTable">
<thead class="myTableHead">
<tr>
<th :colspan="allCol">{{tableName}}</th>
</tr>
<tr>
<th rowspan="3">日期</th>
<th rowspan="3" v-if="query.type==0">班次</th>
<th rowspan="3" v-if="query.type==0">班组</th>
<th rowspan="3">实际产量t</th>
<th rowspan="3">总成本(元)</th>
<th rowspan="3">单位成本(元/吨)</th>
<th :colspan="materialList.length">直接材料</th>
<th colspan="2">直接人工</th>
<th colspan="8">制造费用</th>
</tr>
<tr>
<th v-if="data1>0" :colspan="data1">原材料</th>
<th v-if="data3>0" :colspan="data3">辅助材料</th>
<th v-if="data2>0" :colspan="data2">电/水</th>
<th>车间人员工资</th>
<th>劳务工资</th>
<th>倒运费用</th>
<th>材料出库</th>
<th colspan="2">维修费用</th>
<th>装卸费</th>
<th>差旅费</th>
<th>折旧</th>
<th>摊销</th>
</tr>
<tr>
<th v-for="(item,index) in materialList" :key="index">{{ item }}</th>
<th>单位成本(元/吨)</th>
<th>单位成本(元/吨)</th>
<th>单位成本(元/吨)</th>
<th>单位成本(元/吨)</th>
<th>检修单位成本(元/吨)</th>
<th>外协施工费用单位成本(元/吨)</th>
<th>单位成本(元/吨)</th>
<th>单位成本(元/吨)</th>
<th>单位成本(元/吨)</th>
<th>无形资产摊销单位成本(元/吨)</th>
</tr>
</thead>
<tr v-for="(item,index) in tableData1" :key="index">
<td class="tableCell" v-for="(item1,index1) in item" :key="index1">{{ item1 }}</td>
</tr>
</table>
</div>
</el-card>
</div>
</template>
<script>
export default {
data() {
return {
query:{
type:1,
day:'',
month:'',
year:'',
shift:'',
},
allCol:16,
data1:0,//原材料
data2:0,//电和水
data3:0,//辅助材料
data4:0,//助剂
data5:0,//包装
materialList:[],
mgroupOptions:[],
tableName:'班组成本计算',
options:[
{id:0,name:'班统计'},
{id:1,name:'日统计'},
{id:2,name:'月统计'},
],
tableNmae:'',
tableData1:[],
optionsShift:[],
sourceData:{}
};
},
mounted() {
var myDate = new Date();
let month = myDate.getMonth()+1;
if(month<10){
month = '0'+month;
}
this.query.month = myDate.getFullYear()+'-'+month;
this.getShift();
this.getMgroup();
},
methods: {
//获取工段列表
getMgroup(){
this.$API.mtm.mgroup.list.req({page:0}).then(res=>{
this.mgroupOptions = res;
this.query.mgroup = res[8].id;
this.tableName = '电石渣干粉核算'
})
},
//班组列表
getShift(){
this.$API.mtm.shift.req({page:0}).then(res=>{
this.optionsShift = res;
})
},
mgroupChange(value){
let arr = this.mgroupOptions.filter(item=>{
return item.id==value
})
let name = arr[0].name;
if(name=='电石渣'){
this.tableName = '电石渣干粉核算'
}else if(name=='原料磨'){
this.tableName = '生料核算'
}else if(name=='回转窑'){
this.tableName = '熟料核算'
}else if(name=='水泥磨'){
this.tableName = '水泥核算'
}
},
//查询类型
typeCange(value){
if(value==1){
this.tableName = '班组成本计算'
}else if(value==1){
this.tableName = '日成本计算'
}else{
this.tableName = '月成本计算'
}
},
getData(){
let that = this;
that.data1 = 0;
that.data2 = 0;
that.data3 = 0;
that.data4 = 0;
that.data5 = 0;
let params = {};
let arr = [];
params.page=0;
params.mgroup=that.query.mgroup;
if(that.query.type==0){//班
arr = that.query.day.split('-');
params.year_s = Number(arr[0]);
params.month_s = Number(arr[1]);
params.day_s = Number(arr[2]);
params.type="day_s"
}else if(that.query.type==1){//日
arr = that.query.month.split('-');
params.year_s = Number(arr[0]);
params.month_s = Number(arr[1]);
params.type="day_s"
}else{//月
params.year_s = Number(that.query.year);
params.type="month_s"
}
that.$API.enm.enstat.req(params).then(res=>{
if(res.length>0){
let materials = res[0].imaterial_data;
let arr = [];
materials.forEach(item=>{
if(item.material_type==0){//电水
that.data2=that.data2+4;
}else if(item.material_type==30||item.material_type==20){//原材料
that.data1=that.data1+4;
}else if(item.material_type==40){//辅助材料
that.data3=that.data3+4;
}
arr.push(item.material_name)
arr.push('单价(元/吨)')
arr.push('总成本(元)')
arr.push('单位成本(元/吨)')
})
that.allCol = arr.length+16
that.materialList = arr;
let dataArr = [];
res.forEach(itemData=>{
let time ='';
dataArr = [];
if(that.query.type==0){
time = itemData.year_s+'.'+itemData.month_s+'.'+itemData.day_s;
}else if(that.query.type==1){
time = itemData.year_s+'.'+itemData.month_s+'.'+itemData.day_s;
}else{
time = itemData.year_s+'.'+itemData.month_s;
}
dataArr.push(time);
if(that.query.type==0){
dataArr.push(itemData.shift);
dataArr.push(itemData.team_name);
}
dataArr.push(itemData.total_production);
dataArr.push(itemData.coal_consume_unit);
dataArr.push(itemData.cen_consume_unit);
let sub1data = itemData.imaterial_data;
for(let i=0;i<sub1data.length;i++){
dataArr.push(sub1data[i].cost)
dataArr.push(sub1data[i].price_unit)
dataArr.push(sub1data[i].amount_consume)
dataArr.push(sub1data[i].cost_unit)
}
let otherdata = itemData.other_cost_data;
for(let j=0;j<otherdata.length;j++){
dataArr.push(otherdata[j].cost_unit)
}
that.tableData1.push(dataArr)
})
}
})
},
getTableData(){
this.getData();
},
handlePrint() {
this.$PRINT('#myReport');
},
exportExcel() {
this.exportLoading = true;
this.$XLSX('#myTable', this.tableName)
this.exportLoading = false;
},
}
};
</script>
<style scoped>
.printContainer{
width:100%;
overflow-x:scroll;
}
</style>