factory_web/src/views/inm/mio_form.vue

334 lines
7.4 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-form-item label="编号" prop="number">
<el-input v-model="form.number" placeholder="编号" />
</el-form-item>
<el-form-item label="出入库日期">
<el-date-picker
v-model="form.inout_date"
type="date"
placeholder="出入库日期"
value-format="YYYY-MM-DD"
style="width: 100%"
>
</el-date-picker>
</el-form-item>
<el-form-item label="采购订单" v-if="form.type == 'pur_in'">
<el-select
v-model="form.pu_order"
clearable
style="width: 100%"
>
<el-option
v-for="item in puOrderOptions"
:key="item.id"
:label="item.number"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
<el-form-item
label="供应商"
v-if="form.type == 'other_in' || form.type == 'pur_in'"
>
<el-select
v-model="form.supplier"
clearable
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-form-item label="销售订单" v-if="form.type == 'sale_out'">
<el-select v-model="form.order" clearable style="width: 100%">
<el-option
v-for="item in orderOptions"
:key="item.id"
:label="item.number"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="客户名称" v-if="form.type == 'sale_out'">
<el-select
v-model="form.customer"
clearable
style="width: 100%"
>
<el-option
v-for="item in customerOptions"
:key="item.id"
:label="item.name"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="客户" v-if="form.type == 'other_out'">
<el-select
v-model="form.customer"
clearable
style="width: 100%"
>
<el-option
v-for="item in customerOptions"
:key="item.id"
:label="item.name"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
<el-form-item
label="执行部门"
v-if="form.type == 'do_in' || form.type == 'do_out'"
>
<el-select
v-model="form.belong_dept"
clearable
style="width: 100%"
@change="getgetDeptUsers"
>
<el-option
v-for="item in deptOptions"
:key="item.id"
:label="item.name"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
<el-form-item
label="工段"
v-if="form.type == 'do_in' || form.type == 'do_out'"
>
<el-select
v-model="form.mgroup"
clearable
style="width: 100%"
placeholder="为空时代表领料/入库到车间"
>
<el-option
v-for="item in mgroupOptions"
:key="item.id"
:label="item.name"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
<el-form-item
label="部门执行人"
v-if="form.type == 'do_in' || form.type == 'do_out'"
>
<el-select v-model="form.do_user" clearable style="width: 100%">
<el-option
v-for="item in userOptions"
:key="item.id"
:label="item.name"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
<el-form-item
label="仓库执行人"
>
<el-select
v-model="form.mio_user"
clearable
style="width: 100%"
>
<el-option
v-for="item in userOption"
:key="item.id"
:label="item.name"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
</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,
type: "do_in",
};
export default {
emits: ["success", "closed"],
props: {},
data() {
return {
type: "do_in",
loading: false,
mode: "add",
titleMap: {
do_out: "生产领料",
sale_out: "销售发货",
pur_in: "采购入库",
do_in: "生产入库",
other_in: "其他入库",
other_out: "其他出库",
},
form: {},
rules: {
number: [
{
required: true,
message: "请填写编号",
trigger: "blur",
},
],
},
visible: false,
isSaveing: false,
options: [],
setFiltersVisible: false,
deptOptions: [],
mgroupOptions: [],
userOptions: [],
userOption: [],
orderOptions: [],
puOrderOptions: [],
supplierOptions: [],
customerOptions: [],
};
},
mounted() {},
methods: {
init() {
this.getDeptUser();
var type = this.form.type;
if (type == "pur_in") {
this.getPuOrderOptions();
this.getSupplierOptions();
} else if (type == "sale_out") {
this.getOrderOptions();
this.getCustomerOptions();
} else if (type == "do_in" || type == "do_out") {
this.getDeptOptions();
this.getmgroupOptions();
this.getgetDeptUsers();
} else if (type == "other_in") {
this.getSupplierOptions();
} else if (type == "other_out") {
this.getCustomerOptions();
}
},
getmgroupOptions() {
this.$API.mtm.mgroup.list.req({page: 0}).then(res=>{
this.mgroupOptions = res;
})
},
getSupplierOptions() {
this.$API.pum.supplier.list.req({ page: 0 }).then((res) => {
this.supplierOptions = res;
});
},
getCustomerOptions() {
this.$API.sam.customer.list.req({ page: 0 }).then((res) => {
this.customerOptions = res;
});
},
getDeptOptions() {
this.$API.system.dept.list
.req({ page: 0, type__in: "dept" })
.then((res) => {
this.deptOptions = res;
});
},
getPuOrderOptions() {
this.$API.pum.order.list
.req({ page: 0, type__in: "20,30" })
.then((res) => {
this.puOrderOptions = res;
});
},
getOrderOptions() {
this.$API.sam.order.list
.req({ page: 0, state__in: "20,30" })
.then((res) => {
this.orderOptions = res;
});
},
getgetDeptUsers(){
this.$API.system.user.list.req({ depts: this.form.belong_dept, page: 0 }).then((res) => {
this.userOptions = res;
});
},
getDeptUser() {
this.$API.system.user.list
.req({ posts__name: "库管", page: 0 })
.then((res) => {
this.userOption = res;
});
},
//显示
open(mode = "add", type = "") {
this.mode = mode;
this.form.type = type;
this.init();
this.visible = true;
return this;
},
//提交
submit() {
this.$refs.dialogForm.validate(async (valid) => {
if (valid) {
this.isSaveing = true;
try {
var res;
if (this.mode == "add") {
res = await this.$API.inm.mio.create.req(this.form);
} else if (this.mode == "edit") {
res = await this.$API.inm.mio.update.req(
this.form.id,
this.form
);
}
this.isSaveing = false;
this.$emit("success", this.form, this.mode);
this.visible = false;
this.$message.success("操作成功");
} catch (err) {
console.log(err);
//可以处理校验错误
this.isSaveing = false;
return err;
}
}
});
},
//表单注入数据
setData(data) {
Object.assign(this.form, data);
},
//设置过滤项
setFilters(filters) {
this.selectionFilters = filters;
this.setFiltersVisible = true;
},
},
};
</script>
<style></style>