spring
8 小时以前 bf8467516b08a9c1345b591d5a12174cb006b023
fix: 报工功能调整
已修改3个文件
175 ■■■■ 文件已修改
src/api/productionManagement/productionReporting.js 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/index.vue 84 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/productionManagement/productionReport/index.vue 83 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/productionManagement/productionReporting.js
@@ -17,6 +17,14 @@
    params: query,
  });
}
// 根据ID获取工单详情
export function getProductWorkOrderById(query) {
  return request({
    url: "/productWorkOrder/getProductWorkOrderById",
    method: "get",
    params: query,
  });
}
// 生产报工
export function productionReport(query) {
  return request({
src/pages/index.vue
@@ -192,6 +192,7 @@
<script setup>
  import { ref, onMounted, nextTick, reactive } from "vue";
  import { userLoginFacotryList } from "@/api/login";
  import { getProductWorkOrderById } from "@/api/productionManagement/productionReporting";
  import modal from "@/plugins/modal";
  import useUserStore from "@/store/modules/user";
@@ -527,30 +528,74 @@
  }
  const getcode = () => {
    uni.scanCode({
      success: res => {
      success: async res => {
        // 解析二维码内容
        const scanResult = res.result;
        let orderRow = "";
        // 尝试从扫码结果中提取orderRow参数
        try {
          // 处理混合格式: http://...?orderRow={...}
          const orderRowStart = scanResult.indexOf("orderRow={");
          // 提取从orderRow={开始的JSON内容
          const jsonPart = scanResult.substring(orderRowStart + 9); // 9是"orderRow=".length
          // 尝试直接使用这个JSON部分
          orderRow = jsonPart;
        } catch (e) {
          console.error(e, "解析失败====????=====");
          orderRow = "";
        // 判断扫描结果是否为纯数字(id)
        const isNumericId = /^\d+$/.test(scanResult.trim());
        if (isNumericId) {
          // 如果是纯数字,根据 id 获取工单数据
          const workOrderId = scanResult.trim();
          modal.loading("正在获取工单信息...");
          try {
            const workRes = await getProductWorkOrderById({ id: workOrderId });
            modal.closeLoading();
            console.log("工单查询结果:", workRes);
            if (workRes.code === 200 && workRes.data) {
              // 新接口返回的是单个对象,不是数组
              const workData = workRes.data;
              console.log("工单数据:", workData);
              orderRow = JSON.stringify({
                id: workData.id || workOrderId,
                planQuantity: workData.planQuantity || workData.待生产数量 || 0,
                productProcessRouteItemId: workData.productProcessRouteItemId || workData.产品工艺路线项ID || "",
              });
              console.log("构造的orderRow:", orderRow);
            } else {
              modal.msgError("未找到对应的工单信息");
              return;
            }
          } catch (error) {
            modal.closeLoading();
            console.error("获取工单信息失败:", error);
            modal.msgError("获取工单信息失败: " + (error.message || "未知错误"));
            return;
          }
        } else {
          // 如果不是纯数字,尝试从扫码结果中提取orderRow参数
          try {
            // 处理混合格式: http://...?orderRow={...}
            const orderRowStart = scanResult.indexOf("orderRow={");
            if (orderRowStart !== -1) {
              // 提取从orderRow={开始的JSON内容
              const jsonPart = scanResult.substring(orderRowStart + 9); // 9是"orderRow=".length
              orderRow = jsonPart;
            } else {
              // 如果直接是JSON字符串,尝试解析
              orderRow = scanResult;
            }
          } catch (e) {
            console.error(e, "解析失败====????=====");
            orderRow = "";
          }
          // 验证是否为有效的JSON
          try {
            JSON.parse(orderRow);
          } catch (error) {
            modal.msgError("订单解析失败,请检查二维码格式");
            return;
          }
        }
        console.log(orderRow, "orderRow======@@@@@@@@");
        try {
          JSON.parse(orderRow);
        } catch (error) {
          modal.msgError("订单解析失败");
          return;
        }
        // 扫码成功后跳转到生产报工页面,并传递orderRow参数
        uni.navigateTo({
          url: `/pages/productionManagement/productionReport/index?orderRow=${orderRow}`,
@@ -561,9 +606,6 @@
          title: "扫码失败",
          icon: "none",
        });
        // uni.navigateTo({
        //   url: `/pages/productionManagement/productionReport/index`,
        // });
      },
    });
  };
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;
    }