新增「车间班次」功能(前缫车间排班配置)
后端 - 新增实体 ChejianBanci(表 ChejianBancis:车间 / 班次 / 日工作小时数) - 新增 ChejianBanciService 与 ChejianBanciController(api/prod/chejianbanci) 分页列表、编辑回显、新增、修改、删除、前缫车间下拉;含必填校验与同车间同班次重复校验 - 菜单种子:基础数据 → 车间班次(Timer 图标,权限 base:chejianbanci:list) - 修正历史数据:名称以「前缫」开头的部门职责类型改为「前缫」(25)。 迁移时 duty_type 被统一写成「其他」,导致按职责类型筛选车间取不到数据 前端 - 新增 web/src/views/base/chejianbanci/index.vue(列表 / 搜索 / 分页 / 新增 / 编辑 / 删除) - 注册组件映射 base/chejianbanci/index
This commit is contained in:
@@ -0,0 +1,75 @@
|
|||||||
|
using F9WebAiTest.Application.Common;
|
||||||
|
using F9WebAiTest.Application.Dtos.Prod;
|
||||||
|
using F9WebAiTest.Application.Services.Prod;
|
||||||
|
using F9WebAiTest.Domain.Common;
|
||||||
|
using F9WebAiTest.Domain.Entities;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace F9WebAiTest.Api.Controllers.Prod;
|
||||||
|
|
||||||
|
/// <summary>车间班次(前缫车间排班配置)</summary>
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/prod/chejianbanci")]
|
||||||
|
[Authorize]
|
||||||
|
public class ChejianBanciController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IChejianBanciService _svc;
|
||||||
|
public ChejianBanciController(IChejianBanciService svc) => _svc = svc;
|
||||||
|
|
||||||
|
// 分页列表
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> GetPaged([FromQuery] string like = "", [FromQuery] int pageIndex = 1,
|
||||||
|
[FromQuery] int pageSize = 20)
|
||||||
|
=> Ok(ApiResult<PageResult<ChejianbanciReadDto_View>>.Ok(
|
||||||
|
await _svc.GetPagedAsync(pageIndex, pageSize, like ?? string.Empty)));
|
||||||
|
|
||||||
|
// 车间下拉(前缫车间)
|
||||||
|
[HttpGet("qianxian-deps")]
|
||||||
|
public async Task<IActionResult> GetQianxianDeps()
|
||||||
|
=> Ok(ApiResult<List<ChejianbanciDepOptionDto>>.Ok(await _svc.GetQianxianDepsAsync()));
|
||||||
|
|
||||||
|
// 编辑回显
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public async Task<IActionResult> GetByIdForEdit(long id)
|
||||||
|
{
|
||||||
|
try { return Ok(ApiResult<ChejianbanciReadDto_Edit>.Ok(await _svc.GetByIdForEditAsync(id))); }
|
||||||
|
catch (ServiceException ex) { return StatusCode(ex.Code, ApiResult<object>.Fail(ex.Message, ex.Code)); }
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<IActionResult> Create([FromBody] ChejianbanciReadDto_Edit dto)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _svc.CreateAsync(dto);
|
||||||
|
return Ok(ApiResult<object>.Ok(null, "新增成功"));
|
||||||
|
}
|
||||||
|
catch (ServiceException ex) { return StatusCode(ex.Code, ApiResult<object>.Fail(ex.Message, ex.Code)); }
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改
|
||||||
|
[HttpPut("{id}")]
|
||||||
|
public async Task<IActionResult> Update(long id, [FromBody] ChejianbanciReadDto_Edit dto)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _svc.UpdateAsync(id, dto);
|
||||||
|
return Ok(ApiResult<object>.Ok(null, "修改成功"));
|
||||||
|
}
|
||||||
|
catch (ServiceException ex) { return StatusCode(ex.Code, ApiResult<object>.Fail(ex.Message, ex.Code)); }
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
public async Task<IActionResult> Delete(long id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _svc.DeleteAsync(id);
|
||||||
|
return Ok(ApiResult<object>.Ok(null, "删除成功"));
|
||||||
|
}
|
||||||
|
catch (ServiceException ex) { return StatusCode(ex.Code, ApiResult<object>.Fail(ex.Message, ex.Code)); }
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -23,6 +23,7 @@ public static class DependencyInjection
|
|||||||
services.AddScoped<ILsjlService, LsjlService>();
|
services.AddScoped<ILsjlService, LsjlService>();
|
||||||
services.AddScoped<IXdjyService, XdjyService>();
|
services.AddScoped<IXdjyService, XdjyService>();
|
||||||
services.AddScoped<IHbjyService, HbjyService>();
|
services.AddScoped<IHbjyService, HbjyService>();
|
||||||
|
services.AddScoped<IChejianBanciService, ChejianBanciService>();
|
||||||
services.AddScoped<INotificationService, NotificationService>();
|
services.AddScoped<INotificationService, NotificationService>();
|
||||||
|
|
||||||
// MediatR:注册命令/查询 Handler
|
// MediatR:注册命令/查询 Handler
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using F9WebAiTest.Domain.Enums.SYS.Employees;
|
||||||
|
|
||||||
|
namespace F9WebAiTest.Application.Dtos.Prod;
|
||||||
|
|
||||||
|
/// <summary>车间班次读模型(列表)</summary>
|
||||||
|
public class ChejianbanciReadDto_View
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
public long DepId { get; set; }
|
||||||
|
public string Deptname { get; set; } = "";
|
||||||
|
public Prod_Banci_Enum Banci { get; set; }
|
||||||
|
public string BanciName { get; set; } = "";
|
||||||
|
public double KaoqinDayhours { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>车间班次编辑读模型 / 提交模型</summary>
|
||||||
|
public class ChejianbanciReadDto_Edit
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
public long DepId { get; set; }
|
||||||
|
public Prod_Banci_Enum Banci { get; set; }
|
||||||
|
public double KaoqinDayhours { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>车间下拉项</summary>
|
||||||
|
public class ChejianbanciDepOptionDto
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
public string Name { get; set; } = "";
|
||||||
|
}
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
using F9WebAiTest.Application.Common;
|
||||||
|
using F9WebAiTest.Application.Dtos.Prod;
|
||||||
|
using F9WebAiTest.Domain.Common;
|
||||||
|
using F9WebAiTest.Domain.Entities;
|
||||||
|
using F9WebAiTest.Domain.Entities.Base;
|
||||||
|
using F9WebAiTest.Domain.Entities.Prod;
|
||||||
|
using F9WebAiTest.Domain.Enums.SYS.Departments;
|
||||||
|
using SysDept = F9WebAiTest.Domain.Entities.SYS.Departments;
|
||||||
|
|
||||||
|
namespace F9WebAiTest.Application.Services.Prod;
|
||||||
|
|
||||||
|
public interface IChejianBanciService
|
||||||
|
{
|
||||||
|
Task<PageResult<ChejianbanciReadDto_View>> GetPagedAsync(int pageIndex, int pageSize, string keyword);
|
||||||
|
Task<ChejianbanciReadDto_Edit> GetByIdForEditAsync(long id);
|
||||||
|
Task CreateAsync(ChejianbanciReadDto_Edit dto);
|
||||||
|
Task UpdateAsync(long id, ChejianbanciReadDto_Edit dto);
|
||||||
|
Task DeleteAsync(long id);
|
||||||
|
|
||||||
|
/// <summary>车间下拉:只取职责类型为「前缫」的部门</summary>
|
||||||
|
Task<List<ChejianbanciDepOptionDto>> GetQianxianDepsAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ChejianBanciService : IChejianBanciService
|
||||||
|
{
|
||||||
|
private readonly IRepository<ChejianBanci> _repo;
|
||||||
|
private readonly IRepository<SysDept.Department> _deptRepo;
|
||||||
|
|
||||||
|
public ChejianBanciService(IRepository<ChejianBanci> repo, IRepository<SysDept.Department> deptRepo)
|
||||||
|
{
|
||||||
|
_repo = repo;
|
||||||
|
_deptRepo = deptRepo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<PageResult<ChejianbanciReadDto_View>> GetPagedAsync(int pageIndex, int pageSize, string keyword)
|
||||||
|
{
|
||||||
|
if (pageIndex <= 0) pageIndex = 1;
|
||||||
|
if (pageSize <= 0) pageSize = 20;
|
||||||
|
|
||||||
|
var depts = await _deptRepo.GetAllAsync();
|
||||||
|
var deptDict = depts.ToDictionary(d => d.Id, d => d.Name);
|
||||||
|
|
||||||
|
var all = await _repo.GetAllAsync();
|
||||||
|
var q = all.AsQueryable();
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(keyword))
|
||||||
|
{
|
||||||
|
var kw = keyword.Trim();
|
||||||
|
var kwDeptIds = depts.Where(d => d.Name.Contains(kw)).Select(d => d.Id).ToHashSet();
|
||||||
|
q = q.Where(x => kwDeptIds.Contains(x.DeptId) || x.Banci.ToString().Contains(kw));
|
||||||
|
}
|
||||||
|
|
||||||
|
var total = q.LongCount();
|
||||||
|
var items = q.OrderBy(x => x.DeptId).ThenBy(x => x.Banci)
|
||||||
|
.Skip((pageIndex - 1) * pageSize).Take(pageSize)
|
||||||
|
.Select(x => new ChejianbanciReadDto_View
|
||||||
|
{
|
||||||
|
Id = x.Id,
|
||||||
|
DepId = x.DeptId,
|
||||||
|
Deptname = deptDict.GetValueOrDefault(x.DeptId, ""),
|
||||||
|
Banci = x.Banci,
|
||||||
|
BanciName = x.Banci.ToString(),
|
||||||
|
KaoqinDayhours = x.KaoqinDayhours
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
return new PageResult<ChejianbanciReadDto_View>
|
||||||
|
{
|
||||||
|
Items = items,
|
||||||
|
Total = total,
|
||||||
|
PageIndex = pageIndex,
|
||||||
|
PageSize = pageSize
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ChejianbanciReadDto_Edit> GetByIdForEditAsync(long id)
|
||||||
|
{
|
||||||
|
var e = await _repo.GetByIdAsync(id) ?? throw new ServiceException("记录不存在", 404);
|
||||||
|
return new ChejianbanciReadDto_Edit
|
||||||
|
{
|
||||||
|
Id = e.Id,
|
||||||
|
DepId = e.DeptId,
|
||||||
|
Banci = e.Banci,
|
||||||
|
KaoqinDayhours = e.KaoqinDayhours
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task CreateAsync(ChejianbanciReadDto_Edit dto)
|
||||||
|
{
|
||||||
|
await ValidateAsync(dto, 0);
|
||||||
|
await _repo.AddAsync(new ChejianBanci
|
||||||
|
{
|
||||||
|
DeptId = dto.DepId,
|
||||||
|
Banci = dto.Banci,
|
||||||
|
KaoqinDayhours = dto.KaoqinDayhours
|
||||||
|
});
|
||||||
|
await _repo.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task UpdateAsync(long id, ChejianbanciReadDto_Edit dto)
|
||||||
|
{
|
||||||
|
var e = await _repo.GetByIdAsync(id) ?? throw new ServiceException("记录不存在", 404);
|
||||||
|
await ValidateAsync(dto, id);
|
||||||
|
|
||||||
|
e.DeptId = dto.DepId;
|
||||||
|
e.Banci = dto.Banci;
|
||||||
|
e.KaoqinDayhours = dto.KaoqinDayhours;
|
||||||
|
await _repo.UpdateAsync(e);
|
||||||
|
await _repo.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task DeleteAsync(long id)
|
||||||
|
{
|
||||||
|
var e = await _repo.GetByIdAsync(id) ?? throw new ServiceException("记录不存在", 404);
|
||||||
|
await _repo.DeleteAsync(e);
|
||||||
|
await _repo.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<ChejianbanciDepOptionDto>> GetQianxianDepsAsync()
|
||||||
|
{
|
||||||
|
var depts = await _deptRepo.GetAllAsync();
|
||||||
|
return depts
|
||||||
|
.Where(d => d.DutyType == Department_DutyType_Enum.前缫)
|
||||||
|
.OrderBy(d => d.SortOrder).ThenBy(d => d.Id)
|
||||||
|
.Select(d => new ChejianbanciDepOptionDto { Id = d.Id, Name = d.Name })
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>校验:车间、班次、工时必填,且同一车间的同一班次不可重复</summary>
|
||||||
|
private async Task ValidateAsync(ChejianbanciReadDto_Edit dto, long excludeId)
|
||||||
|
{
|
||||||
|
if (dto.DepId <= 0) throw new ServiceException("请选择车间");
|
||||||
|
if (dto.KaoqinDayhours <= 0) throw new ServiceException("日工作小时数必须大于 0");
|
||||||
|
|
||||||
|
var all = await _repo.GetAllAsync();
|
||||||
|
if (all.Any(x => x.Id != excludeId && x.DeptId == dto.DepId && x.Banci == dto.Banci))
|
||||||
|
throw new ServiceException("该车间的此班次已存在,请勿重复配置");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using F9WebAiTest.Domain.Common;
|
||||||
|
using F9WebAiTest.Domain.Entities.Base;
|
||||||
|
using F9WebAiTest.Domain.Enums.SYS.Employees;
|
||||||
|
|
||||||
|
namespace F9WebAiTest.Domain.Entities.Prod;
|
||||||
|
|
||||||
|
/// <summary>车间班次(前缫车间的排班配置:车间 + 班次 + 日工作小时数)</summary>
|
||||||
|
[Table(Name = "ChejianBancis")]
|
||||||
|
public class ChejianBanci : BaseEntity
|
||||||
|
{
|
||||||
|
public long DeptId { get; set; } // 车间(部门)
|
||||||
|
public Prod_Banci_Enum Banci { get; set; } // 班次(甲/乙)
|
||||||
|
public double KaoqinDayhours { get; set; } // 日工作小时数
|
||||||
|
}
|
||||||
@@ -82,6 +82,10 @@ public static class DbSeeder
|
|||||||
// 6.68 生产模块(按工序拆分:生产-前缫 / 生产-后缫)
|
// 6.68 生产模块(按工序拆分:生产-前缫 / 生产-后缫)
|
||||||
SeedProdMenus(fsql, snowflake);
|
SeedProdMenus(fsql, snowflake);
|
||||||
|
|
||||||
|
// 6.69 车间班次菜单(挂在"基础数据"目录下)+ 修正前缫部门的职责类型
|
||||||
|
SeedChejianBanciMenus(fsql, snowflake);
|
||||||
|
FixQianxianDutyType(fsql);
|
||||||
|
|
||||||
// 6.7 为菜单创建权限单元(Permission),并修正旧菜单权限关联(统一权限模型)
|
// 6.7 为菜单创建权限单元(Permission),并修正旧菜单权限关联(统一权限模型)
|
||||||
FixMenuPermissions(fsql, snowflake);
|
FixMenuPermissions(fsql, snowflake);
|
||||||
|
|
||||||
@@ -763,6 +767,39 @@ public static class DbSeeder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>车间班次菜单(挂在"基础数据"目录下)</summary>
|
||||||
|
private static void SeedChejianBanciMenus(IFreeSql fsql, ISnowflakeIdGenerator snowflake)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
EnsureBaseDataMenu(fsql, snowflake, "/base/chejianbanci", "车间班次",
|
||||||
|
"base/chejianbanci/index", "base:chejianbanci:list", "Timer", 11);
|
||||||
|
Console.WriteLine("[DbSeeder] 车间班次菜单已就绪");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[DbSeeder] 车间班次菜单种子跳过:{ex}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 修正前缫部门的职责类型:历史数据迁移时 duty_type 统一写成了"其他"(5),
|
||||||
|
/// 而车间班次等模块需要按职责类型(前缫=25)筛选部门。
|
||||||
|
/// </summary>
|
||||||
|
private static void FixQianxianDutyType(IFreeSql fsql)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var rows = fsql.Ado.ExecuteNonQuery(
|
||||||
|
"UPDATE sys_departments SET duty_type = 25 WHERE is_deleted = 0 AND name LIKE '前缫%' AND duty_type <> 25");
|
||||||
|
if (rows > 0) Console.WriteLine($"[DbSeeder] 已修正 {rows} 个前缫部门的职责类型");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[DbSeeder] 部门职责类型修正跳过:{ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>确保指定菜单已授权给角色(后续 FixMenuPermissions 会把 permission_id 修正为权限单元 Id)</summary>
|
/// <summary>确保指定菜单已授权给角色(后续 FixMenuPermissions 会把 permission_id 修正为权限单元 Id)</summary>
|
||||||
private static void EnsureMenuPermission(IFreeSql fsql, ISnowflakeIdGenerator snowflake, long roleId, long menuId)
|
private static void EnsureMenuPermission(IFreeSql fsql, ISnowflakeIdGenerator snowflake, long roleId, long menuId)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ export const componentMap = {
|
|||||||
'base/jizuchetai/index': () => import('../views/base/jizuchetai/index.vue'),
|
'base/jizuchetai/index': () => import('../views/base/jizuchetai/index.vue'),
|
||||||
'base/worktype/index': () => import('../views/base/worktype/index.vue'),
|
'base/worktype/index': () => import('../views/base/worktype/index.vue'),
|
||||||
'base/zhangqi/index': () => import('../views/base/zhangqi/index.vue'),
|
'base/zhangqi/index': () => import('../views/base/zhangqi/index.vue'),
|
||||||
|
'base/chejianbanci/index': () => import('../views/base/chejianbanci/index.vue'),
|
||||||
'base/registry/index': () => import('../views/base/registry/index.vue'),
|
'base/registry/index': () => import('../views/base/registry/index.vue'),
|
||||||
'base/yuanliaozhuangkou/index': () => import('../views/base/yuanliaozhuangkou/index.vue'),
|
'base/yuanliaozhuangkou/index': () => import('../views/base/yuanliaozhuangkou/index.vue'),
|
||||||
'base/wuzimulu/index': () => import('../views/base/wuzimulu/index.vue'),
|
'base/wuzimulu/index': () => import('../views/base/wuzimulu/index.vue'),
|
||||||
|
|||||||
@@ -0,0 +1,199 @@
|
|||||||
|
<script setup>
|
||||||
|
import { ref, reactive, onMounted } from 'vue';
|
||||||
|
import request from '../../../utils/request';
|
||||||
|
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||||
|
|
||||||
|
const list = ref([]);
|
||||||
|
const total = ref(0);
|
||||||
|
const loading = ref(false);
|
||||||
|
const query = reactive({ pageIndex: 1, pageSize: 20, like: '' });
|
||||||
|
|
||||||
|
// 车间下拉:只取职责类型为「前缫」的部门(后端接口)
|
||||||
|
const depOptions = ref([]);
|
||||||
|
// 班次枚举(与后端 Prod_Banci_Enum 一致)
|
||||||
|
const banciOptions = [
|
||||||
|
{ value: 1, label: '甲' },
|
||||||
|
{ value: 2, label: '乙' }
|
||||||
|
];
|
||||||
|
|
||||||
|
const dialogVisible = ref(false);
|
||||||
|
const dialogTitle = ref('新增车间班次');
|
||||||
|
const isEdit = ref(false);
|
||||||
|
const editId = ref(null);
|
||||||
|
const form = reactive({ depId: 0, banci: 1, kaoqinDayhours: 0 });
|
||||||
|
|
||||||
|
async function loadList() {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
const res = await request.get('/prod/chejianbanci', { params: query });
|
||||||
|
list.value = res.data.items || [];
|
||||||
|
total.value = res.data.total || 0;
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadDepOptions() {
|
||||||
|
try {
|
||||||
|
const res = await request.get('/prod/chejianbanci/qianxian-deps');
|
||||||
|
depOptions.value = res.data || [];
|
||||||
|
} catch (e) {
|
||||||
|
depOptions.value = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 分页组件挂载时会触发一次 current-change:页码未变化时忽略,避免首次打开重复请求
|
||||||
|
function handlePageChange(p) {
|
||||||
|
if (p === query.pageIndex) return;
|
||||||
|
query.pageIndex = p;
|
||||||
|
loadList();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleSearch() {
|
||||||
|
query.pageIndex = 1;
|
||||||
|
loadList();
|
||||||
|
}
|
||||||
|
|
||||||
|
function openCreate() {
|
||||||
|
isEdit.value = false;
|
||||||
|
dialogTitle.value = '新增车间班次';
|
||||||
|
Object.assign(form, {
|
||||||
|
depId: Number(depOptions.value[0]?.id) || 0,
|
||||||
|
banci: 1,
|
||||||
|
kaoqinDayhours: 0
|
||||||
|
});
|
||||||
|
dialogVisible.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function openEdit(row) {
|
||||||
|
isEdit.value = true;
|
||||||
|
dialogTitle.value = '修改车间班次';
|
||||||
|
editId.value = row.id;
|
||||||
|
try {
|
||||||
|
const res = await request.get(`/prod/chejianbanci/${row.id}`);
|
||||||
|
Object.assign(form, {
|
||||||
|
depId: Number(res.data.depId),
|
||||||
|
banci: Number(res.data.banci),
|
||||||
|
kaoqinDayhours: Number(res.data.kaoqinDayhours)
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dialogVisible.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleSave() {
|
||||||
|
if (!form.depId) {
|
||||||
|
ElMessage.warning('请选择车间');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!form.kaoqinDayhours || form.kaoqinDayhours <= 0) {
|
||||||
|
ElMessage.warning('日工作小时数必须大于 0');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (isEdit.value) {
|
||||||
|
await request.put(`/prod/chejianbanci/${editId.value}`, form);
|
||||||
|
ElMessage.success('修改成功');
|
||||||
|
} else {
|
||||||
|
await request.post('/prod/chejianbanci', form);
|
||||||
|
ElMessage.success('新增成功');
|
||||||
|
}
|
||||||
|
dialogVisible.value = false;
|
||||||
|
loadList();
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleDelete(row) {
|
||||||
|
await ElMessageBox.confirm(`确定删除「${row.deptname} · ${row.banciName}班」的班次配置吗?`, '提示', { type: 'warning' });
|
||||||
|
try {
|
||||||
|
await request.delete(`/prod/chejianbanci/${row.id}`);
|
||||||
|
ElMessage.success('删除成功');
|
||||||
|
loadList();
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
loadDepOptions();
|
||||||
|
loadList();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<el-card shadow="never">
|
||||||
|
<template #header>
|
||||||
|
<div class="card-header">
|
||||||
|
<span>车间班次</span>
|
||||||
|
<el-button type="primary" @click="openCreate">新增车间班次</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div class="search-bar">
|
||||||
|
<el-input
|
||||||
|
v-model="query.like"
|
||||||
|
placeholder="车间 / 班次"
|
||||||
|
clearable
|
||||||
|
style="width: 220px"
|
||||||
|
@keyup.enter="handleSearch"
|
||||||
|
/>
|
||||||
|
<el-button type="primary" @click="handleSearch">查询</el-button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<el-table v-loading="loading" :data="list" row-key="id" border stripe>
|
||||||
|
<el-table-column type="index" label="序号" width="70" align="center" />
|
||||||
|
<el-table-column prop="deptname" label="车间" min-width="200" />
|
||||||
|
<el-table-column prop="banciName" label="班次" width="120" />
|
||||||
|
<el-table-column prop="kaoqinDayhours" label="日工作小时数" width="140" />
|
||||||
|
<el-table-column label="操作" width="150" fixed="right">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-button size="small" type="primary" link @click="openEdit(row)">编辑</el-button>
|
||||||
|
<el-button size="small" type="danger" link @click="handleDelete(row)">删除</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<el-pagination
|
||||||
|
class="pagination"
|
||||||
|
:current-page="query.pageIndex"
|
||||||
|
:page-size="query.pageSize"
|
||||||
|
:total="total"
|
||||||
|
layout="total, prev, pager, next"
|
||||||
|
@current-change="handlePageChange"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<el-dialog v-model="dialogVisible" :title="dialogTitle" width="520px">
|
||||||
|
<el-form :model="form" label-width="120px">
|
||||||
|
<el-form-item label="车间" required>
|
||||||
|
<el-select v-model="form.depId" placeholder="请选择车间" style="width: 100%">
|
||||||
|
<el-option v-for="d in depOptions" :key="d.id" :label="d.name" :value="Number(d.id)" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="班次" required>
|
||||||
|
<el-select v-model="form.banci" style="width: 100%">
|
||||||
|
<el-option v-for="b in banciOptions" :key="b.value" :label="b.label" :value="b.value" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="日工作小时数" required>
|
||||||
|
<el-input-number
|
||||||
|
v-model="form.kaoqinDayhours"
|
||||||
|
:min="0"
|
||||||
|
:max="24"
|
||||||
|
:precision="1"
|
||||||
|
:step="0.5"
|
||||||
|
style="width: 100%"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<el-button @click="dialogVisible = false">取消</el-button>
|
||||||
|
<el-button type="primary" @click="handleSave">确定</el-button>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</el-card>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.card-header { display: flex; justify-content: space-between; align-items: center; }
|
||||||
|
.search-bar { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
|
||||||
|
.pagination { margin-top: 16px; justify-content: flex-end; }
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user