spring
12 小时以前 bf8467516b08a9c1345b591d5a12174cb006b023
src/pages/productionManagement/productionReport/index.vue
@@ -35,7 +35,9 @@
                     required>
          <u-input v-model="form.userName"
                   placeholder="请选择生产人"
                   readonly />
                   readonly
                   @click="openProducerPicker"
                   suffix-icon="arrow-down" />
        </u-form-item>
      </view>
      <!-- 使用FooterButtons组件 -->
@@ -55,7 +57,7 @@
</template>
<script setup>
  import { ref, onMounted } from "vue";
  import { ref, nextTick } from "vue";
  import { onLoad } from "@dcloudio/uni-app";
  import FooterButtons from "@/components/FooterButtons.vue";
@@ -67,35 +69,52 @@
  };
  import { addProductMain } from "@/api/productionManagement/productionReporting";
  import { getInfo } from "@/api/login";
  import { userListNoPageByTenantId } from "@/api/system/user";
  // 表单引用
  const formRef = ref();
  // 表单数据
  let form = ref({
    planQuantity: 0,
    quantity: 0,
    planQuantity: "",
    quantity: "",
    userName: "",
    workOrderId: "",
    reportWork: "",
    productProcessRouteItemId: "",
    userId: "",
    productMainId: null,
    schedulingUserId: "",
  });
  let schedulingUserName = ref("");
  // 日期选择器状态
  const showEnterDatePicker = ref(false);
  const enterDateValue = ref(Date.now());
  // 生产人选择器状态
  const showProducerPicker = ref(false);
  const producerList = ref([]);
  // 打开生产人选择器
  const openProducerPicker = async () => {
    if (producerList.value.length === 0) {
      // 如果列表为空,先加载用户列表
      try {
        const res = await userListNoPageByTenantId();
        const users = res.data || [];
        // 转换为 action-sheet 需要的格式
        producerList.value = users.map(user => ({
          name: user.nickName || user.userName,
          value: user.userId,
        }));
      } catch (error) {
        console.error("加载用户列表失败:", error);
        showToast("加载用户列表失败");
        return;
      }
    }
    showProducerPicker.value = true;
  };
  // 生产人选择确认
  const onProducerConfirm = e => {
    form.value.schedulingUserId = e.value;
    schedulingUserName.value = e.name;
    form.value.userName = e.name;
    form.value.userId = e.value; // 同时更新 userId
    showProducerPicker.value = false;
  };
@@ -115,14 +134,28 @@
      showToast("请输入本次生产数量");
      return;
    }
    if (form.value.quantity > form.value.planQuantity) {
    if (!form.value.schedulingUserId) {
      submitting.value = false;
      showToast("请选择生产人");
      return;
    }
    // 转换为数字进行比较
    const quantity = Number(form.value.quantity);
    const planQuantity = Number(form.value.planQuantity);
    if (quantity > planQuantity) {
      submitting.value = false;
      showToast("本次生产数量不能大于待生产数量");
      return;
    }
    console.log(form.value, "form.value");
    // 准备提交数据,确保数量字段为数字类型
    const submitData = {
      ...form.value,
      quantity: Number(form.value.quantity),
      planQuantity: Number(form.value.planQuantity) || 0,
    };
    console.log(submitData, "submitData");
    addProductMain(form.value).then(res => {
    addProductMain(submitData).then(res => {
      if (res.code === 200) {
        showToast("报工成功");
        submitting.value = false;
@@ -141,19 +174,25 @@
    console.log(options, "options");
    try {
      const orderRow = JSON.parse(options.orderRow);
      console.log("构造的orderRow:", orderRow);
      console.log(orderRow, "orderRow======########");
      form.value.planQuantity = orderRow.planQuantity;
      form.value.quantity = orderRow.quantity;
      form.value.productProcessRouteItemId = orderRow.productProcessRouteItemId;
      form.value.workOrderId = orderRow.id;
      form.value.reportWork = orderRow.reportWork;
      form.value.productMainId = orderRow.productMainId;
      // 确保 planQuantity 转换为字符串,以便在 u-input 中正确显示
      form.value.planQuantity = orderRow.planQuantity != null ? String(orderRow.planQuantity) : "";
      form.value.productProcessRouteItemId = orderRow.productProcessRouteItemId || "";
      form.value.workOrderId = orderRow.id || "";
      getInfo().then(res => {
        // 默认使用当前登录用户,但允许用户修改
        form.value.userId = res.user.userId;
        form.value.userName = res.user.userName;
        form.value.schedulingUserId = res.user.userId;
      });
      // 使用 nextTick 确保 DOM 更新
      nextTick(() => {
        console.log("form.value after assignment:", form.value);
      });
    } catch (error) {
      modal.msgError("订单解析失败");
      console.error("订单解析失败:", error);
      showToast("订单解析失败");
      goBack();
      return;
    }