factory_web/src/views/wpm_gx/handover_form.vue

882 lines
24 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-container>
<el-main class="nopadding">
<el-form
ref="dialogForm"
:model="form"
:rules="rules"
label-width="80px"
>
<el-row>
<el-form-item label="交接物料">
<el-button type="primary" @click="addMaterial" v-if="mode!=='show'">手动添加</el-button>
<scScanner @scanResult="codeTextChange"></scScanner>
</el-form-item>
<el-form-item label-width="0">
<el-input
ref="codeInput"
v-model="codeText"
clearable
placeholder="物料批次"
style="width: 200px;margin-left: 4px;"
@keyup.enter="codeTextChange(codeText)"
></el-input>
</el-form-item>
<el-form-item label="总计:">
{{ totalCount }}
</el-form-item>
<el-form-item label="原始物料" v-if="mode!='add'&&form.mtype==20" style="margin-left: 20px;">
<el-col >{{ form.batch }}</el-col>
</el-form-item>
</el-row>
<el-row v-show="addShow&&route_code!=='tuihuo'">
<el-col>
<el-form-item label="交接物料">
<xtSelect
:apiObj="apiObjM"
v-model="selectObjIds"
v-model:obj="selectObjs"
:labelField="'batch'"
style="width: 100%;"
:params = "paramsM"
:multiple="true"
@change="materialChange0"
>
<el-table-column label="物料" prop="full_name">
<template #default="scope">
<span v-if="scope.row.state==20" style="color: red;border: 1px solid red;border-radius: 3px;">不合格</span>
<span v-if="scope.row.state==30" style="color: orange;border: 1px solid orange;border-radius: 3px;">返工</span>
<span>{{ scope.row.batch }}({{ scope.row.material_name }})</span>
<span v-if="scope.row.defect_name !== null" style="color: orangered">{{ scope.row.defect_name }}</span>
</template>
</el-table-column>
<el-table-column label="可交接数量" prop="count_canhandover" width="110px"></el-table-column>
</xtSelect>
</el-form-item>
</el-col>
</el-row>
<div v-if="route_code!=='tuihuo'">
<el-row v-for="(listItem,$index) in form.handoverb" :key="listItem">
<el-col :span="12">
<el-form-item label="交接物料">
<el-input v-model="listItem.label" disabled></el-input>
</el-form-item>
</el-col>
<el-col :span="4">
<el-form-item label="总数量">
<span>{{ listItem.count_cando }}</span>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="交接数量">
<el-input-number
v-model="listItem.count"
controls-position="right"
:min="0"
step="1"
:max="listItem.count_cando"
:disabled="mode==='show'"
:step-strictly="true"
style="width: 100%"
placeholder="交接数量"
@change="countChange"
>
</el-input-number>
</el-form-item>
</el-col>
<el-col :span="2" v-if="mode!=='show'">
<el-button type="danger" icon="el-icon-delete" @click="delMaterial($index)"></el-button>
</el-col>
</el-row>
</div>
<el-row>
<el-col :md="12" :sm="24">
<el-form-item label="交送日期" prop="send_date">
<el-date-picker
v-model="form.send_date"
type="date"
placeholder="选择时间"
format="YYYY-MM-DD"
value-format="YYYY-MM-DD"
style="width: 100%"
:readonly="mode==='show'"
/>
</el-form-item>
</el-col>
<el-col :md="12" :sm="24" v-if="mtype!==30">
<el-form-item label="交送人">
<span v-if="mode==='show'">{{ form.send_user_name }}</span>
<el-select
v-else
v-model="form.send_user"
placeholder="交送人"
clearable
filterable
style="width: 100%"
>
<el-option
v-for="item in userList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :md="12" :sm="24" v-if="mtype!==30">
<el-form-item label="接收工段" prop="recive_mgroup">
<el-select
v-model="form.recive_mgroup"
placeholder="接收工段"
clearable
style="width: 100%"
:disabled="type==40||mode!=='add'"
@change="getUserList2"
>
<el-option
v-for="item in mgroupOptions"
:key="item.id"
:label="item.name"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :md="12" :sm="24" v-if="mtype!==30">
<el-form-item label="接收人">
<span v-if="mode==='show'">{{ form.recive_user_name }}</span>
<el-select
v-else
v-model="form.recive_user"
placeholder="接收人"
clearable
filterable
style="width: 100%"
>
<el-option
v-for="item in userList2"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :md="12" :sm="24" v-if="type==50">
<el-form-item label="更改物料">
<xtSelect
:apiObj="apiObj"
:params="params"
v-model="form.material_changed"
v-model:label="form.material_changed_fname"
style="width:100%"
>
<el-table-column label="名称" prop="name"></el-table-column>
<el-table-column label="工序" prop="process_name"></el-table-column>
<el-table-column label="规格" prop="specification"></el-table-column>
</xtSelect>
</el-form-item>
</el-col>
<el-col :md="12" :sm="24" v-if="type==10&&mtype==30">
<el-form-item label="更改批次">
<el-switch v-model="change_batch"></el-switch>
</el-form-item>
</el-col>
<el-col :md="12" :sm="24">
<el-form-item label="处理备注">
<el-input v-model="form.note" placeholder="处理备注"></el-input>
</el-form-item>
</el-col>
<el-col :md="12" :sm="24" v-if="change_batch">
<el-form-item label="新批次号" required>
<el-input v-model="form.new_batch" placeholder="新批次号"></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row v-if="addShow&&route_code=='tuihuo'">
<el-col>
<el-form-item label="交接物料">
<xtSelect
:apiObj="apiObjM"
v-model="selectObjIds"
v-model:obj="selectObjs"
:labelField="'batch'"
style="width: 100%;"
:params = "paramsM"
:multiple="true"
@change="materialChange0"
>
<el-table-column label="物料" prop="full_name">
<template #default="scope">
<span v-if="scope.row.state==20" style="color: red;border: 1px solid red;border-radius: 3px;">不合格</span>
<span v-if="scope.row.state==30" style="color: orange;border: 1px solid orange;border-radius: 3px;">返工</span>
<span>{{ scope.row.batch }}({{ scope.row.material_name }})</span>
<span v-if="scope.row.defect_name !== null" style="color: orangered">{{ scope.row.defect_name }}</span>
</template>
</el-table-column>
<el-table-column label="可交接数量" prop="count_canhandover" width="110px"></el-table-column>
</xtSelect>
</el-form-item>
</el-col>
</el-row>
<div v-if="route_code=='tuihuo'">
<el-row v-for="(listItem,$index) in form.handoverb" :key="listItem">
<el-col :span="12">
<el-form-item label="交接物料">
<el-input v-model="listItem.label" disabled></el-input>
</el-form-item>
</el-col>
<el-col :span="4">
<el-form-item label="总数量">
<span>{{ listItem.count_cando }}</span>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="交接数量">
<el-input-number
v-model="listItem.count"
controls-position="right"
:min="0"
step="1"
:max="listItem.count_cando"
:disabled="mode==='show'"
:step-strictly="true"
style="width: 100%"
placeholder="交接数量"
@change="countChange"
>
</el-input-number>
</el-form-item>
</el-col>
<el-col :span="2" v-if="mode!=='show'">
<el-button type="danger" icon="el-icon-delete" @click="delMaterial($index)"></el-button>
</el-col>
<el-col>
<el-form-item>
<sc-upload-file
v-model="form.oinfo_json[listItem.wm]"
:multiple="false"
:limit="1"
:accept="['.xlsx', '.xls']"
:disabled="mode ==='show'"
>
</sc-upload-file>
</el-form-item>
</el-col>
</el-row>
</div>
</el-form>
<el-footer>
<template v-if="(route_code=='tuihuo'&&type==10&&mtype==10)||form.ticket!=null">
<ticketd_b :workflow_key="'backfire'" :title="'退火交接审批单'" :t_id="form.id" :ticket_="form.ticket_"
@success="()=>{$emit('success')} " :submit_b_func="submit_b_func" ref="ticketd_b"></ticketd_b>
</template>
<el-button v-else-if="mode!='show'" type="primary" v-loading="isSaveing" @click="submit">确定</el-button>
<el-button @click="$emit('closed')">取消</el-button>
</el-footer>
</el-main>
<el-aside width="20%" v-if="form.ticket">
<ticketd :ticket_="form.ticket_" @success="$emit('success')"></ticketd>
</el-aside>
</el-container>
</template>
<script>
import ticketd_b from "@/views/wf/ticketd_b.vue";
import ticketd from '@/views/wf/ticketd.vue'
export default {
emits: ["success", "closed"],
components: {
ticketd_b, ticketd
},
props: {
t_id: {
type: String,
default: null
},
type: {
type: Number,
default: 10,
},
mgroupId: {
type: String,
default: "",
},
mgroupName: {
type: String,
default: "",
},
processtype:{
type:String,
default:""
},
process:{
type:String,
default:""
},
changebatch:{
type:Boolean,
default:false
}
},
data() {
return {
change_batch:false,
selectItems:[],
yseorno: ["是", "否"],
loading: false,
mode: "show",
lists:[],//交接数组
handle_user: [],
form: {
send_date: null,
send_user: null,
send_mgroup: null,
recive_user: null,
recive_mgroup: null,
handoverb:[],
ticket:null,
ticket_:null,
oinfo_json:{},
},
initForm:{},
selectObjIds:[],
apiObj:this.$API.mtm.material.list,
apiObjM:null,
params:{},
paramsM:{},
selectObj:{},
selectObjs:[],
transitions:[],
rules: {
batch: [
{
required: true,
message: "请输入批次号",
trigger: "blur",
},
],
wm: {
required: true,
message: "请选择物料",
trigger: "blur",
},
send_date: [
{
required: true,
message: "请选择送料日期",
trigger: "blur",
},
],
send_user: [
{
required: true,
message: "请选择交送人",
trigger: "blur",
},
],
send_mgroup: [
{
required: true,
message: "请选择交送工段",
trigger: "blur",
},
],
new_batch: [
{
required: true,
message: "请填写新批次号",
trigger: "blur",
},
],
recive_mgroup: [
{
required: true,
message: "请选择接收工段",
trigger: "blur",
},
],
},
new_batch:'',
listParams:{},
totalCount: 0,
mtype:10,
deptID:'',
route_code:'',
codeText: "",
batchList:[],
fileList:[],
userList: [],
userList2: [],
handoverbIds:[],
mgroupOptions: [],
materialOptions: [],
addShow: false,
scanVisible:false,
isSaveing: false,
setFiltersVisible: false,
};
},
mounted() {
let that = this;
that.change_batch = that.changebatch;
that.form.type = that.type;
let materialObj = that.$TOOL.data.get("MATERIAL_OBJECT");
that.materialObj = materialObj;
that.form.handle_date = that.form.send_date = this.$TOOL.dateFormat2(new Date());
that.form.send_mgroup = that.mgroupId;
that.route_code = that.$route.path.split("/")[2];
// type=10 正常交接 物料都可交接,接收工段有限制
// type=20 返工交接 不合格品交接,接收工段为该工艺流程中的工段
// type=30 物料检验 合格品交接,检验部接收
// type=40 废品入库 不合格品交接,接收工段固定为废品库
// type=50 改版 灵活无限制
//mtype 10:正常交接 20:分批操作 30:合批操作
//state 10:合格;20:不合格;30:返工;34:返工完成;40:检验;50:报废
//获取交接人员
if(that.type==20&&that.mgroupName=='废品库'){//废品出库交接
that.getCkUserList();
}else{
that.deptID = that.$TOOL.data.get('gx_deptID');
that.getUserList();
}
//获取交接物料
if(that.type==20&&that.mgroupName!=='废品库'){
//返工交接
that.paramsM = {mgroup: that.mgroupId,state__in:'20,34',tag : 'done'};
}else if(that.type==20&&that.mgroupName=='废品库'){
//废品出库
that.paramsM = {state : 50,state_all: 1};
}else if(that.type==40){
//报废交接
that.paramsM = {mgroupx: that.mgroupId,state:20};
}else if(that.type==50){
//改版交接
that.paramsM = {mgroupx: that.mgroupId};
}else{
//其他
that.paramsM = {mgroup: that.mgroupId,state:10,tag : 'done'};
}
that.apiObjM = this.$API.wpm.wmaterial.list;
if(that.type==40||that.type==20){
that.getMgroupOptions();
}else{
that.getMgroupOptions();
}
that.getTid();
},
watch: {
batchList:{
deep:true,
handler (v) {
console.log('batchList',v)
}
}
},
methods: {
getTid (){
var that = this;
if (that.t_id) {
that.$API.wpm.handover.item.req(that.t_id).then(res=>{
that.setData(res);
if(res.ticket_.state_.type == 1 && res.create_by == that.$TOOL.data.get("USER_INFO").id ) {
that.mode = "edit";
}else{
that.mode = "show";
}
// that.$nextTick(()=>{
// that.$refs.ticketd_b.init();
// })
})
}
},
//获取工段列表
getMgroupOptions() {
let that = this;
that.$API.mtm.mgroup.list.req({ page: 0}).then((res) => {
that.mgroupOptions = res;
if(that.type==40){
res.forEach(item=>{
if(item.name=="废品库"){
that.form.recive_mgroup = item.id;
}
})
that.getCkUserList();//废品库接收人
}
});
},
getResaveMgroups(material){
let that = this;
let params = {
material: material,
type: that.type,
};
that.$API.wpm.handover.mgroups.req(params).then((res) => {
that.mgroupOptions = res;
if(res.length==1){
that.form.recive_mgroup = res[0].id;
that.getUserList2();
}
})
},
//获取交送工段人员
getUserList() {
let that = this;
let userInfo = that.$TOOL.data.get("USER_INFO");
this.$API.system.user.list.req({ depts: that.deptID, page: 0 }).then((res) => {
that.userList = res;
let arr = res.filter(item=>{
return item.id==userInfo.id;
})
if(arr.length>0){
that.form.send_user = userInfo.id;
}else{
let obj = {};
obj.id = userInfo.id;
obj.name = userInfo.name;
that.userList.push(obj)
that.form.send_user = userInfo.id;
}
});
},
//获取仓库人员
getCkUserList() {
let that = this;
this.$API.system.user.list.req({ page: 0, posts__code: "inm&check" })
.then((res) => {
if(that.type==40){
that.userList2 = [];
that.userList2 = res;
}else if(that.type==20&&that.mgroupName=='废品库'){
that.userList = [];
that.userList = res;
}
});
},
//获取接收工段人员
getUserList2() {
let that = this;
let deptID = '';
if(that.form.recive_dept&&that.form.recive_dept!==''&&that.form.recive_dept!==null){
deptID = that.form.recive_dept;
}else{
that.mgroupOptions.forEach(item => {
if(item.id==that.form.recive_mgroup){
deptID = item.belong_dept;
}
});
}
that.$API.system.user.list.req({ depts: deptID, page: 0 }).then((res) => {
that.userList2 = res;
});
},
//获取接收部门人员
getUserList3() {
let that = this;
this.$API.system.user.list
.req({ depts: that.form.recive_dept, page: 0 })
.then((res) => {
that.userList2 = res;
});
},
remoFun(val){
let that = this;
let params = {};
that.batchList = [];
params.material = that.form.handoverb[0].material;
params.batch = val;
params.mgroup = that.mgroupId;
params.count_all = 1;
params.defect = that.form.handoverb[0].defect!=null?that.form.handoverb[0].defect:'';
params.defect__isnull = that.form.handoverb[0].defect!=null?false:true;
params.page = 0;
that.$API.wpm.wmaterial.list.req(params).then(res=>{
if(res.length>0){
that.batchList = res;
}else{
let obj = {};
obj.batch = val;
obj.id = val;
that.batchList.push(obj);
}
})
},
new_batch_change(){
let that = this;
let arr = that.batchList.filter(item=>{
return item.batch == that.new_batch;
})
if(arr.length>0){
that.form.new_batch = arr[0].batch;
}else{
that.batchList.forEach(item=>{
if(item.id == that.new_batch){
that.form.new_batch = item.batch;
that.form.new_wm = item.id;
}
})
}
},
addMaterial(){
this.addShow = true;
},
delMaterial(index){
this.form.handoverb.splice(index,1);
this.countChange();
},
//显示
open(mode = "add",data,mtype) {
console.log(data)
this.mode = mode;
this.mtype = mtype;
if(data!==''&&data!==null&&data!==undefined){
console.log(typeof(data)=='string')
if(typeof(data)=='string'){
this.codeText = data.replace(" ","");
this.codeTextChange(this.codeText)
}else{
this.form.handoverb = [];
data.forEach(item=>{
let obj = {};
obj.wm = item.wm;
obj.label = item.label;
obj.batch = item.batch;
obj.defect = item.defect;
obj.material = item.material;
obj.count_cando = item.count_canhandover;
obj.count = item.count_canhandover;
this.form.handoverb.push(obj);
this.totalCount += Number(item.count_canhandover);
})
}
}
if(mtype==30){//合批
this.change_batch = true;
}
return this;
},
//选中物料批次后放入handoverb
materialChange0(){
let that = this;
that.totalCount = 0;
that.selectObjs.forEach(item=>{
if(that.handoverbIds.indexOf(item.id)==-1){
that.handoverbIds.push(item.id);
let obj = {};
obj.wm = item.id;
obj.state = item.state;
obj.batch = item.batch;
obj.label = item.defect !== null?item.batch+'('+item.material_name+')'+item.defect_name:item.batch+'('+item.material_name+')';
obj.count = item.count_canhandover;
obj.defect = item.defect;
obj.defect_name = item.defect_name;
obj.count_cando = item.count_canhandover;
obj.material = item.material;
if(that.type==50){
that.form.material_changed = item.material;
that.form.material_changed_fname = item.material_name;
that.form.recive_mgroup = that.mgroupId;
that.form.new_batch = item.batch;
}
that.form.handoverb.push(obj);
that.getResaveMgroups(obj.material);
}
})
setTimeout(function(){
that.countChange();
},500)
},
countChange(){
let that = this;
let totalCount = 0;
if(this.form.handoverb.length>0){
this.form.handoverb.forEach(item=>{
totalCount += Number(item.count);
})
that.totalCount = totalCount;
}
},
fileUPSuccess(res) {
this.test_file = res.path;
},
async submit_b_func() {
let that = this;
if(that.mode == "add") {
let res = await that.$API.wpm.handover.create.req(that.form);
that.form.id = res.id;
} else if (that.mode == "edit") {
await that.$API.wpm.handover.update.req(that.form.id, that.form);
}
},
//提交
submit() {
let that = this;
that.$refs.dialogForm.validate(async (valid) => {
if (valid) {
if(that.mtype==20||that.mtype==30){
that.form.recive_mgroup = that.form.send_mgroup;
that.form.mtype = that.mtype;
}
if(that.change_batch){
that.form.mtype=30;
that.mtype==30
}
if(that.mtype==30){
let params = {};
params.material = that.form.handoverb[0].material;
params.batch = that.form.new_batch;
params.mgroup = that.mgroupId;
params.count_all = 1;
params.defect = that.form.handoverb[0].defect!=null?that.form.handoverb[0].defect:'';
params.defect__isnull = that.form.handoverb[0].defect!=null?false:true;
params.page = 0;
that.$API.wpm.wmaterial.list.req(params).then(res=>{
if(res.length>0){
that.form.new_wm = res[0].id;
}
console.log('that.form.new_wm',that.form.new_wm);
console.log('that.form.new_batch',that.form.new_batch);
that.$API.wpm.handover.createsubmit.req(that.form).then((res) => {
that.isSaveing = false;
that.$emit("success");
that.$message.success("操作成功");
}).catch((err) => {
that.isSaveing = false;
return err;
});
})
}else if(that.mtype==20||that.type==40){
that.$API.wpm.handover.createsubmit.req(that.form).then((res) => {
that.isSaveing = false;
that.$emit("success");
that.$message.success("操作成功");
}).catch((err) => {
that.isSaveing = false;
return err;
});
}else{
if (that.mode == "add") {
that.$API.wpm.handover.create.req(that.form).then((res) => {
that.isSaveing = false;
that.$emit("success");
that.$message.success("操作成功");
}).catch((err) => {
that.isSaveing = false;
return err;
});
} else if (that.mode == "edit") {
that.$API.wpm.handover.update.req(that.form.id, that.form).then((res) => {
that.isSaveing = false;
that.$emit("success", that.form, that.mode);
that.$message.success("操作成功");
}).catch((err) => {
that.isSaveing = false;
return err;
});
}
}
}
});
},
//表单注入数据
setData(data) {
console.log('交接记录查看',data)
let that = this;
Object.assign(this.form, data);
let obj = {};
if(data.oinfo_json&&data.oinfo_json.test_file){
obj.name=data.oinfo_json.test_file;
obj.url=data.oinfo_json.test_file;
this.fileList.push(obj);
}
that.totalCount = 0;
that.form.handoverb = data.handoverb;
data.handoverb.forEach(item=>{
item.label = item.batch;
that.totalCount += Number(item.count);
})
if(data.type==30){
that.getUserList3();
}else{
that.getUserList2();
}
},
//设置过滤项
setFilters(filters) {
this.selectionFilters = filters;
this.setFiltersVisible = true;
},
//扫描
scanCode(){
let that = this;
that.scanVisible = true;
},
codeTextChange(data){
if(data==''||data==undefined||data==null){
return;
}
let that = this;
// data = data.replace(' ','');
let id = data.split('#')[1];
this.$API.cm.labelmat.item.req(id).then((res) => {
let arr = that.form.handoverb.filter((item) => {
return item.batch == res.batch&&item.state==res.state&&item.defect==res.defect;
})
if(arr.length>0){
that.$message.error("该批次已存在")
}else{
let params = {mgroup: that.mgroupId,page: 0,state__in:res.state,search:res.batch,tag : 'done'};
if(that.type==10){
params.state__in = '10';
}else if(that.type==20){
params.state__in = '20,34';
}
that.$API.wpm.wmaterial.list.req(params).then((res1) => {
if(res1.length>0){
res1.forEach(item=>{
let cando = Number(item.count_canhandover);
if(cando>0&&(item.defect==null||item.defect_name==res.defect_name)){
let obj = {};
obj.wm = item.id;
obj.batch = item.batch;
obj.label = item.defect !== null?item.batch+'('+item.material_name+')'+item.defect_name:item.batch+'('+item.material_name+')';
obj.count = cando;
obj.state = item.state;
obj.defect = item.defect;
obj.defect_name = item.defect_name;
obj.count_cando = cando;
obj.material = item.material;
that.form.handoverb.push(obj)
that.totalCount += Number(obj.count);
that.getResaveMgroups(obj.material);
}
})
}
that.codeText = '';
});
}
})
//根据扫描内容,获取物料详情匹配当前库存物料
this.scanVisible = false;
},
},
};
</script>
<style scoped>
.formTitle {
margin-bottom: 10px;
font-weight: 600;
}
.total-count{
width: 100%;
text-align: right;
height: 50px;
line-height: 50px;
}
</style>