vxe模式的tree表格

This commit is contained in:
DESKTOP-H2PAFLR\Administrator
2023-10-06 16:09:13 +08:00
parent 50c0a7a016
commit f4af5818c8
7 changed files with 528 additions and 46 deletions

View File

@@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Mvc;
using ZR.Model.mes.md;
using ZR.Service.MES.md;
using ZR.Service.MES.md.IService;
namespace ZR.Admin.WebApi.Controllers.MES.md
{
[Route("mes/md/BOM")]
public class MdBOMController :BaseController
{
IMdBOMService mdBOMService;
public MdBOMController(IMdBOMService mdBOMService)
{
this.mdBOMService = mdBOMService;
}
/// <summary>
/// 获取bom信息
/// </summary>
/// <param name="pageNum">页数</param>
/// <param name="pageSize">页尺</param>
/// <param name="productCode">产品code</param>
/// <param name="productName">产品名称</param>
/// <returns></returns>
[HttpGet("list")]
public IActionResult List(int pageNum, int pageSize, string productCode = "", string productName = "")
{
(int, List<MdBom>) data = mdBOMService.GetAll(productCode, productName, pageNum, pageSize);
return ToResponse(new ApiResult(200, "success", data));
}
}
}

View File

@@ -21,7 +21,7 @@ namespace ZR.Admin.WebApi.Controllers.mes.md
/// <summary>
///
/// 获取数据
/// </summary>
/// <param name="pageNum"></param>
/// <param name="pageSize"></param>

View File

@@ -15,46 +15,38 @@ namespace ZR.Model.mes.md
///</summary>
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 父产品名称id
/// 父产品id
///</summary>
[SugarColumn(ColumnName="parent_id" )]
public int? ParentId { get; set; }
[SugarColumn(ColumnName = "parent_product_id")]
public int? ParentProductId { get; set; }
/// <summary>
/// 产品名称code
/// 产品编号
///</summary>
[SugarColumn(ColumnName="parent_code" )]
public string ParentCode { get; set; }
[SugarColumn(ColumnName = "product_code")]
public string ProductCode { get; set; }
/// <summary>
/// 产品名称name
/// 产品名称
///</summary>
[SugarColumn(ColumnName="parent_name" )]
public string ParentName { get; set; }
[SugarColumn(ColumnName = "product_name")]
public string ProductName { get; set; }
/// <summary>
/// 子项物料编号
/// 零件类型
///</summary>
[SugarColumn(ColumnName="material_code" )]
public string MaterialCode { get; set; }
/// <summary>
/// 子项物料名称
///</summary>
[SugarColumn(ColumnName="material_name" )]
public string MaterialName { get; set; }
/// <summary>
/// 类型(产品,物料)
///</summary>
[SugarColumn(ColumnName="material_type" )]
public string MaterialType { get; set; }
[SugarColumn(ColumnName = "product_type")]
public string ProductType { get; set; }
/// <summary>
/// 安全库存
///</summary>
[SugarColumn(ColumnName = "safety_stock")]
public int? SafetyStock { get; set; }
/// <summary>
/// 位置
/// 位置/来源
///</summary>
[SugarColumn(ColumnName="material_position" )]
public string MaterialPosition { get; set; }
[SugarColumn(ColumnName = "product_position")]
public string ProductPosition { get; set; }
/// <summary>
/// 需求数量
///</summary>
@@ -95,5 +87,10 @@ namespace ZR.Model.mes.md
///</summary>
[SugarColumn(ColumnName = "UPDATED_TIME")]
public DateTime? UpdatedTime { get; set; }
[SqlSugar.SugarColumn(IsIgnore = true)]
public List<MdBom> Child { get; set; }
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZR.Model.mes.md;
namespace ZR.Service.MES.md.IService
{
public interface IMdBOMService
{
int AddWorkline(MdBom workline);
public (int, List<MdBom>) GetAll(string productCode, string productName, int pageNum, int pageSize);
public int UpdateWorkline(MdBom workline);
public int deleteWorkline(int[] ids);
}
}

View File

