一套完整的业务逻辑(班次管理)

该博客详细介绍了如何实现一套完整的班次管理业务逻辑,包括数据库表结构设计、菜单及按钮的创建、API控制器的编写、服务层的实现以及前端Vue组件的展示。主要涉及的功能有查询、新增、删除、修改和导出班次信息,同时包含了权限控制和日志记录。此外,还展示了前端Vue组件的交互逻辑,如搜索、排序、多选和操作按钮等。
摘要由CSDN通过智能技术生成

一套完整的业务逻辑(班次管理)

DB

use yxt_mes_db;

-- 班次维护菜单
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by, create_time) 
VALUES ('班次维护', 1145, 999, 'BFlightInfo', 'factorys/BFlightInfo', 0, 0, 'C', '0', '0', 'factorys:bflightinfo:list', 'icon1', 'system', GETDATE());

-- 按钮父菜单id
declare @menuId int = @@identity


INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) 
VALUES ('查询', @menuId, 1, '#', NULL, 0, 0, 'F', '0', '0', 'factorys:bflightinfo:query', '', 'system', GETDATE());

INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) 
VALUES ('新增', @menuId, 2, '#', NULL, 0, 0, 'F', '0', '0', 'factorys:bflightinfo:add', '', 'system', GETDATE());

INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) 
VALUES ('删除', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', 'factorys:bflightinfo:delete', '', 'system', GETDATE());

INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) 
VALUES ('修改', @menuId, 4, '#', NULL, 0, 0, 'F', '0', '0', 'factorys:bflightinfo:edit', '', 'system', GETDATE());

INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) 
VALUES ('导出', @menuId, 5, '#', NULL, 0, 0, 'F', '0', '0', 'factorys:bflightinfo:export', '', 'system', GETDATE());

SELECT * FROM sys_menu WHERE parentId = @menuId;
SELECT * FROM sys_menu WHERE menuId = @menuId;

Controllers/Factorys/BFlightInfoController

using Infrastructure;
using Infrastructure.Attribute;
using Infrastructure.Enums;
using Infrastructure.Model;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using YXT.Model.Dto;
using YXT.Model.Models;
using YXT.Service.Factorys.IFactorysService;
using YXT.Admin.WebApi.Extensions;
using YXT.Admin.WebApi.Filters;
using YXT.Common;

namespace YXT.Admin.WebApi.Controllers
{
    /// <summary>
    /// 班次维护Controller
    /// 
    /// @tableName B_Flight_Info
    /// @author admin
    /// @date 2022-10-21
    /// </summary>
    [Verify]
    [Route("factorys/BFlightInfo")]
    public class BFlightInfoController : BaseController
    {
        /// <summary>
        /// 班次维护接口
        /// </summary>
        private readonly IBFlightInfoService _BFlightInfoService;

        public BFlightInfoController(IBFlightInfoService BFlightInfoService)
        {
            _BFlightInfoService = BFlightInfoService;
        }

        /// <summary>
        /// 查询班次维护列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "factorys:bflightinfo:list")]
        public IActionResult QueryBFlightInfo([FromQuery] BFlightInfoQueryDto parm)
        {
            var response = _BFlightInfoService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询班次维护详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "factorys:bflightinfo:query")]
        public IActionResult GetBFlightInfo(int Id)
        {
            var response = _BFlightInfoService.GetFirst(x => x.Id == Id);
            
            return SUCCESS(response);
        }

