| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319 |
- <template>
- <div>
- <header-title title="物料清单"></header-title>
- <ele-pro-table
- ref="table"
- row-key="id"
- :columns="materialColumns"
- :datasource="materialList"
- cache-key="prenatal-examination-material-list-table-2511031522"
- autoAmendPage
- :needPage="false"
- @refresh="$emit('refresh')"
- >
- <template v-slot:toolbar>
- <el-button type="primary" @click="openMaterialModal"
- >添加物料</el-button
- >
- </template>
- <template v-slot:selectColumn="{ row }">
- <el-checkbox
- v-model="row.selected"
- @change="selectedChange(row)"
- ></el-checkbox>
- </template>
- <template v-slot:feedQuantityHeader>
- <el-tooltip
- effect="dark"
- content="数量是指存在多次投料时,本道工序在本次记录表报工时的累计当时投料数量;"
- placement="top"
- >
- <div>
- <span>数量</span>
- <i
- class="el-icon-info"
- style="margin-left: 4px; color: #909399"
- ></i>
- </div>
- </el-tooltip>
- </template>
- <template v-slot:sumConsumeQuantityHeader>
- <el-tooltip
- effect="dark"
- content="累计消耗数量是指存在多次记录表报工时,本次记录表报工时的累计实时消耗数量;"
- placement="top"
- >
- <div>
- <span>累计消耗数量</span>
- <i
- class="el-icon-info"
- style="margin-left: 4px; color: #909399"
- ></i>
- </div>
- </el-tooltip>
- </template>
- </ele-pro-table>
- <header-title title="产出清单" style="margin-top: 20px"></header-title>
- <ele-pro-table
- ref="table"
- row-key="id"
- :columns="outputDetailsColumns"
- :datasource="localOutputDetails"
- cache-key="prenatal-examination-output-list-table-2511031523"
- autoAmendPage
- :needPage="false"
- @refresh="localOutputDetailsRefresh"
- >
- <template v-slot:reportQuantity="{ row }">
- <div>
- <!-- {{ reportQuantitymax(row) }} -->
- <el-input-number
- size="small"
- v-model.number="row.reportQuantity"
- controls-position="right"
- :min="0"
- :max="reportQuantitymax(row)"
- @change="reportQuantityChange(row)"
- ></el-input-number>
- </div>
- </template>
- <template v-slot:qualifiedQuantity="{ row }">
- <el-input-number
- size="small"
- v-model.number="row.qualifiedQuantity"
- controls-position="right"
- :min="0"
- :max="qualifiedQuantityMax(row)"
- @change="qualifiedQuantityChange(row)"
- ></el-input-number>
- </template>
- <template v-slot:noQualifiedQuantity="{ row }">
- <el-input-number
- size="small"
- v-model.number="row.noQualifiedQuantity"
- controls-position="right"
- :min="0"
- :max="noQualifiedQuantityMax(row)"
- @change="noQualifiedQuantityChange(row)"
- ></el-input-number>
- </template>
- <template v-slot:msg="{ row }">
- <el-input
- v-model="row.msg"
- type="textarea"
- rows="1"
- autosize
- @change="$emit('update:outputDetails', localOutputDetails)"
- ></el-input>
- </template>
- <template v-slot:sumReportQuantityHeader>
- <el-tooltip
- effect="dark"
- content="已报工数量是指存在多次记录表报工时,多次报工数量的累计实时已报工数量;"
- placement="top"
- >
- <div>
- <span>已报工数量</span>
- <i
- class="el-icon-info"
- style="margin-left: 4px; color: #909399"
- ></i>
- </div>
- </el-tooltip>
- </template>
- <template v-slot:sumQualifiedQuantityHeader>
- <el-tooltip
- effect="dark"
- content="合格品数量是指存在多次记录表报工时,多次报工数量的累计实时合格品数量;"
- placement="top"
- >
- <div>
- <span>合格总数</span>
- <i
- class="el-icon-info"
- style="margin-left: 4px; color: #909399"
- ></i>
- </div>
- </el-tooltip>
- </template>
- <template v-slot:sumNoQualifiedQuantityHeader>
- <el-tooltip
- effect="dark"
- content="不合格品数量是指存在多次记录表报工时,多次报工数量的累计实时不合格品数量;"
- placement="top"
- >
- <div>
- <span>不合格总数</span>
- <i
- class="el-icon-info"
- style="margin-left: 4px; color: #909399"
- ></i>
- </div>
- </el-tooltip>
- </template>
- </ele-pro-table>
- <materialModal ref="materialModalRef" @confirm="materialConfirm" />
- </div>
- </template>
- <script>
- import materialModal from './materialModal.vue';
- import {
- getMaterialQuotaInfo,
- getCategoryAndLevelByCategoryId
- } from '@/api/producetaskrecordrulesrecord/index';
- export default {
- components: {
- materialModal
- },
- props: {
- // 物料明细
- pickDetails: {
- type: Array,
- default: () => []
- },
- // 本次产出明细
- outputDetails: {
- type: Array,
- default: () => []
- },
- // 上到工序产出明细
- preOutputDetails: {
- type: Array,
- default: () => []
- },
- sumOutputDetails: {
- type: Array,
- default: () => []
- },
- // 工单id
- workOrderId: {
- type: [String, Number],
- required: true
- },
- // 规则id
- ruleId: {
- type: [String, Number],
- required: false
- },
- // 工序id
- produceTaskId: {
- type: [String, Number],
- required: true
- },
- // 工序实例id
- produceTaskInstanceId: {
- type: [String, Number],
- required: true
- },
- // 工序名称
- produceTaskName: {
- type: String,
- required: true
- },
- // BOM产品分类id
- bomCategoryId: {
- type: [String, Number],
- required: true
- },
- // 产出类型 1-物料本身 2-在制品 3-BOM标准产出
- outputType: {
- type: [Number],
- required: true
- },
- // 产品分类id
- categoryId: {
- type: [String, Number],
- required: false
- },
- // 执行状态
- executeStatus: {
- type: [Number],
- required: false
- }
- },
- watch: {
- pickDetails: {
- handler(newVal) {
- this.localPickDetails = JSON.parse(JSON.stringify(newVal)).map(
- (i) => {
- i.ruleId = this.ruleId;
- i.bomCategoryId = this.bomCategoryId;
- return i;
- }
- );
- },
- deep: true,
- immediate: true
- },
- outputDetails: {
- handler(newVal) {
- this.localOutputDetails = JSON.parse(JSON.stringify(newVal)).map(
- (i) => {
- i.ruleId = this.ruleId;
- i.outputType = this.outputType;
- i.bomCategoryId = this.bomCategoryId;
- i.id = null;
- return i;
- }
- );
- },
- deep: true,
- immediate: true
- },
- outputType: {
- handler() {
- // 重置产出明细
- this.localOutputDetails = [];
- this.localPickDetails = this.localPickDetails.map((item) => {
- return {
- ...item,
- selected: false
- };
- });
- // 根据不同的类型,重置物料明细
- if (this.outputType == 1) {
- this.$emit('update:outputDetails', this.localOutputDetails);
- // 1-物料本身
- } else if (this.outputType == 2) {
- // 2-在制品
- this.categoryInfoSetOutput();
- } else {
- // 3 BOM标准产出
- this.setMaterialQuotaInfo();
- }
- }
- },
- ruleId: {
- handler() {
- // 更新物料明细的ruleId
- this.localPickDetails = this.localPickDetails.map((item) => {
- return {
- ...item,
- ruleId: this.ruleId
- };
- });
- // 更新产出明细的ruleId
- this.localOutputDetails = this.localOutputDetails.map((item) => {
- return {
- ...item,
- ruleId: this.ruleId
- };
- });
- // 通知父组件更新
- this.$emit('update:pickDetails', this.localPickDetails);
- this.$emit('update:outputDetails', this.localOutputDetails);
- }
- },
- produceTaskId: {
- handler() {
- this.getMaterialQuotaInfo();
- this.getCategoryAndLevelByCategoryId();
- },
- immediate: true
- }
- },
- computed: {
- // 物料清单(包含上到工序产出明细)
- materialList() {
- return this.localPickDetails;
- },
- // 物料清单表头
- materialColumns() {
- const list = [
- {
- width: 45,
- type: 'index',
- columnKey: 'index',
- align: 'center'
- },
- {
- label: '类型',
- prop: 'categoryLevelNamePath',
- minWidth: 120
- },
- {
- label: '编码',
- prop: 'categoryCode',
- minWidth: 120
- },
- {
- label: '名称',
- prop: 'categoryName',
- minWidth: 120
- },
- {
- prop: 'model',
- label: '型号',
- align: 'center',
- showOverflowTooltip: true
- },
- {
- prop: 'specifications',
- label: '规格',
- align: 'center',
- width: 160,
- showOverflowTooltip: true
- },
- {
- prop: 'brandNo',
- label: '牌号',
- align: 'center'
- },
- {
- label: '工序名称',
- prop: 'produceTaskName',
- minWidth: 120
- },
- {
- label: '数量',
- prop: 'feedQuantity',
- minWidth: 120,
- formatter: (row) => {
- return (row.quantity || 0) + (row.unit || '');
- },
- headerSlot: 'feedQuantityHeader'
- },
- {
- label: '当次消耗数量',
- prop: '',
- minWidth: 120,
- formatter: (row) => {
- // 产出为物料
- if (this.outputType == 1) {
- // 取值产出清单
- const outputItem = this.localOutputDetails.find(
- (item) => item.categoryCode === row.categoryCode
- );
- if (outputItem) {
- return outputItem.reportQuantity + (row.unit || '');
- }
- return 0 + (row.unit || '');
- } else {
- // 产出为在制品 或 BOM标准产出
- // 查询基数
- if (!this.materialQuotaInfo) {
- return '0' + (row.unit || '');
- }
- // 当前行为在制品 和 BOM标准产出
- const preOutputItem = this.localOutputDetails.find(
- (item) => item.categoryCode === row.categoryCode
- );
- if (preOutputItem) {
- return (preOutputItem.reportQuantity || 0) + (row.unit || '');
- }
- // 当前行为原材料
- const materialItem = this.materialQuotaInfo.materialQuota.find(
- (item) => item.categoryCode === row.categoryCode
- );
- if (!materialItem) {
- return '0' + (row.unit || '');
- }
- // 需要的物料数量比例
- let count =
- materialItem.count / this.materialQuotaInfo.baseCount;
- // 产出清单的报工数量 当次报工+累计报工
- const outputItem = this.localOutputDetails[0];
- if (!outputItem) {
- return '0' + (row.unit || '');
- }
- // 当次消耗
- let needQuantity = this.formatNumber(
- outputItem.reportQuantity * count
- );
- return needQuantity + (row.unit || '');
- }
- }
- },
- {
- label: '累计消耗数量',
- prop: '',
- minWidth: 120,
- formatter: (row) => {
- if (this.outputType == 1) {
- const outputItem = this.localOutputDetails.find(
- (item) => item.categoryCode == row.categoryCode
- );
- // 查询其他工单sumOutputDetails中已产生的bom标准产出和在制品的累计消耗数量
- let preCount = 0;
- if (this.materialQuotaInfo) {
- const materialQuotaItem =
- this.materialQuotaInfo.materialQuota.find(
- (item) => item.categoryCode === row.categoryCode
- );
- if (materialQuotaItem) {
- // 计算比例
- const proportion =
- materialQuotaItem.count /
- this.materialQuotaInfo.baseCount;
- if (this.materialQuotaInfo.standardOutput) {
- // BOM标准产出
- const preItem = this.sumOutputDetails.find(
- (item) =>
- item.categoryCode ===
- this.materialQuotaInfo.standardOutput.categoryCode
- );
- if (preItem) {
- preCount += this.formatNumber(
- preItem.sumReportQuantity * proportion
- );
- }
- }
- if (this.categoryInfo) {
- // 在制品
- const preItem = this.sumOutputDetails.find(
- (item) =>
- item.categoryCode === this.categoryInfo.categoryCode
- );
- if (preItem) {
- preCount += this.formatNumber(
- preItem.sumReportQuantity * proportion
- );
- }
- }
- }
- }
- // debugger;
- let count = 0;
- if (outputItem) {
- if (this.executeStatus === 2) {
- // 已执行,处理重新一键报工时,sumReportQuantity包含了当前报工数量
- count =
- row.sumReportQuantity -
- (outputItem.reportQuantityCopy -
- outputItem.reportQuantity);
- } else {
- count = row.sumReportQuantity + outputItem.reportQuantity;
- }
- } else {
- count = row.sumReportQuantity;
- }
- return count + preCount + (row.unit || '');
- } else {
- // 当前行为在制品 和 BOM标准产出
- const output = this.localOutputDetails.find(
- (item) => item.categoryCode === row.categoryCode
- );
- if (output) {
- // 区分已执行状态
- if (this.executeStatus === 2) {
- // 已执行,处理重新一键报工时,sumReportQuantity包含了当前报工数量
- return (
- output.sumReportQuantity -
- (output.reportQuantityCopy - output.reportQuantity) +
- (row.unit || '')
- );
- }
- return (
- (output.sumReportQuantity || 0) +
- output.reportQuantity +
- (row.unit || '')
- );
- }
- // 产出为在制品 或 BOM标准产出 累计消耗数量
- if (!this.materialQuotaInfo) {
- return row.sumReportQuantity + (row.unit || '');
- }
- const materialItem = this.materialQuotaInfo.materialQuota.find(
- (item) => item.categoryCode === row.categoryCode
- );
- if (!materialItem) {
- return row.sumReportQuantity + (row.unit || '');
- }
- // 计算在制 标准产出消耗原材料
- const outputItem = this.localOutputDetails[0];
- if (!outputItem) {
- return row.sumReportQuantity + (row.unit || '');
- }
- // 单位产出所需物料比例
- const proportion =
- materialItem.count / this.materialQuotaInfo.baseCount;
- // 查询其他工单sumOutputDetails中已产生的bom标准产出和在制品的累计消耗数量
- let preCount = 0;
- // 如果当前物料不是BOM标准产出,则需要加上BOM标准产出的消耗数量
- if (
- outputItem.categoryCode !=
- this.materialQuotaInfo.standardOutput.categoryCode
- ) {
- // BOM标准产出
- const preItem = this.sumOutputDetails.find(
- (item) =>
- item.categoryCode ===
- this.materialQuotaInfo.standardOutput.categoryCode
- );
- if (preItem) {
- preCount += this.formatNumber(
- preItem.sumReportQuantity * proportion
- );
- }
- }
- // 在制品
- if (this.categoryInfo) {
- if (
- this.categoryInfo.categoryCode != outputItem.categoryCode
- ) {
- const preItem = this.sumOutputDetails.find(
- (item) =>
- item.categoryCode === this.categoryInfo.categoryCode
- );
- if (preItem) {
- preCount += this.formatNumber(
- preItem.sumReportQuantity * proportion
- );
- }
- }
- }
- let cumulativeOutputQuantity = 0;
- if (this.executeStatus === 2) {
- // 已执行,处理重新一键报工时,sumReportQuantity包含了当前报工数量
- cumulativeOutputQuantity =
- outputItem.sumReportQuantity -
- (outputItem.reportQuantityCopy - outputItem.reportQuantity);
- } else {
- cumulativeOutputQuantity =
- outputItem.sumReportQuantity + outputItem.reportQuantity;
- }
- const needQuantity = this.formatNumber(
- cumulativeOutputQuantity * proportion
- );
- // 已消耗数量转换
- const sumReportQuantity = row.sumReportQuantity;
- return (
- needQuantity + preCount + sumReportQuantity + (row.unit || '')
- );
- }
- },
- headerSlot: 'sumConsumeQuantityHeader'
- }
- ];
- if (this.outputType == 1) {
- list.push({
- prop: '',
- label: '选择',
- slot: 'selectColumn',
- align: 'center',
- fixed: 'right'
- });
- }
- return list;
- },
- // 产出清单表头
- outputDetailsColumns() {
- return [
- {
- width: 45,
- type: 'index',
- columnKey: 'index',
- align: 'center'
- },
- {
- label: '类型',
- prop: 'categoryLevelNamePath',
- minWidth: 120
- },
- {
- label: '编码',
- prop: 'categoryCode',
- minWidth: 120
- },
- {
- label: '名称',
- prop: 'categoryName',
- minWidth: 120
- },
- {
- prop: 'model',
- label: '型号',
- align: 'center',
- showOverflowTooltip: true
- },
- {
- prop: 'specifications',
- label: '规格',
- align: 'center',
- width: 160,
- showOverflowTooltip: true
- },
- {
- prop: 'brandNo',
- label: '牌号',
- align: 'center'
- },
- {
- label: '工序名称',
- prop: 'produceTaskName',
- minWidth: 120
- },
- {
- label: '当次报工数量',
- prop: 'reportQuantity',
- minWidth: 160,
- slot: 'reportQuantity'
- },
- {
- label: '当次合格数量',
- prop: 'qualifiedQuantity',
- minWidth: 160,
- slot: 'qualifiedQuantity'
- },
- {
- label: '当次不合格数量',
- prop: 'noQualifiedQuantity',
- minWidth: 160,
- slot: 'noQualifiedQuantity'
- },
- {
- label: '不合格原因',
- prop: 'msg',
- minWidth: 160,
- slot: 'msg'
- },
- {
- label: '已报工数量',
- prop: 'sumReportQuantity',
- minWidth: 120,
- formatter: (row) => {
- let count = row.sumReportQuantity || 0;
- if (this.executeStatus === 2) {
- // 已执行,处理重新一键报工时,sumReportQuantity包含了当前报工数量
- count += row.reportQuantity - row.reportQuantityCopy;
- } else {
- count += row.reportQuantity;
- }
- return count + (row.unit || '');
- },
- headerSlot: 'sumReportQuantityHeader'
- },
- {
- label: '合格总数',
- prop: 'sumQualifiedQuantity',
- minWidth: 120,
- formatter: (row) => {
- // 已报工数量
- let sumReportQuantity = row.sumReportQuantity || 0;
- if (this.executeStatus === 2) {
- // 已执行,处理重新一键报工时,sumReportQuantity包含了当前报工数量
- sumReportQuantity +=
- row.reportQuantity - row.reportQuantityCopy;
- } else {
- sumReportQuantity += row.reportQuantity;
- }
- let count = row.sumQualifiedQuantity || 0;
- if (this.executeStatus === 2) {
- // 已执行,处理重新一键报工时,sumQualifiedQuantity包含了当前报工数量
- count += row.qualifiedQuantity - row.qualifiedQuantityCopy;
- } else {
- count += row.qualifiedQuantity;
- }
- // 处理缓存后,物料被其他工单报工超出已报工数量问题
- if (count > sumReportQuantity) {
- count = sumReportQuantity;
- }
- return count + (row.unit || '');
- },
- headerSlot: 'sumQualifiedQuantityHeader'
- },
- {
- label: '不合格总数',
- prop: 'sumNoQualifiedQuantity',
- minWidth: 120,
- formatter: (row) => {
- // 已报工数量
- let sumReportQuantity = row.sumReportQuantity || 0;
- if (this.executeStatus === 2) {
- // 已执行,处理重新一键报工时,sumReportQuantity包含了当前报工数量
- sumReportQuantity +=
- row.reportQuantity - row.reportQuantityCopy;
- } else {
- sumReportQuantity += row.reportQuantity;
- }
- let count = row.sumNoQualifiedQuantity || 0;
- if (this.executeStatus === 2) {
- // 已执行,处理重新一键报工时,sumNoQualifiedQuantity包含了当前报工数量
- count += row.noQualifiedQuantity - row.noQualifiedQuantityCopy;
- } else {
- count += row.noQualifiedQuantity;
- }
- // 处理缓存后,物料被其他工单报工超出已报工数量问题
- if (count > sumReportQuantity) {
- count = sumReportQuantity;
- }
- return count + (row.unit || '');
- },
- headerSlot: 'sumNoQualifiedQuantityHeader'
- }
- ];
- }
- },
- data() {
- return {
- localPickDetails: [],
- localOutputDetails: [],
- // bom配置的 标准产出信息
- materialQuotaInfo: null,
- // 在制品信息
- categoryInfo: null
- };
- },
- methods: {
- // 选择物料
- openMaterialModal() {
- this.$refs.materialModalRef.open(
- {
- workOrderId: this.workOrderId,
- ruleId: this.ruleId,
- produceTaskId: this.produceTaskId
- },
- []
- );
- },
- materialConfirm(data) {
- // 选择物料后添加
- console.log('data', data);
- data.forEach((newItem) => {
- const index = this.localPickDetails.findIndex(
- (item) => item.categoryCode === newItem.categoryCode
- );
- if (index !== -1) {
- // 存在则替换数量
- this.localPickDetails[index].quantity = newItem.quantity;
- } else {
- const sumItem = this.sumOutputDetails.find(
- (item) => item.categoryCode === newItem.categoryCode
- );
- let sumQualifiedQuantity = 0;
- let sumNoQualifiedQuantity = 0;
- let sumReportQuantity = 0;
- if (sumItem) {
- sumQualifiedQuantity = sumItem.sumQualifiedQuantity;
- sumNoQualifiedQuantity = sumItem.sumNoQualifiedQuantity;
- sumReportQuantity = sumItem.sumReportQuantity;
- }
- // 不存在则添加
- this.localPickDetails.push({
- ...newItem,
- // 物料的类型
- outputType: 1,
- reportQuantity: 0,
- ruleId: this.ruleId,
- bomCategoryId: this.bomCategoryId,
- produceTaskId: this.produceTaskId,
- produceTaskInstanceId: this.produceTaskInstanceId,
- produceTaskName: this.produceTaskName,
- workOrderId: this.workOrderId,
- sumQualifiedQuantity,
- sumNoQualifiedQuantity,
- sumReportQuantity
- });
- }
- });
- console.log('this.localPickDetails', this.localPickDetails);
- this.$emit('update:pickDetails', this.localPickDetails);
- },
- // bom标准产出赋值
- setMaterialQuotaInfo() {
- console.log('this.materialQuotaInfo', this.materialQuotaInfo);
- if (this.materialQuotaInfo && this.materialQuotaInfo.standardOutput) {
- const sumItem = this.sumOutputDetails.find(
- (i) =>
- i.categoryCode ===
- this.materialQuotaInfo.standardOutput.categoryCode
- );
- let sumQualifiedQuantity = 0;
- let sumNoQualifiedQuantity = 0;
- let sumReportQuantity = 0;
- if (sumItem) {
- sumQualifiedQuantity = sumItem.sumQualifiedQuantity;
- sumNoQualifiedQuantity = sumItem.sumNoQualifiedQuantity;
- sumReportQuantity = sumItem.sumReportQuantity;
- }
- // 赋值产出
- this.localOutputDetails = [
- {
- ...this.materialQuotaInfo.standardOutput,
- id: null,
- reportQuantity: 0,
- reportQuantityCopy: 0,
- qualifiedQuantity: 0,
- noQualifiedQuantity: 0,
- msg: '',
- sumReportQuantity,
- sumQualifiedQuantity,
- sumNoQualifiedQuantity,
- ruleId: this.ruleId,
- outputType: this.outputType,
- produceTaskId: this.produceTaskId,
- produceTaskInstanceId: this.produceTaskInstanceId,
- produceTaskName: this.produceTaskName,
- workOrderId: this.workOrderId
- }
- ];
- this.$emit('update:outputDetails', this.localOutputDetails);
- } else {
- this.$message.warning('未配置BOM标准产出信息');
- }
- },
- // 获取bom的产出清单
- async getMaterialQuotaInfo() {
- if (this.bomCategoryId && this.produceTaskId) {
- const data = await getMaterialQuotaInfo(
- this.bomCategoryId,
- this.produceTaskId
- );
- console.log('this.materialQuotaInfo', data);
- if (JSON.stringify(data) === '{}') {
- this.materialQuotaInfo = this.materialQuota;
- return;
- }
- if (data.materialQuota) {
- // 过滤数据
- data.materialQuota = data.materialQuota.filter((i) => {
- return i.isReworkBom != 1;
- });
- } else {
- data.materialQuota = [];
- }
- this.materialQuotaInfo = data;
- console.log('this.materialQuotaInfo', this.materialQuotaInfo);
- }
- },
- // qualifiedQuantityMax 最大合格数量
- qualifiedQuantityMax(row) {
- return row.reportQuantity;
- },
- noQualifiedQuantityMax(row) {
- return row.reportQuantity;
- },
- selectedChange(row) {
- console.log('row', row);
- if (this.outputType != 1) return;
- if (row.selected) {
- // 判断是否存在
- const index = this.localOutputDetails.findIndex(
- (item) => item.categoryId === row.categoryId
- );
- if (index === -1) {
- const sumItem = this.sumOutputDetails.find(
- (i) => i.categoryCode === row.categoryCode
- );
- let sumQualifiedQuantity = 0;
- let sumNoQualifiedQuantity = 0;
- let sumReportQuantity = 0;
- if (sumItem) {
- sumQualifiedQuantity = sumItem.sumQualifiedQuantity;
- sumNoQualifiedQuantity = sumItem.sumNoQualifiedQuantity;
- sumReportQuantity = sumItem.sumReportQuantity;
- }
- // 不存在则添加
- this.localOutputDetails.push({
- ...row,
- id: null,
- reportQuantity: 0,
- reportQuantityCopy: 0,
- qualifiedQuantity: 0,
- noQualifiedQuantity: 0,
- msg: '',
- sumReportQuantity,
- sumQualifiedQuantity,
- sumNoQualifiedQuantity,
- ruleId: this.ruleId,
- outputType: this.outputType,
- bomCategoryId: this.bomCategoryId,
- produceTaskId: this.produceTaskId,
- produceTaskInstanceId: this.produceTaskInstanceId,
- produceTaskName: this.produceTaskName,
- workOrderId: this.workOrderId
- });
- } else {
- this.$message.warning('该物料已存在于产出清单中');
- }
- } else {
- // 取消选择则删除
- this.localOutputDetails = this.localOutputDetails.filter(
- (item) => !(item.categoryId === row.categoryId)
- );
- }
- console.log('this.localOutputDetails', this.localOutputDetails);
- this.$emit('update:outputDetails', this.localOutputDetails);
- },
- // getCategoryAndLevelByCategoryId 获取产品 在制品信息
- async getCategoryAndLevelByCategoryId() {
- const data = await getCategoryAndLevelByCategoryId(this.categoryId);
- this.categoryInfo = data;
- console.log('this.categoryInfo 在制品信息', this.categoryInfo);
- },
- // 在制品信息 设置产出物
- categoryInfoSetOutput() {
- if (this.categoryInfo) {
- const sumItem = this.sumOutputDetails.find(
- (i) => i.categoryCode == this.categoryInfo.categoryCode
- );
- let sumQualifiedQuantity = 0;
- let sumNoQualifiedQuantity = 0;
- let sumReportQuantity = 0;
- if (sumItem) {
- sumQualifiedQuantity = sumItem.sumQualifiedQuantity;
- sumNoQualifiedQuantity = sumItem.sumNoQualifiedQuantity;
- sumReportQuantity = sumItem.sumReportQuantity;
- }
- this.localOutputDetails = [
- {
- ...this.categoryInfo,
- id: null,
- reportQuantity: 0,
- reportQuantityCopy: 0,
- qualifiedQuantity: 0,
- noQualifiedQuantity: 0,
- msg: '',
- sumReportQuantity,
- sumQualifiedQuantity,
- sumNoQualifiedQuantity,
- ruleId: this.ruleId,
- outputType: this.outputType,
- produceTaskId: this.produceTaskId,
- produceTaskInstanceId: this.produceTaskInstanceId,
- produceTaskName: this.produceTaskName,
- workOrderId: this.workOrderId
- }
- ];
- }
- this.$emit('update:outputDetails', this.localOutputDetails);
- console.log('this.localOutputDetails', this.localOutputDetails);
- },
- // 计算报工数量最大值
- reportQuantitymax(row) {
- if (this.outputType == 1) {
- // 查询物料本身
- let pickItem = this.localPickDetails.find(
- (item) => item.categoryCode === row.categoryCode
- );
- if (!pickItem) {
- // 查询上到工序产出明细
- pickItem = this.preOutputDetails.find(
- (item) => item.categoryCode === row.categoryCode
- );
- }
- // 未找到物料,则不限制
- if (!pickItem) return Infinity;
- // 查询其他工单sumOutputDetails中已产生的bom标准产出和在制品的累计消耗数量
- let preCount = 0;
- if (this.materialQuotaInfo) {
- const materialQuotaItem = this.materialQuotaInfo.materialQuota.find(
- (item) => item.categoryCode === row.categoryCode
- );
- if (materialQuotaItem) {
- // 计算比例
- const proportion =
- materialQuotaItem.count / this.materialQuotaInfo.baseCount;
- if (this.materialQuotaInfo.standardOutput) {
- // BOM标准产出
- const preItem = this.sumOutputDetails.find(
- (item) =>
- item.categoryCode ===
- this.materialQuotaInfo.standardOutput.categoryCode
- );
- if (preItem) {
- preCount += this.formatNumber(
- preItem.sumReportQuantity * proportion
- );
- }
- }
- if (this.categoryInfo) {
- // 在制品
- const preItem = this.sumOutputDetails.find(
- (item) => item.categoryCode === this.categoryInfo.categoryCode
- );
- if (preItem) {
- preCount += this.formatNumber(
- preItem.sumReportQuantity * proportion
- );
- }
- }
- }
- }
- // 已执行,处理重新一键报工时,sumReportQuantity包含了当前报工数量
- if (this.executeStatus == 2) {
- const count =
- pickItem.quantity -
- (row.sumReportQuantity - row.reportQuantityCopy) -
- preCount;
- // 如果小于本次报工数量 则返回本次报工数量
- if (count < row.reportQuantityCopy) {
- return row.reportQuantityCopy;
- } else {
- return count;
- }
- } else {
- return pickItem.quantity - pickItem.sumReportQuantity - preCount;
- }
- }
- if (row.outputType == 2 || row.outputType == 3) {
- // 当前行为在制品 和 BOM标准产出
- const preOutputItem = this.preOutputDetails.find(
- (item) => item.categoryCode === row.categoryCode
- );
- // debugger;
- // 存在则当前row为在制品或BOM标准产出
- if (preOutputItem) {
- // 区分已执行状态
- if (this.executeStatus === 2) {
- return (
- preOutputItem.quantity -
- (row.sumReportQuantity - row.reportQuantityCopy)
- );
- }
- return preOutputItem.quantity - row.sumReportQuantity;
- }
- // 基于物料配额限制最大可报工数量(兼容已缓存/已保存一次的编辑场景,并区分已执行状态)
- if (!this.materialQuotaInfo) return Infinity;
- const quota = this.materialQuotaInfo.materialQuota || [];
- if (!quota.length) return Infinity;
- const isExecuted = this.executeStatus === 2;
- const { baseCount } = this.materialQuotaInfo;
- if (!baseCount) return Infinity;
- // 计算每个物料的最大可报工数量
- const maxQuantities = quota.map((item) => {
- let pickItem = this.localPickDetails.find(
- (p) => p.categoryCode === item.categoryCode
- );
- // 从上一道工序产出物中找
- if (!pickItem) {
- pickItem = this.preOutputDetails.find(
- (p) => p.categoryCode === item.categoryCode
- );
- }
- if (!pickItem) {
- return Infinity;
- }
- // 单位产出所需物料比例
- const proportion = item.count / baseCount;
- // 查询其他工单 sumOutputDetails 中已产生的 BOM 标准产出和在制品的累计消耗数量
- let preOutputConsumedProportion = 0;
- // BOM标准产出
- if (
- this.materialQuotaInfo &&
- this.materialQuotaInfo.standardOutput &&
- row.categoryCode !==
- this.materialQuotaInfo.standardOutput.categoryCode
- ) {
- const preStd = this.sumOutputDetails.find(
- (s) =>
- s.categoryCode ===
- this.materialQuotaInfo.standardOutput.categoryCode
- );
- if (preStd) {
- preOutputConsumedProportion += this.formatNumber(
- preStd.sumReportQuantity * proportion
- );
- }
- }
- // 在制品
- if (
- this.categoryInfo &&
- row.categoryCode !== this.categoryInfo.categoryCode
- ) {
- const preWip = this.sumOutputDetails.find(
- (s) => s.categoryCode === this.categoryInfo.categoryCode
- );
- if (preWip) {
- preOutputConsumedProportion += this.formatNumber(
- preWip.sumReportQuantity * proportion
- );
- }
- }
- // 已执行,处理重新一键报工时,sumReportQuantity包含了当前报工数量
- let consumedQuantity = isExecuted
- ? row.sumReportQuantity - row.reportQuantityCopy
- : row.sumReportQuantity;
- // 已执行的比例换算,换算为需要多少物料数量
- const consumedProportion = this.formatNumber(
- consumedQuantity * proportion
- );
- // 最大可报工数量
- let maxQuantity =
- (pickItem.quantity -
- consumedProportion -
- preOutputConsumedProportion) /
- proportion;
- // 向下取整
- return Math.floor(maxQuantity);
- });
- // 返回最小的那个物料的最大可报工数量
- return Math.min(...maxQuantities);
- }
- return Infinity;
- },
- // 判断生成产出清单的物料数量是合格
- async validateOutputQuantities() {
- if (this.localOutputDetails.length == 0) {
- this.$message.warning(`产出清单不能为空`);
- return false;
- }
- for (const item of this.localOutputDetails) {
- if (!item.reportQuantity) {
- this.$message.warning(
- `请填写产出清单【${item.categoryName}】的当次报工数量`
- );
- return false;
- }
- }
- if (this.outputType == 1) {
- if (
- this.localPickDetails.length == 0 &&
- this.preOutputDetails.length == 0
- ) {
- this.$message.warning(`物料清单不能为空`);
- return false;
- }
- for (const item of this.localOutputDetails) {
- let pickitem = this.localPickDetails.find(
- (pick) => pick.categoryCode == item.categoryCode
- );
- // 从上一道工序产出物中找
- if (!pickitem) {
- pickitem = this.preOutputDetails.find(
- (pick) => pick.categoryCode == item.categoryCode
- );
- }
- if (!pickitem) {
- this.$message.warning(
- `所需物料【${item.categoryName}】未在物料清单中找到`
- );
- return false;
- }
- if (item.reportQuantity > item.quantity) {
- this.$message.error(
- `物料【${item.categoryName}】的报工数量不能超过领料数量`
- );
- return false;
- }
- }
- }
- return true;
- },
- // 当次报工修改
- reportQuantityChange(row) {
- // 同步当前合格数量 和 不合格数量为0
- // 默认全部合格
- row.qualifiedQuantity = row.reportQuantity;
- row.noQualifiedQuantity = 0;
- this.$emit('update:outputDetails', this.localOutputDetails);
- },
- // qualifiedQuantityChange 当次合格数量变化 计算 noQualifiedQuantity不合格数量
- qualifiedQuantityChange(row) {
- row.noQualifiedQuantity = row.reportQuantity - row.qualifiedQuantity;
- this.$emit('update:outputDetails', this.localOutputDetails);
- },
- // 不合格数量变化
- noQualifiedQuantityChange(row) {
- row.qualifiedQuantity = row.reportQuantity - row.noQualifiedQuantity;
- this.$emit('update:outputDetails', this.localOutputDetails);
- },
- localOutputDetailsRefresh() {
- if (this.outputType == 1) {
- this.$emit('refresh', 'output');
- } else if (this.outputType == 2) {
- this.getCategoryAndLevelByCategoryId();
- } else {
- this.setMaterialQuotaInfo();
- }
- },
- // 处理数字精度问题,不使用toFixed,避免4舍5入
- formatNumber(value, decimalPlaces = 4) {
- const factor = Math.pow(10, decimalPlaces);
- return Math.floor(value * factor) / factor;
- }
- }
- };
- </script>
- <style></style>
|