feat(example): 添加设备管理模块功能

This commit is contained in:
zxy 2026-04-13 16:41:21 +08:00
parent c449e6b6b2
commit 24f63aa3ed
13 changed files with 1295 additions and 0 deletions

View File

@ -0,0 +1,11 @@
package jnpf.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import jnpf.model.equipment.EquipmentEntity;
/**
* 设备主数据 Mapper
*/
public interface EquipmentMapper extends BaseMapper<EquipmentEntity> {
}

View File

@ -0,0 +1,65 @@
package jnpf.service;
import com.baomidou.mybatisplus.extension.service.IService;
import jnpf.model.equipment.EquipmentEntity;
import jnpf.model.equipment.EquipmentForm;
import jnpf.model.equipment.EquipmentPagination;
import java.util.List;
/**
* 设备主数据 Service
*/
public interface EquipmentService extends IService<EquipmentEntity> {
/**
* 列表查询
* @param equipmentPagination 分页参数
* @return 列表数据
*/
List<EquipmentEntity> getList(EquipmentPagination equipmentPagination);
/**
* 详情查询
* @param id 主键
* @return 实体对象
*/
EquipmentEntity getInfo(String id);
/**
* 新增
* @param entity 实体对象
*/
void create(EquipmentEntity entity);
/**
* 修改
* @param id 主键
* @param entity 实体对象
* @return 是否成功
*/
boolean update(String id, EquipmentEntity entity);
/**
* 删除
* @param entity 实体对象
*/
void delete(EquipmentEntity entity);
/**
* 验证表单
* @param form 表单对象
* @param i 0新增-1修改
* @return 错误信息
*/
String checkForm(EquipmentForm form, int i);
/**
* 保存或更新
* @param equipmentForm 表单对象
* @param id 主键
* @param isSave 是否新增
* @throws Exception 异常
*/
void saveOrUpdate(EquipmentForm equipmentForm, String id, boolean isSave) throws Exception;
}

View File

@ -28,5 +28,6 @@ public interface ProLineService extends IService<ProLineEntity> {
boolean update(String id, ProLineEntity entity); boolean update(String id, ProLineEntity entity);
String checkForm(ProLineForm form, int i); String checkForm(ProLineForm form, int i);
void saveOrUpdate(ProLineForm proLineForm, String id, boolean isSave) throws Exception; void saveOrUpdate(ProLineForm proLineForm, String id, boolean isSave) throws Exception;
List<ProLineEntity> getSelectList();
} }

View File

