| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782 |
- <template>
- <ele-modal
- :visible.sync="visible"
- :title="title"
- width="80vw"
- append-to-body
- @close="cancel"
- :maxable="true"
- >
- <el-form
- ref="form"
- :model="form"
- :rules="rules"
- label-width="90px"
- class="create-form"
- >
- <el-row :gutter="15">
- <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
- <el-form-item label="编码:">
- <el-input
- :maxlength="20"
- v-model="form.unqualifiedProductsCode"
- disabled
- />
- </el-form-item>
- </el-col>
- <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
- <el-form-item label="来源编码:">
- <el-input :maxlength="20" v-model="form.sourceCode" disabled />
- </el-form-item>
- </el-col>
- <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
- <el-form-item label="数量:">
- <el-input :maxlength="20" v-model="form.quantity" disabled />
- </el-form-item>
- </el-col>
- <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
- <el-form-item label="工艺路线:">
- <el-input
- @click.native="openVersion"
- clearable
- v-model="form.produceRoutingName"
- />
- </el-form-item>
- </el-col>
- <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
- <el-form-item label="工序:">
- <el-select
- style="width: 100%"
- v-model="form.taskId"
- placeholder="请选择"
- clearable
- @change="produceTaskChange"
- >
- <el-option
- v-for="item in produceTaskList"
- :key="item.id"
- :label="item.name"
- :value="item.id"
- >
- </el-option>
- </el-select>
- </el-form-item>
- </el-col>
- <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
- <el-form-item label="批次号:">
- <el-input :maxlength="20" v-model="form.batchNo" disabled />
- </el-form-item>
- </el-col>
- </el-row>
- <!-- -->
- <el-table :data="form.poList" border height="40vh">
- <el-table-column label="序号" align="center" width="60">
- <template slot-scope="scope">
- <span>{{ scope.$index + 1 }}</span>
- </template>
- </el-table-column>
- <el-table-column label="产品名称" align="center" prop="categoryName">
- </el-table-column>
- <el-table-column label="产品编码" align="center" prop="categoryCode">
- </el-table-column>
- <el-table-column label="牌号" align="center" prop="brandNum">
- </el-table-column>
- <el-table-column label="刻码" align="center" prop="engrave">
- <template slot-scope="scope">
- <el-form-item
- label-width="0px"
- :prop="'poList.' + scope.$index + '.engrave'"
- >
- <el-input
- v-model="scope.row.engrave"
- size="small"
- style="width: 100%"
- placeholder="输入刻码"
- ></el-input>
- </el-form-item>
- </template>
- </el-table-column>
- <!-- <el-table-column label="型号" align="center" prop="model">
- </el-table-column> -->
- <!-- <el-table-column label="规格" align="center" prop="specification">-->
- <!-- </el-table-column>-->
- <el-table-column label="数量" align="center" prop="unqualifiedQuantity">
- <template slot-scope="scope">
- <el-form-item
- label-width="0px"
- :prop="'poList.' + scope.$index + '.unqualifiedQuantity'"
- :rules="[
- {
- required: true,
- message: '请输入数量',
- trigger: 'blur'
- },
- { validator: validatePass, trigger: 'change' }
- ]"
- >
- <el-input
- v-model.number="scope.row.unqualifiedQuantity"
- size="small"
- style="width: 100%"
- placeholder="输入数量"
- @input="
- scope.row.measureQuantity = scope.row.unqualifiedQuantity
- "
- ></el-input>
- </el-form-item>
- </template>
- </el-table-column>
- <el-table-column
- label="工艺路线"
- align="center"
- prop="produceRoutingName"
- >
- </el-table-column>
- <el-table-column label="工序" align="center" prop="produceTaskName">
- </el-table-column>
- <el-table-column
- label="不良类型"
- align="center"
- prop="badTypeId"
- width="180"
- >
- <template v-slot="{ row, $index }">
- <el-form-item
- label-width="0px"
- :prop="'poList.' + $index + '.badTypeId'"
- :rules="{
- // required: true,
- message: '请选择不良类型',
- trigger: 'blur'
- }"
- >
- <el-select
- v-model="row.badTypeId"
- placeholder="请选择不良类型"
- size="small"
- style="width: 100%"
- remote
- filterable
- clearable
- @change="badTypeChange(row)"
- >
- <el-option
- v-for="item in badTypeList"
- :key="item.id"
- :label="item.name"
- :value="item.id"
- >
- </el-option>
- </el-select>
- </el-form-item>
- </template>
- </el-table-column>
- <el-table-column
- label="不良名称"
- align="center"
- prop="badNameId"
- width="180"
- >
- <template v-slot="{ row, $index }">
- <el-form-item
- label-width="0px"
- :prop="'poList.' + $index + '.badNameId'"
- :rules="{
- // required: true,
- message: '请选择不良名称',
- trigger: 'blur'
- }"
- >
- <el-select
- v-model="row.badNameId"
- placeholder="请选择不良名称"
- size="small"
- style="width: 100%"
- remote
- filterable
- clearable
- @change="badNameChange(row)"
- >
- <el-option
- v-for="item in badNameList"
- :key="item.id"
- :label="item.name"
- :value="item.id"
- >
- </el-option>
- </el-select>
- </el-form-item>
- </template>
- </el-table-column>
- <el-table-column
- label="原因类型"
- align="center"
- prop="reasonTypeId"
- width="180"
- >
- <template v-slot="{ row, $index }">
- <el-form-item
- label-width="0px"
- :prop="'poList.' + $index + '.reasonTypeId'"
- :rules="{
- // required: true,
- message: '请选择不良原因类型',
- trigger: 'blur'
- }"
- >
- <el-select
- v-model="row.reasonTypeId"
- placeholder="请选择原因类型"
- size="small"
- style="width: 100%"
- remote
- filterable
- clearable
- @change="reasonTypeChange(row)"
- >
- <el-option
- v-for="item in reasonTypeList"
- :key="item.id"
- :label="item.name"
- :value="item.id"
- >
- </el-option>
- </el-select>
- </el-form-item>
- </template>
- </el-table-column>
- <el-table-column
- label="原因"
- align="center"
- prop="unqualifiedReason"
- width="180"
- >
- <template slot-scope="scope">
- <el-form-item
- label-width="0px"
- :prop="'poList.' + scope.$index + '.unqualifiedReason'"
- :rules="{
- required: true,
- message: '请输入原因',
- trigger: 'blur'
- }"
- >
- <el-input
- v-model="scope.row.unqualifiedReason"
- size="small"
- style="width: 100%"
- placeholder="输入原因"
- ></el-input>
- </el-form-item>
- </template>
- </el-table-column>
- <el-table-column label="操作" align="center" width="70">
- <template slot-scope="scope">
- <el-link
- type="danger"
- :underline="false"
- @click="handleDeleteItem(scope.$index, scope.row.id)"
- >
- 删除
- </el-link>
- </template>
- </el-table-column>
- </el-table>
- <div class="add-product" @click="addEquipment">
- <i class="el-icon-circle-plus-outline"></i>
- </div>
- </el-form>
- <template v-slot:footer>
- <el-button @click="cancel">取消</el-button>
- <el-button type="primary" @click="save" :loading="loading">
- 确定
- </el-button>
- </template>
- <!-- 选择产品 -->
- <EquipmentDialog ref="equipmentRefs" @choose="confirmChoose">
- </EquipmentDialog>
- <ProductionVersion
- ref="versionRefs"
- @changeProduct="changeProduct"
- ></ProductionVersion>
- </ele-modal>
- </template>
- <script>
- import EquipmentDialog from '../components/EquipmentDialog.vue';
- import ProductionVersion from '@/components/ProductionVersion/ProductionVersion.vue';
- import { getProduceTaskList } from '@/api/aps';
- import {
- unqualifiedProductsAdd,
- updateData,
- getDetail,
- deleteUnacceptedProductDetail,
- getById
- } from '@/api/unacceptedProduct/index';
- import { getList as getBadNameList } from '@/api/unacceptedProduct/unqualifiedName';
- import { getList as getBadTypeList } from '@/api/unacceptedProduct/unqualifiedType';
- import { getList as getReasonTypeList } from '@/api/unacceptedProduct/reasonType';
- export default {
- components: {
- EquipmentDialog,
- ProductionVersion
- },
- data() {
- return {
- validatePass: (rule, value, callback) => {
- if (!value) {
- callback(new Error('数量不能为0'));
- } else {
- callback();
- }
- },
- id: '',
- visible: false,
- loading: false,
- produceTaskList: [],
- form: {
- poList: [],
- unqualifiedProductsCode: '',
- sourceCode: '',
- batchNo: '',
- brandNum: '',
- categoryCode: '',
- categoryId: '',
- categoryName: '',
- specification: '',
- modelType: '',
- produceRoutingId: '',
- produceRoutingName: '',
- taskId: '',
- taskName: '',
- quantity: '',
- measureQuantity: '',
- measureUnit: '',
- weight: '',
- weightUnit: '',
- qualityType: ''
- },
- // 表单验证规则
- rules: {
- deliveryTime: [
- { required: true, message: '请选择交付日期', trigger: 'change' }
- ]
- },
- title: '创建',
- // 不良品类型列表
- badTypeList: [],
- // 不良名称列表
- badNameList: [],
- // 原因类型列表
- reasonTypeList: []
- };
- },
- computed: {
- // 是否开启响应式布局
- styleResponsive() {
- return this.$store.state.theme.styleResponsive;
- }
- },
- created() {
- this.getBadTypeList();
- this.getBadNameList();
- this.getReasonTypeList();
- },
- methods: {
- open(row, type) {
- this.visible = true;
- if (type == 'add') {
- this.title = '创建';
- this.form = row;
- this.getProduceTaskList();
- return;
- }
- console.log(row, 'row');
- if (row) {
- this.title = '修改';
- this.getDetail(row);
- } else {
- this.title = '创建';
- }
- },
- //选择工艺路线
- openVersion() {
- this.$refs.versionRefs.open();
- },
- //工艺路线回调
- changeProduct(data) {
- this.form.produceRoutingId = data.id;
- this.form.produceRoutingName = data.name;
- this.form.taskId = '';
- this.form.taskName = '';
- if (this.title == '修改') {
- this.form.poList.forEach((item) => {
- item.produceRoutingId = data.id;
- item.produceRoutingName = data.name;
- item.produceTaskId = '';
- item.produceTaskName = '';
- });
- }
- this.getProduceTaskList();
- },
- async getProduceTaskList() {
- const res = await getProduceTaskList({
- isDetail: true,
- pageNum: 1,
- routingId: this.form.produceRoutingId,
- size: -1
- });
- this.produceTaskList = res.list;
- },
- produceTaskChange() {
- if (!this.form.taskId) {
- return;
- }
- this.form.taskName = this.produceTaskList.find(
- (item) => item.id == this.form.taskId
- ).name;
- this.form.poList.forEach((item, index) => {
- this.$set(
- this.form.poList[index],
- 'produceRoutingId',
- this.form.produceRoutingId
- );
- this.$set(
- this.form.poList[index],
- 'produceRoutingName',
- this.form.produceRoutingName
- );
- this.$set(this.form.poList[index], 'produceTaskId', this.form.taskId);
- this.$set(
- this.form.poList[index],
- 'produceTaskName',
- this.form.taskName
- );
- });
- },
- async getDetail(row) {
- console.log(row.id, 'row.id');
- // this.form = row;
- const data = await getById(row.id);
- this.form.id = row.id;
- this.form.unqualifiedProductsCode = data.unqualifiedProductsCode;
- this.form.sourceCode = data.sourceCode;
- this.form.batchNo = data.batchNo;
- this.form.brandNum = data.brandNum;
- this.form.categoryCode = data.categoryCode;
- this.form.categoryId = data.categoryId;
- this.form.categoryName = data.categoryName;
- this.form.specification = data.specification;
- this.form.modelType = data.modelType;
- this.form.produceRoutingId = data.produceRoutingId;
- this.form.produceRoutingName = data.produceRoutingName;
- this.form.taskId = data.taskId;
- this.form.taskName = data.taskName;
- this.form.quantity = data.quantity;
- this.form.measureQuantity = data.measureQuantity;
- this.form.measureUnit = data.measureUnit;
- this.form.weight = data.weight;
- this.form.weightUnit = data.weightUnit;
- this.form.poList = data.poList;
- console.log(this.form);
- // getDetail(row.id).then((res) => {
- // // this.getProduceTaskList();
- // // this.form.poList = res;
- // });
- },
- cancel() {
- this.form = {
- poList: [],
- unqualifiedProductsCode: '',
- sourceCode: '',
- batchNo: '',
- brandNum: '',
- categoryCode: '',
- categoryId: '',
- categoryName: '',
- weight: '',
- specification: '',
- modelType: '',
- produceRoutingId: '',
- produceRoutingName: '',
- taskId: '',
- taskName: '',
- measureQuantity: '',
- measureUnit: '',
- weight: '',
- weightUnit: ''
- };
- this.$refs.form.clearValidate();
- this.visible = false;
- },
- // 删除产品
- handleDeleteItem(index, id) {
- this.$confirm('确认删除吗?', '提示', {
- confirmButtonText: '确定',
- cancleButtonText: '取消',
- type: 'warning'
- })
- .then((res) => {
- if (id) {
- deleteUnacceptedProductDetail([id]).then((res) => {
- this.form.poList.splice(index, 1);
- });
- } else {
- this.form.poList.splice(index, 1);
- }
- })
- .catch(() => {});
- // this.inputNumber();
- },
- addEquipment() {
- this.$refs.equipmentRefs.open();
- },
- /* 保存编辑 */
- save() {
- console.log(this.form.poList);
- this.$refs.form.validate((valid) => {
- if (!valid) {
- return false;
- }
- if (!this.form.poList.length) {
- return this.$message.warning('产品列表不能为空!');
- }
- for (let key in this.form) {
- if (key.includes('create')) {
- this.form[key] = '';
- }
- }
- this.form.poList.forEach((item) => {
- for (let key in item) {
- if (key.includes('create')) {
- item[key] = '';
- }
- }
- });
- this.loading = true;
- if (this.title == '创建') {
- unqualifiedProductsAdd(this.form)
- .then((res) => {
- this.loading = false;
- this.$message.success('成功');
- this.cancel();
- this.$emit('refresh');
- })
- .catch((e) => {
- this.loading = false;
- });
- }
- if (this.title == '修改') {
- updateData({ ...this.form, id: this.id })
- .then((res) => {
- this.loading = false;
- this.$message.success('成功');
- this.cancel();
- this.$emit('refresh');
- })
- .catch((e) => {
- this.loading = false;
- });
- }
- });
- },
- // 确定选择
- confirmChoose(data) {
- console.log(data);
- this.form.poList = [];
- let list = [];
- list = data.map((item, index) => {
- if (item.productCode) {
- return {
- // 不良品类型
- badTypeId: null,
- // 不良类型名称
- badTypeName: null,
- // 不良品名称id
- badNameId: null,
- // 不良品名称
- badNameName: null,
- // 原因类型id
- reasonTypeId: null,
- // 原因类型名称
- reasonTypeName: null,
- // 原因
- unqualifiedReason: '',
- ...item
- };
- } else {
- return {
- categoryCode: item.code,
- categoryName: item.name,
- categoryId: item.id,
- brandNum: item.brandNum,
- batchNo: item.batchNo,
- specification: item.specification,
- modelType: item.modelType,
- engrave: '',
- unqualifiedQuantity: '',
- produceRoutingId: '',
- produceRoutingName: '',
- produceTaskId: '',
- produceTaskName: '',
- measureQuantity: '',
- measureUnit: item.measuringUnit,
- weight: item.netWeight,
- weightUnit: item.weightUnit,
- // 不良品类型
- badTypeId: null,
- // 不良类型名称
- badTypeName: null,
- // 不良品名称id
- badNameId: null,
- // 不良品名称
- badNameName: null,
- // 原因类型id
- reasonTypeId: null,
- // 原因类型名称
- reasonTypeName: null,
- // 原因
- unqualifiedReason: ''
- };
- }
- });
- this.form.categoryCode = data[0].code;
- this.form.categoryName = data[0].name;
- this.form.categoryId = data[0].id;
- this.form.brandNum = data[0].brandNum;
- this.form.batchNo = data[0].batchNo;
- this.form.specification = data[0].specification;
- this.form.modelType = data[0].modelType;
- this.form.measureQuantity = '';
- this.form.measureUnit = data[0].measuringUnit;
- this.form.weight = data[0].netWeight;
- this.form.weightUnit = data[0].weightUnit;
- this.form.quantity = data.length;
- this.form.poList = this.form.poList.concat(list);
- this.produceTaskChange();
- // this.inputNumber();
- },
- inputNumber() {
- this.form.unqualifiedQuantity = 0;
- this.form.poList.forEach((item) => {
- this.form.unqualifiedQuantity +=
- Number(item.unqualifiedQuantity) || 0;
- });
- },
- // 查询不良类型
- async getBadTypeList() {
- const res = await getBadTypeList({
- pageNum: 1,
- size: 999,
- });
- console.log('this.badTypeList', this.badTypeList);
- this.badTypeList = res.list;
- },
- // 查询不良名称
- async getBadNameList( badTypeId = 0) {
- const res = await getBadNameList({
- pageNum: 1,
- size: 999,
- badTypeId: badTypeId
- });
- console.log('this.badNameList', this.badNameList);
- this.badNameList = res.list;
- },
- // 查询原因类型
- async getReasonTypeList() {
- const res = await getReasonTypeList({
- pageNum: 1,
- size: 999,
- });
- console.log('this.reasonTypeList', this.reasonTypeList);
- this.reasonTypeList = res.list;
- },
- // 不良类型改变
- badTypeChange(row) {
- row.badTypeName = null;
- // 赋值badTypeName
- const badType = this.badTypeList.find(
- (item) => item.id === row.badTypeId
- );
- if (badType) {
- row.badTypeName = badType.name;
- }
- this.getBadNameList( row.badTypeId);
- },
- // 不良名称改变
- badNameChange(row) {
- // 赋值badNameName
- const badItem = this.badNameList.find(
- (item) => item.id === row.badNameId
- );
- if (badItem) {
- row.badNameName = badItem.name;
- }
- },
- // 原因类型改变
- reasonTypeChange(row) {
- row.reasonTypeName = null;
- // 赋值reasonTypeName
- const reasonType = this.reasonTypeList.find(
- (item) => item.id === row.reasonTypeId
- );
- if (reasonType) {
- row.reasonTypeName = reasonType.name;
- }
- }
- },
- watch: {
- 'form.produceRoutingId': {
- handler(val) {
- this.getProduceTaskList();
- }
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .basic-details-title {
- margin: 10px 0;
- }
- .add-product {
- width: 100%;
- display: flex;
- align-items: center;
- justify-content: flex-end;
- font-size: 30px;
- color: #1890ff;
- margin: 10px 0;
- cursor: pointer;
- }
- .create-form .el-form-item {
- margin-bottom: 15px !important;
- }
- </style>
|