<template>
|
<el-dialog
|
width="60%"
|
title="新增生产记录"
|
:visible.sync="innerVisible"
|
append-to-body
|
@close="$emit('update:currshowlist', false)"
|
:show="currshowlist"
|
:close-on-click-modal="false"
|
>
|
<div class="product-record-form-header">
|
<div>
|
<span>生产模板</span>
|
<el-select
|
v-model="selectedTemplateId"
|
placeholder="生产记录模板"
|
filterable
|
@change="getParamValues"
|
>
|
<el-option
|
v-for="item in paramTemplates"
|
:key="item.id"
|
:label="item.templateName"
|
:value="item.id"
|
/>
|
</el-select>
|
</div>
|
<div style="display:flex;margin-left:10px ;">
|
<div>
|
<span style="line-height:30px;">产出零件:</span>
|
</div>
|
<div>
|
<el-popover
|
ref="popover"
|
placement="bottom-start"
|
trigger="manual"
|
width="800"
|
v-model="popoverVisible"
|
>
|
<productoutputList
|
:paramObj="paramObj"
|
ref="outputlist"
|
:outBatchNo="part"
|
@listenToproductionEvent="selectProductOutPut"
|
></productoutputList>
|
<el-button @click="popoverVisible = false" style="float:right"
|
>关闭</el-button
|
>
|
</el-popover>
|
<el-input
|
ref="outBatchInput"
|
v-model="part"
|
slot="reference"
|
placeholder="扫入零件批次"
|
@input="throttle"
|
>
|
<el-button
|
slot="append"
|
icon="el-icon-search"
|
@click.stop="openProductOutPutDialog()"
|
></el-button>
|
</el-input>
|
</div>
|
</div>
|
</div>
|
<div class="product-record-form-header">
|
<div>
|
<span>分割模板</span>
|
<el-select
|
v-model="selectedTemplateIds"
|
placeholder="分割记录模板"
|
filterable
|
@change="getParamValuesi"
|
>
|
<el-option
|
v-for="item in paramTemplatesList"
|
:key="item.id"
|
:label="item.templateName"
|
:value="item.id"
|
/>
|
</el-select>
|
</div>
|
<div style="display:flex;margin-left:10px ;">
|
<div>
|
<span style="line-height:30px;">分割零件:</span>
|
</div>
|
<div>
|
<el-popover
|
ref="popover"
|
placement="bottom-start"
|
trigger="manual"
|
width="800"
|
v-model="popoverVisibles"
|
>
|
<productoutputList
|
:paramObj="paramObjs"
|
ref="outputlists"
|
:outBatchNo="parts"
|
@listenToproductionEvent="selectProductOutPuts"
|
></productoutputList>
|
<el-button @click="popoverVisibles = false" style="float:right"
|
>关闭</el-button
|
>
|
</el-popover>
|
<el-input
|
ref="outBatchInput"
|
v-model="parts"
|
slot="reference"
|
placeholder="扫入零件批次"
|
@input="throttles"
|
>
|
<el-button
|
slot="append"
|
icon="el-icon-search"
|
@click.stop="openProductOutPutDialogs()"
|
></el-button>
|
</el-input>
|
</div>
|
</div>
|
</div>
|
<div class="table">
|
<div class="table-sn">
|
<el-table :data="outputPartsList" :border="true">
|
<el-table-column label="序号" type="index"></el-table-column>
|
<el-table-column label="SN号">
|
<template slot-scope="scope">
|
{{ scope.row.outBatchNo || scope.row.partBatchNo }}
|
</template>
|
</el-table-column>
|
<el-table-column label="操作">
|
<template slot-scope="scope">
|
<el-button
|
size="mini"
|
type="danger"
|
@click="handleDelete(scope.$index, scope.row)"
|
>删除</el-button
|
>
|
</template>
|
</el-table-column>
|
</el-table>
|
</div>
|
<div class="table-product">
|
<el-table
|
ref="productRecordFormTable"
|
:data="params"
|
height="500px"
|
:row-class-name="productRecordFormTableRowClassName"
|
class="product-record-form-table"
|
:border="true"
|
>
|
<el-table-column prop="parameterItem" label="名称" align="center">
|
<template slot-scope="scope">
|
<span>{{ scope.row.parameterItem }}({{ scope.row.unit }})</span>
|
</template>
|
</el-table-column>
|
<el-table-column
|
prop="type"
|
label="参数类型"
|
align="center"
|
:formatter="getParam"
|
></el-table-column>
|
<el-table-column prop="paramValue" label="值" align="center">
|
<template slot-scope="scope">
|
<!-- <el-input v-model="scope.row.paramValue" placeholder="值"></el-input> -->
|
<el-input
|
v-model="scope.row.paramValue"
|
placeholder="值"
|
v-if="scope.row.type != 2"
|
:ref="'reference_' + scope.$index"
|
@keyup.enter.native="nextFocus(scope.$index)"
|
></el-input>
|
<el-select
|
v-if="scope.row.type == 2"
|
:ref="'reference_' + scope.$index"
|
v-model="scope.row.paramValue"
|
style="width:100%"
|
>
|
<el-option
|
v-for="item in scope.row.sysDictItemList"
|
:key="item.value"
|
:label="item.label"
|
:value="item.value"
|
/>
|
</el-select>
|
</template>
|
</el-table-column>
|
</el-table>
|
</div>
|
</div>
|
<div slot="footer" class="dialog-footer">
|
<el-button @click="innerVisible = false">取 消</el-button>
|
<el-button
|
type="primary"
|
:disabled="saveDisabled"
|
v-thinclick="`saveProductRecord`"
|
>
|
确 定
|
</el-button>
|
</div>
|
<productoutputDialog
|
:currshowlist.sync="showProductOutPut"
|
:paramObj="paramObj"
|
:outBatchNo="part"
|
@listenToproductionEvent="selectProductOutPut"
|
/>
|
<productoutputDialogs
|
:currshowlist.sync="showProductOutPuts"
|
:paramObj="paramObjs"
|
:outBatchNo="parts"
|
@listenToproductionEvent="selectProductOutPuts"
|
/>
|
</el-dialog>
|
</template>
|
<style lang="scss" scoped>
|
.table {
|
display: flex;
|
justify-content: space-between;
|
.table-sn {
|
flex: 0.35;
|
}
|
.table-product {
|
flex: 0.6;
|
}
|
}
|
.product-record-form-table >>> .stripe-row {
|
background: #f6f9fe;
|
}
|
.product-record-form-header {
|
display: flex;
|
justify-content: flex-start;
|
margin-bottom: 10px;
|
}
|
</style>
|
<script>
|
import productoutputDialog from './productoutput-dialog.vue'
|
import productoutputDialogs from './product-record-form-list.vue'
|
import productoutputList from '@/views/product/workbench/productoutput-list'
|
import {
|
fetchOutputList,
|
fetchOutputLists,
|
getOutputListByScan
|
} from '@/api/quality/apply'
|
import {
|
getTemplateUpdate,
|
getTemplateUpdates,
|
addTemplateRecord as addProductRecord
|
} from '@/api/plan/operationtask'
|
import { getOperationParamLast as getParams } from '@/api/basic/template'
|
import { remote as dictRemote } from '@/api/admin/dict'
|
|
export default {
|
components: {
|
productoutputDialog,
|
productoutputDialogs,
|
productoutputList
|
},
|
props: {
|
currshowlist: {
|
type: Boolean,
|
default: false
|
},
|
currOperateTask: {
|
type: Object,
|
default: () => {
|
return {}
|
}
|
},
|
currentDutyRecord: {
|
type: Object,
|
default: () => {
|
return {}
|
}
|
},
|
workstationId: {
|
type: Number
|
},
|
currTemplateType: {
|
type: String
|
},
|
createDateRange: {
|
type: Array
|
}
|
},
|
data() {
|
return {
|
popoverVisible: false,
|
popoverVisibles: false,
|
innerVisible: false,
|
params: [],
|
saveDisabled: false,
|
selectedTemplateId: null,
|
selectedTemplateIds: null,
|
paramTemplates: [], // 参数集模板
|
paramTemplatesList: [],
|
cutAparyList: [],
|
typeOptions: [],
|
part: null,
|
parts: null,
|
paramObj: {
|
workstationId: null,
|
startTime: '',
|
endTime: ''
|
},
|
paramObjs: {
|
workstationId: null,
|
startTime: '',
|
endTime: ''
|
},
|
showProductOutPut: false,
|
showProductOutPuts: false,
|
productOutId: null,
|
outputPartsList: [],
|
title: '',
|
idList: [],
|
idLists: [],
|
cutApartList: [],
|
produceList: [],
|
debounceTimer: null,
|
scanArr: [],
|
scanArrs: [],
|
timer: null,
|
startTime: '',
|
endTime: '',
|
createDateRangeArr: []
|
}
|
},
|
methods: {
|
productRecordFormTableRowClassName({ row, rowIndex }) {
|
if (rowIndex % 2 === 1) {
|
return 'stripe-row'
|
} else {
|
return ''
|
}
|
},
|
// debounce(callback, duration, isFirstExecution) {
|
// return function(...args) {
|
// const ctx = this
|
// const delay = function() {
|
// this.debounceTimer = null
|
// console.log('定时器函数执行了')
|
// if (!isFirstExecution) callback.apply(ctx, args)
|
// }
|
// const executeNow = isFirstExecution && !this.debounceTimer
|
// clearTimeout(this.debounceTimer)
|
// this.debounceTimer = setTimeout(delay, duration)
|
// if (executeNow) callback.apply(ctx, args)
|
// }
|
// },
|
throttle() {
|
if (this.timer) {
|
clearTimeout(this.timer)
|
}
|
this.timer = setTimeout(() => {
|
this.inputChange()
|
}, 500)
|
},
|
throttles() {
|
if (this.timer) {
|
clearTimeout(this.timer)
|
}
|
this.timer = setTimeout(() => {
|
this.inputChanges()
|
}, 500)
|
},
|
getNowFormatDate() {
|
const date = new Date()
|
const year = date.getFullYear() // 获取完整的年份(4位)
|
let month = date.getMonth() + 1 // 获取当前月份(0-11,0代表1月)
|
let strDate = date.getDate() // 获取当前日(1-31)
|
if (month < 10) month = `0${month}` // 如果月份是个位数,在前面补0
|
if (strDate < 10) strDate = `0${strDate}` // 如果日是个位数,在前面补0
|
return `${year}${month}${strDate}`
|
},
|
inputChange() {
|
if (this.part) {
|
this.paramObj.workstationId = this.workstationId
|
// this.$refs.outputlists.getData(val)
|
// const obj = { dateTimeFilters: {}, orderBy: {} }
|
if (
|
this.createDateRangeArr === null ||
|
this.createDateRangeArr.length == 0
|
) {
|
this.startTime = this.getNowFormatDate()
|
this.endTime = this.getNowFormatDate()
|
} else if (this.createDateRangeArr.length !== 0) {
|
this.startTime = this.createDateRangeArr[0].split('-').join('')
|
this.endTime = this.createDateRangeArr[1].split('-').join('')
|
}
|
getOutputListByScan({
|
// current: 1,
|
// size: 20,
|
workstationId: this.workstationId,
|
outBatchNo: this.part,
|
startTime: this.startTime,
|
endTime: this.endTime
|
// criteria: JSON.stringify(obj)
|
}).then((res) => {
|
console.log(res.data.data.length)
|
if (res.data.data.length) {
|
const arr = []
|
arr.push(res.data.data[0])
|
for (let i = 0; i < arr.length; i++) {
|
if (!this.outputPartsList.some((e) => e.id == arr[i].id))
|
this.outputPartsList.push(arr[i])
|
}
|
// const arr1 = []
|
this.scanArr.push(res.data.data[0].id)
|
this.idList = [...new Set(this.scanArr)]
|
this.part = null
|
console.log(this.idList)
|
}
|
})
|
}
|
},
|
inputChanges() {
|
if (this.parts) {
|
this.paramObjs.workstationId = this.workstationId
|
// this.$refs.outputlists.getData(val)
|
if (
|
this.createDateRangeArr === null ||
|
this.createDateRangeArr.length == 0
|
) {
|
this.startTime = this.getNowFormatDate()
|
this.endTime = this.getNowFormatDate()
|
} else if (this.createDateRangeArr.length !== 0) {
|
this.startTime = this.createDateRangeArr[0].split('-').join('')
|
this.endTime = this.createDateRangeArr[1].split('-').join('')
|
}
|
fetchOutputLists({
|
current: 1,
|
size: 20,
|
workstationId: this.workstationId,
|
partBatchNo: this.parts,
|
startTime: this.startTime,
|
endTime: this.endTime
|
}).then((res) => {
|
if (res.data.data.records.length) {
|
const arr = []
|
arr.push(res.data.data.records[0])
|
for (let i = 0; i < arr.length; i++) {
|
if (!this.outputPartsList.some((e) => e.id == arr[i].id))
|
this.outputPartsList.push(arr[i])
|
}
|
// const arr1 = []
|
this.scanArrs.push(res.data.data.records[0].id)
|
this.idLists = [...new Set(this.scanArrs)]
|
this.parts = null
|
}
|
})
|
}
|
},
|
// 获取参数集生产模板
|
getParamTemplates() {
|
if (this.currOperateTask.id) {
|
getTemplateUpdate(
|
this.currOperateTask.id,
|
Object.assign({
|
dataType: '生产记录',
|
templateType: this.currTemplateType
|
})
|
).then((response) => {
|
if (response.data.code === 0) {
|
this.paramTemplates = response.data.data.records
|
} else {
|
this.paramTemplates = []
|
}
|
})
|
}
|
getTemplateUpdates(
|
Object.assign({
|
dataType: '生产记录',
|
templateType: this.currTemplateType
|
})
|
).then((response) => {
|
console.log(response)
|
this.paramTemplatesList = response.data.data.records
|
})
|
},
|
// 获取参数集分割模板
|
// getCutApart() {
|
// getTemplateUpdate(
|
// Object.assign({
|
// dataType: '分割记录',
|
// templateType: this.currTemplateType
|
// })
|
// ).then((response) => {
|
// // if (response.data.code === 0) {
|
// // this.paramTemplates = response.data.data.records
|
// // } else {
|
// // this.paramTemplates = []
|
// // }
|
// console.log(response)
|
// })
|
// },
|
getParamValues() {
|
this.params = []
|
var templateJson = {
|
workstationId: this.currentDutyRecord.workstationId,
|
technologyOperationTemplateId: this.selectedTemplateId
|
}
|
getParams(templateJson).then((response) => {
|
if (response.data.code === 0) {
|
const list = response.data.data
|
list.forEach((item) => {
|
item.paramValue = item.defaultValue ? item.defaultValue : null
|
})
|
this.params = JSON.parse(JSON.stringify(list))
|
}
|
})
|
console.log(this.selectedTemplateId)
|
},
|
getParamValuesi() {
|
this.params = []
|
var templateJson = {
|
workstationId: this.currentDutyRecord.workstationId,
|
technologyOperationTemplateId: this.selectedTemplateIds
|
}
|
getParams(templateJson).then((response) => {
|
if (response.data.code === 0) {
|
const list = response.data.data
|
list.forEach((item) => {
|
item.paramValue = item.defaultValue ? item.defaultValue : null
|
})
|
this.params = JSON.parse(JSON.stringify(list))
|
}
|
})
|
console.log(this.selectedTemplateIds)
|
},
|
saveProductRecord() {
|
this.saveDisabled = true
|
if (this.params != null && this.params.length > 0) {
|
// const formdata = new FormData()
|
const paramValueArray = []
|
var paramValue
|
if (this.currOperateTask.id) {
|
for (var i = 0; i < this.params.length; i++) {
|
paramValue = {
|
id: this.params[i].id,
|
code: this.params[i].code,
|
parameterItem: this.params[i].parameterItem,
|
type: this.params[i].type,
|
unit: this.params[i].unit,
|
paramValue: this.params[i].paramValue,
|
operationTemplateId: this.selectedTemplateId,
|
operationTaskRecordId: null,
|
technologyOperationParamId: this.params[i].id,
|
operationTaskId: this.currOperateTask.id
|
}
|
paramValueArray.push(paramValue)
|
}
|
this.obj = {
|
operationTaskId: this.currOperateTask.id,
|
operationTemplateId: this.selectedTemplateId
|
? this.selectedTemplateId
|
: this.selectedTemplateIds,
|
dutyRecordId: this.currentDutyRecord.id,
|
workstationId: this.workstationId,
|
productOutIdList: this.idList,
|
segmentationIdList: this.idLists,
|
operationTaskParamList: JSON.stringify(paramValueArray)
|
}
|
} else {
|
for (var j = 0; j < this.params.length; j++) {
|
paramValue = {
|
id: this.params[j].id,
|
code: this.params[j].code,
|
parameterItem: this.params[j].parameterItem,
|
type: this.params[j].type,
|
unit: this.params[j].unit,
|
paramValue: this.params[j].paramValue,
|
operationTemplateId: this.selectedTemplateIds,
|
operationTaskRecordId: null,
|
technologyOperationParamId: this.params[j].id,
|
operationTaskId: this.currOperateTask.id
|
}
|
paramValueArray.push(paramValue)
|
}
|
this.obj = {
|
operationTemplateId: this.selectedTemplateIds,
|
dutyRecordId: this.currentDutyRecord.id,
|
workstationId: this.workstationId,
|
productOutIdList: this.idList,
|
segmentationIdList: this.idLists,
|
operationTaskParamList: JSON.stringify(paramValueArray)
|
}
|
}
|
// formdata.append('operationTaskId', this.currOperateTask.id)
|
// formdata.append('operationTemplateId', this.selectedTemplateId)
|
// formdata.append('dutyRecordId', this.currentDutyRecord.id)
|
// formdata.append('workstationId', this.workstationId)
|
// if (this.idList != null) {
|
// formdata.append('productOutIdList', JSON.stringify(this.idList))
|
// }
|
// formdata.append(
|
// 'operationTaskParamList',
|
// JSON.stringify(paramValueArray)
|
// )
|
addProductRecord(this.obj)
|
.then((response) => {
|
if (response.data.code === 0) {
|
this.innerVisible = false
|
this.idList = []
|
this.$emit('saveProductRecordSucess', response.data.data.id)
|
this.$message.success('保存成功')
|
} else {
|
this.$message.error('保存失败')
|
this.saveDisabled = false
|
}
|
})
|
.catch(() => {
|
this.saveDisabled = false
|
})
|
} else {
|
this.$message.error('无参数值可以进行保存')
|
this.saveDisabled = false
|
}
|
},
|
// 获取工序参数类型
|
getParamType() {
|
dictRemote('technology_param').then((response) => {
|
if (response.data.code === 0) {
|
this.typeOptions = response.data.data
|
} else {
|
this.typeOptions = []
|
}
|
})
|
},
|
// 表格字段格式化
|
getParam(row, column, cellValue) {
|
for (let i = 0, len = this.typeOptions.length; i < len; i++) {
|
if (cellValue == this.typeOptions[i].value) {
|
return this.typeOptions[i].label
|
}
|
}
|
},
|
// 打开产出记录dialog
|
openProductOutPutDialog() {
|
this.part = null
|
this.paramObj.workstationId = this.workstationId
|
this.showProductOutPut = true
|
},
|
openProductOutPutDialogs() {
|
this.parts = null
|
this.paramObjs.workstationId = this.workstationId
|
this.showProductOutPuts = true
|
},
|
openProductOutPutDialogByScan() {
|
this.paramObj.workstationId = this.workstationId
|
this.showProductOutPut = true
|
},
|
openProductOutPutDialogByScans() {
|
this.paramObjs.workstationId = this.workstationId
|
this.showProductOutPuts = true
|
},
|
// 选择某个产出记录
|
selectProductOutPut(val) {
|
this.productOutId = null
|
// this.part = null
|
this.popoverVisible = false
|
if (val) {
|
// this.part = val.systemNo + ' ' + val.outBatchNo
|
this.part = val.outBatchNo
|
this.productOutId = val.id
|
console.log(this.part)
|
const forData = []
|
console.log(val)
|
forData.push(val)
|
console.log(forData)
|
for (let i = 0; i < forData.length; i++) {
|
if (!this.produceList.some((e) => e.id === forData[i].id))
|
this.produceList.push(forData[i])
|
}
|
for (let i = 0; i < this.produceList.length; i++) {
|
if (
|
!this.outputPartsList.some((e) => e.id === this.produceList[i].id)
|
)
|
this.outputPartsList.push(this.produceList[i])
|
}
|
// const arr = []
|
// this.idList = []
|
this.produceList.forEach((item) => {
|
this.idList.push(item.id)
|
})
|
// arr1 = [...new Set(arr)]
|
for (var i = 0; i < this.idList.length; i++) {
|
for (var j = i + 1; j < this.idList.length; j++) {
|
if (this.idList[i] == this.idList[j]) {
|
this.idList.splice(j, 1)
|
|
j--
|
}
|
}
|
}
|
// this.idList = [...new Set(arr)]
|
console.log(this.outputPartsList)
|
console.log(this.idList)
|
}
|
},
|
selectProductOutPuts(val) {
|
this.productOutId = null
|
// this.part = null
|
this.popoverVisibles = false
|
|
if (val) {
|
// this.part = val.systemNo + ' ' + val.outBatchNo
|
this.parts = val.partBatchNo
|
this.productOutId = val.id
|
console.log(this.parts)
|
const forData = []
|
console.log(val)
|
forData.push(val)
|
console.log(forData)
|
for (let i = 0; i < forData.length; i++) {
|
if (!this.cutApartList.some((e) => e.id === forData[i].id))
|
this.cutApartList.push(forData[i])
|
}
|
for (let i = 0; i < this.cutApartList.length; i++) {
|
if (
|
!this.outputPartsList.some((e) => e.id === this.cutApartList[i].id)
|
)
|
this.outputPartsList.push(this.cutApartList[i])
|
}
|
// const arr = []
|
// this.idLists = []
|
this.cutApartList.forEach((item) => {
|
this.idLists.push(item.id)
|
})
|
for (var i = 0; i < this.idLists.length; i++) {
|
for (var j = i + 1; j < this.idLists.length; j++) {
|
if (this.idLists[i] == this.idLists[j]) {
|
this.idLists.splice(j, 1)
|
|
j--
|
}
|
}
|
}
|
// this.idLists = [...new Set(arr)]
|
console.log(this.outputPartsList)
|
console.log(this.idLists)
|
}
|
},
|
handleDelete(index, row) {
|
console.log(index, row)
|
this.outputPartsList = this.outputPartsList.filter(
|
(item) => item.id !== row.id
|
)
|
this.idList = this.idList.filter((item) => item !== row.id)
|
this.idLists = this.idLists.filter((item) => item !== row.id)
|
this.produceList = this.produceList.filter((item) => item.id !== row.id)
|
this.cutApartList = this.cutApartList.filter((item) => item.id !== row.id)
|
|
console.log(this.idList)
|
console.log(this.outputPartsList)
|
},
|
// 回车换行
|
nextFocus(index) {
|
index++
|
this.$refs['reference_' + index].focus()
|
}
|
},
|
watch: {
|
currshowlist() {
|
this.innerVisible = this.currshowlist
|
if (!this.innerVisible) {
|
this.popoverVisible = false
|
}
|
if (this.currshowlist) {
|
this.createDateRangeArr = this.createDateRange
|
if (
|
this.createDateRangeArr === null ||
|
this.createDateRangeArr.length == 0
|
) {
|
this.paramObj.startTime = this.getNowFormatDate()
|
this.paramObj.endTime = this.getNowFormatDate()
|
this.paramObjs.startTime = this.getNowFormatDate()
|
this.paramObjs.endTime = this.getNowFormatDate()
|
console.log(123456)
|
} else if (this.createDateRangeArr.length !== 0) {
|
console.log(123456)
|
this.paramObj.startTime = this.createDateRangeArr[0]
|
.split('-')
|
.join('')
|
this.paramObj.endTime = this.createDateRangeArr[1].split('-').join('')
|
this.paramObjs.startTime = this.createDateRangeArr[0]
|
.split('-')
|
.join('')
|
this.paramObjs.endTime = this.createDateRangeArr[1]
|
.split('-')
|
.join('')
|
}
|
this.saveDisabled = false
|
this.getParamType()
|
this.selectedTemplateId = null
|
this.selectedTemplateIds = null
|
this.productOutId = null
|
this.part = null
|
this.parts = null
|
this.params = []
|
this.paramTemplates = []
|
this.paramTemplatesList = []
|
this.outputPartsList = []
|
this.cutApartList = []
|
this.produceList = []
|
this.idList = []
|
this.idLists = []
|
this.scanArr = []
|
this.scanArrs = []
|
this.getParamTemplates()
|
}
|
}
|
}
|
}
|
</script>
|