@ -0,0 +1,136 @@
package jnpf.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jnpf.mapper.EquipmentMapper;
import jnpf.model.equipment.EquipmentEntity;
import jnpf.model.equipment.EquipmentForm;
import jnpf.model.equipment.EquipmentPagination;
import jnpf.service.EquipmentService;
import jnpf.util.StringUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 设备主数据 ServiceImpl
*/
@Service
public class EquipmentServiceImpl extends ServiceImpl<EquipmentMapper, EquipmentEntity> implements EquipmentService {
@Override
public List<EquipmentEntity> getList(EquipmentPagination equipmentPagination) {
LambdaQueryWrapper<EquipmentEntity> wrapper = new LambdaQueryWrapper<>();
if (ObjectUtil.isNotEmpty(equipmentPagination.getEqCode())) {
wrapper.like(EquipmentEntity::getEqCode, equipmentPagination.getEqCode());
}
if (ObjectUtil.isNotEmpty(equipmentPagination.getEqName())) {
wrapper.like(EquipmentEntity::getEqName, equipmentPagination.getEqName());
}
if (ObjectUtil.isNotEmpty(equipmentPagination.getEqType())) {
wrapper.eq(EquipmentEntity::getEqType, equipmentPagination.getEqType());
}
if (ObjectUtil.isNotEmpty(equipmentPagination.getMode())) {
wrapper.like(EquipmentEntity::getMode, equipmentPagination.getMode());
}
if (ObjectUtil.isNotEmpty(equipmentPagination.getManufacturer())) {
wrapper.like(EquipmentEntity::getManufacturer, equipmentPagination.getManufacturer());
}
if (ObjectUtil.isNotEmpty(equipmentPagination.getEqStatus())) {
wrapper.eq(EquipmentEntity::getEqStatus, equipmentPagination.getEqStatus());
}
if (ObjectUtil.isNotEmpty(equipmentPagination.getDeptId())) {
wrapper.eq(EquipmentEntity::getDeptId, equipmentPagination.getDeptId());
}
if (ObjectUtil.isNotEmpty(equipmentPagination.getLineId())) {
wrapper.eq(EquipmentEntity::getLineId, equipmentPagination.getLineId());
}
if (ObjectUtil.isNotEmpty(equipmentPagination.getEnabledStatus())) {
wrapper.eq(EquipmentEntity::getEnabledStatus, equipmentPagination.getEnabledStatus());
}
if (ObjectUtil.isNotEmpty(equipmentPagination.getKeyword())) {
String keyword = equipmentPagination.getKeyword();
wrapper.and(w -> w.like(EquipmentEntity::getEqCode, keyword)
.or()
.like(EquipmentEntity::getEqName, keyword)
.or()
.like(EquipmentEntity::getMode, keyword));
}
wrapper.eq(EquipmentEntity::getDeleteMark, 0);
wrapper.orderByDesc(EquipmentEntity::getId);
if ("0".equals(equipmentPagination.getDataType())) {
Page<EquipmentEntity> page = new Page<>(equipmentPagination.getCurrentPage(), equipmentPagination.getPageSize());
IPage<EquipmentEntity> equipmentIPage = this.page(page, wrapper);
equipmentPagination.setData(equipmentIPage.getRecords(), equipmentIPage.getTotal());
return equipmentIPage.getRecords();
} else {
return this.list(wrapper);
}
}
@Override
public EquipmentEntity getInfo(String id) {
QueryWrapper<EquipmentEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(EquipmentEntity::getId, id);
return this.getOne(queryWrapper);
}
@Override
public void create(EquipmentEntity entity) {
this.save(entity);
}
@Override
public boolean update(String id, EquipmentEntity entity) {
return this.updateById(entity);
}
@Override
public void delete(EquipmentEntity entity) {
if (entity != null) {
this.removeById(entity.getId());
}
}
@Override
public String checkForm(EquipmentForm form, int i) {
boolean isUp = StringUtil.isNotEmpty(form.getId()) && !form.getId().equals("0");
String id = "";
String countRecover = "";
if (isUp) {
id = form.getId();
}
if (ObjectUtil.isNotEmpty(form.getEqCode())) {
LambdaQueryWrapper<EquipmentEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(EquipmentEntity::getEqCode, form.getEqCode());
if (isUp) {
wrapper.ne(EquipmentEntity::getId, id);
}
long count = this.count(wrapper);
if (count > 0) {
countRecover += "设备编码已存在,请重新输入!";
}
}
return countRecover;
}
@Override
public void saveOrUpdate(EquipmentForm equipmentForm, String id, boolean isSave) throws Exception {
EquipmentEntity entity = getInfo(id);
if (entity == null) {
entity = new EquipmentEntity();
}
BeanUtils.copyProperties(equipmentForm, entity);
this.saveOrUpdate(entity);
}
}

View File

@ -128,4 +128,15 @@ public class ProLineServiceImpl extends ServiceImpl<ProLineMapper, ProLineEntity
this.saveOrUpdate(entity); this.saveOrUpdate(entity);
} }
@Override
public List<ProLineEntity> getSelectList() {
LambdaQueryWrapper<ProLineEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ProLineEntity::getDeleteMark, 0);
wrapper.eq(ProLineEntity::getEnabledStatus, 1);
wrapper.select(ProLineEntity::getId, ProLineEntity::getProLineName);
wrapper.orderByAsc(ProLineEntity::getProLineName);
return this.list(wrapper);
}
} }

View File

