瀏覽代碼

入库增加一键出库

xiongxing 2 月之前
父節點
當前提交
ebe23fdd2d

+ 8 - 0
src/api/material/stockInAndOut/index.ts

@@ -140,4 +140,12 @@ export const exportMaterialOutbound = (id) => {
   return request.download({
     url: 'material-io/outbound/export?id='+id
   })
+}
+
+// 生成出库单
+export const generateMaterialOutboundByInbound = (params) => {
+  return request.post({
+    url: 'material-io/outbound-by-inbound',
+    data: params
+  })
 }

+ 122 - 0
src/views/warehouses/materialsIn/components/GenerateOutboundDialog.vue

@@ -0,0 +1,122 @@
+<template>
+  <Dialog v-model="visible" :title="dialogTitle" width="600px" @close="handleDialogClose">
+    <el-form ref="formRef" :model="form" label-width="100px" :rules="formRules">
+      <el-form-item label="出库日期" prop="orderDate">
+        <el-date-picker
+          v-model="form.orderDate"
+          type="date"
+          placeholder="选择日期"
+          value-format="YYYY-MM-DD"
+          style="width: 100%"
+        />
+      </el-form-item>
+      <el-form-item label="领用部门" prop="outDeptId">
+        <el-tree-select
+          v-model="form.outDeptId"
+          :data="departmentOptions"
+          :props="defaultProps"
+          check-strictly
+          node-key="id"
+          placeholder="请选择领用部门"
+        />
+      </el-form-item>
+      <el-form-item label="领用人" prop="outUser">
+        <el-input v-model="form.outUser" placeholder="请输入领用人" />
+      </el-form-item>
+      <el-form-item label="出库原因" prop="outReason">
+        <el-input v-model="form.outReason" placeholder="请输入出库原因" />
+      </el-form-item>
+      <el-form-item label="备注" prop="remark">
+        <el-input v-model="form.remark" type="textarea" :rows="3" placeholder="请输入备注信息" />
+      </el-form-item>
+    </el-form>
+
+    <template #footer>
+      <el-button @click="visible = false">取消</el-button>
+      <el-button type="primary" :loading="submitLoading" @click="handleSubmit">保存</el-button>
+    </template>
+  </Dialog>
+</template>
+
+<script setup>
+import { computed, reactive, ref, watch } from 'vue'
+import { ElMessage } from 'element-plus'
+import { defaultProps } from '@/utils/tree'
+import { generateMaterialOutboundByInbound } from '@/api/material/stockInAndOut'
+
+defineOptions({ name: 'GenerateOutboundDialog' })
+
+const props = defineProps({
+  modelValue: { type: Boolean, default: false },
+  inboundOrderId: { type: [Number, String], default: undefined },
+  tenantId: { type: [Number, String], default: undefined },
+  departmentOptions: { type: Array, default: () => [] },
+})
+
+const emit = defineEmits(['update:modelValue', 'success'])
+
+const visible = computed({
+  get: () => props.modelValue,
+  set: (val) => emit('update:modelValue', val),
+})
+
+const formRef = ref(null)
+const submitLoading = ref(false)
+
+const form = reactive({
+  orderDate: new Date().toISOString().split('T')[0],
+  outDeptId: undefined,
+  outUser: '',
+  outReason: '',
+  remark: '',
+})
+
+const formRules = reactive({
+  orderDate: [{ required: true, message: '请选择出库日期' }],
+  outDeptId: [{ required: true, message: '请选择领用部门' }],
+  outUser: [{ required: true, message: '请输入领用人' }],
+  outReason: [{ required: true, message: '请输入出库原因' }],
+})
+
+watch(
+  () => props.modelValue,
+  (opened) => {
+    if (!opened) return
+    form.orderDate = new Date().toISOString().split('T')[0]
+    form.outDeptId = undefined
+    form.outUser = ''
+    form.outReason = ''
+    form.remark = ''
+  }
+)
+
+const dialogTitle = computed(() => '生成出库单')
+
+const handleDialogClose = () => {
+  formRef.value?.resetFields?.()
+}
+
+const handleSubmit = async () => {
+  await formRef.value?.validate?.()
+  submitLoading.value = true
+  try {
+    const payload = {
+      inboundOrderId: Number(props.inboundOrderId),
+      orderDate: form.orderDate,
+      outDeptId: form.outDeptId,
+      outUser: form.outUser,
+      outReason: form.outReason,
+      remark: form.remark || undefined,
+      tenantId: props.tenantId,
+    }
+    await generateMaterialOutboundByInbound(payload)
+    ElMessage.success('生成成功')
+    visible.value = false
+    emit('success')
+  } catch (e) {
+    ElMessage.error(e?.message || '生成失败')
+  } finally {
+    submitLoading.value = false
+  }
+}
+</script>