        /// <summary>
        /// 添加班次维护
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "factorys:bflightinfo:add")]
        [Log(Title = "班次维护", BusinessType = BusinessType.INSERT)]
        public IActionResult AddBFlightInfo([FromBody] BFlightInfoDto parm)
        {
            if (parm == null)
            {
                throw new CustomException("请求参数错误");
            }
            var modal = parm.Adapt<BFlightInfo>().ToCreate(HttpContext);
            var response = _BFlightInfoService.AddBFlightInfo(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 更新班次维护
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "factorys:bflightinfo:edit")]
        [Log(Title = "班次维护", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateBFlightInfo([FromBody] BFlightInfoDto parm)
        {
            if (parm == null)
            {
                throw new CustomException("请求实体不能为空");
            }
            var modal = parm.Adapt<BFlightInfo>().ToUpdate(HttpContext);
            var response = _BFlightInfoService.UpdateBFlightInfo(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除班次维护
        /// </summary>
        /// <returns></returns>
        [HttpDelete("{ids}")]
        [ActionPermissionFilter(Permission = "factorys:bflightinfo:delete")]
        [Log(Title = "班次维护", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteBFlightInfo(string ids)
        {
            int[] idsArr = Tools.SpitIntArrary(ids);
            if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }

            var response = _BFlightInfoService.Delete(idsArr);

            return ToResponse(response);
        }

        /// <summary>
        /// 导出班次维护
        /// </summary>
        /// <returns></returns>
        [Log(Title = "班次维护", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
        [HttpGet("export")]
        [ActionPermissionFilter(Permission = "factorys:bflightinfo:export")]
        public IActionResult Export([FromQuery] BFlightInfoQueryDto parm)
        {
            parm.PageSize = 10000;
            var list = _BFlightInfoService.GetList(parm).Result;

            string sFileName = ExportExcel(list, "BFlightInfo", "班次维护");
            return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
        }

    }
}

Model/Dto/Factorys/BFlightInfoDto

using Model;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using YXT.Model.Dto;
using YXT.Model.Models;

namespace YXT.Model.Dto
{
    /// <summary>
    /// 班次维护输入对象
    /// </summary>
    public class BFlightInfoDto
    {
        public int? Id { get; set; }
        [Required(ErrorMessage = "班次名称不能为空")]
        public string FlightName { get; set; }
        [Required(ErrorMessage = "班次编码不能为空")]
        public string FlightCode { get; set; }
        [Required(ErrorMessage = "班次描述不能为空")]
        public string FlightDescribe { get; set; }
        public string Status { get; set; }
        public int? CreateUserid { get; set; }
        public DateTime? CreateDate { get; set; }
        public int? UpdateUserid { get; set; }
        public DateTime? UpdateDate { get; set; }
        public string WorkTime { get; set; }
        public string NoworkTime { get; set; }
    }

    /// <summary>
    /// 班次维护查询对象
    /// </summary>
    public class BFlightInfoQueryDto : PagerInfo 
    {
        public string FlightName { get; set; }
        public string FlightCode { get; set; }
        public string FlightDescribe { get; set; }
    }
}

Model/Models/Factorys/BFlightInfo.cs

using System;
using System.Collections.Generic;
using SqlSugar;
using OfficeOpenXml.Attributes;

namespace YXT.Model.Models
{
    /// <summary>
    /// 班次维护,数据实体对象
    ///
    /// @author admin
    /// @date 2022-10-21
    /// </summary>
    [SugarTable("B_Flight_Info")]
    public class BFlightInfo
    {
        /// <summary>
        /// 描述 :id 
        /// 空值 : true  
        /// </summary>
        [EpplusTableColumn(Header = "id")]
        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
        public int? Id { get; set; }

        /// <summary>
        /// 描述 :班次名称 
        /// 空值 : false  
        /// </summary>
        [EpplusTableColumn(Header = "班次名称")]
        [SugarColumn(ColumnName = "fLIGHT_NAME")]
        public string FlightName { get; set; }

        /// <summary>
        /// 描述 :班次编码 
        /// 空值 : false  
        /// </summary>
        [EpplusTableColumn(Header = "班次编码")]
        [SugarColumn(ColumnName = "fLIGHT_CODE")]
        public string FlightCode { get; set; }

        /// <summary>
        /// 描述 :班次描述 
        /// 空值 : false  
        /// </summary>
        [EpplusTableColumn(Header = "班次描述")]
        [SugarColumn(ColumnName = "fLIGHT_DESCRIBE")]
        public string FlightDescribe { get; set; }

        /// <summary>
        /// 描述 :状态 
        /// 空值 : true  
        /// </summary>
        [EpplusTableColumn(Header = "状态")]
        public string Status { get; set; }

        /// <summary>
        /// 描述 :创建人id 
        /// 空值 : true  
        /// </summary>
        [EpplusTableColumn(Header = "创建人id")]
        [SugarColumn(ColumnName = "cREATE_USERID")]
        public int? CreateUserid { get; set; }

        /// <summary>
        /// 描述 :创建日期 
        /// 空值 : true  
        /// </summary>
        [EpplusTableColumn(Header = "创建日期", NumberFormat = "yyyy-MM-dd HH:mm:ss")]
        [SugarColumn(ColumnName = "cREATE_DATE")]
        public DateTime? CreateDate { get; set; }

        /// <summary>
        /// 描述 :更新人id 
        /// 空值 : true  
        /// </summary>
        [EpplusTableColumn(Header = "更新人id")]
        [SugarColumn(ColumnName = "uPDATE_USERID")]
        public int? UpdateUserid { get; set; }

        /// <summary>
        /// 描述 :更新日期 
        /// 空值 : true  
        /// </summary>
        [EpplusTableColumn(Header = "更新日期", NumberFormat = "yyyy-MM-dd HH:mm:ss")]
        [SugarColumn(ColumnName = "uPDATE_DATE")]
        public DateTime? UpdateDate { get; set; }

        /// <summary>
        /// 描述 :上班时间 xx:xx
        /// 空值 : true  
        /// </summary>
        [EpplusTableColumn(Header = "上班时间")]
        [SugarColumn(ColumnName = "wORK_TIME")]
        public string WorkTime { get; set; }

        /// <summary>
        /// 描述 :下班时间 xx:xx
        /// 空值 : true  
        /// </summary>
        [EpplusTableColumn(Header = "下班时间")]
        [SugarColumn(ColumnName = "nOWORK_TIME")]
        public string NoworkTime { get; set; }



    }
}

Repository/Factorys/BFlightInfoRepository.cs

using System;
using Infrastructure.Attribute;
using YXT.Repository.System;
using YXT.Model.Models;
using Repository;

namespace YXT.Repository
{
    /// <summary>
    /// 班次维护仓储
    ///
    /// @author admin
    /// @date 2022-10-21
    /// </summary>
    [AppService(ServiceLifetime = LifeTime.Transient)]
    public class BFlightInfoRepository : BaseRepository<BFlightInfo>
    {
        #region 业务逻辑代码
        #endregion
    }
}

Service/Factorys/BFlightInfoService.cs

using System;
using SqlSugar;
using System.Collections.Generic;
using Infrastructure;
using Infrastructure.Attribute;
using Model;
using YXT.Model.Dto;
using YXT.Model.Models;
using YXT.Repository;
using YXT.Service.Factorys.IFactorysService;
using Repository;

namespace YXT.Service.Factorys
{
    /// <summary>
    /// 班次维护Service业务层处理
    ///
    /// @author admin
    /// @date 2022-10-21
    /// </summary>
    [AppService(ServiceType = typeof(IBFlightInfoService), ServiceLifetime = LifeTime.Transient)]
    public class BFlightInfoService : BaseService<BFlightInfo>, IBFlightInfoService
    {
        private readonly BFlightInfoRepository _BFlightInfoRepository;
        public BFlightInfoService(BFlightInfoRepository repository)
        {
            _BFlightInfoRepository = repository;
        }

        #region 业务逻辑代码

        /// <summary>
        /// 查询班次维护列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public PagedInfo<BFlightInfo> GetList(BFlightInfoQueryDto parm)
        {
            //开始拼装查询条件
            var predicate = Expressionable.Create<BFlightInfo>();

            //搜索条件查询语法参考Sqlsugar
            predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.FlightName), it => it.FlightName.Contains(parm.FlightName));
            predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.FlightCode), it => it.FlightCode.Contains(parm.FlightCode));
            predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.FlightDescribe), it => it.FlightDescribe.Contains(parm.FlightDescribe));
            var response = _BFlightInfoRepository
                .Queryable()
                .Where(predicate.ToExpression())
                .ToPage(parm);

            return response;
        }

        /// <summary>
        /// 添加班次维护
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public int AddBFlightInfo(BFlightInfo parm)
        {
            var response = _BFlightInfoRepository.Insert(parm, it => new
            {
                it.FlightName,
                it.FlightCode,
                it.FlightDescribe,
                it.Status,
                it.CreateUserid,
                it.CreateDate,
                it.WorkTime,
                it.NoworkTime,
            });
            return response;
        }

        /// <summary>
        /// 修改班次维护
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public int UpdateBFlightInfo(BFlightInfo parm)
        {
            var response = _BFlightInfoRepository.Update(w => w.Id == parm.Id, it => new BFlightInfo()
            {
                FlightName = parm.FlightName,
                FlightCode = parm.FlightCode,
                FlightDescribe = parm.FlightDescribe,
                Status = parm.Status,
                UpdateUserid = parm.UpdateUserid,
                UpdateDate = parm.UpdateDate,
                WorkTime = parm.WorkTime,
                NoworkTime = parm.NoworkTime,
            });
            return response;
        }
        #endregion
    }
}

