Răsfoiți Sursa

选择物料

lipenghui 4 luni în urmă
părinte
comite
2416a8ffe8

+ 2 - 2
src/api/pms/maintain/material/index.ts

@@ -46,7 +46,7 @@ export const IotMaintainMaterialApi = {
   exportIotMaintainMaterial: async (params) => {
     return await request.download({ url: `/rq/iot-maintain-material/export-excel`, params })
   },
-  getMaterialsByDeviceId: async (deviceId) => {
-    return await request.get({ url: `/rq/iot-maintain-material/choose?deviceId=${deviceId}` })
+  getMaterialsByDeviceId: async (params) => {
+    return await request.get({ url: `/rq/iot-maintain-material/choose`, params })
   },
 }

+ 1 - 1
src/views/pms/maintain/IotMaintain.vue

@@ -156,7 +156,7 @@
     </el-form>
   </ContentWrap>
   <ContentWrap>
-    <MaintainMaterial />
+    <MaintainMaterial  :deptId="formData.deptId"/>
   </ContentWrap>
   <ContentWrap>
   <el-form>

+ 12 - 12
src/views/pms/maintain/material/ChooseMaterial.vue

@@ -14,7 +14,6 @@
             placeholder="请输入物料编码"
             clearable
             @keyup.enter="handleQuery"
-            class="!w-240px"
           />
         </el-form-item>
         <el-form-item label="物料名称" prop="name">
@@ -23,7 +22,6 @@
             placeholder="请输入物料名称"
             clearable
             @keyup.enter="handleQuery"
-            class="!w-240px"
           />
         </el-form-item>
         <el-form-item>
@@ -77,25 +75,24 @@
 </template>
 
 <script setup lang="ts">
-import { DictDataVO } from '@/api/system/dict/dict.data'
-import { dateFormatter } from '@/utils/formatTime'
-import * as DictTypeApi from '@/api/system/dict/dict.type'
-import { checkPermi } from '@/utils/permission'
 import * as MaintainMaterialApi from '@/api/pms/maintain/material'
-import {DICT_TYPE} from "@/utils/dict";
+import { IotMaintainMaterialVO } from '@/api/pms/maintain/material'
+import { propTypes } from '@/utils/propTypes'
 
 const emit = defineEmits(['choose']) // 定义 success 事件,用于操作成功后的回调
 const dialogVisible = ref(false) // 弹窗的是否展示
 const loading = ref(true) // 列表的加载中
 const queryFormRef = ref() // 搜索的表单
-const list = ref<DictDataVO[]>([]) // 列表的数据
-const dictTypeList = ref<DictTypeApi.DictTypeVO[]>() // 字典类型的列表
+const list = ref<IotMaintainMaterialVO[]>([]) // 列表的数据
 const total = ref(0) // 列表的总页数
 const queryParams = reactive({
   pageNo: 1,
   pageSize: 10,
+  deptId: undefined
+})
+const props = defineProps({
+  deptId: propTypes.number.def(undefined)
 })
-
 const selectedRow = ref(null)
 
 // 处理单选逻辑
@@ -117,7 +114,10 @@ defineExpose({ open }) // 提供 open 方法,用于打开弹窗
 const getList = async () => {
   loading.value = true
   try {
-    const data = await MaintainMaterialApi.IotMaintainMaterialApi.getMaterialsByDeviceId(queryParams)
+    queryParams.deptId = props.deptId
+    debugger
+    const data =
+      await MaintainMaterialApi.IotMaintainMaterialApi.getMaterialsByDeviceId(queryParams)
     list.value = data.list
     total.value = data.total
   } finally {
@@ -130,7 +130,7 @@ const handleQuery = () => {
   queryParams.pageNo = 1
   getList()
 }
-const choose = (row: DictDataVO) => {
+const choose = (row: IotMaintainMaterialVO) => {
   emit('choose', row)
   dialogVisible.value = false
 }

+ 6 - 4
src/views/pms/maintain/material/MaintainMaterialDrawer.vue

@@ -49,6 +49,7 @@ import { defineEmits, defineOptions, ref, watch } from 'vue'
 import { ElMessage } from 'element-plus'
 import * as PmsMaterialApi from '@/api/pms/material'
 import {CommonStatusEnum} from "@/utils/constants";
+import MaterialSelect from './MaterialSelect.vue'
 
 const drawerVisible = ref<boolean>(false)
 const emit = defineEmits(['update:modelValue', 'add'])
@@ -86,15 +87,15 @@ const resetDrawerForm = () => {
   drawerFormData.value = {
     id: undefined,
     code1: undefined,
-    name: undefined,
-    unit: undefined,
-    price: undefined,
+    name1: undefined,
+    unit1: undefined,
+    price1: undefined,
     sourceType: undefined,
     depleteCount: undefined,
     totalCount: undefined,
     sapCode: undefined,
     status: undefined,
-    remark: undefined
+    remark1: undefined
   }
   drawerRef.value?.resetFields()
 }
@@ -141,6 +142,7 @@ const handleClose = () => {
 const drawerRef = ref()
 const submitForm= async ()=> {
   await drawerRef.value.validate()
+  drawerFormData.value.sourceType = '手动添加'
   emit('add', drawerFormData.value);
   emit('update:modelValue', false)
 }

+ 72 - 34
src/views/pms/maintain/material/index.vue

@@ -26,44 +26,58 @@
       <el-table-column label="物料名称" align="center" prop="name" />
       <el-table-column label="单位" align="center" prop="unit" />
       <el-table-column label="单价" align="center" prop="price" />
-      <el-table-column label="消耗数量" align="center" prop="depleteCount" />
+      <el-table-column label="消耗数量" align="center" prop="depleteCount" >
+        <template #default="scope">
+          <el-input
+            v-model="scope.row.depleteCount"
+          />
+        </template>
+      </el-table-column>
       <el-table-column label="总库存数量" align="center" prop="totalCount" />
-      <el-table-column label="备注" align="center" prop="remark" />
+      <el-table-column label="备注" align="center" prop="remark" >
+        <template #default="scope">
+          <el-input
+            v-model="scope.row.remark"
+          />
+        </template>
+      </el-table-column>
       <el-table-column label="物料来源" align="center" prop="sourceType" />
       <el-table-column label="操作" align="center" min-width="120px">
         <template #default="scope">
-          <div style="display: flex; justify-content: center;align-items: center;width: 100%">
+          <div style="display: flex; justify-content: center; align-items: center; width: 100%">
             <div>
-              <Icon style="vertical-align: middle;color: #ea3434" icon="ep:zoom-out"/>
-              <el-button style="vertical-align: middle" link type="danger" @click="handleDelete(scope.row.code)"> 移除 </el-button>
+              <Icon style="vertical-align: middle; color: #ea3434" icon="ep:zoom-out" />
+              <el-button
+                style="vertical-align: middle"
+                link
+                type="danger"
+                @click="handleDelete(scope.row.code)"
+              >
+                移除
+              </el-button>
             </div>
           </div>
         </template>
       </el-table-column>
     </el-table>
-    <!-- 分页 -->
-<!--    <Pagination-->
-<!--      :total="total"-->
-<!--      v-model:page="queryParams.pageNo"-->
-<!--      v-model:limit="queryParams.pageSize"-->
-<!--      @pagination="getList"-->
-<!--    />-->
   </ContentWrap>
 
   <!-- 表单弹窗:添加/修改 -->
-  <ChooseMaterial ref="formRef"  />
-  <MaintainMaterialDrawer ref="showDrawer" :model-value="drawerVisible"
-    @update:model-value="val => drawerVisible = val"
+  <ChooseMaterial ref="formRef" :deptId="props.deptId"  @choose="selectChoose"/>
+  <MaintainMaterialDrawer
+    ref="showDrawer"
+    :model-value="drawerVisible"
+    @update:model-value="(val) => (drawerVisible = val)"
     @add="handleChildSubmit"
   />
 </template>
 
 <script setup lang="ts">
-import download from '@/utils/download'
-import { IotMaintainMaterialApi, IotMaintainMaterialVO } from '@/api/pms/maintain/material'
-import IotMaintainMaterialForm from './IotMaintainMaterialForm.vue'
-import {ref} from "vue";
-import MaintainMaterialDrawer from "@/views/pms/maintain/material/MaintainMaterialDrawer.vue";
+import { IotMaintainMaterialVO } from '@/api/pms/maintain/material'
+import { ref } from 'vue'
+import MaintainMaterialDrawer from '@/views/pms/maintain/material/MaintainMaterialDrawer.vue'
+import {propTypes} from "@/utils/propTypes";
+import ChooseMaterial from "@/views/pms/maintain/material/ChooseMaterial.vue";
 
 /** 工单物料 列表 */
 defineOptions({ name: 'IotMaintainMaterial' })
@@ -76,6 +90,9 @@ const drawerVisible = ref<boolean>(false)
 const showDrawer = ref()
 const list = ref<IotMaintainMaterialVO[]>([]) // 列表的数据
 const total = ref(0) // 列表的总页数
+const props = defineProps({
+  deptId: propTypes.number.def(undefined)
+})
 const queryParams = reactive({
   pageNo: 1,
   pageSize: 10,
@@ -91,23 +108,40 @@ const queryParams = reactive({
   remark: undefined,
   createTime: []
 })
+const formData = ref({
+  id: undefined,
+  code: undefined,
+  name: undefined,
+  unit: undefined,
+  price: undefined,
+  sourceType: undefined,
+  depleteCount: undefined,
+  totalCount: undefined,
+  sapCode: undefined,
+  status: undefined,
+  remark: undefined,
+})
 const queryFormRef = ref() // 搜索的表单
 const exportLoading = ref(false) // 导出的加载中
-
-const handleChildSubmit=(formData)=> {
-  console.log('接收到的数据:', JSON.stringify(formData));
-
-  const modified = removeOnesFromKeys(formData);
-  list.value.push(modified);
+const selectChoose = (formData) => {
+  console.log('接收到的数据:', JSON.stringify(formData))
+  list.value.push(formData)
+}
+const handleChildSubmit = (formData) => {
+  const modified = removeOnesFromKeys(formData)
+  list.value.push(modified)
 }
 
 const removeOnesFromKeys = (obj: Record<string, any>) => {
-  return Object.keys(obj).reduce((acc, key) => {
-    const newKey = key.replace(/1/g, ''); // 替换所有 1
-    acc[newKey] = obj[key];
-    return acc;
-  }, {} as Record<string, any>);
-};
+  return Object.keys(obj).reduce(
+    (acc, key) => {
+      const newKey = key.replace(/1/g, '') // 替换所有 1
+      acc[newKey] = obj[key]
+      return acc
+    },
+    {} as Record<string, any>
+  )
+}
 const handleView = () => {
   drawerVisible.value = true
   showDrawer.value.openDrawer()
@@ -137,6 +171,10 @@ const resetQuery = () => {
 /** 添加/修改操作 */
 const formRef = ref()
 const openForm = (type: string, id?: number) => {
+  if(!props.deptId) {
+    message.error("请选择设备")
+    return
+  }
   formRef.value.open(type, id)
 }
 
@@ -150,11 +188,11 @@ const handleDelete = async (id: number) => {
     // message.success(t('common.delSuccess'))
     // // 刷新列表
     // await getList()
-    const index = list.value.findIndex(item => item.code === id);
+    const index = list.value.findIndex((item) => item.code === id)
     debugger
     if (index !== -1) {
       // 通过 splice 删除元素
-      list.value.splice(index, 1);
+      list.value.splice(index, 1)
     }
   } catch {}
 }