factory_web/src/views/wpm_bx/mlog_form.vue

519 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>
<el-dialog append-to-body
:title="titleMap[mode]"
v-model="visible"
style="width: 80%;"
destroy-on-close
:close-on-click-modal="false"
@closed="$emit('closed')"
>
<el-container v-loading="loading">
<el-main style="padding: 0 20px 20px 20px">
<el-form
ref="dialogForm"
:model="form"
:rules="rules"
label-position="right"
label-width="80px"
style="padding: 0 10px"
>
<el-row>
<el-col :md="12" :sm="12" :xs="24" v-if="mgroupMtype == 20">
<el-form-item
label="外协单位"
prop="supplier"
v-if="form.mtype == 20"
>
<el-select
v-model="form.supplier"
placeholder="外协单位"
clearable
:disabled="mode == 'edit'"
style="width: 100%"
>
<el-option
v-for="item in supplierOptions"
:key="item.id"
:label="item.name"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col v-if="mlogtype!=='rework'">
<el-form-item label="工艺路线" prop="route">
<el-select
v-model="form.route"
placeholder="工艺路线"
clearable
filterable
style="width: 100%"
@change="routeChange"
>
<el-option
v-for="item in routeOptions"
:key="item.id"
:label="item.name + (item.routepack_name ? '' + item.routepack_name + '' : '')"
:value="item.id"
>
<span style="display: flex; width: 100%; min-width: 0" :title="item.name + (item.routepack_name ? '' + item.routepack_name + '' : '')">
<span style="flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap">{{ item.name }}</span>
<span v-if="item.routepack_name" style="max-width: 45%; flex-shrink: 0; overflow: hidden; color: var(--el-text-color-secondary); text-overflow: ellipsis; white-space: nowrap">{{ item.routepack_name }}</span>
</span>
</el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :md="12" :sm="12" :xs="24" v-if="base_code=='tcerp'||route_code=='ladansi'||route_code=='yicifusi'||route_code=='ercifusi'||route_code=='zlybcl'||route_code=='djg'||route_code=='cnc'">
<el-form-item label="生产设备" :prop="base_code!=='tcerp' ? 'equipment' : null">
<el-select
v-model="form.equipment"
placeholder="生产设备"
clearable
filterable
style="width: 100%"
>
<el-option
v-for="item in options"
:key="item.id"
:label="item.label"
:value="item.id"
>
<span style="float:left">{{item.name}}</span>
<span style="float:right">{{item.number}}</span>
</el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :md="12" :sm="12" :xs="24" v-for="item in testitems" :key="item.id">
<el-form-item :label="item.name">
<el-input-number
v-if="item.field_type=='input-number'"
v-model="item.value"
:min="0"
class="width-100"
controls-position="right"
>
</el-input-number>
<el-input-number
v-if="item.field_type=='input-int'"
v-model="item.value"
:min="0"
class="width-100"
controls-position="right"
>
</el-input-number>
<el-input
v-if="item.field_type=='input-text'"
v-model="item.value"
class="width-100"
>
</el-input>
<el-select
v-if="item.field_type=='select-text'"
v-model="item.value"
clearable
class="width-100"
>
<el-option
v-for="item0 in item.choices"
:key="item0"
:label="item0"
:value="item0"
>
</el-option>
</el-select>
<el-select
v-if="item.field_type=='selects-text'"
v-model="item.value"
clearable
multiple
class="width-100"
>
<el-option
v-for="item1 in item.choices"
:key="item1"
:label="item1"
:value="item1"
>
</el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :md="12" :sm="12" :xs="24">
<el-form-item
label="开始时间"
prop="work_start_time"
>
<el-date-picker
v-model="form.work_start_time"
type="datetime"
value-format="YYYY-MM-DD HH:mm:ss"
style="width: 100%"
popper-append-to-body
/>
</el-form-item>
</el-col>
<el-col :md="12" :sm="12" :xs="24">
<el-form-item label="结束时间">
<el-date-picker
v-model="form.work_end_time"
type="datetime"
value-format="YYYY-MM-DD HH:mm:ss"
style="width: 100%"
:disabledDate="disabledDateFn"
popper-append-to-body
/>
</el-form-item>
</el-col>
<el-col :md="12" :sm="12" :xs="24">
<el-form-item label="操作人">
<ehsSelect
v-model="form.handle_user"
:showName="form.handle_user_name"
:apiObj="this.$API.system.user.list"
:params="{ depts: dept }"
style="width: 100%;"
></ehsSelect>
</el-form-item>
</el-col>
<el-col :md="12" :sm="12" :xs="24">
<el-form-item label="备注">
<el-input
v-model="form.note"
clearable
></el-input>
</el-form-item>
</el-col>
<el-col :md="12" :sm="12" :xs="24" v-if="route_code=='paiyicibang'&&imageUrl!==''">
<el-form-item label="工艺图纸">
<el-image
style="width: 100px; height: 100px"
:src="imageUrl"
fit="fill"
/>
</el-form-item>
</el-col>
</el-row>
</el-form>
</el-main>
<el-footer>
<el-button type="primary" :loading="isSaveing" @click="submit">保存</el-button>
<el-button @click="visible = false">取消</el-button>
</el-footer>
</el-container>
</el-dialog>
</template>
<script>
const defaultForm = {
mtype: 10,
supplier:'',
route: "",
equipment: "",
handle_user: null,
handle_user_name: "",
work_start_time: "",
work_end_time:null,
note:'',
mgroup:'',
mtask:'',
oinfo_json:{},
is_fix:false,
};
export default {
props: {
process: {
type: String,
default: "",
},
mgroupName:{
type: String,
default: "",
},
mgroup: {
type: String,
default: "",
},
dept: {
type: String,
default: "",
},
mgroupMtype: {
type: String,
default: "",
}
},
computed: {
title() {
return this.titleMap[this.mode];
},
},
emits: ["success", "closed"],
data() {
return {
loading: false,
mode: "add",
titleMap: {
add: "新增日志",
edit: "编辑日志",
show: "查看日志",
},
imageUrl:'',
test_file:'',
fileList:[],
//表单数据
form: Object.assign({}, defaultForm),
//验证规则
rules: {
supplier: [
{
required: true,
message: "请选择供应商",
trigger: "blur",
},
],
equipment: [
{
required: false,
message: "该工序涉及设备采集请选择生产设备",
trigger: "blur",
},
],
work_end_time: [
{
required: true,
message: "请选择结束时间",
trigger: "blur",
},
],
route: [
{
required: true,
message: "请选择工艺路线",
trigger: "blur",
},
],
mtype: [
{
required: true,
message: "请选择生产类型",
trigger: "blur",
},
],
},
typeOptions: [
{ id: 10, name: "自产" },
{ id: 20, name: "外协" },
],
cutCount:0,
mlogtype:"",
route_code:"",
visible: false,
isSaveing: false,
options: [],
testitems:[],
routeOptions: [],
mtaskOptions:[],
supplierOptions: [],
setFiltersVisible: false,
base_code: this.$TOOL.data.get('BASE_INFO').base.base_code,
};
},
mounted() {
let that = this;
this.route_code = this.$route.path.split("/")[2];
// this.form.work_start_time = this.$TOOL.dateFormat(new Date());
if(that.mode=='add'){
that.$API.ops.server_time.get.req().then((res) => {
that.form.work_start_time = res.server_time;
})
}
this.getRoute();
this.getSupplier();
this.getEquipment();
this.getMtask();
this.gettestitem();
if(this.route_code=='ladansi'||this.route_code=='yicifusi'||this.route_code=='ercifusi'||this.route_code=='zlybcl'){
this.rules.equipment[0].required = true;
}
},
methods: {
disabledDateFn(time) {
let that = this;
return time.getTime() < new Date(that.form.work_start_time).getTime()- 1000 * 60 * 60*24;
},
gettestitem(){
let that = this;
that.$API.qm.testitem.list.req({ process: that.process,type:20 }).then((res) => {
res.results.forEach((item) => {
let obj = {};
Object.assign(obj, item);
obj.value = null;
that.testitems.push(obj);
})
});
},
//获取班组设备
getEquipment() {
let that = this;
this.$API.em.equipment.list.req({ page: 0, type: 10,belong_dept:that.dept}).then((res) => {
res.forEach((item) => {
let obj = {};
Object.assign(obj, item);
obj.label = item.name+'-'+item.number;
that.options.push(obj);
});
});
},
//获取任务
getMtask() {
let that = this;
this.$API.pm.mtask.list.req({ page: 0, mgroup: that.mgroup, state: 20 }).then((res) => {
that.mtaskOptions = res;
});
},
getSupplier() {
let that = this;
let obj = {};
obj.page = 0;
obj.can_outsource = true;
that.$API.pum.supplier.list.req(obj).then((res) => {
that.supplierOptions = res;
});
},
getRoute(id) {
let that = this;
that.$API.mtm.route.list.req({ process: that.process, page: 0, routepack__state: 30 }).then((res) => {
that.routeOptions = res;
});
},
routeChange(){
let that = this;
if(that.route_code=='paiyicibang'){
that.$API.mtm.route.item.req(that.form.route).then((res) => {
let json = res.params_json;
if(json.fileurl){
let fileurl = JSON.parse(json.fileurl);
that.imageUrl = fileurl[0].path;
}
})
}
},
//显示
open(mode = "add",type) {
let that = this;
this.mode = mode;
if(mode == "add"){
let userInfo = that.$TOOL.data.get("USER_INFO");
this.form.handle_user = userInfo.id;
this.form.handle_user_name = userInfo.name;
}
this.visible = true;
if(type!==''&&type!==undefined&&type!==null){
this.mlogtype = type;
this.form.mtype=10;
this.form.is_fix=true;
}
return this;
},
//表单注入数据
setData(data) {
let that = this;
Object.assign(this.form, data);
if(data.test_file!==null){
this.form.test_file = data.test_file;
this.fileList = [{name:data.test_file,url:data.test_file}];
}
if(data.oinfo_json!==null){
if(that.testitems.length>0){
that.testitems.forEach((item) => {
item.value = data.oinfo_json[item.id];
});
}else{
setTimeout(() => {
that.testitems.forEach((item) => {
item.value = data.oinfo_json[item.id];
});
},500)
}
if(that.route_code=='paiyicibang'&&data.oinfo_json.imageUrl){
this.imageUrl = data.oinfo_json.imageUrl;
}
}
this.getRoute(data.id);
},
changeMtask(){
let that = this;
that.mtaskOptions.forEach((item) => {
if(item.id == that.form.mtask){
that.form.route = item.route;
}
})
},
fileUPSuccess(res) {
let that = this;
this.test_file = res.path;
},
//表单提交方法
submit() {
let that = this;
that.$refs.dialogForm.validate(async (valid) => {
if (valid) {
that.isSaveing = true;
that.form.mgroup = that.mgroup;
let oinfo_json = {};
that.testitems.forEach((item) => {
oinfo_json[item.id] = item.value;
})
if(that.mgroupName=='排一次棒'&&that.imageUrl!==''){
oinfo_json.imageUrl = that.imageUrl;
}
that.form.oinfo_json = oinfo_json;
if (that.mode === "add") {
that.$API.wpm.mlog.init.req(that.form).then((res) => {
that.isSaveing = false;
that.$emit("success");
that.visible = false;
that.$message.success("操作成功");
}).catch(()=>{
that.isSaveing = false;
});
} else {
let obj = {};
obj.work_end_time = that.form.work_end_time;
obj.handle_user = that.form.handle_user;
obj.note = that.form.note;
if(that.mgroupName=='黑化'){
that.form.test_file = that.test_file;
}
that.$API.wpm.mlog.change.req(that.form.id, that.form).then((res) => {
that.isSaveing = false;
that.$emit("success");
that.visible = false;
that.$message.success("操作成功");
}).catch(()=>{
that.isSaveing = false;
});
}
}
});
},
//设置过滤项
setFilters(filters) {
this.selectionFilters = filters;
this.setFiltersVisible = true;
},
},
};
</script>
<style>
.form_unit {
position: absolute;
right: -25px;
}
</style>