调机记录

This commit is contained in:
2026-01-04 11:51:05 +08:00
parent 5868f8fab9
commit c313a28435
10 changed files with 352 additions and 42 deletions

View File

@@ -0,0 +1,209 @@
<template>
<view class="form-container">
<uni-forms ref="form" :modelValue="formData" :rules="rules">
<uni-forms-item label="作业编码:" :labelWidth='90' name="pwoJobCode">
<uni-easyinput suffixIcon="scan" @iconClick="scanBar" type="text" v-model="formData.pwoJobCode" />
</uni-forms-item>
<uni-forms-item label="工单:" :labelWidth='90' name="pwoCode">
<uni-easyinput type="text" v-model="formData.pwoCode" />
</uni-forms-item>
<uni-forms-item label="产品编码:" :labelWidth='90' name="ptNoTar">
<uni-easyinput type="text" v-model="formData.ptNoTar" />
</uni-forms-item>
<uni-forms-item label="产品名称:" :labelWidth='90' name="ptTitleTar">
<uni-easyinput type="text" v-model="formData.ptTitleTar" />
</uni-forms-item>
<uni-forms-item label="制程编码:" :labelWidth='90' name="opCode">
<uni-easyinput type="text" v-model="formData.opCode" />
</uni-forms-item>
<uni-forms-item label="制程名称:" :labelWidth='90' name="opTitle">
<uni-easyinput type="text" v-model="formData.opTitle" />
</uni-forms-item>
<uni-forms-item label="结束时间:" :labelWidth='90' name="endTime">
<view class="example-body">
<uni-datetime-picker type="datetime" v-model="formData.endTime" />
</view>
</uni-forms-item>
<view class="form-row">
<uni-forms-item label="调机时长:" :labelWidth='90' name="timeTake" class="form-col">
<uni-easyinput type="text" v-model="timeTake" />
</uni-forms-item>
<uni-forms-item label="时间单位:" :labelWidth='90' name="timeUnit" class="form-col">
<uni-data-select v-model="timeUnit" :localdata="unitOptions" placeholder="选择时间单位" />
</uni-forms-item>
</view>
</uni-forms>
<u-button type="primary" @click="submit">提交</u-button>
</view>
</template>
<script>
import { addRecord } from "@/api/mes/mesMachineSetUpRecord";
import { listPwoJob } from "@/api/mes/jobReport.js";
export default {
data() {
return {
formData: {
machineAdjustmentDuration: null,
},
timeTake: null,
timeUnit: 'h',
rules: {
pwoJobCode: {
rules: [{
required: true,
errorMessage: '请扫描作业编码!'
}]
}
},
unitOptions: [
{ value: 'h', text: '小时' },
{ value: 'm', text: '分钟' },
{ value: 's', text: '秒' }
],
}
},
methods: {
scanBar() {
const _this = this;
uni.scanCode({
scanType: ['barCode', 'qrCode'],
success: function(res) {
_this.formData.pwoJobCode = res.result;
_this.scanBarCode(_this.formData.pwoJobCode);
}
});
},
scanBarCode() {
const _this = this;
if (_this.formData.pwoJobCode) {
let obj = {
code: _this.formData.pwoJobCode
}
listPwoJob(obj).then(async res => {
let jobs = res.rows;
if (jobs.length == 0) {
_this.$modal.msg("未检索到该作业编码相关的信息!");
} else {
let job = jobs[0];
_this.formData.pwoCode = job.pwoCode;
_this.formData.ptNoTar = job.ptNoTar;
_this.formData.ptTitleTar = job.ptTitleTar;
_this.formData.opCode = job.opCode;
_this.formData.opTitle = job.opTitle;
}
})
}
},
submit() {
const _this = this;
this.$refs.form.validate().then(res => {
if (_this.timeTake && _this.timeUnit && _this.formData.endTime) {
_this.changeTime();
_this.formData.startTime = _this.getCurrentDatetime();
const isLegal = new Date(_this.formData.startTime).getTime() < new Date(_this.formData.endTime).getTime();
if (!isLegal) {
_this.$modal.msg("结束时间不能早于开始时间");
return;
}
_this.$modal.loading('提交中')
addRecord(_this.formData).then(res => {
_this.$modal.closeLoading();
_this.$modal.msgSuccess("提交成功!");
_this.reset();
setTimeout(() => {
this.$tab.switchTab("/pages/work/index");
}, 500);
})
} else {
_this.$modal.msg("请将信息补充完整");
}
})
},
changeTime() {
const _this = this;
if (_this.timeUnit === 'h') {
_this.formData.machineAdjustmentDuration = _this.timeTake * 60 * 60;
} else if (_this.timeUnit === 'm') {
_this.formData.machineAdjustmentDuration = _this.timeTake * 60;
} else {
_this.formData.machineAdjustmentDuration = _this.timeTake;
}
},
getCurrentDatetime() {
const now = new Date();
// 年4位
const year = now.getFullYear();
// 月补零2位
const month = String(now.getMonth() + 1).padStart(2, '0');
// 日补零2位
const day = String(now.getDate()).padStart(2, '0');
// 时补零2位
const hour = String(now.getHours()).padStart(2, '0');
// 分补零2位
const minute = String(now.getMinutes()).padStart(2, '0');
// 秒补零2位
const second = String(now.getSeconds()).padStart(2, '0');
// 拼接为 "YYYY-MM-DD HH:mm" 格式
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
},
reset() {
this.timeTake = null;
this.timeUnit = 'h';
this.formData = {
startTime: null,
endTime: null,
pwoJobCode: null,
pwoCode: null,
ptNoTar: null,
ptTitleTar: null,
opCode: null,
opTitle: null,
machineAdjustmentDuration: null
};
}
}
}
</script>
<style scoped>
.form-container {
padding: 15px;
}
.form-row {
display: flex;
align-items: center;
gap: 15px;
/* 两个项之间的间距 */
width: 100%;
margin: 10px 0;
/* 与上下表单项保持默认间距 */
}
/* 并列项平分宽度 */
.form-col {
flex: 1;
min-width: 0;
}
/* 可选统一并列项的label样式避免对齐错乱 */
:deep(.form-col .uni-forms-item__label) {
width: 80px !important;
/* 固定label宽度 */
text-align: left;
}
/* 其他表单项保持默认样式,无需额外修改 */
:deep(.uni-forms-item) {
margin-bottom: 80px;
/* 统一所有表单项的底部间距 */
}
.u-button {
height: 10% !important;
position: absolute;
bottom: 0;
}
</style>