@ -0,0 +1,104 @@
package jnpf.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.base.vo.PaginationVO;
import jnpf.model.equipment.EquipmentEntity;
import jnpf.model.equipment.EquipmentForm;
import jnpf.model.equipment.EquipmentPagination;
import jnpf.service.EquipmentService;
import jnpf.util.JsonUtil;
import jnpf.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 设备主数据 控制类
*/
@Tag(name = "设备主数据", description = "Equipment")
@RestController
@RequestMapping("/api/example/equipment")
public class EquipmentController {
@Autowired
private EquipmentService equipmentService;
@Operation(summary = "获取设备列表")
@PostMapping("/getList")
public ActionResult getList(@RequestBody EquipmentPagination equipmentPagination) {
List<EquipmentEntity> list = equipmentService.getList(equipmentPagination);
List<Map<String, Object>> realList = list.stream()
.map(JsonUtil::entityToMap)
.collect(Collectors.toList());
PageListVO vo = new PageListVO();
vo.setList(realList);
PaginationVO page = JsonUtil.getJsonToBean(equipmentPagination, PaginationVO.class);
vo.setPagination(page);
return ActionResult.success(vo);
}
@Operation(summary = "获取设备详情")
@GetMapping("/{id}")
public ActionResult info(@PathVariable("id") String id) {
EquipmentEntity entity = equipmentService.getInfo(id);
if (entity != null) {
return ActionResult.success(JsonUtil.entityToMap(entity));
}
return ActionResult.fail("数据不存在");
}
@Operation(summary = "新建设备")
@PostMapping
public ActionResult create(@RequestBody @Valid EquipmentForm equipmentForm) {
String b = equipmentService.checkForm(equipmentForm, 0);
if (StringUtil.isNotEmpty(b)) {
return ActionResult.fail(b);
}
try {
equipmentService.saveOrUpdate(equipmentForm, "", true);
return ActionResult.success("新建成功");
} catch (Exception e) {
return ActionResult.fail("新建数据失败:" + e.getMessage());
}
}
@Operation(summary = "更新设备")
@PutMapping("/{id}")
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid EquipmentForm equipmentForm) {
equipmentForm.setId(id);
String b = equipmentService.checkForm(equipmentForm, 1);
if (StringUtil.isNotEmpty(b)) {
return ActionResult.fail(b);
}
EquipmentEntity entity = equipmentService.getInfo(id);
if (entity != null) {
try {
equipmentService.saveOrUpdate(equipmentForm, id, false);
return ActionResult.success("更新成功");
} catch (Exception e) {
return ActionResult.fail("更新数据失败:" + e.getMessage());
}
} else {
return ActionResult.fail("更新失败,数据不存在");
}
}
@Operation(summary = "删除设备")
@DeleteMapping("/{id}")
public ActionResult delete(@PathVariable("id") String id) {
EquipmentEntity entity = equipmentService.getInfo(id);
if (entity != null) {
equipmentService.delete(entity);
return ActionResult.success("删除成功");
}
return ActionResult.fail("删除失败,数据不存在");
}
}

View File

@ -116,5 +116,20 @@ public class ProLineController {
return ActionResult.fail("更新失败,数据不存在"); return ActionResult.fail("更新失败,数据不存在");
} }
} }
@Operation(summary = "获取产线下拉列表")
@GetMapping("/getSelectList")
public ActionResult getSelectList() {
List<ProLineEntity> list = proLineService.getSelectList();
List<Map<String, Object>> result = list.stream()
.map(entity -> {
Map<String, Object> map = JsonUtil.entityToMap(entity);
map.put("id", entity.getId());
map.put("name", entity.getProLineName());
return map;
})
.collect(Collectors.toList());
return ActionResult.success(result);
}
} }

View File

@ -0,0 +1,96 @@
package jnpf.model.equipment;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.time.LocalDate;
import java.util.Date;
/**
* 设备主数据
*/
@Data
@TableName("tba_equipment")
public class EquipmentEntity {
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@TableField(value = "f_creator_user_id", fill = FieldFill.INSERT)
private String creatorUserId;
@TableField(value = "f_creator_time", fill = FieldFill.INSERT)
private Date creatorTime;
@TableField(value = "f_last_modify_user_id", fill = FieldFill.INSERT_UPDATE)
private String lastModifyUserId;
@TableField(value = "f_last_modify_time", fill = FieldFill.INSERT_UPDATE)
private Date lastModifyTime;
@TableField(value = "f_delete_user_id", fill = FieldFill.UPDATE)
private String deleteUserId;
@TableField(value = "f_delete_time", fill = FieldFill.UPDATE)
private Date deleteTime;
@TableField(value = "f_delete_mark", updateStrategy = FieldStrategy.IGNORED)
private Integer deleteMark;
@TableField(value = "f_flow_id")
private String flowId;
@TableField(value = "f_flow_task_id")
private String flowTaskId;
@TableField(value = "enabled_status", updateStrategy = FieldStrategy.IGNORED)
private Integer enabledStatus;
@TableField(value = "remark", updateStrategy = FieldStrategy.IGNORED)
private String remark;
@TableField("eq_code")
private String eqCode;
@TableField("eq_name")
private String eqName;
@TableField("eq_type")
private String eqType;
@TableField("mode")
private String mode;
@TableField("manufacturer")
private String manufacturer;
@TableField("factory_no")
private String factoryNo;
@TableField("supplier")
private String supplier;
@TableField("buy_date")
private LocalDate buyDate;
@TableField("eq_status")
private String eqStatus;
@TableField("dept_id")
private String deptId;
@TableField("dept_name")
private String deptName;
@TableField("user_id")
private String userId;
@TableField("user_name")
private String userName;
@TableField("line_id")
private String lineId;
@TableField("line_name")
private String lineName;
}

