<template>
|
<el-table
|
height="100%"
|
ref="artificialInformationTable"
|
:data="artificialInformationList"
|
:row-style="{ height: '26px' }"
|
:cell-style="{ padding: '0' }"
|
:row-class-name="tableRowClassName"
|
row-key="id"
|
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
|
:expand-row-keys="expandRowKeys"
|
class="artificial-table"
|
>
|
<el-table-column
|
label="人工编号"
|
prop="handymanNo"
|
align="center"
|
min-width="140"
|
show-overflow-tooltip
|
></el-table-column>
|
<el-table-column
|
label="序号"
|
prop="index"
|
align="center"
|
width="45px"
|
show-overflow-tooltip
|
/>
|
<el-table-column
|
label="人工名称"
|
prop="handymanName"
|
align="center"
|
min-width="180"
|
show-overflow-tooltip
|
></el-table-column>
|
<el-table-column
|
label="人员"
|
prop="staffName"
|
align="center"
|
min-width="80"
|
></el-table-column>
|
<el-table-column
|
label="个人次数"
|
prop="personNumber"
|
align="center"
|
min-width="80"
|
>
|
<template scope="scope">
|
<!--<el-input size="small" v-model="scope.row.personNumber" placeholder="" v-if="scope.row.isUpdate"-->
|
<!--@change="changePersonNumber($event, scope.row, scope.$index)"></el-input>-->
|
<el-input
|
size="small"
|
v-model="scope.row.personNumber"
|
placeholder=""
|
v-if="scope.row.isUpdate"
|
onkeyup="this.value=this.value.match(/\d+\.?\d{0,6}/);this.dispatchEvent(new Event('input'))"
|
></el-input>
|
<template v-if="!scope.row.isUpdate">{{
|
scope.row.personNumber
|
}}</template>
|
</template>
|
</el-table-column>
|
<el-table-column
|
label="个人工时"
|
prop="workingHours"
|
align="center"
|
min-width="80"
|
>
|
<template scope="scope">
|
<el-input
|
size="small"
|
v-model="scope.row.workingHours"
|
placeholder=""
|
v-if="scope.row.isUpdate"
|
onkeyup="this.value=this.value.match(/\d+\.?\d{0,6}/);this.dispatchEvent(new Event('input'))"
|
></el-input>
|
<template v-if="!scope.row.isUpdate">{{
|
scope.row.workingHours
|
}}</template>
|
</template>
|
</el-table-column>
|
<el-table-column
|
label="个人产量"
|
prop="personOutput"
|
align="center"
|
min-width="80"
|
>
|
<template scope="scope">
|
<el-input
|
size="small"
|
v-model="scope.row.personOutput"
|
placeholder=""
|
v-if="scope.row.isUpdate"
|
onkeyup="this.value=this.value.match(/\d+\.?\d{0,6}/);this.dispatchEvent(new Event('input'))"
|
></el-input>
|
<template v-if="!scope.row.isUpdate">{{
|
scope.row.personOutput
|
}}</template>
|
</template>
|
</el-table-column>
|
<el-table-column label="备注" prop="remark" align="center" min-width="100">
|
<template scope="scope">
|
<el-input
|
size="small"
|
v-model="scope.row.remark"
|
placeholder=""
|
v-if="scope.row.isUpdate"
|
></el-input>
|
<template v-if="!scope.row.isUpdate">{{ scope.row.remark }}</template>
|
</template>
|
</el-table-column>
|
<el-table-column align="center" width="190px" fixed="right">
|
<template slot="header" slot-scope="scope">
|
<el-button
|
type="text"
|
@click="saveArtificialInformationAll()"
|
:disabled="commitLimit"
|
class="commonButton"
|
>全部保存</el-button
|
>
|
<el-button
|
type="text"
|
@click="openSelectHandymanType()"
|
:disabled="commitLimit"
|
class="commonButton"
|
>登记人工</el-button
|
>
|
</template>
|
<template slot-scope="scope">
|
<el-button
|
type="text"
|
v-if="scope.row.isUpdate && scope.row.id < 0"
|
class="commonButton"
|
@click="saveArtificialInformation(scope.$index, scope.row)"
|
:disabled="commitLimit"
|
>批量保存</el-button
|
>
|
<el-button
|
type="text"
|
v-if="!scope.row.isUpdate && scope.row.id < 0"
|
class="commonButton"
|
@click="editArtificialInformation(scope.$index, scope.row)"
|
:disabled="commitLimit"
|
>批量编辑</el-button
|
>
|
<el-button
|
type="text"
|
v-if="scope.row.isUpdate && scope.row.id > 0"
|
class="commonButton"
|
@click="saveArtificialInformation(scope.$index, scope.row)"
|
:disabled="commitLimit"
|
>保存</el-button
|
>
|
<el-button
|
type="text"
|
v-if="!scope.row.isUpdate && scope.row.id > 0"
|
class="commonButton"
|
@click="editArtificialInformation(scope.$index, scope.row)"
|
:disabled="commitLimit"
|
>编辑</el-button
|
>
|
<el-button
|
type="text"
|
class="commonButton"
|
@click="delArtificialInformation(scope.$index, scope.row)"
|
:disabled="commitLimit"
|
>删除</el-button
|
>
|
</template>
|
</el-table-column>
|
<handymanTypeDialog
|
:currshowlist.sync="showHandymanType"
|
:personList="personList"
|
:workstationId="workstationId"
|
@handleSelectionChange="selectHandymanType"
|
/>
|
</el-table>
|
</template>
|
<style lang="scss" scoped>
|
.artificial-table {
|
/deep/ .el-table__fixed-right {
|
height: 100% !important; //设置高优先,以覆盖内联样式
|
}
|
}
|
</style>
|
<script>
|
import {
|
addArtificialInformationList,
|
delArtificialInformation,
|
delArtificialInformationById,
|
putArtificialInformation,
|
putArtificialInformationById,
|
getArtificialInformationByDutyRecordId,
|
checkPersonDutyTimeById,
|
checkPersonDutyTime
|
} from '@/api/product/artificialinformation'
|
import handymanTypeDialog from './handymantype'
|
import { highPrecisionMul } from '@/util/highPrecision'
|
|
export default {
|
props: {
|
personList: {
|
type: Array,
|
default: []
|
},
|
currentDutyRecord: {
|
type: Object,
|
default: null
|
},
|
workstationId: {
|
type: Number,
|
default: null
|
},
|
commitLimit: {
|
type: Boolean,
|
default: false
|
}
|
},
|
data() {
|
return {
|
showHandymanType: false,
|
artificialInformationList: [],
|
expandRowKeys: [],
|
insertFlag: false,
|
insertHandymanTypeIds: []
|
}
|
},
|
components: {
|
handymanTypeDialog
|
},
|
watch: {
|
'currentDutyRecord.id': function(val, oldVal) {
|
if (val) {
|
this.getArtificialInformation()
|
} else {
|
this.artificialInformationList = []
|
}
|
},
|
artificialInformationList: {
|
handler: function(newVal, oldVal) {
|
if (this.insertFlag) {
|
this.expandRowKeys.length = 0
|
for (let i = 0, len = newVal.length; i < len; i++) {
|
for (
|
let j = 0, length = this.insertHandymanTypeIds.length;
|
j < length;
|
j++
|
) {
|
if (newVal[i].handymanTypeId == this.insertHandymanTypeIds[j]) {
|
this.expandRowKeys.push(newVal[i].id + '')
|
break
|
}
|
}
|
}
|
this.insertFlag = false
|
}
|
}
|
}
|
},
|
methods: {
|
// 获取人工列表
|
getArtificialInformation() {
|
if (this.currentDutyRecord != null && this.currentDutyRecord.id) {
|
getArtificialInformationByDutyRecordId(this.currentDutyRecord.id).then(
|
(response) => {
|
this.artificialInformationList = response.data.data
|
}
|
)
|
} else {
|
this.artificialInformationList = []
|
}
|
},
|
// 打开选择人工类型页面
|
openSelectHandymanType() {
|
if (this.currentDutyRecord && this.currentDutyRecord.id) {
|
this.showHandymanType = true
|
} else {
|
this.$message.warning('请先选择上班记录')
|
}
|
},
|
selectHandymanType(handymanType, personSelection) {
|
if (handymanType == null || handymanType.length == 0) {
|
this.$message.warning('请选择人工类型')
|
return
|
}
|
if (personSelection == null || personSelection.length == 0) {
|
this.$message.warning('请选择人员')
|
return
|
}
|
this.insertHandymanTypeIds.length = 0
|
const artificialInformationList = []
|
for (let j = 0, length = handymanType.length; j < length; j++) {
|
this.insertHandymanTypeIds.push(handymanType[j].id)
|
for (let i = 0, len = personSelection.length; i < len; i++) {
|
artificialInformationList.push(
|
Object.assign({
|
productionPersonId: personSelection[i].id,
|
staffName: personSelection[i].staffName,
|
handymanTypeId: handymanType[j].id,
|
handymanNo: handymanType[j].handymanNo,
|
handymanName: handymanType[j].handymanName,
|
conversionCoefficient: handymanType[j].conversionCoefficient,
|
remark: '',
|
handle: '是',
|
dutyRecordId: this.currentDutyRecord.id,
|
isUpdate: true
|
})
|
)
|
}
|
}
|
addArtificialInformationList(artificialInformationList).then(
|
(response) => {
|
this.insertFlag = true
|
this.getArtificialInformation()
|
this.$emit('refreshPersonList')
|
}
|
)
|
},
|
// 删除人工
|
delArtificialInformation(index, row) {
|
if (row.id > 0) {
|
this.$confirm(
|
'是否确认删除人工:' + (row.staffName ? row.staffName : ''),
|
'提示',
|
{
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
closeOnClickModal: false,
|
type: 'warning'
|
}
|
)
|
.then(function() {
|
return delArtificialInformationById(row.id)
|
})
|
.then((data) => {
|
this.$message.success('人工删除成功')
|
this.getArtificialInformation()
|
this.$emit('refreshPersonList')
|
})
|
.catch(() => {})
|
} else {
|
this.$confirm('是否确认批量删除人工:' + row.handymanName, '提示', {
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
closeOnClickModal: false,
|
type: 'warning'
|
})
|
.then(function() {
|
return delArtificialInformation(
|
Object.assign({
|
handymanTypeId: row.handymanTypeId,
|
dutyRecordId: row.dutyRecordId
|
})
|
)
|
})
|
.then((data) => {
|
this.$message.success('人工批量删除成功')
|
this.getArtificialInformation()
|
this.$emit('refreshPersonList')
|
})
|
.catch(() => {})
|
}
|
},
|
// 保存人工
|
saveArtificialInformation(index, row) {
|
if (row.id > 0) {
|
checkPersonDutyTimeById(row).then((response) => {
|
if (!response.data.msg) {
|
putArtificialInformationById(row).then((response) => {
|
this.$message.success('人工更新成功')
|
this.$set(row, 'isUpdate', false)
|
this.$emit('refreshPersonList')
|
})
|
} else {
|
this.$confirm(
|
response.data.msg + '请确认是否继续录入人工:',
|
'提示',
|
{
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
closeOnClickModal: false,
|
type: 'warning'
|
}
|
)
|
.then(function() {
|
return putArtificialInformationById(row)
|
})
|
.then((data) => {
|
this.$message.success('人工更新成功')
|
this.$set(row, 'isUpdate', false)
|
this.$emit('refreshPersonList')
|
})
|
.catch(() => {})
|
}
|
})
|
} else {
|
let list = row.children
|
list.forEach(e => {
|
e.personNumber = row.personNumber
|
e.personOutput = row.personOutput
|
e.workingHours = row.workingHours
|
e.remark = row.remark
|
})
|
|
checkPersonDutyTime(list).then((response) => {
|
if (!response.data.msg) {
|
putArtificialInformation(list).then((response) => {
|
this.$message.success('人工更新成功')
|
this.getArtificialInformation()
|
this.$emit('refreshPersonList')
|
})
|
} else {
|
this.$confirm(
|
response.data.msg + '请确认是否继续录入人工:',
|
'提示',
|
{
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
closeOnClickModal: false,
|
type: 'warning'
|
}
|
)
|
.then(function() {
|
return putArtificialInformation(row)
|
})
|
.then((data) => {
|
this.$message.success('人工更新成功')
|
this.getArtificialInformation()
|
this.$emit('refreshPersonList')
|
})
|
.catch(() => {})
|
}
|
})
|
}
|
},
|
saveArtificialInformationAll() {
|
const promiseList = []
|
for (
|
let i = 0, len = this.artificialInformationList.length;
|
i < len;
|
i++
|
) {
|
const children = this.artificialInformationList[i].children
|
for (let j = 0, length = children.length; j < length; j++) {
|
if (children[j].isUpdate) {
|
const promise = new Promise((resolve) => {
|
if (children[j].id) {
|
putArtificialInformationById(children[j]).then((response) => {
|
this.$set(children[j], 'isUpdate', false)
|
resolve('成功')
|
})
|
}
|
})
|
promiseList.push(promise)
|
}
|
}
|
}
|
if (promiseList.length > 0) {
|
Promise.all(promiseList).then(() => {
|
// 等所有异步请求完成后执行
|
this.$message.success('人工保存成功')
|
this.$emit('refreshPersonList')
|
})
|
} else {
|
this.$message.warning('已全部保存')
|
}
|
},
|
editArtificialInformation(index, row) {
|
this.$set(row, 'isUpdate', true)
|
},
|
// 修改个人次数,计算个人工时
|
changePersonNumber(number, row, index) {
|
this.$set(
|
row,
|
'workingHours',
|
highPrecisionMul(row.conversionCoefficient, number)
|
)
|
},
|
// 人工分组上色
|
tableRowClassName({ row, rowIndex }) {
|
if (row.id < 0) {
|
return 'danger-row'
|
}
|
return ''
|
}
|
}
|
}
|
</script>
|