maven
9 天以前 941b7b96eb85d896a47a9457e1deb3aed1937775
src/views/inventoryManagement/stockManagement/index.vue
@@ -21,11 +21,12 @@
        <el-table-column align="center" label="序号" type="index" width="60" />
        <el-table-column label="库存日期" prop="createTime" width="100" show-overflow-tooltip />
        <el-table-column label="入库日期" prop="createTime" width="100" show-overflow-tooltip />
        <el-table-column label="供应商名称" prop="supplierName" width="160" show-overflow-tooltip />
        <el-table-column label="供应商名称" prop="supplierName" width="240" show-overflow-tooltip />
        <el-table-column label="产品大类" prop="productCategory" width="100" show-overflow-tooltip />
        <el-table-column label="规格型号" prop="specificationModel" width="100" show-overflow-tooltip />
        <el-table-column label="规格型号" prop="specificationModel" width="200" show-overflow-tooltip />
        <el-table-column label="单位" prop="unit" width="80" show-overflow-tooltip />
        <el-table-column label="库存数量" prop="inboundNum0" width="100" show-overflow-tooltip />
        <el-table-column label="最低库存数量" prop="minStock" width="130" show-overflow-tooltip />
        <el-table-column label="含税单价" prop="taxInclusiveUnitPrice" width="100" show-overflow-tooltip />
        <el-table-column label="含税总价" prop="taxInclusiveTotalPrice" width="100" show-overflow-tooltip />
        <el-table-column label="税率(%)" prop="taxRate" width="100" show-overflow-tooltip />
@@ -33,14 +34,14 @@
        <el-table-column label="入库人" prop="createBy" width="80" show-overflow-tooltip />
        <el-table-column fixed="right" label="操作" min-width="60" align="center">
          <template #default="scope">
            <el-button link type="primary" size="small" @click="openForm('edit', scope.row);">编辑</el-button>
            <el-button link type="primary" size="small" @click="openForm('edit', scope.row);" :disabled="scope.row.createUser !== userStore.id">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total > 0" :total="total" layout="total, sizes, prev, pager, next, jumper"
        :page="page.current" :limit="page.size" @pagination="paginationChange" />
    </div>
    <el-dialog v-model="dialogFormVisible" :title="operationType === 'add' ? '新增出库' : '编辑出库'" width="70%"
    <el-dialog v-model="dialogFormVisible" :title="operationType === 'add' ? '新增库存' : '编辑库存'" width="70%"
      @close="closeDia">
      <el-form :model="form" label-width="140px" label-position="top" :rules="rules" ref="formRef">
        <el-row :gutter="30">
@@ -115,7 +116,6 @@
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="出库人:" prop="entryPerson">
              <el-select v-model="form.createUser" placeholder="请选择" clearable>
@@ -123,6 +123,11 @@
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
          <el-form-item label="最低库存:" prop="minStock">
            <el-input v-model="form.minStock" placeholder="请输入最低库存" clearable />
          </el-form-item>
        </el-col>
        </el-row>
      </el-form>
      <template #footer>
@@ -140,7 +145,7 @@
import { ref } from 'vue'
import { ElMessageBox } from "element-plus";
import useUserStore from '@/store/modules/user'
import { userListNoPage } from "@/api/system/user.js";
import { userListNoPageByTenantId } from "@/api/system/user.js";
import { productTreeList,modelList } from "@/api/basicData/product.js"
import {
  getStockManagePage ,
@@ -149,8 +154,11 @@
  exportStockManage
} from "@/api/inventoryManagement/stockManage.js";
import {
  updateManagement
  updateManagement,addSutockIn,selectProductRecordListByPuechaserId,updateStockIn
} from "@/api/inventoryManagement/stockIn.js";
const userStore = useUserStore()
const { proxy } = getCurrentInstance()
const tableData = ref([])
@@ -167,7 +175,7 @@
})
const total = ref(0)
const fileList = ref([])
const loading = ref(false);
// 用户信息表单弹框数据
const operationType = ref('')
const dialogFormVisible = ref(false)
@@ -194,6 +202,8 @@
    inboundBatch: '',
    stockQuantity: '',
    boundTime: '',
    minStock: '', // 新增最低库存字段
    salesLedgerProductId: null,
  },
  rules: {
    supplierName: [{ required: true, message: '请输入供应商名称', trigger: 'blur' }],
@@ -207,7 +217,8 @@
    taxExclusiveTotalPrice: [{ required: true, message: '请输入不含税总价', trigger: 'blur' }],
    boundTime: [{ required: true, message: '请选择库存时间', trigger: 'change' }],
    inboundTime: [{ required: true, message: '请选择入库时间', trigger: 'change' }],
    inboundPerson: [{ required: true, message: '请选择出库人', trigger: 'change' }]
    inboundPerson: [{ required: true, message: '请选择出库人', trigger: 'change' }],
    minStock: [{ required: true, message: '请输入最低库存', trigger: 'blur' }],
  }
})
const { searchForm, form, rules } = toRefs(data)
@@ -228,11 +239,13 @@
  getStockManagePage({ ...searchForm.value, ...page }).then(res => {
    tableLoading.value = false
    tableData.value = res.data.records
    console.log('res', res)
    // console.log('res', res)
    // tableData.value.map(item => {
    //   item.children = []
    // })
    // total.value = res.total
    total.value = res.data.total
    // 数据加载完成后检查库存
    checkStockAndCreatePurchase();
  }).catch(() => {
    tableLoading.value = false
  })
