bonus-ui/src/views/foodManage/purchaseManage/purchasePlan/index.vue

570 lines
25 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="110px">
<el-form-item label="计划日期">
<el-date-picker
v-model="dateRange"
type="datetimerange"
align="right"
unlink-panels
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
format="yyyy-MM-dd HH:mm:ss" style="width: 400px"
:default-time="['00:00:00', '23:59:59']"
:picker-options="pickerOptions" >
</el-date-picker>
</el-form-item>
<el-form-item label="采购计划单号" prop="planCode">
<el-input v-model="queryParams.planCode" placeholder="请输入采购单号" maxlength="20" clearable style="width: 240px"/>
</el-form-item>
<el-form-item label="计划状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择计划状态" style="width: 240px;">
<el-option label="待发布" :value="1"></el-option>
<el-option label="已发布" :value="2"></el-option>
</el-select>
</el-form-item>
<el-form-item label="所属区域" prop="areaId">
<el-cascader v-model="queryParams.areaId"
:options="treeAreaOptions" :filterable="true" style="width: 100%;" :show-all-levels="false"
:props="{
emitPath: false,// 若设置 false则只返回该节点的值只返回最后选择的id
checkStrictly: false,//来设置父子节点取消选中关联,从而达到选择任意一级选项的目的
value:'id',label:'label'
}" clearable @change="handleAreaChange">
</el-cascader>
</el-form-item>
<el-form-item label="所属食堂" prop="canteenId">
<el-select v-model="queryParams.canteenId" placeholder="请选择所属食堂" style="width: 100%;" @change="handleCanteenChange">
<el-option v-for="item in canteenOptions"
:key="item.canteenId"
:label="item.canteenName"
:value="item.canteenId"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="所属档口" prop="stallId">
<el-select v-model="queryParams.stallId" placeholder="请选择所属档口" style="width: 100%;" >
<el-option v-for="item in stallOptions"
:key="item.stallId"
:label="item.stallName"
:value="item.stallId"
></el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleAdd"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleBatchAdd"
>合并生成采购订单</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="tableListData" height="800" :row-key="(row)=>{return row.planId}" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="50" align="center" :reserve-selection="true"/>
<el-table-column label="序号" align="center" width="80" type="index">
<template slot-scope="scope">
<span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
</template>
</el-table-column>
<el-table-column label="是否生成采购订单" align="center" prop="ifBreakDown" :show-overflow-tooltip="true" width="80">
<template slot-scope="scope">
<span v-if="!scope.row.ifBreakDown">否</span>
<span v-if="scope.row.ifBreakDown">是</span>
</template>
</el-table-column>
<el-table-column label="生产计划单号" align="center" prop="productionPlanId" :show-overflow-tooltip="true" width="200"/>
<el-table-column label="采购计划单号" align="center" prop="planCode" :show-overflow-tooltip="true" width="200"/>
<el-table-column label="采购计划时间" align="center" prop="purchaseDate" :show-overflow-tooltip="true" width="160"/>
<el-table-column label="所属区域" align="center" prop="areaName" :show-overflow-tooltip="true" width="120"/>
<el-table-column label="所属食堂" align="center" prop="canteenName" :show-overflow-tooltip="true" width="140"/>
<el-table-column label="所属档口" align="center" prop="stallName" :show-overflow-tooltip="true" width="120"/>
<el-table-column label="计划采购货品总数量" align="center" prop="totalNum" :show-overflow-tooltip="true" width="100"/>
<el-table-column label="采购预算金额(元)" align="center" prop="purchaseBudgetTotal" :show-overflow-tooltip="true" >
<template slot-scope="scope">
<span>{{ (scope.row.purchaseBudgetTotal/100).toFixed(2) }}</span>
</template>
</el-table-column>
<el-table-column label="计划状态" align="center" prop="status" :show-overflow-tooltip="true" width="110">
<template slot-scope="scope">
<span v-if="scope.row.status==1">待发布</span>
<span v-if="scope.row.status==2">已发布</span>
</template>
</el-table-column>
<!-- <el-table-column label="审批人" align="center" prop="approveBy" :show-overflow-tooltip="true" width="120"/>
<el-table-column label="审批完成时间" align="center" prop="approveTime" :show-overflow-tooltip="true" width="120"/>
<el-table-column label="负责人" align="center" prop="contractPerson" :show-overflow-tooltip="true" width="120"/>-->
<!-- <el-table-column label="制表人" align="center" prop="createBy" :show-overflow-tooltip="true" width="100"/>
<el-table-column label="制表时间" align="center" prop="createTime" :show-overflow-tooltip="true" /> -->
<el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
v-if="scope.row.status==1"
@click="handleUpdate(scope.row)"
>编辑</el-button>
<el-button
size="mini"
type="text"
v-if="scope.row.status==2"
@click="handleView(scope.row)"
>详情</el-button>
<el-button
size="mini"
type="text"
v-if="scope.row.status==2"
@click="handlePurchaseOrder(scope.row)"
>生成采购订单</el-button>
<el-button
size="mini"
type="text"
v-if="scope.row.status==2"
@click="handlePurchaseInquiry(scope.row)"
>生成询价单</el-button>
<el-button
size="mini"
type="text"
v-if="scope.row.status==1"
@click="handleDelete(scope.row)"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改参数配置对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { systemAreaTreeApi,getCanteenByAreaApi,getStallByCanteenApi } from "@/api/base/stall";
import { purchasePlanPageApi, getPurchasePlanInfoApi, delPurchasePlanApi,addPurchaseOrderApi,addGoodsInquiryApi } from "@/api/foodManage/purchaseManage";
export default {
name: "",
dicts: [],
data() {
return {
// 遮罩层
loading: true,
loadingBtn: false,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
//表格数据
tableListData: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
planCode: '',
status: null,
areaId: null,
canteenId: null,
stallId: null
},
treeAreaOptions:[],//区域树
canteenOptions:[],//食堂下拉选
stallOptions:[],//档口下拉选
dateRange:this.defaultDateRange(),//区域树
pickerOptions: {
shortcuts: [{
text: '最近一周',
onClick(picker) {
const start = new Date();
const end = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 6);
picker.$emit('pick', [start, end]);
}
},{
text: '最近一个月',
onClick(picker) {
const start = new Date();
const end = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
picker.$emit('pick', [start, end]);
}
},{
text: '最近三个月',
onClick(picker) {
const start = new Date();
const end = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 91);
picker.$emit('pick', [start, end]);
}
}]
},
batchList:[],
detailList:[],
// 表单参数
form: {},
// 表单校验
rules: {
// canteenName: [
// { required: true, message: "字典名称不能为空", trigger: "blur" }
// ],
// dictType: [
// { required: true, message: "字典类型不能为空", trigger: "blur" }
// ]
}
};
},
created() {
this.getAreaTreeData();
this.getList();
},
methods: {
//区域树
getAreaTreeData() {
systemAreaTreeApi({}).then((response) => {
this.treeAreaOptions = response.data;
});
},
handleAreaChange(e){
let param= {
areaId:e,canteenType: 1
}
getCanteenByAreaApi(param).then((response) => {
this.canteenOptions=response.rows||[]
this.$set(this.queryParams,"canteenId",null)
this.stallOptions = []
this.$set(this.queryParams,"stallId",null)
});
},
handleCanteenChange(e){
let param= {
canteenId:e
}
getStallByCanteenApi(param).then((response) => {
this.stallOptions=response.rows||[]
this.$set(this.queryParams,"stallId",null)
});
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.dateRange = this.defaultDateRange()
this.queryParams = {
pageNum: 1,
pageSize: 10,
}
this.resetForm("queryForm");
this.handleQuery();
},
/** 查询列表 */
getList() {
this.loading = true;
let param = {
"pageNum": this.queryParams.pageNum,
"pageSize": this.queryParams.pageSize,
"planCode": this.queryParams.planCode,
"status": this.queryParams.status,
"areaId": this.queryParams.areaId,
"canteenId": this.queryParams.canteenId,
"stallId": this.queryParams.stallId,
}
if(this.dateRange&&this.dateRange.length>0){
param.startDateTime=this.formatDateTime(this.dateRange[0])
param.endDateTime=this.formatDateTime(this.dateRange[1])
}else{
param.startDateTime=undefined;
param.endDateTime=undefined;
}
purchasePlanPageApi(param).then(response => {
this.tableListData = response.rows;
this.total = Number(response.total);
this.loading = false;
});
},
/** 新增按钮操作 */
handleAdd() {
this.$router.push({ path: "/foodManage/purchaseManage/purchasePlanEdit" });
},
/** 修改按钮操作 */
handleView(row) {
this.$router.push({ path: "/foodManage/purchaseManage/purchasePlanDetail",query: {purchasePlanRowData:JSON.stringify(row)} });
},
/** 修改按钮操作 */
handleUpdate(row) {
this.$router.push({ path: "/foodManage/purchaseManage/purchasePlanEdit",query: {purchasePlanRowData:JSON.stringify(row)} });
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {};
this.resetForm("form");
},
/** 提交按钮 */
submitForm: function() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.dictId != undefined) {
// updateType(this.form).then(response => {
// this.$modal.msgSuccess("修改成功");
// this.open = false;
// this.getList();
// });
} else {
// addType(this.form).then(response => {
// this.$modal.msgSuccess("新增成功");
// this.open = false;
// this.getList();
// });
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
this.$modal.confirm('是否确认删除数据项?').then(function() {
return delPurchasePlanApi({planIds:[row.planId]});
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
//生成采购订单
handlePurchaseOrder(row){
//获取计划详情
getPurchasePlanInfoApi({planId:row.planId}).then((response) => {
var purchasePlanDetailList = response.data.purchasePlanDetailList
this.$modal.confirm('是否确认生成采购订单?').then(function() {
let param = {
orderTitle:"采购计划生成采购订单",
purchasePlanCode:row.planCode,
requestArrivalTime:null,
warehouseId:null,
supplierId:null,
areaId:row.areaId,
canteenId:row.canteenId,
stallId:row.stallId,
orderAmount: 0,
totalNum: 0,
orderStatus: 1,
orderGoodsDetailList: [],
remark:"采购计划生成采购订单",
}
purchasePlanDetailList.forEach(item=>{
let obj = Object.assign({}, item)
console.log(obj)
obj.singlePrice = Number(item.unitPrice)
obj.orderNum = Number(item.purchaseNum)
obj.totalPrice = (Number(obj.singlePrice)*Number(obj.orderNum))
param.orderAmount = param.orderAmount+obj.totalPrice;
param.totalNum = param.totalNum+Number(obj.orderNum)
param.orderGoodsDetailList.push(obj)
})
return addPurchaseOrderApi(param);//新增采购订单
}).then((res) => {
this.getList();
this.$router.push({ path: "/foodManage/purchaseManage/orderEdit",query: {purchaseOrderRowData:JSON.stringify(res.data)} });
}).catch(() => {});
});
},
//生成询价单
handlePurchaseInquiry(row){
//获取计划详情
getPurchasePlanInfoApi({planId:row.planId}).then((response) => {
var purchasePlanDetailList = response.data.purchasePlanDetailList
this.$modal.confirm('是否确认生成询价单?').then(function() {
let param = {
title:"采购计划生成询价单",
purchasePlanCode:row.planCode,
requestArrivalTime:null,
startTime:null,
endTime:null,
supplierIds:[],
areaId:row.areaId,
canteenId:row.canteenId,
stallId:row.stallId,
linkMan:null,
phone:null,
address:null,
inquiryNotes:"采购计划生成询价单",
detailList:[],
status: 1,
}
purchasePlanDetailList.forEach(item=>{
let obj = Object.assign({}, item)
obj.purNum = Number(item.purchaseNum)
param.detailList.push(obj)
})
return addGoodsInquiryApi(param);//新增询价单
}).then((res) => {
this.getList();
this.$router.push({ path: "/foodManage/purchaseManage/goodsInquiryEdit",query: {goodsInquiryData:JSON.stringify(res.data)} });
}).catch(() => {});
});
},
//批量弹窗勾选
handleSelectionChange(selection){
this.batchList = [...selection];
},
handleBatchAdd(){
if(this.batchList.length>0){
const canteenIdIsSame = this.batchList.every(item => item.canteenId == this.batchList[0].canteenId);
const stallIdIsSame = this.batchList.every(item => item.stallId == this.batchList[0].stallId);
if(canteenIdIsSame&&stallIdIsSame){//只能选择相同食堂,档口
this.detailList=[]
this.getPurchasePlanList()
this.$modal.confirm('是否确认生成采购订单?').then(()=> {
return new Promise(resolve => {
let param = {
orderTitle:"采购计划生成采购订单",
purchasePlanCode:null,
requestArrivalTime:null,
warehouseId:null,
supplierId:null,
areaId:this.batchList[0].areaId,
canteenId:this.batchList[0].canteenId,
stallId:this.batchList[0].stallId,
orderAmount: 0,
totalNum: 0,
orderStatus: 1,
orderGoodsDetailList: [],
remark:"采购计划生成采购订单",
}
this.detailList.forEach(item=>{
let obj = Object.assign({}, item)
console.log(obj)
obj.singlePrice = Number(item.unitPrice)
obj.orderNum = Number(item.purchaseNum)
obj.totalPrice = (Number(obj.singlePrice)*Number(obj.orderNum))
param.orderAmount = param.orderAmount+obj.totalPrice;
param.totalNum = param.totalNum+Number(obj.orderNum)
param.orderGoodsDetailList.push(obj)
})
console.log(param)
resolve(addPurchaseOrderApi(param))
})
}).then((res) => {
this.getList();
this.$router.push({ path: "/foodManage/purchaseManage/orderEdit",query: {purchaseOrderRowData:JSON.stringify(res.data)} });
}).catch(() => {});
}else{
this.$modal.msgError("只能选择相同食堂,档口的采购计划");
}
}else{
this.$modal.msgError("请至少选择一个采购计划!");
}
},
// 获取地址
async getPurchasePlanList() {
await this.batchList.forEach(item=>{
getPurchasePlanInfoApi({planId:item.planId}).then((response) => {
response.data.purchasePlanDetailList.forEach(sub=>{
let index = this.detailList.findIndex(v=>v.materialId==sub.materialId)
if(index==-1){
let obj = Object.assign({}, sub)
this.detailList.push(obj)
}else{
let index2 = this.detailList.findIndex(v=>v.unitPrice==sub.unitPrice)
if(index2==-1){
let obj = Object.assign({}, sub)
this.detailList.push(obj)
}else{
this.detailList[index].purchaseNum = Number(this.detailList[index].purchaseNum)+Number(sub.purchaseNum)
}
}
})
})
})
return this.detailList
},
defaultDateRange() {
const end = new Date(new Date().toLocaleDateString());
end.setTime(end.getTime() + 24 * 60 * 60 * 1000 -1);
const start = new Date((new Date().toLocaleDateString()));
start.setTime(start.getTime() - 30 * 24 * 60 * 60 * 1000);
this.start = parseInt(start.getTime() / 1000)
this.end = parseInt(end.getTime() / 1000)
return [start, end]
},
//日期
formatDate(date) {
// 格式化为 YYYY-MM-DD
date = new Date(date)
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始
const day = String(date.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`;
},
//日期时间
formatDateTime(date) {
// 格式化为 YYYY-MM-DD
date = new Date(date)
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始
const day = String(date.getDate()).padStart(2, '0');
const hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
const minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
const seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
}
};
</script>