@@ -0,0 +1,93 @@
using Infrastructure.Attribute;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZR.Model.mes.md;
using ZR.Service.mes.md.IService;
using ZR.Service.MES.md.IService;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace ZR.Service.MES.md
{
[AppService(ServiceType = typeof(IMdBOMService), ServiceLifetime = LifeTime.Transient)]
public class MdBOMService : BaseService<MdWorkstation>, IMdBOMService
{
int IMdBOMService.AddWorkline(MdBom workline)
{
throw new NotImplementedException();
}
int IMdBOMService.deleteWorkline(int[] ids)
{
throw new NotImplementedException();
}
(int, List<MdBom>) IMdBOMService.GetAll(string productCode, string productName, int pageNum, int pageSize)
{
int totalNum = 0;
if (string.IsNullOrEmpty(productCode) && string.IsNullOrEmpty(productName))
{
var data = Context.Queryable<MdBom>().ToPageList(pageNum, pageSize,ref totalNum);
return (totalNum, data);
}
else
{
//1. 查询本体
var predicate = Expressionable.Create<MdBom>()
.AndIF(!string.IsNullOrEmpty(productCode), it => it.ProductCode.Contains(productCode))
.AndIF(!string.IsNullOrEmpty(productName), it => it.ProductName.Contains(productName))
.ToExpression();
List<MdBom> data = Context.Queryable<MdBom>().Where(predicate).ToList();
//2. 查询儿子
if (data != null & data.Count > 0)
{
List<MdBom> data1 = new List<MdBom>();
List<MdBom> data2 = new List<MdBom>();
foreach (var item in data)
{
List<MdBom> dataItems = Context.Queryable<MdBom>().Where(it => it.ParentProductId == item.Id).ToList();
data1.AddRange(dataItems);
dataItems.Clear();
// 3. 查询孙子
if (data1 != null & data1.Count > 0)
{
foreach (var item1 in data1)
{
List<MdBom> dataItemss = Context.Queryable<MdBom>().Where(it1 => it1.ParentProductId == item1.Id).ToList();
data2.AddRange(dataItemss);
dataItemss.Clear();
}
}
}
data.AddRange(data1);
data.AddRange(data2);
}
return (data.Count(),data);
}
}
int IMdBOMService.UpdateWorkline(MdBom workline)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,48 @@
import request from '@/utils/request'
import { downFile } from '@/utils/request'
export function getBomList(query) {
return request({
url: '/mes/md/bom/list',
method: 'get',
params: query,
})
}
export function insertBom(data) {
return request({
url: '/mes/md/Bom/addBom',
method: 'post',
data: data,
contextType:"application/json"
})
}
export function updateBom(data) {
return request({
url: '/mes/md/Bom/updateBom',
method: 'post',
data: data,
contextType:"application/json"
})
}
export function delBom(data) {
return request({
url: '/mes/md/Bom/delBom',
method: 'post',
data: data,
contextType:"application/json"
})
}
export function getWorkshopList(query) {
return request({
url: '/mes/md/Bom/getWorkshopList',
method: 'get',
params: query,
})
}

View File

@@ -0,0 +1,290 @@
<template>
<div class="app-container">
<!-- 搜索部分 -->
<div>
<el-form :model="search" inline v-show="search.showSearch">
<el-form-item label="产品编码 ">
<el-input v-model="search.productCode" placeholder="输入产品编号"></el-input>
</el-form-item>
<el-form-item label="产品名称 ">
<el-input v-model="search.productName" placeholder="输入产品名称"></el-input>
</el-form-item>
<el-button icon="el-icon-search" circle @click="getList"></el-button>
</el-form>
</div>
<div>
<!-- <el-table
:data="table.bomList"
style="width: 100%; margin-bottom: 20px"
row-key="id"
border
default-expand-all
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
>
<el-table-column prop="productCode" label="产品编码" sortable width="180"> </el-table-column>
<el-table-column prop="productName" label="产品名称" sortable> </el-table-column>
<el-table-column prop="productType" label="零件类型"> </el-table-column>
<el-table-column prop="productPosition" label="来源"> </el-table-column>
<el-table-column prop="requireNum" label="需求数量"> </el-table-column>
<el-table-column prop="unitId" label="单位"> </el-table-column>
</el-table> -->
<vxe-table
border
align="center"
:print-config="{}"
ref="xTable1"
:data="table.bomList"
:loading="table.loading"
@checkbox-change="selectChangeEvent"
:row-config="{ isHover: true }"
:tree-config="{ transform: true, rowField: 'id', parentField: 'parentProductId' }"
>
<vxe-column field="productCode" title="产品编码" tree-node></vxe-column>
<vxe-column field="productName" title="产品名称"></vxe-column>
<vxe-column field="productType" title="零件类型"></vxe-column>
<vxe-column field="productPosition" title="来源"></vxe-column>
<vxe-column field="requireNum" title="需求数量"></vxe-column>
<vxe-column field="unitId" title="单位"></vxe-column>
<vxe-column title="操作" show-overflow>
<template slot-scope="scope">
<el-button size="mini" type="text" icon="el-icon-edit" @click="updataItem(false, scope.row)">修改</el-button>
<el-button size="mini" type="text" icon="el-icon-delete" @click="deleteItem(false, scope.row)" class="delred">删除</el-button>
</template>
</vxe-column>
</vxe-table>
<vxe-pager
background
:current-page.sync="pagination.pageNum"
:page-size.sync="pagination.pageSize"
:total="pagination.total"
:layouts="['PrevJump', 'PrevPage', 'JumpNumber', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total']"
@page-change="getList"
>
</vxe-pager>
</div>
<!-- 弹窗-- 修改和删除 -->
<el-dialog :title="DMLdialog.title" :visible.sync="DMLdialog.visiable" width="600px" append-to-body>
<el-form ref="DMLdialog" :model="DMLdialog.form" label-width="150px" label-position="left" :rules="DMLdialog.rules">
<el-form-item label="线体编码 " prop="lineCode">
<el-input v-model="DMLdialog.form.lineCode" placeholder="输入线体编码"></el-input>
</el-form-item>
<el-form-item label="线体名称 " prop="lineName">
<el-input v-model="DMLdialog.form.lineName" placeholder="输入线体名称"></el-input>
</el-form-item>
<el-form-item label="车间 " prop="pkWorkshopName">
<el-select v-model="DMLdialog.form.fkWorkShopId" placeholder="请选择车间">
<el-option
v-for="item in DMLdialog.workshopOption"
:key="item.id"
:label="item.id + '_' + item.workshopId + '_' + item.workshopName"
:value="item.id"
>
</el-option>
</el-select>
</el-form-item>
</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 { getBomList, insertbom, updatebom, delbom, getWorkshopList } from '@/api/basisManagement/bom.js'
export default {
name: 'bom',
data() {
return {
//搜索框配置
search: {
productCode: '',
productName: '',
showSearch: true,
},
//表格
table: {
loading: true,
bomList: [],
},
//分页
pagination: {
total: 0,
pageNum: 1,
pageSize: 10,
},
//新增修改数据项配置
DMLdialog: {
title: '',
visiable: false,
form: {
lineCode: '',
lineName: '',
fkWorkShopId: '',
},
workshopOption: [],
rules: {
lineCode: [{ required: true, message: '线体编码不能为空', trigger: 'blur' }],
lineName: [{ required: true, message: '线体名称不能为空', trigger: 'blur' }],
},
},
//修改按钮
updateDisable: true,
//删除按钮
delDisable: true,
flag: 'update', //区分修改和删除
}
},
created() {
this.getList()
},
methods: {
//获取表格数据
getList() {
const query = { ...this.search, ...this.pagination }
delete query.showSearch
getBomList(query).then((res) => {
if (res.code == 200) {
this.table.loading = false
this.pagination.total = res.data.item1
this.table.bomList = res.data.item2
}
})
},
//获取车间
getWorkshopOption() {
getWorkshopList().then((res) => {
if (res.code == 200) this.DMLdialog.workshopOption = res.data
})
},
//行更新
handleUpdate(row) {},
//行删除
handleDelete(row) {},
selectChangeEvent({ checked }) {
const records = this.$refs.xTable1.getCheckboxRecords()
if (records.length == 1) {
this.updateDisable = false
} else {
this.updateDisable = true
}
if (records.length > 0) {
this.delDisable = false
} else {
this.delDisable = true
}
},
//新增按钮
addItem() {
this.DMLdialog.title = '新增'
this.DMLdialog.visiable = true
this.flag = 'add'
},
//新增确认
submitForm() {
if (this.flag == 'update') {
updatebom(this.DMLdialog.form).then((res) => {
if (res.code == 200 && res.data == 1) {
this.$notify.success('修改成功')
this.getList()
this.DMLdialog.visiable = false
this.reset()
}
})
} else if (this.flag == 'add') {
this.$refs['DMLdialog'].validate((valid) => {
if (valid) {
insertbom(this.DMLdialog.form).then((res) => {
if (res.code == 200) {
this.getList()
this.DMLdialog.visiable = false
this.reset()
}
})
}
})
}
},
cancel() {
this.DMLdialog.visiable = false
this.reset()
},
reset() {
this.DMLdialog.form = {
lineCode: '',
lineName: '',
}
this.DMLdialog.form.reset()
},
//修改事件
updataItem(flag, row) {
this.DMLdialog.title = '修改'
this.DMLdialog.visiable = true
this.flag = 'update'
if (!flag) {
this.DMLdialog.form.lineCode = row.lineCode
this.DMLdialog.form.lineName = row.lineName
this.DMLdialog.form.id = row.id
this.DMLdialog.form.fkWorkShopId = row.fkWorkShopId
} else {
const records = this.$refs.xTable1.getCheckboxRecords()
if (records.length == 1) {
this.DMLdialog.form.lineCode = records[0].lineCode
this.DMLdialog.form.lineName = records[0].lineName
this.DMLdialog.form.id = records[0].id
this.DMLdialog.form.fkWorkShopId = records[0].fkWorkShopId
}
}
},
//删除事件
deleteItem(flag, row) {
if (!flag) {
this.$modal
.confirm('是否确认删除线体名称为"' + row.lineName + '"的数据项?')
.then(function () {
const array = []
array.push(row.id)
return delbom(array)
})
.then(() => {
this.getList()
this.$modal.msgSuccess('删除成功')
})
.catch(() => {})
} else {
const records = this.$refs.xTable1.getCheckboxRecords()
if (records.length > 0) {
this.$modal
.confirm('是否确认删除线体名称为"' + records.map((it) => it.lineName) + '"的数据项?')
.then(function () {
return delbom(records.map((it) => it.id))
})
.then(() => {
this.getList()
this.$modal.msgSuccess('删除成功')
})
.catch(() => {})
}
}
},
},
}
</script>
<style lang="scss" scoped>
.delred {
::v-deep .el-icon-delete {
color: #f56c6c;
}
::v-deep span {
color: #f56c6c;
}
}
</style>