Service\Factorys\IFactorysService\IFactorysService.cs

using System;
using Model;
using YXT.Model.Dto;
using YXT.Model.Models;
using System.Collections.Generic;

namespace YXT.Service.Factorys.IFactorysService
{
    /// <summary>
    /// 班次维护service接口
    ///
    /// @author admin
    /// @date 2022-10-21
    /// </summary>
    public interface IBFlightInfoService : IBaseService<BFlightInfo>
    {
        PagedInfo<BFlightInfo> GetList(BFlightInfoQueryDto parm);

        int AddBFlightInfo(BFlightInfo parm);

        int UpdateBFlightInfo(BFlightInfo parm);
    }
}

Vue\src\api\factorys\bFlightInfo.js

import request from '@/utils/request'

/**
* 班次维护分页查询
* @param {查询条件} data
*/
export function listBFlightInfo(query) {
  return request({
    url: 'factorys/BFlightInfo/list',
    method: 'get',
    params: query,
  })
}


/**
* 新增班次维护
* @param data
*/
export function addBFlightInfo(data) {
  return request({
    url: 'factorys/BFlightInfo',
    method: 'post',
    data: data,
  })
}

/**
* 修改班次维护
* @param data
*/
export function updateBFlightInfo(data) {
  return request({
    url: 'factorys/BFlightInfo',
    method: 'PUT',
    data: data,
  })
}

