Преглед на файлове

pms 物料领用 详情

zhangcl преди 2 месеца
родител
ревизия
56e1a52446

+ 59 - 54
src/api/pms/iotmaterialrequisition/index.ts

@@ -1,54 +1,59 @@
-import request from '@/config/axios'
-
-// 物料领用 VO
-export interface IotMaterialRequisitionVO {
-  id: number // 主键id
-  deptId: number // 部门id
-  requisitionNumber: string // 物料领用单编号
-  name: string // 物料领用单名称
-  type: number // 领用用途(1维修  2保养 3其它)
-  responsiblePerson: string // 领用人姓名
-  cost: number // 物料总费用
-  result: number // 领用结果(1待执行 2已执行)
-  otherCost: number // 其他费用
-  laborCost: number // 人工费用
-  requisitionTime: Date // 领用日期
-  reason: string // 领用原因
-  remark: string // 备注(如特殊要求、紧急程度)
-  status: number // 状态 0=未出库 1=已出库 2=已关闭
-  processInstanceId: string // 流程实例id
-  auditStatus: number // 审批状态 未提交、审批中、审批通过、审批不通过、已取消
-}
-
-// 物料领用 API
-export const IotMaterialRequisitionApi = {
-  // 查询物料领用分页
-  getIotMaterialRequisitionPage: async (params: any) => {
-    return await request.get({ url: `/pms/iot-material-requisition/page`, params })
-  },
-
-  // 查询物料领用详情
-  getIotMaterialRequisition: async (id: number) => {
-    return await request.get({ url: `/pms/iot-material-requisition/get?id=` + id })
-  },
-
-  // 新增物料领用
-  createIotMaterialRequisition: async (data: IotMaterialRequisitionVO) => {
-    return await request.post({ url: `/pms/iot-material-requisition/create`, data })
-  },
-
-  // 修改物料领用
-  updateIotMaterialRequisition: async (data: IotMaterialRequisitionVO) => {
-    return await request.put({ url: `/pms/iot-material-requisition/update`, data })
-  },
-
-  // 删除物料领用
-  deleteIotMaterialRequisition: async (id: number) => {
-    return await request.delete({ url: `/pms/iot-material-requisition/delete?id=` + id })
-  },
-
-  // 导出物料领用 Excel
-  exportIotMaterialRequisition: async (params) => {
-    return await request.download({ url: `/pms/iot-material-requisition/export-excel`, params })
-  },
-}
+import request from '@/config/axios'
+
+// 物料领用 VO
+export interface IotMaterialRequisitionVO {
+  id: number // 主键id
+  deptId: number // 部门id
+  requisitionNumber: string // 物料领用单编号
+  name: string // 物料领用单名称
+  type: number // 领用用途(1维修  2保养 3其它)
+  responsiblePerson: string // 领用人姓名
+  cost: number // 物料总费用
+  result: number // 领用结果(1待执行 2已执行)
+  otherCost: number // 其他费用
+  laborCost: number // 人工费用
+  requisitionTime: Date // 领用日期
+  reason: string // 领用原因
+  remark: string // 备注(如特殊要求、紧急程度)
+  status: number // 状态 0=未出库 1=已出库 2=已关闭
+  processInstanceId: string // 流程实例id
+  auditStatus: number // 审批状态 未提交、审批中、审批通过、审批不通过、已取消
+}
+
+// 物料领用 API
+export const IotMaterialRequisitionApi = {
+  // 查询物料领用分页
+  getIotMaterialRequisitionPage: async (params: any) => {
+    return await request.get({ url: `/pms/iot-material-requisition/page`, params })
+  },
+
+  // 查询物料领用详情
+  getIotMaterialRequisition: async (id: number) => {
+    return await request.get({ url: `/pms/iot-material-requisition/get?id=` + id })
+  },
+
+  // 新增物料领用
+  createIotMaterialRequisition: async (data: IotMaterialRequisitionVO) => {
+    return await request.post({ url: `/pms/iot-material-requisition/create`, data })
+  },
+
+  // 新增物料领用单
+  addMaterialRequisition: async (data: any) => {
+    return await request.put({ url: `/pms/iot-material-requisition/addMaterialRequisition`, data })
+  },
+
+  // 修改物料领用
+  updateIotMaterialRequisition: async (data: IotMaterialRequisitionVO) => {
+    return await request.put({ url: `/pms/iot-material-requisition/update`, data })
+  },
+
+  // 删除物料领用
+  deleteIotMaterialRequisition: async (id: number) => {
+    return await request.delete({ url: `/pms/iot-material-requisition/delete?id=` + id })
+  },
+
+  // 导出物料领用 Excel
+  exportIotMaterialRequisition: async (params) => {
+    return await request.download({ url: `/pms/iot-material-requisition/export-excel`, params })
+  },
+}

