张诺
9 小时以前 4743d5644fb9c1a4d4a8038331526a0890a453e9
src/views/productionManagement/workOrder/index.vue
@@ -186,6 +186,15 @@
                    placeholder="请输入本次生产数量"
                    @input="handleQuantityInput" />
        </el-form-item>
        <el-form-item label="补产数量"
                      prop="replenishQty">
          <el-input v-model.number="reportForm.replenishQty"
                    type="number"
                    min="0"
                    step="1"
                    style="width: 300px"
                    placeholder="请输入补产数量" />
        </el-form-item>
        <el-form-item label="报废数量"
                      prop="scrapQty">
          <el-input v-model.number="reportForm.scrapQty"
@@ -197,16 +206,22 @@
                    @input="handleScrapQtyInput" />
        </el-form-item>
        <el-form-item label="班组信息">
          <el-select v-model="reportForm.userId"
                     style="width: 300px"
                     placeholder="请选择班组信息"
                     clearable
                     filterable
                     @change="handleUserChange">
            <el-option v-for="user in userOptions"
                       :key="user.userId"
                       :label="user.nickName"
                       :value="user.userId" />
          <el-select
              v-model="reportForm.teamList"
              multiple
              filterable
              clearable
              collapse-tags
              value-key="userId"
              placeholder="请选择班组成员"
              style="width: 300px"
          >
            <el-option
                v-for="user in userTeamOptions"
                :key="user.userId"
                :label="user.nickName"
                :value="{ userId: user.userId, userName: user.nickName }"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="开始时间"