/**
* 获取班次维护详情
* @param {Id}
*/
export function getBFlightInfo(id) {
  return request({
    url: 'factorys/BFlightInfo/' + id,
    method: 'get'
  })
}

/**
* 删除班次维护
* @param {主键} pid
*/
export function delBFlightInfo(pid) {
  return request({
    url: 'factorys/BFlightInfo/' + pid,
    method: 'delete'
  })
}

// 导出班次维护
export function exportBFlightInfo(query) {
  return request({
    url: 'factorys/BFlightInfo/export',
    method: 'get',
    params: query
  })
}


Vue\src\views\factorys\BFlightInfo.vue

<!--
 * @Descripttion: (班次维护/B_Flight_Info)
 * @version: (1.0)
 * @Author: (admin)
 * @Date: (2022-10-21)
 * @LastEditors: (admin)
 * @LastEditTime: (2022-10-21)
-->
<template>
  <div class="app-container">
    <!-- :model属性用于表单验证使用 比如下面的el-form-item 的 prop属性用于对表单值进行验证操作 -->
    <el-form :model="queryParams" size="small" label-position="right" inline ref="queryForm" :label-width="labelWidth" v-show="showSearch" 
      @submit.native.prevent>
          				    
      <el-form-item label="班次名称" prop="flightName">
        <el-input v-model="queryParams.flightName" placeholder="请输入班次名称" />
      </el-form-item>
    				    
      <el-form-item label="班次编码" prop="flightCode">
        <el-input v-model="queryParams.flightCode" placeholder="请输入班次编码" />
      </el-form-item>
    				    
      <el-form-item label="班次描述" prop="flightDescribe">
        <el-input v-model="queryParams.flightDescribe" placeholder="请输入班次描述" />
      </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" v-hasPermi="['factorys:bflightinfo:add']" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" :disabled="single" v-hasPermi="['factorys:bflightinfo:edit']" plain icon="el-icon-edit" size="mini" @click="handleUpdate">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" :disabled="multiple" v-hasPermi="['factorys:bflightinfo:delete']" plain icon="el-icon-delete" size="mini" @click="handleDelete">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['factorys:bflightinfo:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 数据区域 -->
    <el-table :data="dataList" v-loading="loading" ref="table" border highlight-current-row @sort-change="sortChange" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50" align="center"/>
      <el-table-column prop="flightName" label="班次名称" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="flightCode" label="班次编码" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="flightDescribe" label="班次描述" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="status" label="状态" align="center">
        <template slot-scope="scope">
          <dict-tag :options="statusOptions" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column prop="createDate" label="创建日期" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="updateDate" label="更新日期" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="workTime" label="上班时间" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="noworkTime" label="下班时间" align="center" :show-overflow-tooltip="true" />

      <el-table-column label="操作" align="center" width="140">
        <template slot-scope="scope">
          <el-button size="mini" v-hasPermi="['factorys:bflightinfo:edit']" type="success" icon="el-icon-edit" title="编辑" 
            @click="handleUpdate(scope.row)"></el-button>      
          <el-button size="mini" v-hasPermi="['factorys:bflightinfo:delete']" type="danger" icon="el-icon-delete" title="删除" 
            @click="handleDelete(scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination class="mt10" background :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改班次维护对话框 -->
    <el-dialog :title="title" :lock-scroll="false" :visible.sync="open" >
      <el-form ref="form" :model="form" :rules="rules" :label-width="formLabelWidth">
        <el-row :gutter="20">
            
          <el-col :lg="12" v-if="opertype == 2">
            <el-form-item label="id">{{form.id}}</el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="班次名称" prop="flightName">
              <el-input v-model="form.flightName" placeholder="请输入班次名称" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="班次编码" prop="flightCode">
              <el-input v-model="form.flightCode" placeholder="请输入班次编码" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="班次描述" prop="flightDescribe">
              <el-input v-model="form.flightDescribe" placeholder="请输入班次描述" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="状态" prop="status">
              <el-radio-group v-model="form.status">
                <el-radio v-for="item in statusOptions" :key="item.dictValue" :label="item.dictValue">{{item.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
    
          <el-col :lg="12">
            <el-form-item label="创建人id" prop="createUserid">
              <el-input v-model="form.createUserid" placeholder="请输入创建人id" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="创建日期" prop="createDate">
              <el-date-picker v-model="form.createDate" type="datetime" placeholder="选择日期时间"></el-date-picker>
            </el-form-item>
          </el-col>
    
          <el-col :lg="12">
            <el-form-item label="更新人id" prop="updateUserid">
              <el-input v-model="form.updateUserid" placeholder="请输入更新人id" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="更新日期" prop="updateDate">
              <el-date-picker v-model="form.updateDate" type="datetime" placeholder="选择日期时间"></el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="上班时间" prop="workTime">
              <el-input v-model="form.workTime" placeholder="请输入上班时间" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item label="下班时间" prop="noworkTime">
              <el-input v-model="form.noworkTime" placeholder="请输入下班时间" />
            </el-form-item>
          </el-col>

        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="text" @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>
<script>
import { 
  listBFlightInfo,
  addBFlightInfo,
  delBFlightInfo,
  updateBFlightInfo,
  getBFlightInfo,
  exportBFlightInfo,
} from '@/api/factorys/bFlightInfo.js';

export default {
  name: "bflightinfo",
  data() {
    return {
      labelWidth: "100px",
      formLabelWidth:"100px",
      // 选中id数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sort: undefined,
        sortType: undefined,
        flightName: undefined,
        flightCode: undefined,
        flightDescribe: undefined,
      },
      // 弹出层标题
      title: "",
      // 操作类型 1、add 2、edit
      opertype: 0,
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      columns: [
        { index: 0, key: 'id', label: `id`, checked:  true  },
        { index: 1, key: 'flightName', label: `班次名称`, checked:  true  },
        { index: 2, key: 'flightCode', label: `班次编码`, checked:  true  },
        { index: 3, key: 'flightDescribe', label: `班次描述`, checked:  true  },
        { index: 4, key: 'status', label: `状态`, checked:  true  },
        { index: 5, key: 'createUserid', label: `创建人id`, checked:  true  },
        { index: 6, key: 'createDate', label: `创建日期`, checked:  true  },
        { index: 7, key: 'updateUserid', label: `更新人id`, checked:  true  },
        { index: 8, key: 'updateDate', label: `更新日期`, checked:  true  },
        { index: 9, key: 'workTime', label: `上班时间`, checked:  false  },
        { index: 10, key: 'noworkTime', label: `下班时间`, checked:  false  },
      ],
      // 状态选项列表 格式 eg:{ dictLabel: '标签', dictValue: '0'}
      statusOptions: [],
      // 数据列表
      dataList: [],
      // 总记录数
      total: 0,
      // 提交按钮是否显示
      btnSubmitVisible: true,
      // 表单校验
      rules: {
        flightName: [
          { required: true, message: "班次名称不能为空", trigger: "blur" }
        ],
        flightCode: [
          { required: true, message: "班次编码不能为空", trigger: "blur" }
        ],
        flightDescribe: [
          { required: true, message: "班次描述不能为空", trigger: "blur" }
        ],
      },
    };
  },
  created() {    
    // 列表数据查询
    this.getList();

    var dictParams = [
      { dictType: "sys_notice_status", columnName: "statusOptions" },
    ];
    this.getDicts(dictParams).then((response) => {
      response.data.forEach((element) => {
        this[element.columnName] = element.list;
      });
    });
  },
  methods: {
    // 查询数据
    getList() {
      this.loading = true;
      listBFlightInfo(this.queryParams).then(res => {
         if (res.code == 200) {
           this.dataList = res.data.result;
           this.total = res.data.totalNum;
           this.loading = false;
         }
       })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 重置数据表单
    reset() {
      this.form = {
        flightName: undefined,
        flightCode: undefined,
        flightDescribe: undefined,
        status: undefined,
        createUserid: undefined,
        createDate: undefined,
        updateUserid: undefined,
        updateDate: undefined,
        workTime: undefined,
        noworkTime: undefined,
      };
      this.resetForm("form");
    },
    // 重置查询操作
    resetQuery() {
      this.timeRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length != 1
      this.multiple = !selection.length;
    },
     // 自定义排序
    sortChange(column) {
      if (column.prop == null || column.order == null) {
        this.queryParams.sort = undefined;
        this.queryParams.sortType = undefined;
      } else {
        this.queryParams.sort = column.prop;
        this.queryParams.sortType = column.order;
      }

      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加";
      this.opertype = 1;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const Ids = row.id || this.ids;

      this.$confirm('是否确认删除参数编号为"' + Ids + '"的数据项?')
        .then(function () {
          return delBFlightInfo(Ids);
        })
        .then(() => {
          this.handleQuery();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getBFlightInfo(id).then((res) => {
        const { code, data } = res;
        if (code == 200) {
          this.open = true;
          this.title = "修改数据";
          this.opertype = 2;

          this.form = {
            ...data,
          };
        }
      });
    },
    // 状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          console.log(JSON.stringify(this.form));
          
          if (this.form.id != undefined && this.opertype === 2) {
            updateBFlightInfo(this.form)
              .then((res) => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
            })
            .catch((err) => {
                //TODO 错误逻辑
              });
          } else {
            addBFlightInfo(this.form)
              .then((res) => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
            })
            .catch((err) => {
                //TODO 错误逻辑
              });
          }
        }
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有班次维护数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportBFlightInfo(queryParams);
        })
        .then((response) => {
          this.download(response.data.path);
        });
    },
  },
};
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

是貔貅喔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值