601 lines
16 KiB
JavaScript
601 lines
16 KiB
JavaScript
var pfcomponent = {
|
||
template:`
|
||
<div>
|
||
<div id="" style="display: flex">
|
||
<el-input v-model="p_id_v" placeholder="产品编号" clearable style="width: 160px;" @change="input_change"></el-input>
|
||
<el-input v-model="p_name_v" placeholder="产品名称" clearable style="width: 160px;" @change="input_change"></el-input>
|
||
<el-input v-model="plan_name_v" placeholder="工序名称" clearable style="width: 160px;" @change="input_change"></el-input>
|
||
<el-button id ="bt_search" plain type="primary" icon="el-icon-search" @click="get_process()">搜索</el-button>
|
||
<el-button plain type="primary" icon="el-icon-circle-plus-outline" @click="importCsv()">导入</el-button>
|
||
<el-button id ="bt_export" plain type="primary" icon="el-icon-circle-plus-outline" @click="export_csv()">导出</el-button>
|
||
<el-button id ="bt_del" plain type="primary" icon="el-icon-circle-plus-outline" @click="del_p()">删除</el-button>
|
||
</div>
|
||
<div>
|
||
<el-progress v-if="if_show_process" :percentage="percent_len" ></el-progress>
|
||
</div>
|
||
<div class="span">
|
||
<el-table
|
||
:data="tableData"
|
||
style="width: 100%"
|
||
:height="tHeight"
|
||
:cell-style="{background:'#fff'}"
|
||
border
|
||
@selection-change="handleSelectionChange"
|
||
>
|
||
<el-table-column
|
||
type="selection"
|
||
>
|
||
</el-table-column>
|
||
<el-table-column
|
||
prop="p_id"
|
||
label="产品编号"
|
||
width="120"
|
||
:show-overflow-tooltip="true">
|
||
</el-table-column>
|
||
|
||
<el-table-column
|
||
prop="p_name"
|
||
label="产品名称"
|
||
width="120"
|
||
:show-overflow-tooltip="true">
|
||
</el-table-column>
|
||
|
||
<el-table-column
|
||
prop="process_name"
|
||
label="工序"
|
||
width="120"
|
||
:show-overflow-tooltip="true">
|
||
</el-table-column>
|
||
|
||
<el-table-column
|
||
prop="process_t"
|
||
label="工时"
|
||
width="120"
|
||
:show-overflow-tooltip="true">
|
||
</el-table-column>
|
||
|
||
<el-table-column
|
||
label="操作"
|
||
width="120">
|
||
<template slot-scope="scope">
|
||
<el-button @click="update_process(scope.row)" type="text" size="medium" >修改</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
</div>
|
||
|
||
<div class="block">
|
||
<span class="demonstration"></span>
|
||
<el-pagination
|
||
@size-change="handleSizeChange"
|
||
@current-change="handleCurrentChange"
|
||
:current-page="currentPage"
|
||
:page-sizes="[50,100, 200, 300]"
|
||
:page-size="pagesize"
|
||
layout="total, sizes, prev, pager, next, jumper"
|
||
:total="recordTotal">
|
||
</el-pagination>
|
||
</div>
|
||
|
||
<el-dialog
|
||
title="工序信息"
|
||
:visible.sync="update_visible"
|
||
:lock-scroll ="false"
|
||
width="40%"
|
||
style="height: 100%;">
|
||
<el-form ref="form_p" :model="form" label-width="80px" :rules="rules">
|
||
<el-row :gutter="10">
|
||
<el-col :span="12">
|
||
<el-form-item label="产品编号" prop="p_id">
|
||
<el-input v-model="form.p_id" :disabled="disabled"></el-input>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="产品名称" prop="p_id">
|
||
<el-input v-model="form.p_name" :disabled="disabled"></el-input>
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-row :gutter="10">
|
||
<el-col :span="12">
|
||
<el-form-item label="工序" prop="process_name">
|
||
<el-input v-model="form.process_name" ></el-input>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="工时" prop="process_t">
|
||
<el-input v-model="form.process_t" ></el-input>
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
</el-form>
|
||
<span slot="footer" class="dialog-footer">
|
||
<el-button @click="update_visible = false">取 消</el-button>
|
||
<el-button id ="bt_ok" plain type="primary" @click="post_process()">确 定</el-button>
|
||
</span>
|
||
</el-dialog>
|
||
|
||
<el-dialog
|
||
title="基础数据导入"
|
||
:visible.sync="importdialogVisible"
|
||
:lock-scroll ="false"
|
||
:before-close="importDialog_close"
|
||
width="40%">
|
||
<div style="display: flex;">
|
||
<el-upload
|
||
class="upload-demo"
|
||
action=""
|
||
:on-change="handleChange"
|
||
:file-list="fileListUpload"
|
||
:show-file-list="false"
|
||
accept=".csv"
|
||
:auto-upload="false">
|
||
<el-button id ="bt_upload" size="small" plain type="primary">点击上传(csv文件)</el-button>
|
||
</el-upload>
|
||
<el-button id ="bt_import" size="small" plain type="primary" @click="importData" style="margin-left: 10px;">确认导入</el-button>
|
||
<!--<el-button id ="bt_download" size="small" plain type="primary" @click="download_template" style="margin-left: 10px;">下载导入模板文件</el-button>-->
|
||
</div>
|
||
<div>
|
||
<el-progress v-if="if_show_process1" :percentage="percent_len" ></el-progress>
|
||
</div>
|
||
<el-table
|
||
:data="importTableData"
|
||
style="font-size:13px;margin-top: 10px;width: 100%;"
|
||
:height="tHeight*0.5"
|
||
:cell-style="{background:'#fff'}"
|
||
stripe border>
|
||
|
||
<el-table-column
|
||
prop="p_id"
|
||
label="产品编号"
|
||
width="120"
|
||
:show-overflow-tooltip="true">
|
||
</el-table-column>
|
||
<el-table-column
|
||
prop="p_name"
|
||
label="产品名称"
|
||
width="120"
|
||
:show-overflow-tooltip="true">
|
||
</el-table-column>
|
||
<el-table-column
|
||
prop="process_name"
|
||
label="工序"
|
||
width="120"
|
||
:show-overflow-tooltip="true">
|
||
</el-table-column>
|
||
|
||
<el-table-column
|
||
prop="process_t"
|
||
label="工时"
|
||
width="120"
|
||
:show-overflow-tooltip="true">
|
||
</el-table-column>
|
||
</el-table>
|
||
</el-dialog>
|
||
</div>
|
||
`,
|
||
data(){
|
||
// 获取当前屏幕的分辨率
|
||
let screenW = window.screen.width;
|
||
let screenH = window.screen.height;
|
||
console.log("screen width:",screenW);
|
||
console.log("screen height:",screenH);
|
||
return {
|
||
tHeight:screenH*0.8,
|
||
tableData: [],
|
||
currentPage: 1,
|
||
pagesize:50,
|
||
recordTotal:0,
|
||
p_id_v:'',
|
||
p_name_v:'',
|
||
plan_name_v:'',
|
||
dialogVisible:false,
|
||
multipleSelection: [],
|
||
importdialogVisible:false,
|
||
fileListUpload:[],
|
||
importTableData:[],
|
||
disabled:true,
|
||
|
||
if_show_process:false,
|
||
percent_len:0,
|
||
interval:'',
|
||
if_show_process1:false,
|
||
|
||
fileList:[],
|
||
|
||
update_visible:false,
|
||
form: {
|
||
id:'',
|
||
p_id: '',
|
||
p_name:'',
|
||
process_name:'',
|
||
process_t:'',
|
||
},
|
||
|
||
rules: {
|
||
p_id: [
|
||
{ required: true, message: '产品编号不可为空', trigger: 'blur' }
|
||
],
|
||
process_name: [
|
||
{ required: true, message: '工序不可为空', trigger: 'blur' }
|
||
],
|
||
process_t: [
|
||
{ required: true, message: '工时不可为空', trigger: 'blur' }
|
||
],
|
||
},
|
||
}
|
||
},
|
||
mounted() {
|
||
|
||
var _this = this;
|
||
|
||
var objs;
|
||
axios.post('/u_ma/get_process', {
|
||
opuser:localStorage.getItem("online_user"),
|
||
opuser_uuid:localStorage.getItem("uuid"),
|
||
p_id: _this.$data.p_id_v,
|
||
p_name:_this.$data.p_name_v,
|
||
process_name: _this.$data.plan_name_v,
|
||
index: _this.$data.currentPage,
|
||
count: _this.$data.pagesize
|
||
})
|
||
.then(function (response) {
|
||
|
||
console.log(response.data);
|
||
objs = response.data.data;
|
||
rcnt = response.data.total;
|
||
_this.$data.tableData = objs;
|
||
_this.$data.recordTotal = rcnt;
|
||
})
|
||
.catch(function (error) {
|
||
console.log(error);
|
||
});
|
||
},
|
||
methods: {
|
||
export_csv(){
|
||
document.getElementById("bt_export").blur();
|
||
|
||
var _this = this;
|
||
var objs;
|
||
axios.post('/u_ma/export_base_processes', {
|
||
opuser:localStorage.getItem("online_user"),
|
||
opuser_uuid:localStorage.getItem("uuid"),
|
||
p_id: _this.$data.p_id_v,
|
||
p_name:_this.$data.p_name_v,
|
||
process_name: _this.$data.plan_name_v,
|
||
})
|
||
.then(function (response) {
|
||
|
||
var date = new Date();
|
||
//年 getFullYear():四位数字返回年份
|
||
var year = date.getFullYear()%2000; //getFullYear()代替getYear()
|
||
console.log(year.toString());
|
||
//月 getMonth():0 ~ 11
|
||
var month = date.getMonth() + 1;
|
||
if(month<10){
|
||
month='0'+month
|
||
}
|
||
//日 getDate():(1 ~ 31)
|
||
var day = date.getDate();
|
||
if(day<10){
|
||
day='0'+day;
|
||
}
|
||
//时 getHours():(0 ~ 23)
|
||
var hour = date.getHours();
|
||
if (hour<10){
|
||
hour='0'+hour;
|
||
}
|
||
//分 getMinutes(): (0 ~ 59)
|
||
var minute = date.getMinutes();
|
||
if (minute<10){
|
||
minute='0'+minute;
|
||
}
|
||
//秒 getSeconds():(0 ~ 59)
|
||
var second = date.getSeconds();
|
||
if (second<10){
|
||
second='0'+second;
|
||
}
|
||
|
||
var filename=year.toString()+month.toString()+day.toString() +" " + hour.toString()+minute.toString()+second.toString();
|
||
filename = "工序工时 "+filename+".xlsx"
|
||
console.log(response.data);
|
||
var fileid = response.data.fileId;
|
||
|
||
var downUrl = '/u_ma/download_file'+"?id="+fileid;
|
||
downloadUrl(filename,downUrl);
|
||
})
|
||
.catch(function (error) {
|
||
console.log(error);
|
||
});
|
||
},
|
||
post_process(){
|
||
this.$refs['form_p'].validate((valid) => {
|
||
if(valid){
|
||
this.$data.update_visible = false;
|
||
|
||
var _this = this;
|
||
|
||
console.log(_this.$data.form);
|
||
|
||
var objs;
|
||
axios.post('/u_ma/update_process', {
|
||
opuser:localStorage.getItem("online_user"),
|
||
opuser_uuid:localStorage.getItem("uuid"),
|
||
data:{
|
||
id: _this.$data.form.id,
|
||
p_id: _this.$data.form.p_id,
|
||
p_name: _this.$data.form.p_name,
|
||
process_name: _this.$data.form.process_name,
|
||
process_t: _this.$data.form.process_t,
|
||
}
|
||
})
|
||
.then(function (response) {
|
||
|
||
let r = response.data.r;
|
||
let s = ""
|
||
let errType = ""
|
||
if (r == 0) {
|
||
errType = "success"
|
||
} else{
|
||
errType = "error"
|
||
}
|
||
|
||
if (r ==0) {
|
||
s = "修改成功!";
|
||
} else{
|
||
s = "修改失败!";
|
||
}
|
||
|
||
_this.$message({
|
||
message: s,
|
||
type: errType,
|
||
duration: 1500
|
||
});
|
||
|
||
//更新页面
|
||
_this.get_process();
|
||
})
|
||
.catch(function (error) {
|
||
console.log(error);
|
||
});
|
||
|
||
}
|
||
});
|
||
},
|
||
update_process(row){
|
||
this.$data.form = {
|
||
id:row.id,
|
||
p_id: row.p_id,
|
||
p_name:row.p_name,
|
||
process_name:row.process_name,
|
||
process_t:row.process_t
|
||
};
|
||
this.$nextTick(() => {
|
||
this.$refs['form_p'].clearValidate()
|
||
});
|
||
this.$data.update_visible = true;
|
||
},
|
||
input_change(value) {
|
||
console.log(value);
|
||
this.get_process();
|
||
},
|
||
importData(){
|
||
document.getElementById("bt_import").blur();
|
||
if(this.$data.importTableData.length==0){
|
||
this.$message({
|
||
message: "请选择导入文件",
|
||
type: "warning",
|
||
duration: 1500
|
||
});
|
||
return;
|
||
}
|
||
|
||
this.$confirm('是否确认导入?', '提示', {
|
||
confirmButtonText: '确定',
|
||
cancelButtonText: '取消',
|
||
type: 'warning'
|
||
}).then(() => {
|
||
var _this = this;
|
||
_this.$data.percent_len=0;
|
||
_this.$data.if_show_process1=true;
|
||
_this.$data.interval= setInterval(()=>{
|
||
if(_this.$data.percent_len>=99){
|
||
clearInterval(_this.$data.interval);
|
||
return;
|
||
}
|
||
|
||
if (_this.$data.percent_len<98){
|
||
_this.$data.percent_len+=2
|
||
}
|
||
},20)
|
||
|
||
axios.post('/u_ma/import_process', {
|
||
opuser:localStorage.getItem("online_user"),
|
||
opuser_uuid:localStorage.getItem("uuid"),
|
||
data:this.$data.importTableData,
|
||
})
|
||
.then(function (response) {
|
||
|
||
let r = response.data.r;
|
||
let s = ""
|
||
let errType = ""
|
||
if (r == 0) {
|
||
let len = _this.$data.importTableData.length;
|
||
errType = "success"
|
||
s = "导入成功("+len+"条)";
|
||
_this.$data.percent_len=100;
|
||
_this.$data.if_show_process1=false;
|
||
} else if(r == 1) {
|
||
errType = "error"
|
||
s = "正在导入,请稍后!";
|
||
clearInterval(_this.$data.interval);
|
||
} else{
|
||
errType = "error"
|
||
s = "导入失败!";
|
||
clearInterval(_this.$data.interval);
|
||
}
|
||
|
||
console.log(s);
|
||
_this.$message({
|
||
message: s,
|
||
type: errType,
|
||
duration: 3000
|
||
});
|
||
|
||
_this.$data.importdialogVisible=false;
|
||
//更新页面
|
||
_this.get_process();
|
||
})
|
||
.catch(function (error) {
|
||
console.log(error);
|
||
});
|
||
}).catch(() => {
|
||
this.$message({
|
||
type: 'info',
|
||
message: '已取消'
|
||
});
|
||
return;
|
||
});
|
||
},
|
||
handleChange(file, fileList) {
|
||
document.getElementById("bt_upload").blur();
|
||
|
||
this.fileTemp = file.raw
|
||
console.log("filetype:",this.fileTemp);
|
||
if (this.fileTemp) {
|
||
console.log("begin ...")
|
||
console.log(this.fileTemp.type);
|
||
if ((this.fileTemp.type == 'text/csv') || (this.fileTemp.type == '.csv') || (this.fileTemp.type == 'application/vnd.ms-excel')) {
|
||
let _this = this//如果需要点击事件结束之后对DOM进行操作使用)_this.xx=xx进行操作
|
||
Papa.parse(_this.fileTemp, {
|
||
encoding:'gb2312',
|
||
complete (results) {
|
||
console.log(results)//这个是csv文件的数据
|
||
let data = []
|
||
//遍历csv文件中的数据,存放到data中 方法不唯一,可自己更改
|
||
for (let i = 0; i < results.data.length; ++i) {
|
||
if(i==0){
|
||
continue;
|
||
}
|
||
let obj = {}
|
||
obj.p_id = results.data[i][0]
|
||
if(obj.p_id==""|| obj.p_id==undefined){
|
||
continue;
|
||
}
|
||
obj.p_name = results.data[i][1]
|
||
obj.process_name = results.data[i][2]
|
||
obj.process_t = results.data[i][3]
|
||
data.push(obj)
|
||
}
|
||
//data.splice(0, 1)//将数组第一位的表格名称去除
|
||
console.log('data', data)
|
||
_this.$data.importTableData=data;
|
||
}
|
||
})
|
||
|
||
} else {
|
||
this.$data.fileListUpload=[];
|
||
this.$message({
|
||
type: 'warning',
|
||
message: '附件格式错误,请删除后重新上传!'
|
||
})
|
||
}
|
||
} else {
|
||
this.$message({
|
||
type: 'warning',
|
||
message: '请上传附件!'
|
||
})
|
||
}
|
||
},
|
||
|
||
importCsv(){
|
||
this.$data.fileListUpload=[];
|
||
this.$data.importTableData=[];
|
||
this.$data.importdialogVisible=true;
|
||
},
|
||
importDialog_close(done){
|
||
done();
|
||
},
|
||
handleSelectionChange(val) {
|
||
console.log("已选择");
|
||
console.log(val);
|
||
this.multipleSelection = val;
|
||
},
|
||
|
||
del_p(){
|
||
var _this = this;
|
||
|
||
axios.post('/u_ma/del_process', {
|
||
opuser:localStorage.getItem("online_user"),
|
||
opuser_uuid:localStorage.getItem("uuid"),
|
||
ids: _this.$data.multipleSelection,
|
||
})
|
||
.then(function (response) {
|
||
|
||
let r = response.data.r;
|
||
let s = ""
|
||
let errType = ""
|
||
if (r == 0) {
|
||
s = "删除成功!";
|
||
errType = "success"
|
||
} else{
|
||
s = "删除失败!";
|
||
errType = "error"
|
||
}
|
||
|
||
_this.$message({
|
||
message: s,
|
||
type: errType,
|
||
duration: 1500
|
||
});
|
||
|
||
if (r ==0) {
|
||
_this.get_process();//更新页面
|
||
}
|
||
|
||
})
|
||
.catch(function (error) {
|
||
console.log(error);
|
||
});
|
||
},
|
||
|
||
get_process(){
|
||
document.getElementById("bt_search").blur();
|
||
var _this = this;
|
||
|
||
var objs;
|
||
axios.post('/u_ma/get_process', {
|
||
opuser:localStorage.getItem("online_user"),
|
||
opuser_uuid:localStorage.getItem("uuid"),
|
||
p_id: _this.$data.p_id_v,
|
||
p_name:_this.$data.p_name_v,
|
||
process_name: _this.$data.plan_name_v,
|
||
index: _this.$data.currentPage,
|
||
count: _this.$data.pagesize
|
||
})
|
||
.then(function (response) {
|
||
console.log(response.data);
|
||
objs = response.data.data;
|
||
rcnt = response.data.total;
|
||
_this.$data.tableData = objs;
|
||
_this.$data.recordTotal = rcnt;
|
||
})
|
||
.catch(function (error) {
|
||
console.log(error);
|
||
});
|
||
|
||
},
|
||
|
||
handleSizeChange(val) {
|
||
this.$data.pagesize = val;
|
||
|
||
this.get_process();
|
||
},
|
||
handleCurrentChange(val) {
|
||
this.$data.currentPage = val;
|
||
|
||
this.get_process();
|
||
}
|
||
}
|
||
}
|
||
|