@@ -257,7 +270,7 @@
  operationType.value = type
  form.value = {}
  productData.value = []
  let userLists = await userListNoPage()
  let userLists = await userListNoPageByTenantId()
  userList.value = userLists.data
  // customerList().then(res => {
  //   customerOption.value = res
@@ -294,26 +307,69 @@
  console.log(form.value)
  proxy.$refs["formRef"].validate(valid => {
    if (valid) {
      // if (productData.value.length > 0) {
      //   form.value.productData = proxy.HaveJson(productData.value)
      // } else {
      //   proxy.$modal.msgWarning('请添加产品信息')
      //   return
      // }
      // let tempFileIds = []
      // if (fileList.value.length > 0) {
      //   tempFileIds = fileList.value.map(item => item.tempId)
      // }
      // form.value.tempFileIds = tempFileIds
      // form.value.type = 1
      updateManagement(form.value).then(res => {
        proxy.$modal.msgSuccess("提交成功")
        closeDia()
        getList()
        // 提交后检查库存并尝试创建请购单
        checkStockAndCreatePurchase();
      })
    }
  })
}
// const handList = () => {
//   selectProductRecordListByPuechaserId().then(res => {
//     productModelList.value = res.data.filter(item => item.productName === value)
//     console.log('productModelList.value', productModelList.value)
//   })
// }
// 检查库存并创建请购单
const checkStockAndCreatePurchase = async () => {
  const stockList = tableData.value;
  // handList()
  for (const item of stockList) {
    if (item.inboundNum0 < item.minStock) {
      try {
        console.log('item', item)
          // const stockInData = {
          //   nickName: userStore.nickName,// 使用新格式化函数
          //   details: [{
          //     id: item.salesLedgerProductId,
          //     inboundQuantity: item.minStock - item.inboundNum0
          //   }]
          // };
          const stockInData = {
            id: item.id,
            quantityStock: item.minStock + item.totalInboundNum,// 使用新格式化函数
          };
        console.log('准备提交的数据:', JSON.parse(JSON.stringify(stockInData)));
          loading.value = true
          // await addSutockIn(stockInData)
          await updateStockIn(stockInData)
          proxy.$modal.msgSuccess(`产品 ${item.productCategory} 修改入库成功`)
          loading.value = false
        // // 生成请购单
        // const createRes = await createPurchaseRequest({
        //   productId: item.productId,
        //   requiredQuantity: item.minStock - item.inboundNum0,
        //   supplierId: item.supplierId
        // });
        // if (createRes.code === 200) {
        //   // 流转请购单到采购模块
        //   await transferPurchaseRequest({ requestId: createRes.data.id });
        //   proxy.$modal.msgSuccess(`产品 ${item.productName} 请购单已生成并流转`);
        // }
      } catch (error) {
        proxy.$modal.msgError(`产品 ${item.productCategory} 生成请购单失败,请手动处理`);
      }
    }
  }
};
// 关闭弹框
const closeDia = () => {
  proxy.resetForm("formRef")
@@ -339,6 +395,12 @@
const handleDelete = () => {
  let ids = []
  if (selectedRows.value.length > 0) {
      // 检查是否有他人维护的数据
      const unauthorizedData = selectedRows.value.filter(item => item.createUser !== userStore.id);
      if (unauthorizedData.length > 0) {
         proxy.$modal.msgWarning("不可删除他人维护的数据");
         return;
      }
    ids = selectedRows.value.map(item => item.id);
  } else {
    proxy.$modal.msgWarning('请选择数据')
@@ -370,6 +432,14 @@
}
onMounted(() => {
  getList()
  checkStockAndCreatePurchase();
    // 每小时检查一次库存
    const intervalId = setInterval(checkStockAndCreatePurchase, 60 * 60 * 1000);
onUnmounted(() => {
  // 组件卸载时清除定时器
  clearInterval(intervalId);
});
})
</script>