gaoluyang
3 天以前 f2770f03e7251b32eb576113c522bfbe96e5e385
src/pages/productionDesign/processManagement/edit.vue
@@ -6,36 +6,59 @@
             :model="form"
             :rules="rules"
             :errorType="['none']"
             label-width="110">
      <up-form-item label="工序编码"
                    prop="no">
        <up-input v-model="form.no"
                  placeholder="请输入工序编码"
                  clearable />
      </up-form-item>
      <up-form-item label="工序名称"
             label-width="130">
      <up-form-item label="部件"
                    prop="name"
                    required>
        <up-input v-model="form.name"
                  placeholder="请输入工序名称"
                  placeholder="请输入部件"
                  clearable />
      </up-form-item>
      <up-form-item label="工资定额"
      <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="请输入工资定额"
                  placeholder="请输入计划工时"
                  clearable />
      </up-form-item>
      <up-form-item label="计费类型"
                    prop="type">
        <up-input v-model="typeText"
                  placeholder="请选择计费类型"
      <up-form-item label="计划人员"
                    prop="planPerson">
        <up-input v-model="planPersonText"
                  placeholder="请选择计划人员"
                  readonly
                  @click="showTypeSheet = true" />
                  @click="showPlanPersonSheet = true" />
        <template #right>
          <up-icon name="arrow-right"
                   @click="showTypeSheet = true"></up-icon>
                   @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="是否质检"
@@ -44,27 +67,22 @@
          <up-switch v-model="form.isQuality" />
        </view>
      </up-form-item>
      <up-form-item label="是否生产"
                    prop="isProduction">
      <up-form-item label="是否入库"
                    prop="inbound">
        <view style="display: flex; justify-content: flex-end; width: 100%;">
          <up-switch v-model="form.isProduction" />
          <up-switch v-model="form.inbound" />
        </view>
      </up-form-item>
      <up-form-item label="关联设备"
                    prop="deviceLedgerId">
        <up-input v-model="deviceText"
                  placeholder="请选择关联设备"
                  readonly
                  @click="showDeviceSheet = true" />
        <template #right>
          <up-icon name="arrow-right"
                   @click="showDeviceSheet = true"></up-icon>
        </template>
      <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="工序描述"
      <up-form-item label="备注"
                    prop="remark">
        <up-textarea v-model="form.remark"
                     placeholder="请输入工序描述"
                     placeholder="请输入备注"
                     autoHeight />
      </up-form-item>
    </up-form>
@@ -72,18 +90,24 @@
                   :confirmText="processId ? '保存' : '新增'"
                   @cancel="goBack"
                   @confirm="handleSubmit" />
    <!-- 计费类型选择 -->
    <up-action-sheet :show="showTypeSheet"
                     title="选择计费类型"
                     :actions="typeActions"
                     @select="onSelectType"
                     @close="showTypeSheet = false" />
    <!-- 设备选择 -->
    <up-action-sheet :show="showDeviceSheet"
                     title="选择关联设备"
                     :actions="deviceActions"
                     @select="onSelectDevice"
                     @close="showDeviceSheet = false" />
    <!-- 工序类型选择 -->
    <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>
@@ -91,35 +115,49 @@
  import { reactive, ref, computed, onMounted } from "vue";
  import { onLoad, onReady } from "@dcloudio/uni-app";
  import FooterButtons from "@/components/FooterButtons.vue";
  import {
    add,
    update,
    getDeviceLedger,
  } from "@/api/productionManagement/processManagement";
  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,
    isProduction: false,
    inbound: false,
    reportWork: false,
    remark: "",
    deviceLedgerId: null,
    type: 0,
  });
  const rules = {
    name: [{ required: true, message: "请输入工序名称" }],
    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("工资定额必须是非负数字"));
            callback(new Error("计划工时必须是非负数字"));
          } else {
            callback();
          }
@@ -128,46 +166,60 @@
    ],
  };
  const showTypeSheet = ref(false);
  const typeActions = [
    { name: "计时", value: 0 },
    { name: "计件", value: 1 },
  ];
  const typeText = computed(() => {
    const action = typeActions.find(a => a.value === form.value.type);
    return action ? action.name : "";
  });
  const showProcessTypeSheet = ref(false);
  const processTypeActions = processTypeOptions.map(item => ({ name: item, value: item }));
  const processTypeText = ref("");
  const showDeviceSheet = ref(false);
  const deviceActions = ref([]);
  const deviceText = ref("");
  const showPlanPersonSheet = ref(false);
  const showExecutorSheet = ref(false);
  const planPersonText = ref("");
  const executorText = ref("");
  const onSelectType = e => {
    form.value.type = e.value;
    showTypeSheet.value = false;
  };
  const onSelectDevice = e => {
    form.value.deviceLedgerId = e.id;
    deviceText.value = e.name;
    showDeviceSheet.value = false;
  };
  const loadDevices = async () => {
    try {
      const { data } = await getDeviceLedger();
      deviceActions.value = (data || []).map(item => ({
        name: item.deviceName,
  const employeeActions = computed(() =>
    employeeList.value.map(item => ({
      name: item.staffName,
        id: item.id,
      }));
      if (form.value.deviceLedgerId) {
        const device = deviceActions.value.find(
          d => d.id === Number(form.value.deviceLedgerId)
    }))
        );
        if (device) deviceText.value = device.name;
      }
  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);
      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;
    }
  };
@@ -210,10 +262,9 @@
      const item = JSON.parse(decodeURIComponent(option.item));
      processId.value = item.id;
      Object.assign(form.value, item);
      // 处理类型转换,确保是数字
      form.value.type = Number(form.value.type);
      form.value.isQuality = !!form.value.isQuality;
      form.value.isProduction = !!form.value.isProduction;
      form.value.inbound = !!form.value.inbound;
      form.value.reportWork = !!form.value.reportWork;
    }
  });
@@ -222,7 +273,7 @@
  });
  onMounted(() => {
    loadDevices();
    loadEmployees().then(() => resolveDisplayTexts());
  });
</script>