View File

@ -0,0 +1,78 @@
package jnpf.model.equipment;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotBlank;
import java.time.LocalDate;
/**
* 设备主数据 Form
*/
@Data
public class EquipmentForm {
@Schema(description = "主键")
private String id;
@NotBlank(message = "设备编码不能为空")
@Schema(description = "设备编码")
private String eqCode;
@NotBlank(message = "设备名称不能为空")
@Schema(description = "设备名称")
private String eqName;
@Schema(description = "设备类型(1生产设备 2动力设备 3特种设备)")
private String eqType;
@Schema(description = "型号")
private String mode;
@Schema(description = "制造商")
private String manufacturer;
@Schema(description = "出厂编号")
private String factoryNo;
@Schema(description = "供应商")
private String supplier;
@DateTimeFormat(pattern = "yyyy-MM-dd")
@Schema(description = "购置日期")
private LocalDate buyDate;
@Schema(description = "设备状态(1在用 2备用 3维修 4封存 5报废)")
private String eqStatus;
@Schema(description = "责任部门id")
private String deptId;
@Schema(description = "责任部门")
private String deptName;
@Schema(description = "责任人id")
private String userId;
@Schema(description = "责任人")
private String userName;
@Schema(description = "产线id")
private String lineId;
@Schema(description = "产线名称")
private String lineName;
@Schema(description = "状态(1启用 2未启用)")
private Integer enabledStatus;
@Schema(description = "备注")
private String remark;
@Schema(description = "流程ID")
private String flowId;
@Schema(description = "流程任务ID")
private String flowTaskId;
}

View File

@ -0,0 +1,45 @@
package jnpf.model.equipment;
import io.swagger.v3.oas.annotations.media.Schema;
import jnpf.base.Pagination;
import lombok.Data;
/**
* 设备主数据 Pagination
*/
@Data
public class EquipmentPagination extends Pagination {
@Schema(description = "数据类型")
private String dataType;
@Schema(description = "设备编码")
private String eqCode;
@Schema(description = "设备名称")
private String eqName;
@Schema(description = "设备类型(1生产设备 2动力设备 3特种设备)")
private String eqType;
@Schema(description = "型号")
private String mode;
@Schema(description = "制造商")
private String manufacturer;
@Schema(description = "设备状态(1在用 2备用 3维修 4封存 5报废)")
private String eqStatus;
@Schema(description = "责任部门id")
private Integer deptId;
@Schema(description = "产线id")
private Integer lineId;
@Schema(description = "状态(1启用 2未启用)")
private Integer enabledStatus;
@Schema(description = "关键词")
private String keyword;
}

View File

@ -0,0 +1,89 @@
import request from '@/utils/request'
// 获取设备列表
export function getEquipmentList(data) {
return request({
url: '/api/example/equipment/getList',
method: 'post',
data
})
}
// 获取设备详情
export function getEquipmentInfo(id) {
return request({
url: `/api/example/equipment/${id}`,
method: 'get'
})
}
// 新建设备
export function createEquipment(data) {
return request({
url: '/api/example/equipment',
method: 'post',
data
})
}
// 更新设备
export function updateEquipment(id, data) {
return request({
url: `/api/example/equipment/${id}`,
method: 'put',
data
})
}
// 删除设备
export function deleteEquipment(id) {
return request({
url: `/api/example/equipment/${id}`,
method: 'delete'
})
}
// 获取部门列表
export function getDeptList() {
return request({
url: '/api/example/equipment/getDeptList',
method: 'get'
})
}
// 获取人员列表
export function getUserList(deptId) {
return request({
url: `/api/example/equipment/getUserList/${deptId || ''}`,
method: 'get'
})
}
// 获取产线列表
export function getLineList() {
return request({
url: '/api/example/proLine/getSelectList',
method: 'get'
})
}
// 客户管理字典映射配置id -> 名称)
export const equipmentMaps = {
eqType: {'1': ' 生产设备', '2': '动力设备', '3': '特种设备'},
eqStatus: {'1': ' 在用', '2': '备用', '3': '维修', '4': '封存', '5': '报废'},
}
// 根据映射自动生成下拉选项
export const customerOptions = {}
for (const key in equipmentMaps) {
const map = equipmentMaps[key]
customerOptions[key] = Object.entries(map).map(([id, fullName]) => ({id, fullName}))
}
// 获取显示名称
export function getLabel(type, value) {
const map = equipmentMaps[type]
return map ? (map[value] || value) : value
}

