<template>
|
<view class="process-edit">
|
<PageHeader :title="pageTitle"
|
@back="goBack" />
|
<up-form ref="formRef"
|
:model="form"
|
:rules="rules"
|
:errorType="['none']"
|
label-width="130">
|
<up-form-item label="部件"
|
prop="name"
|
required>
|
<up-input v-model="form.name"
|
placeholder="请输入部件"
|
clearable />
|
</up-form-item>
|
<up-form-item label="工序编号"
|
prop="no">
|
<up-input v-model="form.no"
|
placeholder="请输入工序编号"
|
clearable />
|
</up-form-item>
|
<up-form-item label="工序类型"
|
prop="processType"
|
required>
|
<up-input v-model="processTypeText"
|
placeholder="请选择工序类型"
|
readonly
|
@click="showProcessTypeSheet = true" />
|
<template #right>
|
<up-icon name="arrow-right"
|
@click="showProcessTypeSheet = true"></up-icon>
|
</template>
|
</up-form-item>
|
<up-form-item label="计划工时(小时)"
|
prop="salaryQuota">
|
<up-input v-model="form.salaryQuota"
|
type="number"
|
placeholder="请输入计划工时"
|
clearable />
|
</up-form-item>
|
<up-form-item label="计划人员"
|
prop="planPerson">
|
<up-input v-model="planPersonText"
|
placeholder="请选择计划人员"
|
readonly
|
@click="showPlanPersonSheet = true" />
|
<template #right>
|
<up-icon name="arrow-right"
|
@click="showPlanPersonSheet = true"></up-icon>
|
</template>
|
</up-form-item>
|
<up-form-item label="计划执行人员"
|
prop="executor">
|
<up-input v-model="executorText"
|
placeholder="请选择计划执行人员"
|
readonly
|
@click="showExecutorSheet = true" />
|
<template #right>
|
<up-icon name="arrow-right"
|
@click="showExecutorSheet = true"></up-icon>
|
</template>
|
</up-form-item>
|
<up-form-item label="是否质检"
|
prop="isQuality">
|
<view style="display: flex; justify-content: flex-end; width: 100%;">
|
<up-switch v-model="form.isQuality" />
|
</view>
|
</up-form-item>
|
<up-form-item label="是否入库"
|
prop="inbound">
|
<view style="display: flex; justify-content: flex-end; width: 100%;">
|
<up-switch v-model="form.inbound" />
|
</view>
|
</up-form-item>
|
<up-form-item label="是否报工"
|
prop="reportWork">
|
<view style="display: flex; justify-content: flex-end; width: 100%;">
|
<up-switch v-model="form.reportWork" />
|
</view>
|
</up-form-item>
|
<up-form-item label="备注"
|
prop="remark">
|
<up-textarea v-model="form.remark"
|
placeholder="请输入备注"
|
autoHeight />
|
</up-form-item>
|
</up-form>
|
<FooterButtons :loading="loading"
|
:confirmText="processId ? '保存' : '新增'"
|
@cancel="goBack"
|
@confirm="handleSubmit" />
|
<!-- 工序类型选择 -->
|
<up-action-sheet :show="showProcessTypeSheet"
|
title="选择工序类型"
|
:actions="processTypeActions"
|
@select="onSelectProcessType"
|
@close="showProcessTypeSheet = false" />
|
<!-- 计划人员选择 -->
|
<up-action-sheet :show="showPlanPersonSheet"
|
title="选择计划人员"
|
:actions="employeeActions"
|
@select="onSelectPlanPerson"
|
@close="showPlanPersonSheet = false" />
|
<!-- 计划执行人员选择 -->
|
<up-action-sheet :show="showExecutorSheet"
|
title="选择计划执行人员"
|
:actions="employeeActions"
|
@select="onSelectExecutor"
|
@close="showExecutorSheet = false" />
|
</view>
|
</template>
|
|
<script setup>
|
import { reactive, ref, computed, onMounted } from "vue";
|
import { onLoad, onReady } from "@dcloudio/uni-app";
|
import FooterButtons from "@/components/FooterButtons.vue";
|
import { add, update } from "@/api/productionManagement/processManagement";
|
import { staffOnJobListPage } from "@/api/personnelManagement/onboarding";
|
|
const formRef = ref(null);
|
const loading = ref(false);
|
const processId = ref(null);
|
const pageTitle = computed(() => (processId.value ? "编辑工序" : "新增工序"));
|
|
const processTypeOptions = [
|
"机加工",
|
"刮板冷芯制作",
|
"管路组对",
|
"罐体连接及调试",
|
"测试打压",
|
"其他",
|
];
|
|
const employeeList = ref([]);
|
|
const form = ref({
|
no: "",
|
name: "",
|
processType: "",
|
salaryQuota: "",
|
planPerson: null,
|
executor: null,
|
isQuality: false,
|
inbound: false,
|
reportWork: false,
|
remark: "",
|
});
|
|
const rules = {
|
name: [
|
{ required: true, message: "请输入部件" },
|
{ max: 100, message: "最多100个字符" },
|
],
|
processType: [{ required: true, message: "请选择工序类型" }],
|
salaryQuota: [
|
{
|
validator: (rule, value, callback) => {
|
if (value !== "" && value !== null && (isNaN(value) || value < 0)) {
|
callback(new Error("计划工时必须是非负数字"));
|
} else {
|
callback();
|
}
|
},
|
},
|
],
|
};
|
|
const showProcessTypeSheet = ref(false);
|
const processTypeActions = processTypeOptions.map(item => ({ name: item, value: item }));
|
const processTypeText = ref("");
|
|
const showPlanPersonSheet = ref(false);
|
const showExecutorSheet = ref(false);
|
const planPersonText = ref("");
|
const executorText = ref("");
|
|
const employeeActions = computed(() =>
|
employeeList.value.map(item => ({
|
name: item.staffName,
|
id: item.id,
|
}))
|
);
|
|
const onSelectProcessType = e => {
|
form.value.processType = e.value;
|
processTypeText.value = e.name;
|
showProcessTypeSheet.value = false;
|
};
|
|
const onSelectPlanPerson = e => {
|
form.value.planPerson = e.id;
|
planPersonText.value = e.name;
|
showPlanPersonSheet.value = false;
|
};
|
|
const onSelectExecutor = e => {
|
form.value.executor = e.id;
|
executorText.value = e.name;
|
showExecutorSheet.value = false;
|
};
|
|
const loadEmployees = async () => {
|
try {
|
const res = await staffOnJobListPage({ current: -1, size: -1, staffState: 1 });
|
employeeList.value = res.data?.records || [];
|
} catch (error) {
|
console.error("加载员工列表失败", error);
|
}
|
};
|
|
const resolveDisplayTexts = () => {
|
if (form.value.processType) {
|
processTypeText.value = form.value.processType;
|
}
|
if (form.value.planPerson) {
|
const emp = employeeList.value.find(e => e.id === form.value.planPerson);
|
if (emp) planPersonText.value = emp.staffName;
|
}
|
if (form.value.executor) {
|
const emp = employeeList.value.find(e => e.id === form.value.executor);
|
if (emp) executorText.value = emp.staffName;
|
}
|
};
|
|
const goBack = () => {
|
uni.navigateBack();
|
};
|
|
const handleSubmit = () => {
|
formRef.value
|
.validate()
|
.then(() => {
|
loading.value = true;
|
const promise = processId.value ? update(form.value) : add(form.value);
|
promise
|
.then(() => {
|
uni.showToast({ title: processId.value ? "保存成功" : "新增成功" });
|
setTimeout(() => {
|
goBack();
|
}, 1500);
|
})
|
.catch(err => {
|
uni.showToast({ title: err.msg || "提交失败", icon: "error" });
|
})
|
.finally(() => {
|
loading.value = false;
|
});
|
})
|
.catch(errors => {
|
if (errors && errors.length > 0) {
|
uni.showToast({
|
title: errors[0].message,
|
icon: "none",
|
});
|
}
|
});
|
};
|
|
onLoad(option => {
|
if (option.item) {
|
const item = JSON.parse(decodeURIComponent(option.item));
|
processId.value = item.id;
|
Object.assign(form.value, item);
|
form.value.isQuality = !!form.value.isQuality;
|
form.value.inbound = !!form.value.inbound;
|
form.value.reportWork = !!form.value.reportWork;
|
}
|
});
|
|
onReady(() => {
|
formRef.value.setRules(rules);
|
});
|
|
onMounted(() => {
|
loadEmployees().then(() => resolveDisplayTexts());
|
});
|
</script>
|
|
<style scoped lang="scss">
|
@import "@/static/scss/form-common.scss";
|
|
.process-edit {
|
min-height: 100vh;
|
background: #f5f5f5;
|
}
|
</style>
|