kpi-web/scripts/tpm.js

632 lines
17 KiB
JavaScript
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.

var tpmcomponent = {
template:`
<div>
<div id="" style="display: flex">
<el-input v-model="p_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_inspection()">搜索</el-button>
<el-button plain type="primary" icon="el-icon-circle-plus-outline" @click="add()">新增</el-button>
<el-button id ="bt_del" plain type="primary" icon="el-icon-circle-plus-outline" @click="del_inspection()">删除</el-button>
</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="id"
label="序号"
width="60">
</el-table-column>
<el-table-column
prop="p_name"
label="产品型号及名称"
width="160"
:show-overflow-tooltip="true">
</el-table-column>
<el-table-column
label="检验项目"
width="100">
<template slot-scope="scope">
<el-button @click="show_dis(scope.row)" type="text" size="medium" >详情</el-button>
</template>
</el-table-column>
<el-table-column
label="操作"
width="100">
<template slot-scope="scope">
<el-button @click="show_op(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="dialogVisible"
:lock-scroll ="false"
width="65%">
<span>产品型号及名称:</span>
<el-select style="width: 50%;" v-model="g_p_name" clearable filterable placeholder="请选择产品" :disabled="disabled">
<el-option
v-for="item in p_name_options"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
<div style="display: flex;margin-top: 20px;">
<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>
<el-button id ="bt_export" size="small" plain type="primary" @click="export_ins" 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="inspection_items_cn"
label="检验项目(中)"
width="120"
:show-overflow-tooltip="true">
</el-table-column>
<el-table-column
prop="inspection_items_en"
label="检验项目(英)"
width="120"
:show-overflow-tooltip="true">
</el-table-column>
<el-table-column
prop="inspection_rs_cn"
label="检验要求(中)"
width="120"
:show-overflow-tooltip="true">
</el-table-column>
<el-table-column
prop="inspection_rs_en"
label="检验要求(英)"
width="120"
:show-overflow-tooltip="true">
</el-table-column>
<el-table-column
prop="inspection_scheme_cn"
label="检验方法(中)"
width="120"
:show-overflow-tooltip="true">
</el-table-column>
<el-table-column
prop="inspection_scheme_en"
label="检验方法(英)"
width="120"
:show-overflow-tooltip="true">
</el-table-column>
<el-table-column
prop="inspection_type"
label="结果类型"
width="60"
:show-overflow-tooltip="true">
</el-table-column>
<el-table-column
label="操作"
width="80">
<template slot-scope="scope">
<el-button v-if='scope.row.inspection_type=="文本"' @click="show_i_result(scope.row)" type="text" size="medium" >结果详情</el-button>
</template>
</el-table-column>
</el-table>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取 消</el-button>
<el-button id ="bt_ok" plain type="primary" @click="post_inspection()">确 定</el-button>
</span>
</el-dialog>
<el-drawer
title="日志"
:visible.sync="drawer"
:direction="direction"
:before-close="handleClose"
size="40%"
>
<el-table
:data="tableData1"
style="font-size:14px;margin-left: 20px;width: 90%;"
:cell-style="{background:'#fff'}"
border
>
<el-table-column
prop="op_time"
label="操作时间"
width="150">
</el-table-column>
<el-table-column
prop="op_user"
label="操作人"
width="80">
</el-table-column>
<el-table-column
prop="op_context"
label="记录内容"
width="200"
:show-overflow-tooltip="true">
</el-table-column>
</el-table>
</el-drawer>
<el-drawer
title="结果详情"
:visible.sync="drawer_result"
:direction="direction"
:before-close="handleClose"
size="40%"
>
<el-table
:data="tableData_result"
style="font-size:14px;margin-left: 20px;width: 90%;"
:cell-style="{background:'#fff'}"
border
>
<el-table-column
prop="result_cn"
label="结果(中)"
width="120"
:show-overflow-tooltip="true">
</el-table-column>
<el-table-column
prop="result_en"
label="结果(英)"
width="120"
:show-overflow-tooltip="true">
</el-table-column>
</el-table>
</el-drawer>
</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.7,
tableData: [],
tableData1:[],
currentPage: 1,
pagesize:50,
recordTotal:0,
p_name_v:'',
g_p_name:'',
dialogVisible:false,
oper_type:0,
multipleSelection: [],
importdialogVisible:false,
fileListUpload:[],
importTableData:[],
disabled:false,
if_show_process:false,
percent_len:0,
interval:'',
if_show_process1:false,
fileList:[],
rules: {
p_name_cn: [
{ required: true, message: '产品型号及名称(中)不可为空', trigger: 'blur' }
],
p_name_en: [
{ required: true, message: '产品型号及名称(英)不可为空', trigger: 'blur' }
],
p_ibase_cn: [
{ required: true, message: '检验依据(中)不可为空', trigger: 'blur' }
],
p_ibase_en: [
{ required: true, message: '检验依据(英)不可为空', trigger: 'blur' }
],
},
p_name_options:[],
drawer:false,
direction: 'rtl',
tableData_result:[],
drawer_result:false,
}
},
mounted() {
this.get_inspection();
},
methods: {
export_ins(){
document.getElementById("bt_export").blur();
var _this = this;
var objs;
axios.post('/pkpi/export_inspection', {
opuser:localStorage.getItem("online_user"),
opuser_uuid:localStorage.getItem("uuid"),
p_name: _this.$data.g_p_name,
})
.then(function (response) {
console.log(response.data);
var fileid = response.data.fileId;
var downUrl = 'file/'+fileid;
downloadUrl("检验项目.csv",downUrl);
})
.catch(function (error) {
console.log(error);
});
},
show_i_result(row){
this.$data.tableData_result=row.result_contain;
this.$data.drawer_result=true;
},
download_template(){
document.getElementById("bt_download").blur();
var downUrl = 'file/'+"检测项目导入.csv";
downloadUrl("检测项目导入.csv",downUrl);
return;
},
show_op(row){
var _this = this;
axios.post('/pkpi/get_inspection_op_history', {
opuser:localStorage.getItem("online_user"),
opuser_uuid:localStorage.getItem("uuid"),
p_name:row.p_name,
})
.then(function (response) {
console.log(response.data);
objs = response.data.data;
_this.$data.tableData1 = objs;
})
.catch(function (error) {
console.log(error);
});
this.drawer=true;
},
handleClose(done) {
done();
},
show_dis(row){
this.$data.disabled=true;
this.$data.g_p_name=row.p_name;
this.$data.importTableData=row.data;
this.$data.dialogVisible=true;
},
post_inspection(){
document.getElementById("bt_ok").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('/pkpi/post_inspection', {
opuser:localStorage.getItem("online_user"),
opuser_uuid:localStorage.getItem("uuid"),
data:this.$data.importTableData,
p_name:this.$data.g_p_name,
})
.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.dialogVisible=false;
//更新页面
_this.get_inspection();
})
.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.inspection_items_cn = results.data[i][0]
if(obj.inspection_items_cn==""|| obj.inspection_items_cn==undefined){
continue;
}
obj.inspection_items_en = results.data[i][1]
obj.inspection_rs_cn = results.data[i][2]
if(obj.inspection_rs_cn==""|| obj.inspection_rs_cn==undefined){
continue;
}
obj.inspection_rs_en = results.data[i][3]
obj.inspection_scheme_cn = results.data[i][4]
obj.inspection_scheme_en = results.data[i][5]
obj.inspection_type= results.data[i][6]
obj.Result_contain=[];
if(obj.inspection_type=="文本"){
let tobj={}
var cnt = 0;
for(let j=7; j<results.data[i].length;++j){
if(results.data[i][j]==''){
break;
}
console.log(results.data[i][j]);
if (cnt==0){
tobj.result_cn=results.data[i][j]
++cnt;
} else if(cnt==1){
tobj.result_en=results.data[i][j]
cnt=0;
obj.Result_contain.push(tobj);
tobj={};
}
}
}
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: '请上传附件!'
})
}
},
get_p_names(){
var _this = this;
axios.post('/pkpi/get_p_name_options',{
opuser:localStorage.getItem("online_user"),
opuser_uuid:localStorage.getItem("uuid"),
})
.then(function (response) {
_this.$data.p_name_options=[];
console.log(response.data);
objs = response.data.data;
for(var i=0;i<objs.length;++i){
var obj ={
value:objs[i],
label:objs[i],
}
_this.$data.p_name_options.push(obj);
}
})
.catch(function (error) {
console.log(error);
});
},
input_change(value) {
console.log(value);
this.get_inspection();
},
add(){
this.get_p_names();
this.$data.disabled=false;
this.$data.fileListUpload=[];
this.$data.importTableData=[];
this.$data.g_p_name='';
this.$data.dialogVisible=true;
},
handleSelectionChange(val) {
console.log("已选择");
console.log(val);
this.multipleSelection = val;
},
del_inspection(){
var _this = this;
axios.post('/pkpi/del_inspection', {
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_inspection();//更新页面
}
})
.catch(function (error) {
console.log(error);
});
},
get_inspection(cur_page){
document.getElementById("bt_search").blur();
if (cur_page==undefined){
this.$data.currentPage=1;
} else {
this.$data.currentPage=cur_page;
}
var _this = this;
var objs;
axios.post('/pkpi/get_inspection', {
opuser:localStorage.getItem("online_user"),
opuser_uuid:localStorage.getItem("uuid"),
p_name: _this.$data.p_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_inspection();
},
handleCurrentChange(val) {
this.$data.currentPage = val;
this.get_inspection();
}
}
}