maven
5 天以前 39600f3c42c7d7b6ecc9fadddd71731c781cd054
src/views/collaborativeApproval/approvalProcess/components/infoFormDia.vue
@@ -9,31 +9,32 @@
      <el-form :model="form" label-width="140px" label-position="top" :rules="rules" ref="formRef">
        <el-row>
          <el-col :span="24">
            <el-form-item label="流程编号:" prop="supplier">
              <el-input v-model="form.model" placeholder="自动编号" clearable disabled/>
            <el-form-item label="流程编号:" prop="approveId">
              <el-input v-model="form.approveId" placeholder="自动编号" clearable disabled/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="申请部门:" prop="productId">
              <el-tree-select
                  v-model="form.productId"
                  placeholder="请选择"
                  clearable
                  check-strictly
                  @change="getModels"
                  :data="productOptions"
                  :render-after-expand="false"
                  style="width: 100%"
              />
            <el-form-item label="申请部门:" prop="approveDeptId">
                     <el-select
                        v-model="form.approveDeptId"
                        placeholder="选择部门"
                     >
                        <el-option
                           v-for="user in productOptions"
                           :key="user.deptId"
                           :label="user.deptName"
                           :value="user.deptId"
                        />
                     </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="审批事由:" prop="model">
              <el-input v-model="form.model" placeholder="请输入" clearable type="textarea" />
            <el-form-item label="审批事由:" prop="approveReason">
              <el-input v-model="form.approveReason" placeholder="请输入" clearable type="textarea" />
            </el-form-item>
          </el-col>
        </el-row>
@@ -59,9 +60,9 @@
                  >
                    <el-option
                      v-for="user in userList"
                      :key="user.id"
                      :label="user.name"
                      :value="user.id"
                      :key="user.userId"
                      :label="user.nickName"
                      :value="user.userId"
                    />
                  </el-select>
                  <div>
@@ -79,14 +80,24 @@
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="申请人:" prop="checkName">
              <el-input v-model="form.checkName" placeholder="请输入" clearable/>
            <el-form-item label="申请人:" prop="approveUser">
                     <el-select
                        v-model="form.approveUser"
                        placeholder="选择人员"
                     >
                        <el-option
                           v-for="user in userList"
                           :key="user.userId"
                           :label="user.nickName"
                           :value="user.userId"
                        />
                     </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请日期:" prop="checkTime">
            <el-form-item label="申请日期:" prop="approveTime">
              <el-date-picker
                  v-model="form.checkTime"
                  v-model="form.approveTime"
                  type="date"
                  placeholder="请选择日期"
                  value-format="YYYY-MM-DD"