@@ -289,7 +304,8 @@
</template>
<script setup>
  import { onMounted, ref, nextTick } from "vue";
  import { onMounted, ref, nextTick, computed } from "vue";
  import { deepClone } from "@/utils/index.js"
  import { ElMessageBox, ElMessage } from "element-plus";
  import dayjs from "dayjs";
  import {
@@ -303,6 +319,85 @@
  import { getCurrentInstance, reactive, toRefs } from "vue";
  import FilesDia from "./components/filesDia.vue";
  const { proxy } = getCurrentInstance();
  const currentUserId = ref("");
  const currentUserName = ref("");
  const ensureCurrentUser = async () => {
    if (currentUserId.value) return;
    try {
      const res = await getUserProfile();
      if (res?.code === 200) {
        currentUserId.value = String(res?.data?.userId ?? "");
        currentUserName.value = String(res?.data?.nickName ?? "");
      }
    } catch (err) {
      console.error("获取用户信息失败", err);
    }
  };
  const normalizeArray = (val) => {
    if (val === null || val === undefined) return [];
    if (Array.isArray(val)) return val;
    if (typeof val === "string") {
      return val
        .split(/[,,;;\s]+/g)
        .map((s) => s.trim())
        .filter(Boolean);
    }
    return [val];
  };
  const isCurrentUserReportWorker = (row) => {
    const uid = String(currentUserId.value || "");
    if (!uid) return false;
    if (!row) return false;
    const candidateIds = [
      row.reportUserIds,
      row.reportWorkerIds,
      row.userIds,
      row.userIdList,
      row.reportUserId,
      row.userId,
    ]
      .flatMap((v) => normalizeArray(v))
      .map((v) => String(v))
      .filter(Boolean);
    if (candidateIds.includes(uid)) return true;
    const candidateNames = [
      row.userNames,
      row.reportUserNames,
      row.reportWorkerNames,
      row.userName,
    ]
      .flatMap((v) => normalizeArray(v))
      .map((v) => String(v))
      .filter(Boolean);
    if (currentUserName.value && candidateNames.includes(currentUserName.value)) {
      return true;
    }
    if (Array.isArray(row.reportWorkerList)) {
      const list = row.reportWorkerList
        .map((item) => String(item?.userId ?? item?.id ?? ""))
        .filter(Boolean);
      if (list.includes(uid)) return true;
      const nameList = row.reportWorkerList
        .map((item) => String(item?.userName ?? item?.nickName ?? ""))
        .filter(Boolean);
      if (currentUserName.value && nameList.includes(currentUserName.value)) return true;
    }
    return false;
  };
  const canOperateByReportWorker = computed(() => {
    return (row) => isCurrentUserReportWorker(row);
  });
  const tableColumn = ref([
    {
@@ -359,6 +454,11 @@
      width: "140",
    },
    {
      label: "报工人",
      prop: "userNames",
      width: "140",
    },
    {
      label: "计划开始时间",
      prop: "planStartTime",
      width: "140",
@@ -391,7 +491,9 @@
            handleEdit(row);
          },
          // 当需求数量等于完成数量的时候,按钮不可点击
          disabled: row => Number(row?.planQuantity) === Number(row?.completeQuantity),
          disabled: row =>
            Number(row?.planQuantity) === Number(row?.completeQuantity) ||
            !canOperateByReportWorker.value(row),
        },
        {
          name: "流转卡",
@@ -410,7 +512,10 @@
          clickFun: row => {
            showReportDialog(row);
          },
          disabled: row => Number(row?.planQuantity) <= Number(row?.completeQuantity) || row.planQuantity <= 0,
          disabled: row =>
            Number(row?.planQuantity) <= Number(row?.completeQuantity) ||
            row.planQuantity <= 0 ||
            !canOperateByReportWorker.value(row),
        },
        // {
        //   name:"审核",
@@ -440,6 +545,7 @@
  const workOrderFilesRef = ref(null);
  const reportFormRef = ref(null);
  const userOptions = ref([]);
  const userTeamOptions = ref([]);
  const reportForm = reactive({
    planQuantity: 0,
    quantity: null,
@@ -452,6 +558,7 @@
    productProcessRouteItemId: "",
    userId: "",
    productMainId: null,
    teamList:[]
  });
  // 本次生产数量验证规则
@@ -721,6 +828,10 @@
  };
  const handleEdit = row => {
    if (!isCurrentUserReportWorker(row)) {
      ElMessage.warning("当前用户不是该工单的报工人,无法编辑");
      return;
    }
    editrow.value = JSON.parse(JSON.stringify(row));
    editDialogVisible.value = true;
  };
@@ -740,7 +851,10 @@
  };
  const showReportDialog = row => {
    const nowTime = dayjs().format("YYYY-MM-DD HH:mm:ss");
    if (!isCurrentUserReportWorker(row)) {
      ElMessage.warning("当前用户不是该工单的报工人,无法报工");
      return;
    }
    currentReportRowData.value = row;
    reportForm.planQuantity = row.planQuantity - row.completeQuantity;
    reportForm.quantity =
@@ -749,24 +863,19 @@
    reportForm.workOrderId = row.id;
    reportForm.reportWork = row.reportWork;
    reportForm.productMainId = row.productMainId;
    reportForm.startTime = nowTime;
    reportForm.endTime = nowTime;
    reportForm.scrapQty =
      row.scrapQty !== undefined && row.scrapQty !== null ? row.scrapQty : null;
    reportForm.startTime = "";
    reportForm.endTime = "";
    reportForm.replenishQty = 0;
    reportForm.teamList = [];
    reportForm.scrapQty = 0;
    nextTick(() => {
      reportFormRef.value?.clearValidate();
    });
    // 获取当前登录用户信息,设置为默认选中
    getUserProfile()
      .then(res => {
        if (res.code === 200) {
          reportForm.userId = res.data.userId;
          reportForm.userName = res.data.nickName;
        }
      })
      .catch(err => {
        console.error("获取用户信息失败", err);
      });
    ensureCurrentUser().then(() => {
      reportForm.userId = currentUserId.value;
      reportForm.userName = currentUserName.value;
    });
    reportDialogVisible.value = true;
  };
@@ -871,7 +980,12 @@
    userListNoPageByTenantId()
      .then(res => {
        if (res.code === 200) {
          userOptions.value = res.data || [];
          const list = Array.isArray(res.data) ? res.data : []
          userOptions.value = [
            { nickName: "任意用户", userId: "-1" },
            ...deepClone(list)
          ]
          userTeamOptions.value = deepClone(list)
        }
      })
      .catch(err => {
@@ -903,6 +1017,7 @@
  }
  onMounted(() => {
    ensureCurrentUser();
    getList();
    getUserList();
  });