View File

@ -0,0 +1,354 @@
<template>
<el-dialog
:title="!dataForm.id ? '新建设备' : '编辑设备'"
:visible.sync="dialogVisible"
width="700px"
:close-on-click-modal="false"
@close="handleClose"
>
<el-form ref="formRef" :model="dataForm" :rules="dataRule" size="small" label-width="100px" label-position="right">
<template v-if="!loading">
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="设备编码" prop="eqCode">
<JnpfInput v-model="dataForm.eqCode" placeholder="请输入设备编码" clearable :disabled="!!dataForm.id">
</JnpfInput>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="设备名称" prop="eqName">
<JnpfInput v-model="dataForm.eqName" placeholder="请输入设备名称" clearable>
</JnpfInput>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="设备类型" prop="eqType">
<JnpfSelect v-model="dataForm.eqType" placeholder="请选择设备类型" :options="eqTypeOptions" :props="eqTypeProps" clearable>
</JnpfSelect>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="型号" prop="mode">
<JnpfInput v-model="dataForm.mode" placeholder="请输入型号" clearable>
</JnpfInput>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="生产厂家" prop="manufacturer">
<JnpfInput v-model="dataForm.manufacturer" placeholder="请输入生产厂家" clearable>
</JnpfInput>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="出厂编号" prop="factoryNo">
<JnpfInput v-model="dataForm.factoryNo" placeholder="请输入出厂编号" clearable>
</JnpfInput>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="供应商" prop="supplier">
<JnpfInput v-model="dataForm.supplier" placeholder="请输入供应商" clearable>
</JnpfInput>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="购买日期" prop="buyDate">
<JnpfDatePicker v-model="dataForm.buyDate"
placeholder="请选择购买日期"
clearable
:style='{ "width": "100%" }'
format="yyyy-MM-dd">
</JnpfDatePicker>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="所属部门" prop="deptId">
<JnpfSelect v-model="dataForm.deptId" placeholder="请选择部门" filterable clearable
:style='{ "width": "100%" }' :options="saleDeptIdOptions" @change="handleDeptChange"
:props="saleDeptIdProps">
</JnpfSelect>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="责任人" prop="userId">
<JnpfSelect v-model="dataForm.userId" placeholder="请选择责任人" filterable clearable
:style="{ width: '100%' }" :options="userIdOptions" @change="handleUserChange"
:props="userIdProps">
</JnpfSelect>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="所属产线" prop="lineId">
<el-select v-model="dataForm.lineId" placeholder="请选择产线" filterable clearable :style="{ width: '100%' }" @change="handleLineChange">
<el-option v-for="item in lineList" :key="item.id" :label="item.name || item.lineName" :value="item.id"></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="设备状态" prop="eqStatus">
<JnpfSelect v-model="dataForm.eqStatus" placeholder="请选择设备状态" :options="eqStatusOptions" :props="eqStatusProps" clearable>
</JnpfSelect>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="启用状态" prop="enabledStatus">
<JnpfSelect v-model="dataForm.enabledStatus" placeholder="请选择启用状态" :options="enabledStatusOptions" :props="enabledStatusProps" clearable>
</JnpfSelect>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="24">
<el-form-item label="备注" prop="remark">
<JnpfTextarea v-model="dataForm.remark" placeholder="请输入备注" :autoSize="{ minRows: 4, maxRows: 4 }" type="textarea">
</JnpfTextarea>
</el-form-item>
</el-col>
</el-row>
</template>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="dataFormSubmit()" :loading="btnLoading"> </el-button>
<el-button @click="handleClose"> </el-button>
</div>
</el-dialog>
</template>
<script>
import {createEquipment, customerOptions, getEquipmentInfo, getUserList, updateEquipment} from './equipment'
import {mapGetters} from 'vuex'
import {getDataInterfaceRes} from "@/api/systemData/dataInterface";
export default {
components: {},
props: {
lineList: {
type: Array,
default: () => []
}
},
data() {
return {
dialogVisible: false,
loading: false,
btnLoading: false,
dataForm: {
id: '',
eqCode: undefined,
eqName: undefined,
eqType: undefined,
mode: undefined,
manufacturer: undefined,
factoryNo: undefined,
supplier: undefined,
buyDate: undefined,
eqStatus: undefined,
deptId: undefined,
deptName: undefined,
userId: undefined,
userName: undefined,
lineId: undefined,
lineName: undefined,
enabledStatus: 1,
remark: undefined,
},
dataRule: {
eqCode: [
{
required: true,
message: '请输入设备编码',
trigger: 'blur',
},
],
eqName: [
{
required: true,
message: '请输入设备名称',
trigger: 'blur',
},
],
eqType: [
{
required: true,
message: '请选择设备类型',
trigger: 'change',
},
],
deptId: [
{
required: true,
message: '请选择所属部门',
trigger: 'change',
},
],
userId: [
{
required: true,
message: '请选择责任人',
trigger: 'change',
},
],
enabledStatus: [
{
required: true,
message: '请选择启用状态',
trigger: 'change',
},
],
},
enabledStatusOptions: [
{fullName: "启用", id: 1},
{fullName: "未启用", id: 2},
],
enabledStatusProps: {label: "fullName", value: "id"},
eqTypeOptions: customerOptions.eqType || [],
eqTypeProps: {label: "fullName", value: "id"},
eqStatusOptions: customerOptions.eqStatus || [],
eqStatusProps: {label: "fullName", value: "id"},
saleDeptIdOptions: [],
saleDeptIdProps: {label: 'name', value: 'id'},
userIdOptions: [],
userIdProps: {label: 'name', value: 'id'},
}
},
computed: {
...mapGetters(['userInfo']),
},
created() {
this.getSaleDeptIdOptions()
this.getUserIdOptions()
},
methods: {
init(id) {
this.dataForm.id = id || '';
this.dialogVisible = true;
this.loading = true;
this.$nextTick(() => {
this.$refs.formRef.resetFields();
if (this.dataForm.id) {
getEquipmentInfo(this.dataForm.id).then(res => {
const data = res.data;
this.dataForm = {
...this.dataForm,
...data,
};
if (this.dataForm.buyDate && typeof this.dataForm.buyDate === 'string') {
this.dataForm.buyDate = new Date(this.dataForm.buyDate).getTime();
}
this.loading = false;
}).catch(() => {
this.loading = false;
});
} else {
this.loading = false;
}
});
},
// ... existing code ...
handleDeptChange(deptId) {
this.dataForm.userId = undefined;
this.dataForm.userName = undefined;
const dept = this.saleDeptIdOptions.find(item => item.id === deptId);
this.dataForm.deptName = dept ? dept.name : undefined;
},
handleUserChange(userId) {
const user = this.userIdOptions.find(item => item.id === userId);
this.dataForm.userName = user ? user.name : undefined;
},
getSaleDeptIdOptions() {
getDataInterfaceRes('811583643129479301').then(res => {
this.saleDeptIdOptions = res.data || [];
console.log(this.saleDeptIdOptions);
}).catch(() => {
this.saleDeptIdOptions = [];
});
},
getUserIdOptions() {
getDataInterfaceRes('811594014137516101').then(res => {
this.userIdOptions = res.data || [];
}).catch(() => {
this.userIdOptions = [];
});
},
handleLineChange(lineId) {
const line = this.lineList.find(item => item.id === lineId);
this.dataForm.lineName = line ? (line.name || line.lineName) : undefined;
},
dataFormSubmit() {
this.$refs.formRef.validate((valid) => {
if (valid) {
this.btnLoading = true;
if (this.dataForm.deptId && !this.dataForm.deptName) {
const dept = this.saleDeptIdOptions.find(item => item.id === this.dataForm.deptId);
if (dept) {
this.dataForm.deptName = dept.name;
}
}
if (this.dataForm.userId && !this.dataForm.userName) {
const user = this.userIdOptions.find(item => item.id === this.dataForm.userId);
if (user) {
this.dataForm.userName = user.name;
}
}
if (this.dataForm.lineId && !this.dataForm.lineName) {
const line = this.lineList.find(item => item.id === this.dataForm.lineId);
if (line) {
this.dataForm.lineName = line.name || line.lineName;
}
}
const submitData = {...this.dataForm};
if (submitData.buyDate) {
const date = new Date(submitData.buyDate);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
submitData.buyDate = `${year}-${month}-${day}`;
}
const isEdit = !!this.dataForm.id;
const request = isEdit ? updateEquipment(this.dataForm.id, submitData) : createEquipment(submitData);
request.then(res => {
this.$message({
message: res.msg,
type: 'success',
duration: 1500,
onClose: () => {
this.btnLoading = false;
this.dialogVisible = false;
this.$emit('refresh', true)
}
})
}).catch(() => {
this.btnLoading = false
})
}
})
},
// ... existing code ...
handleClose() {
this.dialogVisible = false;
this.$emit('refresh', false)
},
}
}
</script>

