瀏覽代碼

新增物料

lipenghui 4 月之前
父節點
當前提交
6d6c21d6de

+ 52 - 49
src/api/pms/maintain/material/index.ts

@@ -1,49 +1,52 @@
-import request from '@/config/axios'
-
-// 工单物料 VO
-export interface IotMaintainMaterialVO {
-  id: number // 主键
-  code: string // 物料编码
-  name: string // 物料名称
-  unit: string // 单位
-  price: number // 单价
-  sourceType: string // 物料来源
-  depleteCount: number // 消耗数量
-  totalCount: number // 总库存数量
-  sapCode: string // SAP系统中的物料唯一编号
-  status: number // 状态 0启用  1停用
-  remark: string // 备注
-}
-
-// 工单物料 API
-export const IotMaintainMaterialApi = {
-  // 查询工单物料分页
-  getIotMaintainMaterialPage: async (params: any) => {
-    return await request.get({ url: `/rq/iot-maintain-material/page`, params })
-  },
-
-  // 查询工单物料详情
-  getIotMaintainMaterial: async (id: number) => {
-    return await request.get({ url: `/rq/iot-maintain-material/get?id=` + id })
-  },
-
-  // 新增工单物料
-  createIotMaintainMaterial: async (data: IotMaintainMaterialVO) => {
-    return await request.post({ url: `/rq/iot-maintain-material/create`, data })
-  },
-
-  // 修改工单物料
-  updateIotMaintainMaterial: async (data: IotMaintainMaterialVO) => {
-    return await request.put({ url: `/rq/iot-maintain-material/update`, data })
-  },
-
-  // 删除工单物料
-  deleteIotMaintainMaterial: async (id: number) => {
-    return await request.delete({ url: `/rq/iot-maintain-material/delete?id=` + id })
-  },
-
-  // 导出工单物料 Excel
-  exportIotMaintainMaterial: async (params) => {
-    return await request.download({ url: `/rq/iot-maintain-material/export-excel`, params })
-  },
-}
+import request from '@/config/axios'
+
+// 工单物料 VO
+export interface IotMaintainMaterialVO {
+  id: number // 主键
+  code: string // 物料编码
+  name: string // 物料名称
+  unit: string // 单位
+  price: number // 单价
+  sourceType: string // 物料来源
+  depleteCount: number // 消耗数量
+  totalCount: number // 总库存数量
+  sapCode: string // SAP系统中的物料唯一编号
+  status: number // 状态 0启用  1停用
+  remark: string // 备注
+}
+
+// 工单物料 API
+export const IotMaintainMaterialApi = {
+  // 查询工单物料分页
+  getIotMaintainMaterialPage: async (params: any) => {
+    return await request.get({ url: `/rq/iot-maintain-material/page`, params })
+  },
+
+  // 查询工单物料详情
+  getIotMaintainMaterial: async (id: number) => {
+    return await request.get({ url: `/rq/iot-maintain-material/get?id=` + id })
+  },
+
+  // 新增工单物料
+  createIotMaintainMaterial: async (data: IotMaintainMaterialVO) => {
+    return await request.post({ url: `/rq/iot-maintain-material/create`, data })
+  },
+
+  // 修改工单物料
+  updateIotMaintainMaterial: async (data: IotMaintainMaterialVO) => {
+    return await request.put({ url: `/rq/iot-maintain-material/update`, data })
+  },
+
+  // 删除工单物料
+  deleteIotMaintainMaterial: async (id: number) => {
+    return await request.delete({ url: `/rq/iot-maintain-material/delete?id=` + id })
+  },
+
+  // 导出工单物料 Excel
+  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}` })
+  },
+}

+ 150 - 0
src/views/pms/maintain/material/ChooseMaterial.vue

@@ -0,0 +1,150 @@
+<template>
+  <Dialog v-model="dialogVisible" title="选择物料" style="width: 1100px; max-height: 800px">
+    <ContentWrap>
+      <el-form
+        class="-mb-15px"
+        :model="queryParams"
+        ref="queryFormRef"
+        :inline="true"
+        label-width="68px"
+      >
+        <el-form-item label="物料编码" prop="code">
+          <el-input
+            v-model="queryParams.code"
+            placeholder="请输入物料编码"
+            clearable
+            @keyup.enter="handleQuery"
+            class="!w-240px"
+          />
+        </el-form-item>
+        <el-form-item label="物料名称" prop="name">
+          <el-input
+            v-model="queryParams.name"
+            placeholder="请输入物料名称"
+            clearable
+            @keyup.enter="handleQuery"
+            class="!w-240px"
+          />
+        </el-form-item>
+        <el-form-item>
+          <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
+          <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
+        </el-form-item>
+      </el-form>
+    </ContentWrap>
+    <ContentWrap>
+      <el-table
+        v-loading="loading"
+        :data="list"
+        :stripe="true"
+        :show-overflow-tooltip="true"
+        @row-click="handleRowClick"
+      >
+        <el-table-column width="60" label="选择">
+          <template #default="{ row }">
+            <el-radio
+              :model-value="selectedRow?.id"
+              :label="row.id"
+              @click.stop="selectRow(row)"
+              class="no-label-radio"
+            />
+          </template>
+        </el-table-column>
+        <el-table-column
+          label="物料编码"
+          align="center"
+          prop="code"
+          :show-overflow-tooltip="true"
+        />
+        <el-table-column
+          label="物料名称"
+          align="center"
+          prop="name"
+          :show-overflow-tooltip="true"
+        />
+        <el-table-column label="单位" align="center" prop="unit" width="120" />
+        <el-table-column label="总库存数量" align="center" prop="totalCount" width="120" />
+      </el-table>
+      <!-- 分页 -->
+      <Pagination
+        :total="total"
+        v-model:page="queryParams.pageNo"
+        v-model:limit="queryParams.pageSize"
+        @pagination="getList"
+      />
+    </ContentWrap>
+  </Dialog>
+</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";
+
+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 total = ref(0) // 列表的总页数
+const queryParams = reactive({
+  pageNo: 1,
+  pageSize: 10,
+})
+
+const selectedRow = ref(null)
+
+// 处理单选逻辑
+const selectRow = (row) => {
+  selectedRow.value = selectedRow.value?.id === row.id ? null : row
+  emit('choose', row)
+  dialogVisible.value = false
+}
+
+// 点击整行选中
+const handleRowClick = (row) => {
+  selectRow(row)
+}
+const open = async (type: string, id?: number) => {
+  dialogVisible.value = true
+  await getList()
+}
+defineExpose({ open }) // 提供 open 方法,用于打开弹窗
+const getList = async () => {
+  loading.value = true
+  try {
+    const data = await MaintainMaterialApi.IotMaintainMaterialApi.getMaterialsByDeviceId(queryParams)
+    list.value = data.list
+    total.value = data.total
+  } finally {
+    loading.value = false
+  }
+}
+
+/** 搜索按钮操作 */
+const handleQuery = () => {
+  queryParams.pageNo = 1
+  getList()
+}
+const choose = (row: DictDataVO) => {
+  emit('choose', row)
+  dialogVisible.value = false
+}
+/** 重置按钮操作 */
+const resetQuery = () => {
+  queryFormRef.value.resetFields()
+  handleQuery()
+}
+</script>
+<style lang="scss">
+.no-label-radio .el-radio__label {
+  display: none;
+}
+.no-label-radio .el-radio__inner {
+  margin-right: 0;
+}
+</style>

+ 1 - 2
src/views/pms/maintain/material/MaterialSelect.vue

@@ -1,5 +1,5 @@
 <template>
-  <Dialog v-model="dialogVisible" title="选择品牌" style="width: 1100px; max-height: 800px">
+  <Dialog v-model="dialogVisible" title="选择物料" style="width: 1100px; max-height: 800px">
     <ContentWrap>
       <el-form
         class="-mb-15px"
@@ -108,7 +108,6 @@ const queryParams = reactive({
   pageSize: 10,
   label: '',
   status: undefined,
-  dictType: 'pms_device_brand'
 })
 
 const selectedRow = ref(null)

+ 2 - 2
src/views/pms/maintain/material/index.vue

@@ -9,7 +9,7 @@
       label-width="68px"
     >
       <el-form-item>
-        <el-button @click="handleQuery" type="primary"
+        <el-button @click="openForm" type="primary"
           ><Icon icon="ep:plus" class="mr-5px" /> 选择物料</el-button
         >
         <el-button @click="handleView" type="warning"
@@ -51,7 +51,7 @@
   </ContentWrap>
 
   <!-- 表单弹窗:添加/修改 -->
-<!--  <IotMaintainMaterialForm ref="formRef" @success="getList" />-->
+  <ChooseMaterial ref="formRef"  />
   <MaintainMaterialDrawer ref="showDrawer" :model-value="drawerVisible"
     @update:model-value="val => drawerVisible = val"
     @add="handleChildSubmit"