factory_web/src/views/inm/mioitem_form.vue

867 lines
25 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
:title="titleMap[form.type]"
v-model="visible"
:size="1000"
destroy-on-close
@closed="$emit('closed')"
>
<el-form
ref="dialogForm"
:model="form"
:rules="rules"
label-width="120px"
>
<el-row>
<el-col v-if="mTracking==20&&form.type == 'sale_out'&&project_code=='bxerp'">
<el-form-item label="大箱序号" prop="pack_index">
<el-input-number precision="0" v-model="form.pack_index"></el-input-number>该小箱放在第几个大箱
</el-form-item>
</el-col>
<el-col>
<el-form-item label="物料" prop="material">
<xtSelect
:apiObj="apiObj"
v-model="form.material"
v-model:obj="selectObj"
:labelField="'full_name'"
style="width:100%"
:params="query"
@change="selectMaterialChange"
>
<el-table-column label="物料" prop="full_name"></el-table-column>
</xtSelect>
</el-form-item>
</el-col>
<el-col>
<el-form-item label="批次号" prop="batch">
<el-input
v-if="form.type == 'pur_in'||form.type == 'other_in'"
v-model="form.batch"
clearable
placeholder="手动输入批次号"
:disabled="inputBatchDisable"
/>
<el-select
v-else
v-model="form.batch"
filterable
allow-create
clearable
style="width: 100%"
:disabled="inputBatchDisable"
@clear="selectBatchClear"
@change="selectChange"
>
<el-option
v-for="item in wbatchOptions"
:key="item.id"
:value="item.batch"
>
<span style="float: left">{{ item.batch }}</span>
<span
style="
float: right;
color: var(--el-text-color-secondary);
font-size: 13px;
"
>{{ item.count }}</span
>
</el-option>
</el-select>
</el-form-item>
<el-form-item label="物料单价" v-if="form.type != 'do_in'||form.type != 'do_out'">
<el-input-number
v-model="form.unit_price"
:min="0"
style="width: 100%;"
controls-position="right"
/>
</el-form-item>
</el-col>
<el-col v-if="form.type == 'pur_in'||form.type == 'pur_out'||form.type == 'other_in'||form.type == 'do_out'||form.type=='sale_out'||form.type=='other_out'||form.type=='pur_out'||form.type=='borrow_out'">
<el-form-item label="仓库已有批次">
<el-select
v-model="selectBatch"
value-key="id"
clearable
filterable
remote = "true"
style="width: 100%"
:remote-method="inputChange"
@change="selectBatchChange"
@clear="selectBatchClear"
>
<el-option
v-for="item in batchOptions"
:key="item.id"
:label="item.batch"
:value="item"
>
<span style="float: left">{{ item.batch }}</span>
<span
style="
float: right;
color: var(--el-text-color-secondary);
font-size: 13px;
"
>{{ item.count_canmio }} -- {{ item.warehouse_name }}</span
>
</el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :md="12" :sm="24">
<el-form-item label="仓库" prop="warehouse">
<el-select
v-model="form.warehouse"
clearable
style="width: 100%"
:disabled="form.type == 'do_out'||form.type=='sale_out'"
>
<el-option
v-for="item in warehouseOptions"
: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="mTracking==20&&(form.type == 'pur_in'||form.type == 'other_in')">
<el-form-item label="数量">
<el-input-number
v-model="form.count"
:min="1"
:precision="3"
style="width: 100%"
@change="countChange"
/>
</el-form-item>
</el-col>
<el-col :md="12" :sm="24" v-else-if="mTracking==20&&form.type == 'sale_out'&&project_code=='bxerp'">
<el-form-item label="数量">
<el-input-number
v-model="form.count"
:min="0"
:precision="3"
:max="batchcount"
style="width: 100%"
@change="countChange"
/>
</el-form-item>
</el-col>
<el-col :md="12" :sm="24" v-else>
<el-form-item label="数量">
<el-input-number
v-model="form.count"
:min="0"
:max="batchcount"
:disabled="form.type == 'do_out'&&project_code=='bxerp'"
style="width: 100%"
@change="countChangegx('1')"
/>
</el-form-item>
</el-col>
<el-col :md="12" :sm="24" v-if="mtype==40&&project_code=='gx'">
<el-form-item label="物料单位">
<el-input v-model="form.unit" disabled placeholder="物料单位"/>
</el-form-item>
</el-col>
<el-col :md="12" :sm="24" v-if="mtype==40&&project_code=='gx'">
<el-form-item label="出库单位">
<el-input v-model="form.note" placeholder="出库单位"/>
</el-form-item>
</el-col>
<el-col :md="12" :sm="24" v-if="form.type == 'sale_out'&&project_code=='bxerp'">
<el-form-item label="编号前缀">
<el-input v-model="prefix" placeholder="编号前缀"/>
</el-form-item>
</el-col>
<el-col :md="12" :sm="24" v-if="form.type == 'sale_out'&&project_code=='gx'">
<el-form-item label="发出数量">
<el-input-number v-model="form.count_send" :max="batchcount" placeholder="发出数量" @change="countChangegx('2')"/>
</el-form-item>
</el-col>
<el-col :md="12" :sm="24" v-if="form.type == 'sale_out'&&project_code=='gx'">
<el-form-item label="样品数量">
<el-input-number v-model="count_send_yp" :max="batchcount" placeholder="样品数量" @change="countChangegx('3')"/>
</el-form-item>
</el-col>
<el-button v-if="form.type == 'sale_out'&&project_code=='bxerp'" type="primary" @click="getNumber">获取编号</el-button>
<el-col :md="12" :sm="24" v-if="digitNum!==null">
<el-form-item label="流水位数">
<el-input-number controls-position="right" precision="0" @change="digitChange" v-model="digitNum"></el-input-number>
</el-form-item>
</el-col>
</el-row>
<el-col v-if="form.type == 'pur_in'&&project_code=='bxerp'&& cate == 'halfgood'">
<el-form-item label="编号前缀">
<el-input v-model="halfgoodprefix" @input="halfgoodprefixChange" placeholder="编号前缀"/>
</el-form-item>
</el-col>
<el-row v-if="mTracking==20&&form.count>0&&(form.type == 'pur_in'||form.type == 'other_in'||(form.type == 'sale_out'&&project_code=='bxerp'))">
<el-col :md="12" :sm="24" v-for="i in form.count" :key="i">
<el-form-item :label="'编号'+i" required>
<template v-if="form.type == 'sale_out'&&project_code=='bxerp'">
<el-input v-model="mioitems[i-1]" placeholder="请输入编号" disabled />
</template>
<el-input v-else v-model="mioitems[i-1]" placeholder="请输入编号" :disabled="cate == 'mainso'" />
</el-form-item>
</el-col>
</el-row>
<div v-if="assembShow">
<el-row
v-for="item in components"
v-bind:key="item"
style="margin-bottom: 8px"
>
<el-col :span="12" style="padding-left: 120px">
{{ item.name}}
<span v-if="item.model !== null">|{{ item.model }}</span>
<span v-if="item.specification !== null">|{{ item.specification }}</span>
</el-col>
<el-col :span="12">
<el-select
v-model="item.batch"
clearable
filterable
style="width: 100%"
>
<el-option
v-for="itemx in item.batchOptions"
:key="itemx.id"
:label="itemx.batch"
:value="itemx.batch"
>
<span style="float: left">{{itemx.batch}}</span>
<span
style="
float: right;
color: var(--el-text-color-secondary);
font-size: 13px;
">{{ itemx.count }}</span>
</el-option>
</el-select>
</el-col>
</el-row>
</div>
</el-form>
<template #footer>
<el-button type="primary" :loading="isSaveing" @click="submit">
保存
</el-button>
<el-button @click="visible = false">取消</el-button>
</template>
</el-dialog>
<el-dialog title="设置发货流水位数" v-model="showDigit">
<h4>没有找到该前缀的发货编号,请完善发货流水号位数(填整数)</h4>
<el-form :model="wprParams" label-width="80px">
<el-form-item label="流水位数">
<el-input-number controls-position="right" precision="0" v-model="digitNum"></el-input-number>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="digitSure">确定</el-button>
</template>
</el-dialog>
</template>
<script>
const defaultForm = {
state: 10,
count: 1,
type: "do_in",
};
export default {
emits: ["success", "closed"],
props: {
mioObj: { type: Object },
cate: { type: String, default: null },
htype: { type: String, default: null },
mioId: { type: String, default: null },
mgroup: { type: String, default: null },
belongDeptName: { type: String, default: null },
belongDeptId: { type: String, default: null },
tableDatas: { type: Array ,default:function(){return []}},
},
data() {
return {
type: "do_in",
loading: false,
mode: "add",
query: {},
titleMap: {
do_out: "生产领料",
sale_out: "销售发货",
pur_in: "采购入库",
do_in: "生产入库",
other_in: "其他入库",
other_out: "其他出库",
},
form: {count: 1,note: '',pack_index: 1},
rules: {
pack_index:[{required: true,message: "请填写包装序号",trigger: "blur"}],
batch:[{required: true,message: "请填写批次号",trigger: "blur"}],
material: [{required: true,message: "请选择所需产品",trigger: "blur"}],
warehouse: [{required: true,message: "请选择仓库",trigger: "blur"}],
},
selectObj:null,
showDigit:false,
visible: false,
isSaveing: false,
materialOptions: [],
batchOptions: [],
batchOptions_o: [],
setFiltersVisible: false,
warehouseOptions: [],
// warehouseDisable: false,
selectBatchDisable: false,
assembShow: false,
selectMaterial: null,
selectBatch: null,
components: [],
wbatchOptions: [],
mioitems:[''],
mioitemw:[],
wprList:[],
prefix:'',
halfgoodprefix:'',
count_send_yp:0,
project_code:'',
digitNum:null,
mtype:null,
batchcount:null,
mTracking:10,
apiObj:this.$API.mtm.material.list,
};
},
mounted() {
let that = this;
let config_base = that.$TOOL.data.get("BASE_INFO").base;
that.project_code = config_base.base_code;
//原料库
if(that.htype=='baofei'){
//操作工段:废品库
//部门操作人员:原料库
that.$API.mtm.mgroup.list.req({ name:'废品库',page: 0}).then((res) => {
that.form.recive_mgroup = item.id;
that.getCkUserList();//废品库接收人
});
}
},
methods: {
init() {
this.getMaterialOptions();
this.getWarehouseOptions();
},
//获取仓库人员
getCkUserList() {
let that = this;
this.$API.system.user.list.req({ page: 0, posts__code__contains: "inm" })
.then((res) => {
if(that.type==40){
that.userList2 = [];
that.userList2 = res;
}else if(that.type==20&&that.mgroupName=='废品库'){
that.userList = [];
that.userList = res;
}
});
},
getWarehouseOptions() {
let that = this;
this.$API.inm.warehouse.list.req({ page: 0 }).then((res) => {
this.warehouseOptions = res;
if(that.form.type=='pur_in'){
res.forEach((item) => {
if (item.name == "原料库") {
that.form.warehouse = item.id;
}
})
}
});
},
//获取车间物料批次号
getWBatchs() {
let that = this;
let params = {material: this.form.material,page: 0};
if (this.mgroup != null) {
params.mgroup= this.mgroup;
if(that.type=='do_in'){
params.state = 10;
}
}else if (this.mioObj.belong_dept != null){
params.belong_dept = this.mioObj.belong_dept;
}
this.$API.wpm.wmaterial.list.req(params).then((res) => {
this.wbatchOptions = res;
});
},
inputChange(e){
let that = this;
if(e!==''&&e!==null&&e!==undefined){
if(e.indexOf('#')>-1){
let codeId = e.split('#')[1];
this.$API.cm.labelmat.item.req(codeId).then((res) => {
if(res){
let arr = that.batchOptions.filter((item) => {
return item.batch == res.batch&&item.state==res.state;
})
that.batchOptions = arr;
}else{
that.selectBatch = '';
}
})
}else{
let arr = that.batchOptions.filter((item) => {
return item.batch.indexOf(e)>-1;
})
that.batchOptions = arr;
}
}else{
that.batchOptions = that.batchOptions_o;
}
},
getMaterialOptions() {
var type = this.form.type;
var cate = this.cate;
var query = {};
// 'do_out': '生产领料',
// 'sale_out': '销售发货',
// 'pur_in': '采购入库',
// 'do_in': '生产入库',
// 'other_in': '其他入库',
// 'other_out': '其他出库',
//(10, '成品'), (20, '半成品'), (30, '主要原料'),
// (40, '辅助材料'), (50, '加工工具'), (60, '辅助工装'), (70, '办公用品')
//主要原料 生产领料do_out 采购入库pur_in
let type__in = "";
if (cate == "good") {
type__in = "10";
} else if (cate == "halfgood") {
type__in = "20";
} else if (cate == "mainso") {
type__in = "30";
} else if (cate == "helpso") {
type__in = "40, 50, 60, 70";
}
if (type == "do_out") {
//生产领料'10, 20, 30'
query = {
page: 0,
type__in: type__in,
is_hidden: false,
is_assemb: false,
};
this.inputBatchDisable = true;
} else if (type == "do_in") {
//生产入库
query = { page: 0,is_hidden: false, type__in: type__in };
this.inputBatchDisable = false;
} else if (type == "pur_in") {
//采购入库
query = {
page: 0,
type__in: type__in,
is_hidden: false,
pu_orderitem_material__pu_order: this.mioObj.pu_order,
};
this.inputBatchDisable = false;
} else if (type == "sale_out") {
//销售发货
query = {
page: 0,
type__in: 10,
is_hidden: false,
orderitem_material__order: this.mioObj.order,
};
this.inputBatchDisable = true;
} else if (type == "other_out") {
this.inputBatchDisable = true;
} else if (type == "pur_out"||type == "borrow_out"||type == "return_in") {
query = {
page: 0,
type__in: 40,
is_hidden: false,
orderitem_material__order: this.mioObj.order?this.mioObj.order:null,
};
this.inputBatchDisable = true;
}else {
query = { page: 0 ,is_hidden:false};
}
if(type == "return_in"){
this.inputBatchDisable = false;
}
this.query = query;
this.apiObj=this.$API.mtm.material.list;
// this.$API.mtm.material.list.req(query).then((res) => {
// this.materialOptions = res;
// });
},
async initAssemb(item) {
this.selectBatchDisable = true;
this.assembShow = true;
this.components = [];
var id__in = Object.keys(item.components).join(",");
if (id__in.length > 0) {
var res = await this.$API.mtm.material.list.req({
page: 0,
id__in: id__in,
});
this.components = res;
for (var i = 0; i < this.components.length; i++) {
var res2 = await this.$API.wpm.wmaterial.list.req({
page: 0,
material: this.components[i].id,
belong_dept: this.belongDeptId,
});
this.components[i].batchOptions = res2;
}
}
},
getBatchOptions() {
// 车间批次
this.getWBatchs();
this.$API.inm.warehouse.batch
.req({ page: 0, material: this.form.material })
.then((res) => {
this.batchOptions_o = this.batchOptions = res;
if (res.length == 0) {
this.selectBatchDisable = true;
} else {
this.selectBatchDisable = false;
}
});
},
selectChange(item){
// console.log(item)
let that = this;
that.wbatchOptions.forEach((item) => {
if(that.form.batch == item.batch){
that.form.count = item.count;
that.form.wm = item.id;
if(!that.assembShow){
that.batchcount = item.count;
}
}
})
},
selectMaterialChange() {
var that = this;
if(that.selectObj.id!==undefined&&that.selectObj.id!==null){
sessionStorage.setItem("mioitemSelecObj",JSON.stringify(that.selectObj));
}
var type = this.form.type;
that.form.material = that.selectObj.id;
that.form.unit = that.selectObj.unit;
that.form.unit_price = that.selectObj.unit_price;
that.form.batch = that.cate=='helpso'?that.selectObj.bin_number_main:'';
that.mTracking = that.selectObj.tracking;
if (type == "do_in") {
if (that.selectObj.is_assemb) {
this.initAssemb(that.selectObj);
} else {
that.getBatchOptions();
}
} else {
this.getBatchOptions();
}
if(that.form.type == 'pur_in'||that.form.type == 'other_in'||that.assembShow){
that.batchcount = 99999999999;
if(that.project_code=='gx'){
that.form.batch = '无'
}
}
},
getItem(options, id) {
for (var i = 0; i < options.length; i++) {
if (options[i].id == id) {
return options[i];
}
}
},
selectBatchChange(items) {
let that = this;
that.wprList = [];
that.mioitems = [];
if(items){
if(that.form.type == 'sale_out'&&that.project_code=='bxerp'){
let count = 0;
if(that.tableDatas.length>0){
that.tableDatas.forEach((item0) => {
if(item0.batch == that.selectBatch.batch){
count += item0.count;
}
})
}
let canDo = Number(items.count_canmio);
that.$API.wpm.wpr.list.req({ page: 0, mb: items.id,querys:"{id,number,number_out}" }).then((res) => {
if (canDo>50) {
res.forEach((item,index) => {
if(index>=count&&index<50+count){
that.wprList.push(item);
}
})
}else{
res.forEach((item,index) => {
if(index>=count){
that.wprList.push(item);
}
})
}
if(that.wprList.length>0){
that.wprList.forEach((item1,index) => {
if(item1.number_out!==null){
that.mioitems[index] = item1.number_out;
}
})
}
that.form.batch = items.batch;
that.form.mb = items.id;
that.batchcount = canDo;
that.form.count =canDo>50?50: that.wprList.length;
that.form.warehouse = items.warehouse;
that.inputBatchDisable = true;
})
}else{
that.$API.wpm.wpr.list.req({ page: 0, mb: items.id }).then((res) => {
that.wprList = res;
})
// that.getnumberOutLast();
that.form.batch = items.batch;
that.form.mb = items.id;
that.batchcount = Number(items.count_canmio);
that.form.count = Number(items.count_canmio);
that.form.warehouse = items.warehouse;
that.inputBatchDisable = true;
}
}
},
selectBatchClear() {
this.form.mb = "";
this.form.wm = "";
this.form.batch = "";
this.form.count = "";
this.form.warehouse = "";
this.inputBatchDisable = false;
},
//显示
open(mode = "add", type = "",mtype) {
let that = this;
this.mode = mode;
this.mtype = mtype?mtype:null;
this.form.type = this.type = type;
if (mode == "add") {
this.init();
}
this.visible = true;
if(that.type=='other_in'||that.type=='do_out'){
let mioitemSelecObj =JSON.parse(sessionStorage.getItem("mioitemSelecObj"));
if(mioitemSelecObj!==null){
that.selectObj = mioitemSelecObj;
that.form.material = that.selectObj.id;
that.form.unit = that.selectObj.unit;
that.form.unit_price = that.selectObj.unit_price;
that.form.batch = that.cate=='helpso'?that.selectObj.bin_number_main:'';
that.mTracking = that.selectObj.tracking;
that.getBatchOptions();
}
}
return this;
},
countChange(){
let that = this;
that.mioitems = [];that.mioitemw = [];
if(that.form.count>1){
if(that.form.type == 'pur_in'|| that.form.type == 'other_in'){
for(let i=0;i<that.form.count;i++){
let indexs = i+1;
indexs = indexs<10?'0'+indexs:indexs;
that.mioitems[i] = that.cate == "halfgood"?'': that.form.batch+'-'+indexs;
let obj = {};
obj.number = that.mioitems[i];
that.mioitemw.push(obj);
}
}else{
for(let i=0;i<that.form.count;i++){
that.mioitems[i] = that.wprList[i].number_out;
}
}
}else{
//生产入库
for(let i=0;i<that.form.count;i++){
let obj = {};
obj.number = that.form.batch+'-'+(i+1);
that.mioitemw.push(obj);
}
}
},
countChangegx(tip){
let that = this;
if(tip=='1'){
that.count_send_yp = Number(that.form.count) - Number(that.form.count_send);
}else{
that.form.count = Number(that.form.count_send) + Number(that.count_send_yp);
}
},
firstNumberChange(){
let that = this;
that.mioitemw = [];
let numbers = that.mioitems[0];
if(that.type== 'sale_out'){
let num = numbers.slice(-3)
let str = numbers.slice(0,-3)
console.log(str,num)
for(let i=0;i<that.form.count;i++){
let numb = Number(num)+i;
that.mioitems[i] =str + numb;
}
}else{
for(let i=0;i<that.form.count;i++){
that.mioitems[i] = Number(numbers)+i;
let obj = {};
obj.number = that.form.batch+'-'+(i+1);
that.mioitemw.push(obj);
}
}
},
getnumberOutLast(){
let that = this;
that.$API.wpm.wpr.numberOutLast.req({prefix:that.prefix}).then((res) => {
console.log(res);
});
},
//没有找到前缀的发货编号从1开始编号时
digitSure(){
let that = this;
that.showDigit = false;
//根据前缀和流水位数获取编号
for(let i=0;i<that.form.count;i++){
let numb = i+1,str = '';
numb+= '';
let len = numb.length;
for(let j=0;j<that.digitNum-len;j++){
str+='0';
}
that.mioitems[i] =that.prefix + str + numb;
}
},
//流水位数变化后重新获取编号
digitChange(){
let that = this;
that.mioitems = [];
console.log('that.digitNum',that.digitNum)
that.digitSure();
},
getNumber(){
let that = this;
that.mioitemw = [];
let params0 = {};
params0.prefix = that.prefix;
that.$API.wpm.wpr.numberOutLast.req(params0).then((res) => {
let numbers = '';
if(res.number_out_last==null){//没有该前缀的发货编号
that.number_out_last = null;
that.showDigit = true;
}else{//有该前缀的发货编号
numbers = res.number_out_last;
let str = numbers.replace(/[^a-zA-Z]/g, ''); // 提取字母
let num = numbers.replace(/[^0-9]/g, ''); // 提取数字
let length = num.length;//流水号的长度
for(let i=0;i<that.form.count;i++){
let numb = Number(num)+i+1;
let numbs = numb+'';
let len = numbs.length;
let zoreStr = '';
for(let j=0;j<length-len;j++){
zoreStr+='0';
}
that.mioitems[i] =str + zoreStr + numb;
}
}
})
},
halfgoodprefixChange(){
let that = this;
that.mioitems = [];
for(let i=0;i<that.form.count;i++){
that.mioitems[i] = that.halfgoodprefix;
}
},
validateInput(i){
this.mioitems[i] = this.mioitems[i].replace(/\D/g, '');
},
//提交
submit() {
let that = this;
that.$refs.dialogForm.validate(async (valid) => {
if (valid) {
that.isSaveing = true;
that.form.mio = that.mioId;
if (that.components.length > 0) {
that.form.assemb = [];
for (var i = 0; i < that.components.length; i++) {
that.form.assemb.push({
material: that.components[i].id,
batch: that.components[i].batch,
});
}
}
if(that.mTracking==20&&that.form.count>1&&(that.form.type == 'pur_in'||that.form.type == 'other_in')){
let mioitemw = [];
that.mioitems.forEach((item,index) => {
mioitemw[index]={ number: item };
})
if(mioitemw.length==that.mioitems.length){
that.form.mioitemw = mioitemw;
}else{
that.$message.error("请输入正确数量的编号")
return;
}
}else if(that.form.type == 'sale_out'&&that.project_code=='bxerp'){
let mioitemw = [];
that.mioitems.forEach((item,index) => {
mioitemw[index]={
number: that.wprList[index]? that.wprList[index].number:'' ,
number_out : item,
wpr:that.wprList[index]? that.wprList[index].id:null
}
})
that.form.mioitemw = mioitemw.filter(item=>item.wpr!==null);
}
try {
let res;
if (that.mode == "add") {
res = await that.$API.inm.mioitem.create.req(that.form);
} else if (that.mode == "edit") {
res = await that.$API.inm.mioitem.update.req(that.form.id,that.form);
}
that.isSaveing = false;
that.$emit("success", that.form, that.mode);
that.visible = false;
that.$message.success("操作成功");
} catch (err) {
console.log(err);
//可以处理校验错误
that.isSaveing = false;
return err;
}
}
});
},
//表单注入数据
setData(data) {
Object.assign(this.form, data);
},
//设置过滤项
setFilters(filters) {
this.selectionFilters = filters;
this.setFiltersVisible = true;
},
},
};
</script>
<style></style>