TblProductionAddpgForm.vue
9.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<template>
<a-spin :spinning="confirmLoading">
<j-form-container :disabled="formDisabled">
<a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
<!-- <table style="width: 100%; text-align: center" border>
<tr>
<th style="width: 200px">工序</th>
<th style="width: 200px">承接人</th>
<th style="width: 200px">工时</th>
</tr>
<tr v-for="(item, index) in res" :key="index">
<td>
<a-form-model-item prop="gongxu" style="margin-bottom: 0px">
<a-input
v-model="item.gongxu"
style="border: none; background-color: transparent; text-align: center"
:readOnly="true"
></a-input>
</a-form-model-item>
</td>
<td>
<a-form-model-item prop="undertakerjig" style="margin-bottom: 0px">
<a-select size="small" v-model="model.undertaker" placeholder="请选择承接人" allowClear>
<a-select-option
v-for="(option, optionIndex) in options"
:key="optionIndex"
:value="option.userName"
>{{ option.userName }}</a-select-option
>
</a-select>
</a-form-model-item>
</td>
<td>
<a-form-model-item prop="workHours" style="margin-bottom: 0px">
<a-input v-model="model.workHoursjig" style="text-align: center"></a-input>
</a-form-model-item>
</td>
</tr>
</table> -->
<a-table
ref="table"
size="middle"
bordered
rowKey="id"
class="j-table-force-nowrap"
:scroll="{ x: true }"
:columns="columns"
:dataSource="res"
:pagination="false"
>
</a-table>
</a-form-model>
</j-form-container>
</a-spin>
</template>
<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
import Axios from 'axios'
import { addPg, gongxuList, queryBynumber, querygx } from '../../../api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { listSalary } from '@/api/TblSalaryBase'
import { mapGetters } from 'vuex'
export default {
name: 'TblProductionAddpgForm',
mixins: [JeecgListMixin],
components: {},
props: {
//表单禁用
disabled: {
type: Boolean,
default: false,
required: false,
},
},
data() {
return {
orderNumber: '',
productType: '',
zong: 0,
yp: 0,
options: [],
model: {},
res: [],
panduan: [],
columns: [
{
title: '工序',
align: 'center',
width: 200,
dataIndex: 'workingProcedure',
},
{
title: '承接人',
align: 'center',
dataIndex: 'undertaker',
width: 200,
scopedSlots: { customRender: 'undertaker' },
customRender: (text, record, index) => {
return (
<a-select size="small" v-model={record.undertaker} placeholder="请选择承接人" allowClear>
{this.options.map((option, optionIndex) => (
<a-select-option key={optionIndex} value={option.userName}>
{option.userName}
</a-select-option>
))}
</a-select>
)
},
},
{
title: '工时',
align: 'center',
dataIndex: 'workHours',
scopedSlots: { customRender: 'workHours' },
customRender: (text, record, index) => {
return <a-input v-model={record.workHours} style="text-align: center" />
},
},
],
labelCol: {
xs: { span: 24 },
sm: { span: 5 },
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 16 },
},
confirmLoading: false,
validatorRules: {
undertaker: [{ required: true, message: '请选择承接人!' }],
},
url: {
add: '/production/tblProductionGongxu/add',
list: '/production/tblProductionPlan/list',
queryByType: '/production/tblProductTypeGongxu/queryByType',
},
}
},
computed: {
formDisabled() {
return this.disabled
},
},
created() {
//备份model原始值
// this.modelDefault = JSON.parse(JSON.stringify(this.model))
this.loadUser()
},
methods: {
loadUser() {
var that = this
listSalary().then((res) => {
if (res.success) {
// that.treeData = [];
that.options = res.result
}
})
},
add(record) {
console.log('产品类型:', record.productType)
this.productType = record.productType
this.panduan = record
gongxuList(this.url.queryByType, { productTypeId: record.productType }).then((ress) => {
if (ress) {
//如果已派工时为0总工时*工时比例,否则(总工时-已派工时)*工时比例
console.log(record.dispatchedWorkingHours)
if (record.dispatchedWorkingHours <= 0 || record.dispatchedWorkingHours === '') {
console.log('aa', ress.result)
console.log(record.totalWorkingHours)
// 将获取到的工序列表添加到数据源中
this.res = ress.result.map((item) => ({
workingProcedure: item.gongxu + ' (' + (item.bili * 100).toFixed() + '%)',
undertaker: '', // 初始为空,等待用户输入
workHours: parseFloat((record.totalWorkingHours * item.bili).toFixed(2))
.toString()
.replace(/(\.\d*?[1-9])0+$/, '$1'), // 初始为空,等待用户输入
dispatchTime: new Date(),
orderNumber: record.orderId,
dispatchRen: this.userInfo().realname,
productType: record.productType,
}))
} else if (record.dispatchedWorkingHours > 0) {
console.log('bb', ress.result)
console.log(record.totalWorkingHours)
// 将获取到的工序列表添加到数据源中
this.res = ress.result.map((item) => ({
workingProcedure: item.gongxu + ' (' + (item.bili * 100).toFixed() + '%)',
undertaker: '', // 初始为空,等待用户输入
workHours: parseFloat(((record.totalWorkingHours - record.dispatchedWorkingHours) * item.bili).toFixed(2))
.toString()
.replace(/(\.\d*?[1-9])0+$/, '$1'), // 初始为空,等待用户输入
dispatchTime: new Date(),
orderNumber: record.orderId,
dispatchRen: this.userInfo().realname,
productType: record.productType,
}))
}
}
})
console.log('派发人:', this.userInfo().realname)
},
...mapGetters(['nickname', 'avatar', 'userInfo']),
submitForm() {
const that = this
// 构造数据对象数组
let data = []
// 触发表单验证
this.$refs.form.validate((valid) => {
if (valid) {
// 过滤出承接人不为空的记录
const nonEmptyUndertakerRecords = this.res.filter((record) => record.undertaker)
if (nonEmptyUndertakerRecords.length>0) {
// 检查是否所有输入框的值都是数字
const allNumeric = this.res.every((record) => /^\d+(\.\d+)?$/.test(record.workHours))
if (allNumeric) {
that.confirmLoading = true
data=nonEmptyUndertakerRecords;
console.log('res:', this.res)
// 使用 reduce 方法累加工时字段值
const zong = this.res.reduce((acc, current) => {
console.log('current.workhours:', current.workHours)
return acc + parseFloat(current.workHours)
}, 0)
console.log(this.panduan.dispatchedWorkingHours)
if (this.panduan.dispatchedWorkingHours === '' || this.panduan.dispatchedWorkingHours === null) {
this.panduan.dispatchedWorkingHours = 0
}
console.log(this.panduan.dispatchedWorkingHours)
const zongpaifa = parseFloat(this.panduan.dispatchedWorkingHours) + zong
console.log('派发工时和:', zong)
console.log('已派发工时:', zongpaifa)
if (zongpaifa <= this.panduan.totalWorkingHours) {
addPg(this.url.add, data)
.then((res) => {
if (res.success) {
that.$message.success(res.message)
that.$emit('ok')
} else {
that.$message.warning(res.message)
}
})
.finally(() => {
that.confirmLoading = false
})
} else if (zongpaifa > this.panduan.totalWorkingHours) {
that.$message.error('派发工时超过总工时')
that.confirmLoading = false
}
} else {
that.$message.error('工时格式错误')
that.confirmLoading = false
}
} else {
that.$message.error('没有派工给承接人')
that.confirmLoading = false
}
}
})
},
},
}
</script>
<style lang="less" scoped>
.input_dis {
border-color: #91d5ff;
background-color: #e6f7ff;
}
</style>