585 lines
15 KiB
Vue
585 lines
15 KiB
Vue
<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>
|
||
<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"
|
||
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="物料单价">
|
||
<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 == 'other_in'||form.type == 'do_out'||form.type=='sale_out'||form.type=='other_out'">
|
||
<el-form-item label="仓库已有批次">
|
||
<el-select
|
||
v-model="selectBatch"
|
||
value-key="id"
|
||
clearable
|
||
style="width: 100%"
|
||
@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 }} -- {{ 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"
|
||
:disabled="form.type == 'do_out'"
|
||
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="1"
|
||
style="width: 100%"
|
||
/>
|
||
</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-row>
|
||
<el-row v-if="mTracking==20&&form.count>1&&(form.type == 'pur_in'||form.type == 'other_in')">
|
||
<el-col :md="12" :sm="24" v-for="i in form.count" :key="i">
|
||
<el-form-item :label="'编号'+i" required>
|
||
<!-- <el-input-number v-if="i==1" v-model="mioitems[0]" @change="firstNumberChange" placeholder="请输入编号" controls-position="right" style="width:100%"/> -->
|
||
<el-input 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>
|
||
</template>
|
||
<script>
|
||
const defaultForm = {
|
||
state: 10,
|
||
count: 1,
|
||
type: "do_in",
|
||
};
|
||
export default {
|
||
emits: ["success", "closed"],
|
||
props: {
|
||
cate: { type: String, default: null },
|
||
mioId: { type: String, default: null },
|
||
belongDeptName: { type: String, default: null },
|
||
belongDeptId: { type: String, default: null },
|
||
mgroup: { type: String, default: null },
|
||
mioObj: { type: Object },
|
||
},
|
||
data() {
|
||
return {
|
||
type: "do_in",
|
||
loading: false,
|
||
mode: "add",
|
||
titleMap: {
|
||
do_out: "生产领料",
|
||
sale_out: "销售发货",
|
||
pur_in: "采购入库",
|
||
do_in: "生产入库",
|
||
other_in: "其他入库",
|
||
other_out: "其他出库",
|
||
},
|
||
form: {count: 1,note: ''},
|
||
rules: {
|
||
batch:[
|
||
{
|
||
required: true,
|
||
message: "请填写批次号",
|
||
trigger: "blur",
|
||
},
|
||
],
|
||
material: [
|
||
{
|
||
required: true,
|
||
message: "请选择所需产品",
|
||
trigger: "blur",
|
||
},
|
||
],
|
||
warehouse: [
|
||
{
|
||
required: true,
|
||
message: "请选择仓库",
|
||
trigger: "blur",
|
||
},
|
||
],
|
||
},
|
||
selectObj:{},
|
||
visible: false,
|
||
isSaveing: false,
|
||
materialOptions: [],
|
||
batchOptions: [],
|
||
setFiltersVisible: false,
|
||
warehouseOptions: [],
|
||
// warehouseDisable: false,
|
||
selectBatchDisable: false,
|
||
assembShow: false,
|
||
selectMaterial: null,
|
||
selectBatch: null,
|
||
components: [],
|
||
wbatchOptions: [],
|
||
mioitems:[''],
|
||
mioitemw:[],
|
||
project_code:'',
|
||
mtype:null,
|
||
mTracking:10,
|
||
apiObj:this.$API.mtm.material.list,
|
||
};
|
||
},
|
||
mounted() {
|
||
let that = this;
|
||
let url1 = window.location.href;
|
||
this.url_code = url1.split('/')[3];
|
||
let config_base = that.$TOOL.data.get("BASE_INFO").base;
|
||
that.project_code = config_base.base_code;
|
||
},
|
||
methods: {
|
||
init() {
|
||
this.getMaterialOptions();
|
||
this.getWarehouseOptions();
|
||
},
|
||
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;
|
||
if (this.mgroup != null) {
|
||
this.$API.wpm.wmaterial.list.req({mgroup: this.mgroup,material: this.form.material,state:10,page: 0}).then((res) => {
|
||
this.wbatchOptions = res;
|
||
});
|
||
}
|
||
},
|
||
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, 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 {
|
||
query = { page: 0 ,is_hidden: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 = 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;
|
||
}
|
||
})
|
||
},
|
||
selectMaterialChange() {
|
||
var that = this;
|
||
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.selectObj.batch;
|
||
that.mTracking = that.selectObj.tracking;
|
||
if (type == "do_in") {
|
||
if (that.selectObj.is_assemb) {
|
||
this.initAssemb(that.selectObj);
|
||
} else {
|
||
this.selectBatchDisable = false;
|
||
this.components = [];
|
||
this.assembShow = false;
|
||
this.getBatchOptions();
|
||
}
|
||
} else {
|
||
this.getBatchOptions();
|
||
}
|
||
},
|
||
getItem(options, id) {
|
||
for (var i = 0; i < options.length; i++) {
|
||
if (options[i].id == id) {
|
||
return options[i];
|
||
}
|
||
}
|
||
},
|
||
selectBatchChange(item) {
|
||
this.form.batch = item.batch;
|
||
this.form.mb = item.id;
|
||
this.form.count = Number(item.count);
|
||
this.form.warehouse = item.warehouse;
|
||
// this.warehouseDisable = true;
|
||
this.inputBatchDisable = true;
|
||
},
|
||
selectBatchClear() {
|
||
this.form.mb = "";
|
||
this.form.wm = "";
|
||
this.form.batch = "";
|
||
this.form.count = "";
|
||
this.form.warehouse = "";
|
||
// this.warehouseDisable = false;
|
||
this.inputBatchDisable = false;
|
||
},
|
||
//显示
|
||
open(mode = "add", type = "",mtype) {
|
||
this.mode = mode;
|
||
this.mtype = mtype?mtype:null;
|
||
this.form.type = this.type = type;
|
||
if (mode == "add") {
|
||
this.init();
|
||
}
|
||
this.visible = true;
|
||
return this;
|
||
},
|
||
countChange(){
|
||
let that = this;
|
||
if(that.mTracking == 20&&that.form.count>1&&( that.form.type == 'pur_in'|| that.form.type == 'other_in')){
|
||
that.mioitems = [];that.mioitemw = [];
|
||
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++){
|
||
let obj = {};
|
||
obj.number = that.form.batch+'-'+(i+1);
|
||
that.mioitemw.push(obj);
|
||
}
|
||
}
|
||
},
|
||
firstNumberChange(){
|
||
let that = this;
|
||
that.mioitemw = [];
|
||
let numbers = that.mioitems[0];
|
||
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);
|
||
}
|
||
},
|
||
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;
|
||
}
|
||
}
|
||
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>
|