Files
FT501-WMS/ruoyi-ui/src/views/out/addOutStockout.vue
2025-08-14 16:54:51 +08:00

313 lines
11 KiB
Vue

<template>
<div class="app-container">
<!-- 主表信息录入 -->
<el-form :model="formData" ref="formRef" size="small" :inline="true" label-width="68px" :rules="rules">
<el-form-item :label="$t('addOutStockout.warehouse')" prop="warehouseId" required><!--仓库-->
<el-select v-model="formData.warehouseId" :placeholder="$t('addOutStockout.selectWarehouse')" clearable>
<el-option
v-for="dict in warehouseOptions"
:key="dict.warehouseId"
:label="dict.warehouseName"
:value="dict.warehouseId"
/>
</el-select>
</el-form-item>
<el-form-item :label="$t('addOutStockout.customer')" prop="customerNo" required><!--客户-->
<el-input
v-model="formData.customerNo"
:placeholder="$t('addOutStockout.inputCustomerNo')"
clearable
/>
</el-form-item>
<el-form-item :label="$t('addOutStockout.documentType')" prop="outType" required><!--单据类型-->
<el-select v-model="formData.outType" :placeholder="$t('addOutStockout.selectDocumentType')" clearable>
<el-option
v-for="dict in dict.type.out_bill_type"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="warning" icon="el-icon-refresh" size="mini" @click="reset">{{$t('addOutStockout.reset')}}<!--重置--></el-button>
<el-button type="success" icon="el-icon-check" size="mini" @click="handleSave" v-hasPermi="['out:outStockout:saveBill']">{{$t('addOutStockout.saveDocument')}}<!--保存单据--></el-button>
</el-form-item>
</el-form>
<div class="mb8">
<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleSelectMaterials" v-hasPermi="['out:productAndStock:list']">{{$t('addOutStockout.selectMaterial')}}<!--选择物资--></el-button>
<el-button type="info" icon="el-icon-refresh-right" size="mini" @click="handleReload">{{$t('addOutStockout.recreateDocument')}}<!--重新建单--></el-button>
</div>
<!-- 物资明细表格 -->
<el-table v-loading="loading" :data="materialList">
<el-table-column :label="$t('addOutStockout.materialCode')" align="left" prop="productId" /><!--物资编号-->
<el-table-column :label="$t('addOutStockout.materialName')" align="left" prop="productName" /><!--物资名称-->
<!-- <el-table-column :label="$t('addOutStockout.batchNo')" align="left" prop="lotNo" />&lt;!&ndash;批号&ndash;&gt;-->
<el-table-column :label="$t('addOutStockout.quantity')" align="right" prop="quantity"><!--数量-->
<template slot-scope="scope">
<el-input-number v-model="scope.row.quantity" :min="1" size="mini" @change="handleQuantityChange(scope.row)" />
</template>
</el-table-column>
<el-table-column :label="$t('addOutStockout.operation')" align="center" class-name="small-padding fixed-width"><!--操作-->
<template slot-scope="scope">
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.$index)">{{$t('addOutStockout.delete')}}<!--删除--></el-button>
</template>
</el-table-column>
</el-table>
<!-- 选择物资弹窗 -->
<el-dialog :title="$t('addOutStockout.selectMaterial')" :visible.sync="materialDialog" width="800px" append-to-body><!--选择物资-->
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
<el-form-item :label="$t('addOutStockout.materialCode')" prop="productId"><!--物资编码-->
<el-input
v-model="queryParams.productId"
:placeholder="$t('addOutStockout.inputMaterialCode')"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item :label="$t('addOutStockout.materialName')" prop="productName"><!--物资名称-->
<el-input
v-model="queryParams.productName"
:placeholder="$t('addOutStockout.inputMaterialName')"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{$t('addOutStockout.search')}}<!--搜索--></el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{$t('addOutStockout.reset')}}<!--重置--></el-button>
</el-form-item>
</el-form>
<el-table v-loading="materialLoading" :data="materialOptions" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column :label="$t('addOutStockout.materialCode')" align="left" prop="productId" /><!--物资编码-->
<el-table-column :label="$t('addOutStockout.materialName')" align="left" prop="productName" /><!--物资名称-->
<el-table-column :label="$t('addOutStockout.quantity')" align="right" prop="quantity" /><!--数量-->
<el-table-column :label="$t('addOutStockout.warehouse')" align="left" prop="warehouseId" /><!--仓库-->
</el-table>
<pagination
v-show="total > 0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getMaterialList"
/>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="confirmSelectMaterials">{{$t('addOutStockout.confirm')}}<!--确 定--></el-button>
<el-button @click="cancelSelectMaterials">{{$t('addOutStockout.cancel')}}<!--取 消--></el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { listProductAndStock,saveOutStock } from "@/api/out/outStockout";
import {listWarehouse} from "@/api/bas/warehouse";
import Pagination from "@/components/Pagination";
export default {
name: "AddOutStock",
dicts: ['out_bill_type', 'bill_status'],
components: {
Pagination
},
data() {
return {
// 遮罩层
loading: false,
materialLoading: false,
// 总条数
total: 0,
// 表单验证规则
rules: {
warehouseId: [
{ required: true, message: this.$t('addOutStockout.selectWarehouse'), trigger: "change" }
],
customerNo: [
{ required: true, message: this.$t('addOutStockout.inputCustomerNo'), trigger: "blur" }
],
outType: [
{ required: true, message: this.$t('addOutStockout.selectDocumentType'), trigger: "change" }
]
},
// 主表数据
formData: {
warehouseId: null,
customerNo: null,
outType: null
},
// 仓库选项
warehouseOptions: [],
// 物资明细列表
materialList: [],
// 选择物资弹窗
materialDialog: false,
// 物资选项数据
materialOptions: [],
// 已选择的物资
selectedMaterials: [],
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
onlyIdentity: null,
productId: null,
lotNo: null,
productName: null,
quantity: null,
warehouseId: null
}
};
},
created() {
this.getWarehouseOptions();
},
methods: {
/** 获取仓库选项 */
getWarehouseOptions() {
listWarehouse({
pageNum: 1,
pageSize: 100
}).then(response => {
this.warehouseOptions = response.rows;
});
},
/** 打开选择物资弹窗 */
handleSelectMaterials() {
if (!this.formData.warehouseId) {
this.$modal.msgError(this.$t('addOutStockout.selectWarehouse'));
return;
}
this.materialDialog = true;
this.queryParams.warehouseId = this.formData.warehouseId;
this.getMaterialList();
},
/** 获取物资列表 */
getMaterialList() {
this.materialLoading = true;
listProductAndStock(this.queryParams).then(response => {
this.materialOptions = response.rows;
this.total = response.total;
this.materialLoading = false;
});
},
/** 物资选择变更 */
handleSelectionChange(selection) {
this.selectedMaterials = selection;
},
/** 确认选择物资 */
confirmSelectMaterials() {
if (this.selectedMaterials.length === 0) {
this.$modal.msgError(this.$t('addOutStockout.selectMaterials'));
return;
}
// 过滤掉已经存在的物资
const newMaterials = this.selectedMaterials.filter(item => {
return !this.materialList.some(existing => existing.onlyIdentity === item.onlyIdentity);
});
if (newMaterials.length === 0) {
this.$modal.msgWarning(this.$t('addOutStockout.selectExistsMaterials'));
return;
}
this.materialList = this.materialList.concat(
newMaterials.map(item => ({
productId: item.productId,
productName: item.productName,
quantity: item.quantity,
quantityOrignal: item.quantity,
lotNo: item.lotNo,
onlyIdentity: item.onlyIdentity
}))
);
this.materialDialog = false;
this.selectedMaterials = [];
},
/** 取消选择物资 */
cancelSelectMaterials() {
this.selectedMaterials = [];
this.materialDialog = false;
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getMaterialList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
/** 删除物资 */
handleDelete(index) {
this.materialList.splice(index, 1);
},
/** 数量变更 */
handleQuantityChange(row) {
// 如果没有初始数量,则设置初始数量
// 如果修改后的数量大于初始数量,给出提示并重置为当前值
if (row.quantity > row.quantityOrignal) {
this.$modal.msgError(this.$t('addOutStockout.error1'));
row.quantity = row.quantityOrignal;
}
},
/** 保存单据 */
handleSave() {
this.$refs.formRef.validate(valid => {
if (valid) {
if (this.materialList.length === 0) {
this.$modal.msgError(this.$t('addOutStockout.selectMaterials'));
return;
}
const data = {
outStockout: this.formData,
detailList: this.materialList
};
// 这里需要调用保存接口
saveOutStock(data).then(response => {
console.log(response)
this.$modal.msgSuccess(this.$t('addOutStockout.operaSuccess')+":"+response.msg);
this.$tab.refreshPage(this.$route);
// this.reset();
});
}
});
},
/** 重置数据 */
reset() {
this.formData = {
warehouseId: null,
customerNo: null,
outType: null
};
this.materialList = [];
},
/** 重新建单 */
handleReload() {
this.$tab.refreshPage(this.$route);
}
}
};
</script>
<style scoped>
.el-table >>> .current-row {
background-color: #f0f9eb;
}
.el-form-item >>> .el-form-item__label {
white-space: nowrap;
width: auto;
min-width: fit-content;
}
</style>