@@ -110,42 +121,39 @@
<script setup>
import {ref, reactive, toRefs, getCurrentInstance} from "vue";
import {getOptions} from "@/api/procurementManagement/procurementLedger.js";
import {productTreeList} from "@/api/basicData/product.js";
import {qualityInspectAdd, qualityInspectUpdate} from "@/api/qualityManagement/rawMaterialInspection.js";
import {
  approveProcessAdd, approveProcessGetInfo,
  approveProcessUpdate,
  getDept
} from "../../../../api/collaborativeApproval/approvalProcess.js";
import {userListNoPage} from "../../../../api/system/user.js";
const { proxy } = getCurrentInstance()
const emit = defineEmits(['close'])
import useUserStore from "@/store/modules/user";
const userStore = useUserStore();
const dialogFormVisible = ref(false);
const operationType = ref('')
const data = reactive({
  form: {
    checkTime: "",
    supplier: "",
    checkName: "",
    productName: "",
    productId: "",
    model: "",
    unit: "",
    quantity: "",
    checkCompany: "",
    approveTime: "",
    approveId: "",
    approveUser: "",
      approveDeptId: "",
    approveReason: "",
    checkResult: "",
    approverList: [] // 新增字段,存储所有节点的审批人id
  },
  rules: {
    checkTime: [{ required: false, message: "请输入", trigger: "blur" },],
    supplier: [{ required: true, message: "请输入", trigger: "blur" }],
    checkName: [{ required: false, message: "请输入", trigger: "blur" }],
    productId: [{ required: true, message: "请输入", trigger: "blur" }],
    model: [{ required: false, message: "请输入", trigger: "blur" }],
    unit: [{ required: false, message: "请输入", trigger: "blur" }],
    quantity: [{ required: true, message: "请输入", trigger: "blur" }],
    checkCompany: [{ required: false, message: "请输入", trigger: "blur" }],
    approveTime: [{ required: false, message: "请输入", trigger: "change" },],
    approveId: [{ required: false, message: "请输入", trigger: "blur" }],
    approveUser: [{ required: false, message: "请输入", trigger: "blur" }],
      approveDeptId: [{ required: true, message: "请输入", trigger: "blur" }],
    approveReason: [{ required: true, message: "请输入", trigger: "blur" }],
    checkResult: [{ required: false, message: "请输入", trigger: "blur" }],
  },
});
const { form, rules } = toRefs(data);
const supplierList = ref([]);
const productOptions = ref([]);
// 审批人节点相关
@@ -153,11 +161,7 @@
  { id: 1, userId: null }
])
let nextApproverId = 2
const userList = ref([
  { id: 1, name: '张三' },
  { id: 2, name: '李四' },
  { id: 3, name: '王五' }
])
const userList = ref([])
function addApproverNode() {
  approverNodes.value.push({ id: nextApproverId++, userId: null })
}
@@ -169,46 +173,42 @@
const openDialog = (type, row) => {
  operationType.value = type;
  dialogFormVisible.value = true;
  getOptions().then((res) => {
    supplierList.value = res.data;
  userListNoPage().then((res) => {
    userList.value = res.data;
  });
  getProductOptions();
   form.value = {}
   approverNodes.value = [
      { id: 1, userId: null }
   ]
   console.log(userStore)
  form.value.approveUser = userStore.id;
  form.value.approveTime = getCurrentDate();
  if (operationType.value === 'edit') {
    form.value = {...row}
    // 回显审批人节点
    if (row.approverList && Array.isArray(row.approverList) && row.approverList.length > 0) {
      approverNodes.value = row.approverList.map((userId, idx) => ({ id: idx + 1, userId }))
      nextApproverId = row.approverList.length + 1
    } else {
      approverNodes.value = [{ id: 1, userId: null }]
      nextApproverId = 2
    }
  } else {
    approverNodes.value = [{ id: 1, userId: null }]
    nextApproverId = 2
    approveProcessGetInfo({id: row.approveId,approveReason: '1'}).then(res => {
         form.value = {...res.data}
      // 反显审批人
      // if (res.data && res.data.approverIds) {
      //   const nameArr = res.data.approverIds.split(',')
      //   approverNodes.value = nameArr.map((name, idx) => {
      //     const user = userList.value.find(u => u.name === name)
      //     return { id: idx + 1, userId: user ? user.id : null }
      //   })
      //   nextApproverId = nameArr.length + 1
      // } else if (row.approverList && Array.isArray(row.approverList) && row.approverList.length > 0) {
      //   approverNodes.value = row.approverList.map((userId, idx) => ({ id: idx + 1, userId }))
      //   nextApproverId = row.approverList.length + 1
      // } else {
      //   approverNodes.value = [{ id: 1, userId: null }]
      //   nextApproverId = 2
      // }
    })
  }
}
const getProductOptions = () => {
  productTreeList().then((res) => {
    productOptions.value = convertIdToValue(res);
  getDept().then((res) => {
    productOptions.value = res.data;
  });
};
const getModels = (value) => {
  form.value.productName = findNodeById(productOptions.value, value);
};
const findNodeById = (nodes, productId) => {
  for (let i = 0; i < nodes.length; i++) {
    if (nodes[i].value === productId) {
      return nodes[i].label; // 找到节点,返回该节点
    }
    if (nodes[i].children && nodes[i].children.length > 0) {
      const foundNode = findNodeById(nodes[i].children, productId);
      if (foundNode) {
        return foundNode; // 在子节点中找到,返回该节点
      }
    }
  }
  return null; // 没有找到节点,返回null
};
function convertIdToValue(data) {
  return data.map((item) => {
@@ -227,17 +227,22 @@
// 提交产品表单
const submitForm = () => {
  // 收集所有节点的审批人id
  form.value.approverList = approverNodes.value.map(node => node.userId)
  form.value.approverIds = approverNodes.value.map(node => node.userId).join(',')
  // 审批人必填校验
  const hasEmptyApprover = approverNodes.value.some(node => !node.userId)
  if (hasEmptyApprover) {
    proxy.$modal.msgError("请为所有审批节点选择审批人!")
    return
  }
  proxy.$refs.formRef.validate(valid => {
    if (valid) {
      form.value.inspectType = 0
      if (operationType.value === "add") {
        qualityInspectAdd(form.value).then(res => {
        approveProcessAdd(form.value).then(res => {
          proxy.$modal.msgSuccess("提交成功");
          closeDia();
        })
      } else {
        qualityInspectUpdate(form.value).then(res => {
        approveProcessUpdate(form.value).then(res => {
          proxy.$modal.msgSuccess("提交成功");
          closeDia();
        })
@@ -251,6 +256,14 @@
  dialogFormVisible.value = false;
  emit('close')
};
// 获取当前日期并格式化为 YYYY-MM-DD
function getCurrentDate() {
  const today = new Date();
  const year = today.getFullYear();
  const month = String(today.getMonth() + 1).padStart(2, "0"); // 月份从0开始
  const day = String(today.getDate()).padStart(2, "0");
  return `${year}-${month}-${day}`;
}
defineExpose({
  openDialog,
});