+ 32 - 1
src/views/warehouses/materialsIn/index.vue

@@ -58,6 +58,7 @@
             <el-button v-hasPermi="['warehouses:materialsIn:export']" link type="success" @click="handleExport(row.id)" :loading="exportLoading">导出</el-button>
             <el-button v-hasPermi="['warehouses:materialsIn:print']" link type="primary" @click="handlePrint(row)">打印</el-button>
             <el-button v-hasPermi="['warehouses:materialsIn:delete']" link type="danger" @click="handleDelete(row)">删除</el-button>
+            <el-button v-hasPermi="['warehouses:materialsIn:generateOutbound']" link type="primary" @click="handleGenerateOutbound(row)">生成出库单</el-button>
           </template>
         </el-table-column>
       </el-table>
@@ -83,6 +84,13 @@
       :warehouse-options="warehouseOptions"
       @refresh="getTableData"
     />
+    <GenerateOutboundDialog
+      v-model="generateOutboundVisible"
+      :inbound-order-id="generateInboundOrderId"
+      :tenant-id="generateTenantId"
+      :department-options="departmentOptions"
+      @success="getTableData"
+    />
     <Print ref="printRef" />
     <!-- 导入弹窗(复用 system/user 的 ImportFile 组件) -->
     <Import ref="importRef" :config="importConfig" @success="handleImportSuccess" />
@@ -99,10 +107,13 @@ import { materialList } from '@/api/material/basicMessage'
 import { getStrDictOptions, DICT_TYPE } from '@/utils/dict'
 import download from '@/utils/download'
 import Import from '@/components/ImportFile/index.vue'
+import { handleTree } from '@/utils/tree'
+import * as DeptApi from '@/api/system/dept'
 
 const message = useMessage()
 
 const MaterialsInDialog = defineAsyncComponent(() => import('./components/MaterialsInDialog.vue'))
+const GenerateOutboundDialog = defineAsyncComponent(() => import('./components/GenerateOutboundDialog.vue'))
 const Print = defineAsyncComponent(() => import('./components/Print.vue'))
 
 const userStore = useUserStore()  
@@ -123,6 +134,9 @@ const exportLoading = ref(false)
 // 弹窗
 const dialogVisible = ref(false)
 const dialogMode = ref('add') // 'add', 'edit', 'view'
+const generateOutboundVisible = ref(false)
+const generateInboundOrderId = ref(undefined)
+const generateTenantId = ref(undefined)
 
 const initialForm = {
   id: null,
@@ -141,13 +155,14 @@ const initialForm = {
 
 const form = reactive({ ...initialForm })
 
-
 // 模拟的物资选项 (用于 el-select-v2)
 const materialOptions = ref([])
 
 // 模拟的仓库选项
 const warehouseOptions = ref([])
 
+// 部门下拉
+const departmentOptions = ref([])
 
 // 导入(复用 ImportFile 组件)
 const importRef = ref()
@@ -222,6 +237,10 @@ const fetchStoreOptions = async () => {
   }
 }
 
+const fetchDepartmentOptions = async () => {
+  departmentOptions.value = handleTree(await DeptApi.getSimpleDeptList())
+}
+
 // 获取表格数据(分页接口)
 const getTableData = async () => {
   loading.value = true
@@ -387,6 +406,18 @@ const handleDelete = (row) => {
     })
     .catch(() => {})
 }
+
+// 生成出库单
+const handleGenerateOutbound = async (row) => {
+  if(queryParams.tenantIds.length == 0 || queryParams.tenantIds.length > 1){
+    ElMessage.error('生成出库单只能选择一个机构')
+    return
+  }
+  await fetchDepartmentOptions()
+  generateInboundOrderId.value = row.id
+  generateTenantId.value = row.tenantId || (queryParams.tenantIds ? queryParams.tenantIds[0] : undefined)
+  generateOutboundVisible.value = true
+}
 </script>
 
 <style scoped>