+ 7 - 0
src/api/pms/iotmaterialrequisitiondetail/index.ts

@@ -4,6 +4,8 @@ import request from '@/config/axios'
 export interface IotMaterialRequisitionDetailVO {
   id: number // 主键
   requisitionId: number // 物料领用单id
+  factoryId: number     // 工厂id
+  costCenterId: number  // 成本中心id
   materialId: number // 物料id
   materialCode: string // 物料编码
   materialName: string // 物料名称
@@ -25,6 +27,11 @@ export const IotMaterialRequisitionDetailApi = {
     return await request.get({ url: `/pms/iot-material-requisition-detail/page`, params })
   },
 
+  // 查询PMS 物料领用明细列表
+  getIotMaterialRequisitionDetailList: async (params: any) => {
+    return await request.get({ url: `/pms/iot-material-requisition-detail/list`, params })
+  },
+
   // 查询PMS 物料领用明细详情
   getIotMaterialRequisitionDetail: async (id: number) => {
     return await request.get({ url: `/pms/iot-material-requisition-detail/get?id=` + id })

+ 13 - 0
src/router/modules/remaining.ts

@@ -565,6 +565,19 @@ const remainingRouter: AppRouteRecordRaw[] = [
           activeMenu: '/materialreq/add'
         }
       },
+      {
+        path: 'materialreq/detail/:id(\\d+)',
+        component: () => import('@/views/pms/iotmaterialrequisition/IotMaterialReqDetail.vue'),
+        name: 'IotMaterialReqDetail',
+        meta: {
+          noCache: false,
+          hidden: true,
+          canTo: true,
+          icon: 'ep:view',
+          title: '领用单详情',
+          activeMenu: '/materialreq/detail'
+        }
+      },
     ]
   },
 

+ 0 - 9
src/views/pms/iotmainworkorder/IotMainWorkOrderAdd.vue