View File

@ -0,0 +1,290 @@
<template>
<div class="JNPF-common-layout equipment_data">
<div class="JNPF-common-layout-center">
<el-row class="JNPF-common-search-box" :gutter="14">
<el-form @submit.native.prevent>
<el-col :span="6">
<el-form-item label="设备编码">
<el-input v-model="query.eqCode" placeholder="请输入设备编码" clearable></el-input>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="设备名称">
<el-input v-model="query.eqName" placeholder="请输入设备名称" clearable></el-input>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="设备类型">
<JnpfSelect v-model="query.eqType" placeholder="请选择设备类型" :options="eqTypeOptions" :props="eqTypeProps" clearable></JnpfSelect>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="启用状态">
<JnpfSelect v-model="query.enabledStatus" placeholder="请选择" clearable :options="enabledStatusOptions"
:props="enabledStatusProps">
</JnpfSelect>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="设备状态">
<JnpfSelect v-model="query.eqStatus" placeholder="请选择设备状态" clearable :options="eqStatusOptions"
:props="eqStatusProps">
</JnpfSelect>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="所属部门">
<el-select v-model="query.deptId" placeholder="请选择部门" clearable>
<el-option
v-for="item in deptList"
:key="item.id"
:label="item.fullName"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="所属产线">
<el-select v-model="query.lineId" placeholder="请选择产线" clearable>
<el-option
v-for="item in lineList"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item class="btn">
<el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
<el-button icon="el-icon-refresh-right" @click="reset()">重置</el-button>
</el-form-item>
</el-col>
</el-form>
</el-row>
<div class="JNPF-common-layout-main JNPF-flex-main">
<div class="JNPF-common-head">
<div>
<el-button type="primary" icon="icon-ym icon-ym-btn-add" @click="addOrUpdateHandle()">新建</el-button>
<!-- <el-button type="danger" icon="el-icon-delete" :disabled="!multipleSelection.length" @click="batchDelete()">批量删除</el-button>-->
</div>
<div class="JNPF-common-head-right"></div>
</div>
<JNPF-table
v-loading="listLoading"
:data="list"
@selection-change="handleSelectionChange">
<el-table-column type="selection" width="50" align="center"/>
<el-table-column prop="eqCode" label="设备编码" align="center" min-width="120"/>
<el-table-column prop="eqName" label="设备名称" align="center" min-width="120"/>
<el-table-column prop="eqType" label="设备类型" align="center" min-width="100">
<template slot-scope="scope">
{{ getEqTypeLabel(scope.row.eqType) }}
</template>
</el-table-column>
<el-table-column prop="mode" label="型号" align="center" min-width="100"/>
<el-table-column prop="manufacturer" label="生产厂家" align="center" min-width="120"/>
<el-table-column prop="supplier" label="供应商" align="center" min-width="120"/>
<el-table-column prop="deptName" label="所属部门" align="center" min-width="100"/>
<el-table-column prop="userName" label="责任人" align="center" min-width="80"/>
<el-table-column prop="lineName" label="所属产线" align="center" min-width="100"/>
<el-table-column prop="buyDate" label="购买日期" align="center" min-width="100" :formatter="jnpf.tableDateFormat1"/>
<el-table-column prop="eqStatus" label="设备状态" align="center" min-width="80">
<template slot-scope="scope">
{{ getEqStatusLabel(scope.row.eqStatus) }}
</template>
</el-table-column>
<el-table-column prop="enabledStatus" label="启用状态" align="center" min-width="80">
<template slot-scope="scope">
<el-tag :type="scope.row.enabledStatus == 1 ? 'success' : 'info'" size="small">
{{ scope.row.enabledStatus == 1 ? '启用' : '未启用' }}
</el-tag>
</template>
</el-table-column>
<el-table-column prop="remark" label="备注" align="center" min-width="150" show-overflow-tooltip/>
<el-table-column prop="creatorTime" label="创建时间" align="center" min-width="150" :formatter="jnpf.tableDateFormat1"/>
<el-table-column label="操作" fixed="right" align="center" width="150">
<template slot-scope="scope">
<el-button type="text" @click="addOrUpdateHandle(scope.row)">编辑</el-button>
<el-button type="text" class="JNPF-table-delBtn" @click="handleDel(scope.row)">删除</el-button>
</template>
</el-table-column>
</JNPF-table>
<pagination :total="total" :page.sync="listQuery.currentPage" :limit.sync="listQuery.pageSize"
@pagination="initData"/>
</div>
</div>
<JNPF-Form v-if="formVisible" ref="JNPFForm" @refresh="refresh" :deptList="deptList" :lineList="lineList"/>
</div>
</template>
<script>
import {customerOptions, deleteEquipment, getEquipmentList, getLabel, getLineList} from "./equipment";
import {mapGetters} from "vuex";
import JNPFForm from "./form";
import jnpf from "@/utils/jnpf";
export default {
name: "equipment",
components: {
JNPFForm,
},
data() {
return {
query: {
eqCode: undefined,
eqName: undefined,
eqType: undefined,
enabledStatus: undefined,
deptId: undefined,
lineId: undefined,
eqStatus: undefined,
},
list: [],
listLoading: false,
multipleSelection: [],
total: 0,
listQuery: {
currentPage: 1,
pageSize: 20,
sort: "",
sidx: "",
},
formVisible: false,
deptList: [],
lineList: [],
enabledStatusOptions: [
{fullName: "启用", id: 1},
{fullName: "未启用", id: 2},
],
enabledStatusProps: {label: "fullName", value: "id"},
eqTypeOptions: customerOptions.eqType || [],
eqTypeProps: {label: "fullName", value: "id"},
eqStatusOptions: customerOptions.eqStatus || [],
eqStatusProps: {label: "fullName", value: "id"},
};
},
computed: {
jnpf() {
return jnpf
},
...mapGetters(["userInfo"]),
menuId() {
return this.$route.meta.modelId || "";
},
},
created() {
this.initData();
this.getDeptList();
this.getLineList();
},
methods: {
initData() {
this.listLoading = true;
let _query = {
...this.listQuery,
...this.query,
dataType: 0,
};
Object.keys(_query).forEach(key => {
if (_query[key] === undefined || _query[key] === null || _query[key] === '') {
delete _query[key];
}
});
getEquipmentList(_query).then((res) => {
this.list = res.data.list;
this.total = res.data.pagination.total;
this.listLoading = false;
}).catch(() => {
this.listLoading = false;
});
},
handleSelectionChange(val) {
this.multipleSelection = val;
},
getDeptList() {
// TODO: API
// getDeptList().then(res => {
// this.deptList = res.data || [];
// });
},
getLineList() {
getLineList().then(res => {
this.lineList = res.data || [];
});
},
addOrUpdateHandle(row) {
let id = row ? row.id : "";
this.formVisible = true;
this.$nextTick(() => {
this.$refs.JNPFForm.init(id);
});
},
handleDel(row) {
this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
type: 'warning'
}).then(() => {
deleteEquipment(row.id).then(res => {
this.$message({
message: res.msg,
type: 'success',
duration: 1500,
onClose: () => {
this.initData();
}
});
});
}).catch(() => {
});
},
batchDelete() {
this.$confirm('此操作将永久删除选中的 ' + this.multipleSelection.length + ' 条数据, 是否继续?', '提示', {
type: 'warning'
}).then(() => {
const ids = this.multipleSelection.map(item => item.id);
Promise.all(ids.map(id => deleteEquipment(id))).then(() => {
this.$message({
message: '删除成功',
type: 'success',
duration: 1500,
onClose: () => {
this.initData();
}
});
});
}).catch(() => {
});
},
search() {
this.listQuery.currentPage = 1;
this.listQuery.pageSize = 20;
this.initData();
},
refresh(isRefresh) {
this.formVisible = false;
if (isRefresh) this.search();
},
reset() {
this.query = {
eqCode: undefined,
eqName: undefined,
eqType: undefined,
eqStatus: undefined,
enabledStatus: undefined,
deptId: undefined,
lineId: undefined,
};
this.search();
},
getEqTypeLabel(value) {
return getLabel('eqType', value);
},
getEqStatusLabel(value) {
return getLabel('eqStatus', value);
},
},
};
</script>