@@ -938,14 +938,6 @@ onMounted(async () => {
 })
 
 const handleDelete = async (str: string) => {
-  /* try {
-    const index = list.value.findIndex((item) => (item.deviceId+'-'+item.bomNodeId) === str)
-    if (index !== -1) {
-      // 通过 splice 删除元素
-      list.value.splice(index, 1)
-      deviceIds.value = []
-    }
-  } catch {} */
   try {
     const [deviceIdStr, bomNodeId] = str.split('-')
     const deviceId = parseInt(deviceIdStr)
@@ -962,7 +954,6 @@ const handleDelete = async (str: string) => {
       devicePersonsMap.value.delete(deviceId) // 移除对应设备的责任人
       updateDevicePersonsDisplay() // 立即更新显示
     }
-    // message.success('移除成功')
   } catch (error) {
     console.error('移除失败:', error)
     message.error('移除失败')

+ 0 - 2
src/views/pms/iotmainworkorder/IotMainWorkOrderDetail.vue

@@ -899,10 +899,8 @@ onMounted(async () => {
   const deptId = useUserStore().getUser.deptId
   // 查询当前登录人所属部门名称
   dept.value = await DeptApi.getDept(deptId)
-  // formData.value.name = dept.value.name + ' - 保养计划'
   deptUsers.value = await UserApi.getDeptUsersByDeptId(deptId)
   formData.value.deptId = deptId
-  // if (id){
   try{
     formType.value = 'update'
     // 查询保养工单 主表数据

+ 370 - 0
src/views/pms/iotmaterialrequisition/IotMaterialReqDetail.vue

@@ -0,0 +1,370 @@
+<template>
+  <ContentWrap v-loading="formLoading">
+    <el-form
+      ref="formRef"
+      :model="formData"
+      :rules="formRules"
+      v-loading="formLoading"
+      style="margin-right: 4em; margin-left: 0.5em; margin-top: 1em"
+      label-width="130px"
+    >
+      <div class="base-expandable-content">
+        <el-row>
+          <el-col :span="8">
+            <el-form-item label="领料单名称" prop="name">
+              <el-input type="text" v-model="formData.name" disabled/>
+            </el-form-item>
+          </el-col>
+          <el-col :span="8">
+            <el-form-item label="费用" prop="cost">
+              <el-input
+                v-model="formData.cost"
+                placeholder="根据领用物料自动生成"
+                disabled
+              />
+            </el-form-item>
+          </el-col>
+          <el-col :span="8">
+            <el-form-item label="领用日期" prop="actualStartTime">
+              <el-date-picker
+                style="width: 150%"
+                v-model="formData.requisitionTime"
+                type="datetime"
+                value-format="x"
+                placeholder="实际保养开始时间"
+                disabled
+              />
+            </el-form-item>
+          </el-col>
+          <el-col :span="8">
+            <el-form-item label="领用人" prop="otherCost">
+              <el-input
+                v-model="formData.responsiblePerson"
+                placeholder="请输入领用人"
+                disabled
+              />
+            </el-form-item>
+          </el-col>
+          <el-col :span="16">
+            <el-form-item label="领用原因" prop="remark">
+              <el-input v-model="formData.reason" type="textarea" placeholder="请输入领用原因" disabled/>
+            </el-form-item>
+          </el-col>
+          <el-col :span="24">
+            <el-form-item label="备注" prop="remark">
+              <el-input v-model="formData.remark" type="textarea" placeholder="请输入备注" disabled/>
+            </el-form-item>
+          </el-col>
+
+        </el-row>
+      </div>
+    </el-form>
+  </ContentWrap>
+  <ContentWrap>
+    <ContentWrap>
+      <!-- 搜索工作栏 -->
+      <el-form
+        class="-mb-15px"
+        :model="queryParams"
+        ref="queryFormRef"
+        :inline="true"
+        label-width="68px"
+      >
+      <el-form-item>
+        <el-button @click="openForm" type="warning">
+          <Icon icon="ep:plus" class="mr-5px" />选择物料</el-button>
+      </el-form-item>
+      </el-form>
+    </ContentWrap>
+
+    <!-- 列表 -->
+    <ContentWrap>
+      <el-table v-loading="loading" :data="materialList" :stripe="true" :show-overflow-tooltip="true">
+        <!-- 添加序号列 -->
+        <el-table-column
+          type="index"
+          label="序号"
+          width="60"
+          align="center"
+        />
+        <el-table-column label="工厂" align="center" prop="factory" />
+        <el-table-column label="成本中心" align="center" prop="costCenter" />
+        <el-table-column label="物料编码" align="center" prop="materialCode" />
+        <el-table-column label="物料名称" align="center" prop="materialName" />
+        <el-table-column label="单价" align="center" prop="unitPrice" :formatter="erpPriceTableColumnFormatter"/>
+        <el-table-column label="库存数量" align="center" prop="quantity" :formatter="erpPriceTableColumnFormatter"/>
+        <el-table-column label="领用数量" align="center" prop="requisitionQuantity" :formatter="erpPriceTableColumnFormatter"/>
+        <el-table-column label="单位" align="center" prop="unit" />
+      </el-table>
+    </ContentWrap>
+
+  </ContentWrap>
+  <ContentWrap>
+    <el-form>
+      <el-form-item style="float: right">
+        <!-- <el-button @click="submitForm" type="primary" :disabled="formLoading">保 存</el-button> -->
+        <el-button @click="close">确 定</el-button>
+      </el-form-item>
+    </el-form>
+  </ContentWrap>
+  <SelectLocalStock ref="localStockFormRef" @choose="stockChoose" />
+</template>
+<script setup lang="ts">
+import * as UserApi from '@/api/system/user'
+import { useUserStore } from '@/store/modules/user'
+import { ref } from 'vue'
+import { IotMaterialRequisitionApi, IotMaterialRequisitionVO } from '@/api/pms/iotmaterialrequisition'
+import { IotMaterialRequisitionDetailApi, IotMaterialRequisitionDetailVO } from '@/api/pms/iotmaterialrequisitiondetail'
+import { useTagsViewStore } from '@/store/modules/tagsView'
+import {CACHE_KEY, useCache} from "@/hooks/web/useCache";
+import SelectLocalStock from "@/views/pms/iotmaterialrequisition/SelectLocalStock.vue";
+import * as DeptApi from "@/api/system/dept";
+import {erpPriceTableColumnFormatter} from "@/utils";
+
+/** 物料领用 表单 */
+defineOptions({ name: 'IotMaterialRequisitionAdd' })
+
+const { t } = useI18n() // 国际化
+const message = useMessage() // 消息弹窗
+const { delView } = useTagsViewStore() // 视图操作
+const { currentRoute, push } = useRouter()
+const dept = ref() // 当前登录人所属部门对象
+const dialogTitle = ref('') // 弹窗的标题
+const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
+const formType = ref('') // 表单的类型:create - 新增;update - 修改
+const materialList = ref<IotMaterialRequisitionDetailVO[]>([]) // 领用单明细
+const { params, name } = useRoute() // 查询参数
+const id = params.id
+
+const formData = ref({
+  id: undefined,
+  deptId: undefined,
+  name: '',
+  orderNumber: undefined,
+  responsiblePerson: undefined,
+  requisitionTime: undefined,
+  cost: undefined,
+  reason: undefined,
+  remark: undefined,
+  status: undefined,
+})
+
+const formRules = reactive({
+  name: [{ required: true, message: '工单名称不能为空', trigger: 'blur' }],
+  responsiblePerson: [{ required: true, message: '领用人不能为空', trigger: 'blur' }],
+})
+const formRef = ref() // 表单 Ref
+
+// 监听物料列表变化
+watch(
+  () => materialList.value,
+  () => {
+    calculateTotalCost()
+  },
+  { deep: true }
+)
+
+const localStockFormRef = ref()
+const openForm = () => {
+  localStockFormRef.value.open()
+}
+
+// 计算保养金额
+const calculateTotalCost = () => {
+  // 物料总金额 = ∑(单价 * 消耗数量)
+  const materialTotal = materialList.value.reduce((sum, item) => {
+    const price = Number(item.unitPrice) || 0
+    const quantity = Number(item.requisitionQuantity) || 0
+    return sum + (price * quantity)
+  }, 0)
+
+  // 费用 = 物料总金额
+  formData.value.cost = (materialTotal).toFixed(2)
+}
+
+// 多选 物料
+const stockChoose = (selectedStocks) => {
+  // 转换数据结构(根据你的接口定义调整)
+  const newItems = selectedStocks.map(stock => ({
+    id: stock.id,
+    materialCode: stock.materialCode,
+    materialName: stock.materialName,
+    unit: stock.unit,
+    quantity: stock.quantity,        // 库存数量
+    requisitionQuantity: stock.requisitionQuantity,   // 领用数量
+    unitPrice: stock.unitPrice,      // 单价
+    remark: null,
+    code: stock.materialCode  // 移除操作需要
+  }))
+
+  // 合并到现有列表(去重)
+  newItems.forEach(item => {
+    const exists = materialList.value.some(
+      existing => existing.materialCode === item.materialCode
+    )
+    if (!exists) {
+      materialList.value.push(item)
+    }
+  })
+}
+
+const handleInput = (value, obj) => {
+  // 1. 过滤非法字符(只允许数字和小数点)
+  let filtered = value.replace(/[^\d.]/g, '')
+
+  // 2. 处理多个小数点的情况
+  filtered = filtered.replace(/\.{2,}/g, '.')
+
+  // 3. 限制小数点后最多两位
+  let decimalParts = filtered.split('.')
+  if (decimalParts.length > 1) {
+    decimalParts = decimalParts.slice(0, 2)
+    filtered = decimalParts.join('.')
+  }
+
+  // 4. 处理以小数点开头的情况(自动补0)
+  if (filtered.startsWith('.')) {
+    filtered = '0' + filtered
+  }
+
+  // 5. 更新绑定值(同时处理连续输入多个0的情况)
+  formData.value[obj] = filtered.replace(/^0+(?=\d)/, '')
+}
+
+const queryParams = reactive({
+  requisitionId: id,
+})
+
+const close = () => {
+  delView(unref(currentRoute))
+  push({ name: 'IotMaterialRequisition', params:{}})
+}
+
+/** 提交表单 */
+const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
+const submitForm = async () => {
+  // 校验表单
+  await formRef.value.validate()
+  // 校验表格数据
+  const isValid = validateTableData()
+  if (!isValid) return
+  // 提交请求
+  formLoading.value = true
+  try {
+    const data = {
+      materialRequisition: formData.value,
+      materialReqDetails: materialList.value
+    }
+    await IotMaterialRequisitionApi.addMaterialRequisition(data)
+    message.success(t('common.createSuccess'))
+    close()
+    // 发送操作成功的事件
+    emit('success')
+  } finally {
+    formLoading.value = false
+  }
+}
+
+/** 校验表格数据 */
+const validateTableData = (): boolean => {
+  let isValid = true
+  const errorMessages: string[] = []
+
+  if (materialList.value.length === 0) {
+    errorMessages.push('请至少添加一条物料明细')
+    isValid = false
+    // 直接返回无需后续校验
+    message.error('请至少添加一条物料明细')
+    return isValid
+  }
+  return isValid
+}
+
+/** 重置表单 */
+const resetForm = () => {
+  formData.value = {
+    id: undefined,
+    status: undefined,
+    description: undefined,
+    pic: undefined,
+    remark: undefined,
+    deviceName: undefined,
+    processInstanceId: undefined,
+    auditStatus: undefined,
+    deptId: undefined
+  }
+  formRef.value?.resetFields()
+}
+onMounted(async () => {
+  materialList.value = []
+  const deptId = useUserStore().getUser.deptId
+  // 查询当前登录人所属部门名称
+  dept.value = await DeptApi.getDept(deptId)
+  formData.value.name = dept.value.name + ' - 领料单'
+  formData.value.deptId = deptId
+  try {
+    // 领料单主表数据
+    const requisition = await IotMaterialRequisitionApi.getIotMaterialRequisition(id);
+    formData.value = requisition;
+    // 查询领料单物料明细
+    const requisitionDetails = await IotMaterialRequisitionDetailApi.getIotMaterialRequisitionDetailList(queryParams);
+    materialList.value = []
+    if (Array.isArray(requisitionDetails)) {
+      materialList.value = requisitionDetails.map(item => ({
+        ...item,
+      }))
+    }
+  } catch (error) {
+    console.error('数据加载失败:', error)
+    message.error('数据加载失败,请重试')
+  }
+})
+
+const handleDelete = async (materialCode: string) => {
+  try {
+    // 从 materialList 中移除对应物料
+    const index = materialList.value.findIndex(item => item.materialCode === materialCode);
+    if (index !== -1) {
+      materialList.value.splice(index, 1);
+      calculateTotalCost(); // 重新计算总费用
+    }
+  } catch (error) {
+    console.error('移除失败:', error);
+    message.error('移除失败');
+  }
+}
+
+</script>
+<style scoped>
+.base-expandable-content {
+  overflow: hidden; /* 隐藏溢出的内容 */
+  transition: max-height 0.3s ease; /* 平滑过渡效果 */
+}
+
+:deep(.el-input-number .el-input__inner) {
+  text-align: left !important;
+  padding-left: 10px; /* 保持左侧间距 */
+}
+
+/* 分组容器样式 */
+.form-group {
+  position: relative;
+  border: 1px solid #dcdfe6;
+  border-radius: 4px;
+  padding: 20px 15px 10px;
+  margin-bottom: 18px;
+  transition: border-color 0.2s;
+}
+
+/* 分组标题样式 */
+.group-title {
+  position: absolute;
+  top: -10px;
+  left: 20px;
+  background: white;
+  padding: 0 8px;
+  color: #606266;
+  font-size: 12px;
+  font-weight: 500;
+}
+</style>

+ 24 - 73
src/views/pms/iotmaterialrequisition/IotMaterialRequisitionAdd.vue

@@ -85,6 +85,10 @@
           width="60"
           align="center"
         />
+        <el-table-column label="工厂id" align="center" prop="factoryId" v-if="false"/>
+        <el-table-column label="成本中心id" align="center" prop="costCenterId" v-if="false"/>
+        <el-table-column label="工厂" align="center" prop="factory" v-if="true"/>
+        <el-table-column label="成本中心" align="center" prop="costCenter" v-if="true"/>
         <el-table-column label="物料编码" align="center" prop="materialCode" />
         <el-table-column label="物料名称" align="center" prop="materialName" />
         <el-table-column label="单价" align="center" prop="unitPrice" :formatter="erpPriceTableColumnFormatter"/>
@@ -100,7 +104,7 @@
                   style="vertical-align: middle"
                   link
                   type="danger"
-                  @click="handleDelete(scope.row.deviceId+'-'+scope.row.bomNodeId)"
+                  @click="handleDelete(scope.row.materialCode)"
                 >
                   移除
                 </el-button>
@@ -120,39 +124,19 @@
       </el-form-item>
     </el-form>
   </ContentWrap>
-  <MainPlanDeviceList ref="deviceFormRef" @choose="deviceChoose" />
   <SelectLocalStock ref="localStockFormRef" @choose="stockChoose" />
-  <!-- 表单弹窗:添加/修改 -->
-  <WorkOrderMaterial ref="materialFormRef" @choose="selectChoose" />
-  <!-- 抽屉组件 展示已经选择的物料 并编辑物料消耗 -->
-  <MaterialListDrawer
-    :model-value="drawerVisible"
-    @update:model-value="val => drawerVisible = val"
-    :node-id="currentBomNodeId"
-    :materials="materialList.filter(item => item.bomNodeId === currentBomNodeId)"
-  />
 </template>
 <script setup lang="ts">
-import { IotDeviceApi, IotDeviceVO } from '@/api/pms/device'
 import * as UserApi from '@/api/system/user'
 import { useUserStore } from '@/store/modules/user'
 import { ref } from 'vue'
-import type { ComponentPublicInstance } from 'vue'
-import { IotMaintenanceBomApi, IotMaintenanceBomVO } from '@/api/pms/iotmaintenancebom'
-import { IotMainWorkOrderBomApi, IotMainWorkOrderBomVO } from '@/api/pms/iotmainworkorderbom'
-import { IotMainWorkOrderBomMaterialApi, IotMainWorkOrderBomMaterialVO } from '@/api/pms/iotmainworkorderbommaterial'
-import { IotMainWorkOrderApi, IotMainWorkOrderVO } from '@/api/pms/iotmainworkorder'
+import { IotMaterialRequisitionApi, IotMaterialRequisitionVO } from '@/api/pms/iotmaterialrequisition'
 import { IotMaterialRequisitionDetailApi, IotMaterialRequisitionDetailVO } from '@/api/pms/iotmaterialrequisitiondetail'
 import { useTagsViewStore } from '@/store/modules/tagsView'
 import {CACHE_KEY, useCache} from "@/hooks/web/useCache";
-import MainPlanDeviceList from "@/views/pms/maintenance/MainPlanDeviceList.vue";
+import SelectLocalStock from "@/views/pms/iotmaterialrequisition/SelectLocalStock.vue";
 import * as DeptApi from "@/api/system/dept";
 import {erpPriceTableColumnFormatter} from "@/utils";
-import dayjs from 'dayjs'
-import MaterialListDrawer from "@/views/pms/iotmainworkorder/SelectedMaterialDrawer.vue";
-import WorkOrderMaterial from "@/views/pms/iotmainworkorder/WorkOrderMaterial.vue";
-import { IotDevicePersonApi, IotDevicePersonVO } from '@/api/pms/iotdeviceperson'
-import {DICT_TYPE, getIntDictOptions, getStrDictOptions} from "@/utils/dict";
 
 /** 物料领用 表单 */
 defineOptions({ name: 'IotMaterialRequisitionAdd' })
@@ -163,21 +147,12 @@ const { delView } = useTagsViewStore() // 视图操作
 const { currentRoute, push } = useRouter()
 const deptUsers = ref<UserApi.UserVO[]>([]) // 用户列表
 const dept = ref() // 当前登录人所属部门对象
-const configFormRef = ref() // 配置弹出框对象
-const bomNodeId = ref() // 最新的bomNodeId
 const dialogTitle = ref('') // 弹窗的标题
 const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
 const formType = ref('') // 表单的类型:create - 新增;update - 修改
-const deviceLabel = ref('') // 表单的类型:create - 新增;update - 修改
-const drawerVisible = ref<boolean>(false)
-const currentBomNodeId = ref() // 当前选中的bom节点
-const showDrawer = ref()
-const list = ref<IotMainWorkOrderBomVO[]>([]) // 保养工单bom关联列表的数据
 const materialList = ref<IotMaterialRequisitionDetailVO[]>([]) // 领用单明细
-const deviceIds = ref<number[]>([]) // 已经选择的设备id数组
 const { params, name } = useRoute() // 查询参数
 const id = params.id
-const devicePersonsMap = ref<Map<number, Set<string>>>(new Map()) // 存储设备-责任人映射
 
 const formData = ref({
   id: undefined,
@@ -198,12 +173,6 @@ const formRules = reactive({
 })
 const formRef = ref() // 表单 Ref
 
-interface MaterialFormExpose {
-  open: (deptId: number, bomNodeId: number) => void
-}
-
-const materialFormRef = ref<MaterialFormExpose>();
-
 // 监听物料列表变化
 watch(
   () => materialList.value,
@@ -231,19 +200,15 @@ const calculateTotalCost = () => {
   formData.value.cost = (materialTotal).toFixed(2)
 }
 
-/** 查看已经选择的物料 并编辑 */
-const handleView = (nodeId) => {
-  currentBomNodeId.value = nodeId
-  drawerVisible.value = true
-  // showDrawer.value.openDrawer()
-  console.log('当前bom节点:', currentBomNodeId.value)
-}
-
 // 多选 物料
 const stockChoose = (selectedStocks) => {
   // 转换数据结构(根据你的接口定义调整)
   const newItems = selectedStocks.map(stock => ({
     id: stock.id,
+    factoryId: stock.factoryId,
+    factory: stock.factory,
+    costCenterId: stock.costCenterId,
+    costCenter: stock.costCenter,
     materialCode: stock.materialCode,
     materialName: stock.materialName,
     unit: stock.unit,
@@ -311,14 +276,12 @@ const submitForm = async () => {
   formLoading.value = true
   try {
     const data = {
-      mainWorkOrder: formData.value,
-      mainWorkOrderBom: list.value,
-      mainWorkOrderMaterials: materialList.value
+      materialRequisition: formData.value,
+      materialReqDetails: materialList.value
     }
-    await IotMainWorkOrderApi.addWorkOrder(data)
+    await IotMaterialRequisitionApi.addMaterialRequisition(data)
     message.success(t('common.createSuccess'))
     close()
-
     // 发送操作成功的事件
     emit('success')
   } finally {
@@ -331,11 +294,11 @@ const validateTableData = (): boolean => {
   let isValid = true
   const errorMessages: string[] = []
 
-  if (list.value.length === 0) {
-    errorMessages.push('请至少添加一条设备保养明细')
+  if (materialList.value.length === 0) {
+    errorMessages.push('请至少添加一条物料明细')
     isValid = false
     // 直接返回无需后续校验
-    message.error('请至少添加一条设备保养明细')
+    message.error('请至少添加一条物料明细')
     return isValid
   }
   return isValid
@@ -362,38 +325,26 @@ onMounted(async () => {
   // 查询当前登录人所属部门名称
   dept.value = await DeptApi.getDept(deptId)
   formData.value.name = dept.value.name + ' - 领料单'
-  deptUsers.value = await UserApi.getDeptUsersByDeptId(deptId)
   formData.value.deptId = deptId
   try {
     formType.value = 'create'
-    const { wsCache } = useCache()
-    const userInfo = wsCache.get(CACHE_KEY.USER)
   } catch (error) {
     console.error('数据加载失败:', error)
     message.error('数据加载失败,请重试')
   }
 })
 
-const handleDelete = async (str: string) => {
+const handleDelete = async (materialCode: string) => {
   try {
-    const [deviceIdStr, bomNodeId] = str.split('-')
-    const deviceId = parseInt(deviceIdStr)
-    // 删除列表项
-    const index = list.value.findIndex((item) => (item.deviceId+'-'+item.bomNodeId) === str)
+    // 从 materialList 中移除对应物料
+    const index = materialList.value.findIndex(item => item.materialCode === materialCode);
     if (index !== -1) {
-      list.value.splice(index, 1)
-      deviceIds.value = []
-    }
-    // 更新设备ID列表(需要检查是否还有该设备的其他项)
-    const hasOtherItems = list.value.some(item => item.deviceId === deviceId)
-    if (!hasOtherItems) {
-      deviceIds.value = deviceIds.value.filter(id => id !== deviceId)
-      devicePersonsMap.value.delete(deviceId) // 移除对应设备的责任人
+      materialList.value.splice(index, 1);
+      calculateTotalCost(); // 重新计算总费用
     }
-    // message.success('移除成功')
   } catch (error) {
-    console.error('移除失败:', error)
-    message.error('移除失败')
+    console.error('移除失败:', error);
+    message.error('移除失败');
   }
 }
 

+ 5 - 1
src/views/pms/iotmaterialrequisition/SelectLocalStock.vue

@@ -114,6 +114,7 @@ import {DICT_TYPE} from "@/utils/dict";
 import {ContentWrap} from "@/components/ContentWrap";
 import {IotSapStockApi, IotSapStockVO} from "@/api/pms/iotsapstock";
 import {IotLockStockApi, IotLockStockVO} from "@/api/pms/iotlockstock";
+import {useUserStore} from "@/store/modules/user";
 const { t } = useI18n() // 国际化
 // 调整 emit 类型
 const emit = defineEmits<{
@@ -132,6 +133,7 @@ const queryParams = reactive({
   pageNo: 1,
   pageSize: 10,
   label: '',
+  deptId: undefined,
   materialName: undefined,
   materialCode: undefined,
   status: undefined,
@@ -193,7 +195,9 @@ defineExpose({ open }) // 提供 open 方法,用于打开弹窗
 const getList = async () => {
   loading.value = true
   try {
-    // const data = await SapStockApi.IotSapStockApi.getIotSapStockPage(queryParams)
+    // 查询当前登录人所在部门关联的本地库存
+    const deptId = useUserStore().getUser.deptId
+    queryParams.deptId = deptId;
     const data = await IotLockStockApi.getIotLockStockPage(queryParams)
     list.value = data.list
     total.value = data.total

+ 12 - 0
src/views/pms/iotmaterialrequisition/index.vue

@@ -68,6 +68,14 @@
       />
       <el-table-column label="操作" align="center" min-width="120px">
         <template #default="scope">
+          <el-button
+            link
+            type="primary"
+            @click="detail(scope.row.id)"
+            v-hasPermi="['pms:iot-material-requisition:query']"
+          >
+            {{ t('operationFill.view')  }}
+          </el-button>
           <el-button
             link
             type="primary"
@@ -180,6 +188,10 @@ const openForm = (type: string, id?: number) => {
   }
 }
 
+const detail = (id?: number) => {
+  push({ name: 'IotMaterialReqDetail', params:{id} })
+}
+
 /** 删除按钮操作 */
 const handleDelete = async (id: number) => {
   try {