controller
package com.rome.hotel.data.controller; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.List; import javax.servlet.http.HttpServletResponse; import io.jsonwebtoken.lang.Assert; import org.apache.ibatis.annotations.Param; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.rome.hotel.common.annotation.Log; import com.rome.hotel.common.core.controller.BaseController; import com.rome.hotel.common.core.domain.AjaxResult; import com.rome.hotel.common.enums.BusinessType; import com.rome.hotel.data.domain.HotelReserve; import com.rome.hotel.data.service.IHotelReserveService; import com.rome.hotel.common.utils.poi.ExcelUtil; import com.rome.hotel.common.core.page.TableDataInfo; /** * 预定Controller * * @author rome * @date 2024-01-20 */ @RestController @RequestMapping("/data/reserve") public class HotelReserveController extends BaseController { @Autowired private IHotelReserveService hotelReserveService; /** * 查询预定列表 */ @PreAuthorize("@ss.hasPermi('data:reserve:list')") @GetMapping("/list") public TableDataInfo list(HotelReserve hotelReserve) { startPage(); List<HotelReserve> list = hotelReserveService.selectHotelReserveList(hotelReserve); return getDataTable(list); } /** * 导出预定列表 */ @PreAuthorize("@ss.hasPermi('data:reserve:export')") @Log(title = "预定", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, HotelReserve hotelReserve) { List<HotelReserve> list = hotelReserveService.selectHotelReserveList(hotelReserve); ExcelUtil<HotelReserve> util = new ExcelUtil<HotelReserve>(HotelReserve.class); util.exportExcel(response, list, "预定数据"); } /** * 获取预定详细信息 */ @PreAuthorize("@ss.hasPermi('data:reserve:query')") @GetMapping(value = "/{reserveId}") public AjaxResult getInfo(@PathVariable("reserveId") Long reserveId) { return AjaxResult.success(hotelReserveService.selectHotelReserveByReserveId(reserveId)); } /** * 新增预定 */ @PreAuthorize("@ss.hasPermi('data:reserve:add')") @Log(title = "预定", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody HotelReserve hotelReserve) { return toAjax(hotelReserveService.insertHotelReserve(hotelReserve)); } /** * 修改预定 */ @PreAuthorize("@ss.hasPermi('data:reserve:edit')") @Log(title = "预定", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody HotelReserve hotelReserve) { Assert.state( hotelReserveService.updateHotelReserve(hotelReserve)!=0,"这个时间已被预约"); return AjaxResult.success(); } /** * 删除预定 */ @PreAuthorize("@ss.hasPermi('data:reserve:remove')") @Log(title = "预定", businessType = BusinessType.DELETE) @DeleteMapping("/{reserveIds}") public AjaxResult remove(@PathVariable Long[] reserveIds) { try { return toAjax( hotelReserveService.deleteHotelReserveByReserveIds(reserveIds)); }catch (Exception e){ return AjaxResult.error("数据异常,请联系管理员"); } } /** * 查询在预约时间段的 */ @PreAuthorize("@ss.hasPermi('data:reserve:listQueryTime')") @GetMapping("/listQueryTime") public AjaxResult listQueryTime(@Param("roomNumber") String roomNumber) { HotelReserve hotelReserve = new HotelReserve(); hotelReserve.setRoomNumber(roomNumber); Date time = new Date(); Calendar calendar = new GregorianCalendar(); calendar.setTime(time); calendar.add(calendar.DATE,-1);//把日期往后增加一天.整数往后推,负数往前移动 time=calendar.getTime(); //这个时间就是日期往后推一天的结果 System.out.println(time); hotelReserve.setCheckOutTime(time); List<HotelReserve> list = hotelReserveService.selectHotelReserveQueryByCheckOut(hotelReserve); return AjaxResult.success(list); } }
mapper
package com.rome.hotel.data.mapper; import java.util.List; import com.rome.hotel.data.domain.HotelReserve; /** * 预定Mapper接口 * * @author rome * @date 2024-01-20 */ public interface HotelReserveMapper { /** * 查询预定 * * @param reserveId 预定主键 * @return 预定 */ public HotelReserve selectHotelReserveByReserveId(Long reserveId); /** * 查询预定列表 * * @param hotelReserve 预定 * @return 预定集合 */ public List<HotelReserve> selectHotelReserveList(HotelReserve hotelReserve); /** * 新增预定 * * @param hotelReserve 预定 * @return 结果 */ public int insertHotelReserve(HotelReserve hotelReserve); /** * 修改预定 * * @param hotelReserve 预定 * @return 结果 */ public int updateHotelReserve(HotelReserve hotelReserve); /** * 删除预定 * * @param reserveId 预定主键 * @return 结果 */ public int deleteHotelReserveByReserveId(Long reserveId); /** * 批量删除预定 * * @param reserveIds 需要删除的数据主键集合 * @return 结果 */ public int deleteHotelReserveByReserveIds(Long[] reserveIds); /** * 根据时间查询是否在预约时间和退房时间 * @return */ public List<HotelReserve> selectHotelReserveListQuerytime(HotelReserve hotelReserve); /** * 根据时间查询预约时间在今天之后的房间 * @return */ public List<HotelReserve> selectHotelReserveQueryByCheckOut(HotelReserve hotelReserve); /** * 根据时间查询退房时间在今天之前的房间 * @return */ public List<HotelReserve> selectHotelReserveQueryByCheckOutNotRoomNumber(HotelReserve hotelReserve); }
service
package com.rome.hotel.data.service; import java.util.List; import com.rome.hotel.data.domain.HotelReserve; /** * 预定Service接口 * * @author rome * @date 2024-01-20 */ public interface IHotelReserveService { /** * 查询预定 * * @param reserveId 预定主键 * @return 预定 */ public HotelReserve selectHotelReserveByReserveId(Long reserveId); /** * 查询预定列表 * * @param hotelReserve 预定 * @return 预定集合 */ public List<HotelReserve> selectHotelReserveList(HotelReserve hotelReserve); /** * 新增预定 * * @param hotelReserve 预定 * @return 结果 */ public int insertHotelReserve(HotelReserve hotelReserve); /** * 修改预定 * * @param hotelReserve 预定 * @return 结果 */ public int updateHotelReserve(HotelReserve hotelReserve); /** * 批量删除预定 * * @param reserveIds 需要删除的预定主键集合 * @return 结果 */ public int deleteHotelReserveByReserveIds(Long[] reserveIds); /** * 删除预定信息 * * @param reserveId 预定主键 * @return 结果 */ public int deleteHotelReserveByReserveId(Long reserveId); /** * 根据时间查询是否在预约时间和退房时间 * @return */ public List<HotelReserve> selectHotelReserveListQuerytime(HotelReserve hotelReserve); /** * 根据时间查询预约时间在今天之后的房间 * @return */ public List<HotelReserve> selectHotelReserveQueryByCheckOut(HotelReserve hotelReserve); }
sveviceImpl
package com.rome.hotel.data.service.impl; import java.util.Date; import java.util.List; import com.rome.hotel.data.utils.RegexUtils; import com.rome.hotel.data.utils.SnowFlake; import io.jsonwebtoken.lang.Assert; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.rome.hotel.data.mapper.HotelReserveMapper; import com.rome.hotel.data.domain.HotelReserve; import com.rome.hotel.data.service.IHotelReserveService; /** * 预定Service业务层处理 * * @author rome * @date 2024-01-20 */ @Service public class HotelReserveServiceImpl implements IHotelReserveService { @Autowired private HotelReserveMapper hotelReserveMapper; /** * 查询预定 * * @param reserveId 预定主键 * @return 预定 */ @Override public HotelReserve selectHotelReserveByReserveId(Long reserveId) { return hotelReserveMapper.selectHotelReserveByReserveId(reserveId); } /** * 查询预定列表 * * @param hotelReserve 预定 * @return 预定 */ @Override public List<HotelReserve> selectHotelReserveList(HotelReserve hotelReserve) { // 每次查询前看看是否退房时间小于今天,如果是将状态改为已退房 HotelReserve hotelReserveBycheeckOut = new HotelReserve(); Date date = new Date(); date.setHours(12); date.setMinutes(0); date.setSeconds(0); hotelReserveBycheeckOut.setCheckOutTime(date); System.out.println(hotelReserveBycheeckOut.getCheckOutTime()); List<HotelReserve> hotelReserves = hotelReserveMapper.selectHotelReserveQueryByCheckOutNotRoomNumber(hotelReserveBycheeckOut); for (HotelReserve item:hotelReserves ) { item.setJoinState("2"); updateHotelReserve(item); } return hotelReserveMapper.selectHotelReserveList(hotelReserve); } /** * 新增预定 * * @param hotelReserve 预定 * @return 结果 */ @Override public int insertHotelReserve(HotelReserve hotelReserve) { // 防御性编程 Assert.notNull(hotelReserve,"参数异常"); Assert.notNull(hotelReserve.getRoomNumber(),"房间号不能为空"); Assert.notNull(hotelReserve.getCustomerName(),"客户姓名不能为空"); Assert.notNull(hotelReserve.getJoinState(),"入住状态不能为空"); Assert.notNull(hotelReserve.getGender(),"性别不能为空"); Assert.notNull(hotelReserve.getPhoneNumber(),"手机号不能为空"); Assert.notNull(hotelReserve.getIdCard(),"身份证不能为空"); Assert.notNull(hotelReserve.getJoinTime(),"入住时间不能为空"); Assert.notNull(hotelReserve.getCheckOutTime(),"退房时间不能为空"); Assert.state(RegexUtils.testStringNoWuShi(hotelReserve.getRoomNumber()),"房间号不能超过50位"); Assert.state(RegexUtils.testStringNoWuShi(hotelReserve.getCustomerName()),"客户姓名不能超过50位"); Assert.state(RegexUtils.testStringNoWuShi(hotelReserve.getJoinState()),"入住状态不能超过50位"); Assert.state(hotelReserve.getGender().length()==1,"性别参数异常"); Assert.state(RegexUtils.testPhoneNumber(hotelReserve.getPhoneNumber()),"请输入规范的手机号"); Assert.state(RegexUtils.testIdCards(hotelReserve.getIdCard()),"请输入规范的身份证"); Assert.state(hotelReserve.getJoinTime().before(hotelReserve.getCheckOutTime()),"入住时间要在离开时间之前"); //查询预约时间是否已被预约 HotelReserve hotelReserveQuery = new HotelReserve(); hotelReserveQuery.setRoomNumber(hotelReserve.getRoomNumber()); hotelReserveQuery.setJoinTime(hotelReserve.getJoinTime()); hotelReserveQuery.setCheckOutTime(hotelReserve.getCheckOutTime()); List<HotelReserve> hotelReserves = selectHotelReserveListQuerytime(hotelReserveQuery); Assert.state(hotelReserves.size()==0,"这个时间已被预定"); // 设置订单号 // 生成订单号 String orderId = new SnowFlake(0, 0).createOrderNo(); hotelReserve.setOrderNumber(orderId); hotelReserve.setJoinState("0"); return hotelReserveMapper.insertHotelReserve(hotelReserve); } /** * 修改预定 * * @param hotelReserve 预定 * @return 结果 */ @Override public int updateHotelReserve(HotelReserve hotelReserve) { // 防御性编程 Assert.notNull(hotelReserve,"参数异常"); Assert.notNull(hotelReserve.getRoomNumber(),"房间号不能为空"); Assert.notNull(hotelReserve.getCustomerName(),"客户姓名不能为空"); Assert.notNull(hotelReserve.getJoinState(),"入住状态不能为空"); Assert.notNull(hotelReserve.getGender(),"性别不能为空"); Assert.notNull(hotelReserve.getPhoneNumber(),"手机号不能为空"); Assert.notNull(hotelReserve.getIdCard(),"身份证不能为空"); Assert.notNull(hotelReserve.getJoinTime(),"入住时间不能为空"); Assert.notNull(hotelReserve.getCheckOutTime(),"退房时间不能为空"); Assert.state(RegexUtils.testStringNoWuShi(hotelReserve.getRoomNumber()),"房间号不能超过50位"); Assert.state(RegexUtils.testStringNoWuShi(hotelReserve.getCustomerName()),"客户姓名不能超过50位"); Assert.state(RegexUtils.testStringNoWuShi(hotelReserve.getJoinState()),"入住状态不能超过50位"); Assert.state(hotelReserve.getGender().length()==1,"性别参数异常"); Assert.state(RegexUtils.testPhoneNumber(hotelReserve.getPhoneNumber()),"请输入规范的手机号"); Assert.state(RegexUtils.testIdCards(hotelReserve.getIdCard()),"请输入规范的身份证"); Assert.state(hotelReserve.getJoinTime().before(hotelReserve.getCheckOutTime()),"入住时间要在离开时间之前"); //查询预约时间是否已被预约 HotelReserve hotelReserveQuery = new HotelReserve(); hotelReserveQuery.setRoomNumber(hotelReserve.getRoomNumber()); hotelReserveQuery.setJoinTime(hotelReserve.getJoinTime()); hotelReserveQuery.setCheckOutTime(hotelReserve.getCheckOutTime()); List<HotelReserve> hotelReserves = selectHotelReserveListQuerytime(hotelReserveQuery); // 等于0说明这个时间段没人预约,等于1说明是自己 if(hotelReserves.size()==0){ return hotelReserveMapper.updateHotelReserve(hotelReserve); } if(hotelReserves.size()==1&&hotelReserve.getReserveId()==hotelReserves.get(0).getReserveId()){ return hotelReserveMapper.updateHotelReserve(hotelReserve); } return 0; } /** * 批量删除预定 * * @param reserveIds 需要删除的预定主键 * @return 结果 */ @Override public int deleteHotelReserveByReserveIds(Long[] reserveIds) { return hotelReserveMapper.deleteHotelReserveByReserveIds(reserveIds); } /** * 删除预定信息 * * @param reserveId 预定主键 * @return 结果 */ @Override public int deleteHotelReserveByReserveId(Long reserveId) { return hotelReserveMapper.deleteHotelReserveByReserveId(reserveId); } /** * 根据时间查询是否在预约时间和退房时间 * @return */ public List<HotelReserve> selectHotelReserveListQuerytime(HotelReserve hotelReserve){ return hotelReserveMapper.selectHotelReserveListQuerytime(hotelReserve); } /** * 根据时间查询预约时间在今天之后的房间 * @return */ public List<HotelReserve> selectHotelReserveQueryByCheckOut(HotelReserve hotelReserve){ return hotelReserveMapper.selectHotelReserveQueryByCheckOut(hotelReserve); } }
xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.rome.hotel.data.mapper.HotelReserveMapper"> <resultMap type="HotelReserve" id="HotelReserveResult"> <result property="reserveId" column="reserve_id" /> <result property="orderNumber" column="order_number" /> <result property="roomNumber" column="room_number" /> <result property="customerName" column="customer_name" /> <result property="joinState" column="join_state" /> <result property="gender" column="gender" /> <result property="phoneNumber" column="phone_number" /> <result property="idCard" column="id_card" /> <result property="joinTime" column="join_time" /> <result property="checkOutTime" column="check_out_time" /> </resultMap> <sql id="selectHotelReserveVo"> select reserve_id, order_number, room_number, customer_name, join_state, gender, phone_number, id_card, join_time, check_out_time from hotel_reserve </sql> <!-- <select id="selectHotelReserveListRoom" parameterType="HotelReserve" resultMap="HotelReserveResult">--> <!-- <include refid="selectHotelReserveVo"/>--> <!-- <where>--> <!-- <if test="params.beginTime != null and params.beginTime != ''"><!– 开始时间检索 –>--> <!-- and date_format(create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')--> <!-- </if>--> <!-- <if test="params.endTime != null and params.endTime != ''"><!– 结束时间检索 –>--> <!-- and date_format(create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')--> <!-- </if>--> <!-- </where>--> <!-- </select>--> <select id="selectHotelReserveListQuerytime" parameterType="HotelReserve" resultMap="HotelReserveResult"> <include refid="selectHotelReserveVo"/> <where> <if test="orderNumber != null and orderNumber != ''"> and order_number = #{orderNumber}</if> <if test="roomNumber != null and roomNumber != ''"> and room_number = #{roomNumber}</if> <if test="customerName != null and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if> <if test="joinState != null and joinState != ''"> and join_state = #{joinState}</if> <if test="gender != null and gender != ''"> and gender = #{gender}</if> <if test="phoneNumber != null and phoneNumber != ''"> and phone_number = #{phoneNumber}</if> <if test="idCard != null and idCard != ''"> and id_card = #{idCard}</if> <if test="joinTime != null and checkOutTime != null"> and join_time >= #{joinTime} and join_time < #{checkOutTime}</if> </where> </select> <select id="selectHotelReserveQueryByCheckOut" parameterType="HotelReserve" resultMap="HotelReserveResult"> <include refid="selectHotelReserveVo"/> <where> <if test="roomNumber != null and roomNumber != ''"> and room_number = #{roomNumber}</if> <if test="checkOutTime != null "> and check_out_time > #{checkOutTime}</if> </where> </select> <select id="selectHotelReserveQueryByCheckOutNotRoomNumber" parameterType="HotelReserve" resultMap="HotelReserveResult"> <include refid="selectHotelReserveVo"/> <where> <if test="checkOutTime != null "> and check_out_time <= #{checkOutTime}</if> </where> </select> <select id="selectHotelReserveList" parameterType="HotelReserve" resultMap="HotelReserveResult"> <include refid="selectHotelReserveVo"/> <where> <if test="orderNumber != null and orderNumber != ''"> and order_number = #{orderNumber}</if> <if test="roomNumber != null and roomNumber != ''"> and room_number = #{roomNumber}</if> <if test="customerName != null and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if> <if test="joinState != null and joinState != ''"> and join_state = #{joinState}</if> <if test="gender != null and gender != ''"> and gender = #{gender}</if> <if test="phoneNumber != null and phoneNumber != ''"> and phone_number = #{phoneNumber}</if> <if test="idCard != null and idCard != ''"> and id_card = #{idCard}</if> <if test="joinTime != null and checkOutTime == null"> and join_time = #{joinTime}</if> <if test="checkOutTime != null and joinTime ==null"> and check_out_time = #{checkOutTime}</if> <if test="checkOutTime != null and joinTime !=null"> and join_time BETWEEN #{joinTime} AND #{checkOutTime}</if> </where> </select> <select id="selectHotelReserveByReserveId" parameterType="Long" resultMap="HotelReserveResult"> <include refid="selectHotelReserveVo"/> where reserve_id = #{reserveId} </select> <insert id="insertHotelReserve" parameterType="HotelReserve" useGeneratedKeys="true" keyProperty="reserveId"> insert into hotel_reserve <trim prefix="(" suffix=")" suffixOverrides=","> <if test="orderNumber != null">order_number,</if> <if test="roomNumber != null">room_number,</if> <if test="customerName != null">customer_name,</if> <if test="joinState != null">join_state,</if> <if test="gender != null">gender,</if> <if test="phoneNumber != null">phone_number,</if> <if test="idCard != null">id_card,</if> <if test="joinTime != null">join_time,</if> <if test="checkOutTime != null">check_out_time,</if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="orderNumber != null">#{orderNumber},</if> <if test="roomNumber != null">#{roomNumber},</if> <if test="customerName != null">#{customerName},</if> <if test="joinState != null">#{joinState},</if> <if test="gender != null">#{gender},</if> <if test="phoneNumber != null">#{phoneNumber},</if> <if test="idCard != null">#{idCard},</if> <if test="joinTime != null">#{joinTime},</if> <if test="checkOutTime != null">#{checkOutTime},</if> </trim> </insert> <update id="updateHotelReserve" parameterType="HotelReserve"> update hotel_reserve <trim prefix="SET" suffixOverrides=","> <if test="orderNumber != null">order_number = #{orderNumber},</if> <if test="roomNumber != null">room_number = #{roomNumber},</if> <if test="customerName != null">customer_name = #{customerName},</if> <if test="joinState != null">join_state = #{joinState},</if> <if test="gender != null">gender = #{gender},</if> <if test="phoneNumber != null">phone_number = #{phoneNumber},</if> <if test="idCard != null">id_card = #{idCard},</if> <if test="joinTime != null">join_time = #{joinTime},</if> <if test="checkOutTime != null">check_out_time = #{checkOutTime},</if> </trim> where reserve_id = #{reserveId} </update> <delete id="deleteHotelReserveByReserveId" parameterType="Long"> delete from hotel_reserve where reserve_id = #{reserveId} </delete> <delete id="deleteHotelReserveByReserveIds" parameterType="String"> delete from hotel_reserve where reserve_id in <foreach item="reserveId" collection="array" open="(" separator="," close=")"> #{reserveId} </foreach> </delete> </mapper>
re'serve请求接口中新加一个接口
//查询哪些时间被预约了
export function queryAppointmentTime(roomNumber) {
return request({
url: '/data/reserve/listQueryTime?roomNumber=' + roomNumber,
method: 'get'
})
}
视图index.vue
<template> <div class="app-container"> <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> <el-form-item label="订单号" prop="orderNumber"> <el-input v-model="queryParams.orderNumber" placeholder="请输入订单号" clearable @keyup.enter.native="handleQuery" /> </el-form-item> <el-form-item label="房间号" prop="roomNumber"> <el-input v-model="queryParams.roomNumber" placeholder="请输入房间号" clearable @keyup.enter.native="handleQuery" /> </el-form-item> <el-form-item label="客户姓名" prop="customerName"> <el-input v-model="queryParams.customerName" placeholder="请输入客户姓名" clearable @keyup.enter.native="handleQuery" /> </el-form-item> <el-form-item label="入住状态" prop="joinState"> <el-select v-model="queryParams.joinState" placeholder="选择入住状态"> <el-option v-for="dict in dict.type.join_state" :key="dict.value" :label="dict.label" :value="dict.value" /> </el-select> </el-form-item> <el-form-item label="手机号" prop="phoneNumber"> <el-input v-model="queryParams.phoneNumber" placeholder="请输入手机号" clearable @keyup.enter.native="handleQuery" /> </el-form-item> <el-form-item label="入住时间" prop="joinTime"> <el-date-picker clearable v-model="queryParams.joinTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择入住时间"> </el-date-picker> </el-form-item> <el-form-item label="退房时间" prop="checkOutTime"> <el-date-picker clearable v-model="queryParams.checkOutTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择退房时间"> </el-date-picker> </el-form-item> <el-form-item> <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> </el-form-item> </el-form> <el-row :gutter="10" class="mb8"> <el-col :span="1.5"> <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['data:reserve:add']" >新增</el-button> </el-col> <el-col :span="1.5"> <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['data:reserve:edit']" >修改</el-button> </el-col> <el-col :span="1.5"> <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['data:reserve:remove']" >删除</el-button> </el-col> <el-col :span="1.5"> <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['data:reserve:export']" >导出</el-button> </el-col> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> </el-row> <el-table v-loading="loading" :data="reserveList" @selection-change="handleSelectionChange"> <el-table-column type="selection" width="55" align="center" /> <el-table-column label="id" align="center" prop="reserveId" /> <el-table-column label="订单号" align="center" prop="orderNumber" /> <el-table-column label="房间号" align="center" prop="roomNumber" /> <el-table-column label="客户姓名" align="center" prop="customerName" /> <el-table-column label="入住状态" align="center" prop="joinState"> <template slot-scope="scope"> <dict-tag :options="dict.type.join_state" :value="scope.row.joinState"> </dict-tag> </template> </el-table-column> <el-table-column label="性别" align="center" prop="gender"> <template slot-scope="scope"> <dict-tag :options="dict.type.gender" :value="scope.row.gender"> </dict-tag> </template> </el-table-column> <el-table-column label="手机号" align="center" prop="phoneNumber" /> <el-table-column label="身份证" align="center" prop="idCard" /> <el-table-column label="入住时间" align="center" prop="joinTime" width="180"> <template slot-scope="scope"> <span>{{ parseTime(scope.row.joinTime, '{y}-{m}-{d}') }}</span> </template> </el-table-column> <el-table-column label="退房时间" align="center" prop="checkOutTime" width="180"> <template slot-scope="scope"> <span>{{ parseTime(scope.row.checkOutTime, '{y}-{m}-{d}') }}</span> </template> </el-table-column> <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> <template slot-scope="scope"> <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['data:reserve:edit']" >修改</el-button> <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['data:reserve:remove']" >删除</el-button> </template> </el-table-column> </el-table> <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" /> <!-- 添加或修改预定对话框 --> <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> <el-form ref="form" :model="form" :rules="rules" label-width="80px"> <el-form-item label="房间号" prop="roomNumber"> <el-select v-model="form.roomNumber" placeholder="请选择房间号" @change="getNo"> <el-option v-for="item in roomNumberList" :key="item.value" :label="item.label" :value="item.value"> </el-option> </el-select> </el-form-item> <el-form-item label="客户姓名" prop="customerName"> <el-input v-model="form.customerName" placeholder="请输入客户姓名" /> </el-form-item> <el-form-item label="入住状态" prop="joinState"> <el-select v-model="form.joinState" placeholder="选择入住状态"> <el-option v-for="dict in dict.type.join_state" :key="dict.value" :label="dict.label" :value="dict.value" /> </el-select> </el-form-item> <el-form-item label="性别" prop="gender"> <el-select v-model="form.gender" placeholder="选择性别"> <el-option v-for="dict in dict.type.gender" :key="dict.value" :label="dict.label" :value="dict.value" /> </el-select> </el-form-item> <el-form-item label="手机号" prop="phoneNumber"> <el-input v-model="form.phoneNumber" placeholder="请输入手机号" /> </el-form-item> <el-form-item label="身份证" prop="idCard"> <el-input v-model="form.idCard" type="text" placeholder="请输入身份证" /> </el-form-item> <el-form-item label="入住时间" prop="joinTime"> <el-date-picker clearable v-model="form.joinTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择入住时间" :picker-options="pickerOptions" :disabled="isRoomNumber" > </el-date-picker> </el-form-item> <el-form-item label="退房时间" prop="checkOutTime"> <el-date-picker clearable v-model="form.checkOutTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择退房时间" :picker-options="pickerOptions" :disabled="isRoomNumber" > </el-date-picker> </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 { listReserve, getReserve, delReserve, addReserve, updateReserve,queryAppointmentTime } from "@/api/data/reserve"; import { getAllRoomType } from "@/api/data/roomType"; import { getAllRoom} from '@/api/data/room' export default { name: "Reserve", dicts: ['gender','join_state'], data() { return { //房间类型 roomTypeList:[], // 房间号数据 roomNumberList:[], // 房间列表 roomList:[], //已被预约的房间 roomNo:[], // 对日期可选参数 isRoomNumber: true, // 禁用之前 pickerOptions: { disabledDate: (time) => { const today = new Date().toLocaleDateString(); //禁用这一天之前的日期 let disable = time < new Date(today); //循环后端返回的数据,禁用时间大于joinTime小于checkOutTime,注意dayStart要减去一天,才能真正禁用dayStart这一天。 this.roomNo.forEach((item) => { disable = disable || (time.getTime() > new Date(item.joinTime).getTime() - 8.64e7 && time.getTime() < new Date(item.checkOutTime).getTime()); //减去一天8.64e7 }); // return time.getTime() < new Date().getTime() - 24 * 60 * 60 * 1000; return disable }, }, // 遮罩层 loading: true, // 选中数组 ids: [], // 非单个禁用 single: true, // 非多个禁用 multiple: true, // 显示搜索条件 showSearch: true, // 总条数 total: 0, // 预定表格数据 reserveList: [], // 弹出层标题 title: "", // 是否显示弹出层 open: false, // 查询参数 queryParams: { pageNum: 1, pageSize: 10, orderNumber: null, roomNumber: null, customerName: null, joinState: null, gender: null, phoneNumber: null, idCard: null, joinTime: null, checkOutTime: null }, // 表单参数 form: {}, // 表单校验 rules: { roomNumber: [ { required: true, message: '请选择房间号', trigger: 'change' } ], customerName: [ { required: true, message: '请输入客户姓名', trigger: 'blur' } ], joinState: [ { required: true, message: '请选择入住状态', trigger: 'change' } ], gender: [ { required: true, message: '请选择性别', trigger: 'change' } ], phoneNumber: [ { required: true, message: '请输入客户手机号', trigger: 'blur' } ], idCard: [ { required: true, message: '请输入客户身份证', trigger: 'blur' } ], joinTime: [ { required: true, message: '请选择入住时间', trigger: 'blur' } ], checkOutTime: [ { required: true, message: '请选择退房时间', trigger: 'blur' } ], } }; }, created() { this.getList(); }, watch: { form: { handler(newVal) { if( newVal.roomNumber!=null&& newVal.roomNumber!='') { this.isRoomNumber=false } else{ this.isRoomNumber = true } }, deep: true // 深度监听(例如对象中的数据) } }, methods: { // 禁用已被预约的日期 async getNo() { this.form.joinTime = null this.form.checkOutTime = null let response = await queryAppointmentTime(this.form.roomNumber) this.roomNo = response.data }, /** 查询预定列表 */ getList() { this.loading = true; listReserve(this.queryParams).then(response => { this.reserveList = response.rows; this.total = response.total; this.loading = false; }); }, // 取消按钮 cancel() { this.open = false; this.reset(); }, // 表单重置 reset() { this.form = { reserveId: null, orderNumber: null, roomNumber: null, customerName: null, joinState: null, gender: null, phoneNumber: null, idCard: null, joinTime: null, checkOutTime: null }; this.roomList=[] this.roomNumberList=[] this.resetForm("form"); }, /** 搜索按钮操作 */ handleQuery() { this.queryParams.pageNum = 1; this.getList(); }, /** 重置按钮操作 */ resetQuery() { this.resetForm("queryForm"); this.handleQuery(); }, // 多选框选中数据 handleSelectionChange(selection) { this.ids = selection.map(item => item.reserveId) this.single = selection.length!==1 this.multiple = !selection.length }, /** 新增按钮操作 */ async handleAdd() { this.reset(); this.open = true; this.title = "添加预定"; // 获取房间列表数据 await this.getAllRoomData() // 对房间列表数据进行处理 this.roomListSelect() }, /** 修改按钮操作 */ async handleUpdate(row) { this.reset(); // 获取房间列表数据 await this.getAllRoomData() // 对房间列表数据进行处理 this.roomListSelect() const reserveId = row.reserveId || this.ids getReserve(reserveId).then(response => { this.form = response.data; this.open = true; this.title = "修改预定"; }); }, /** 提交按钮 */ submitForm() { this.$refs["form"].validate(valid => { if (valid) { if (this.form.reserveId != null) { updateReserve(this.form).then(response => { this.$modal.msgSuccess("修改成功"); this.open = false; this.getList(); }); } else { addReserve(this.form).then(response => { this.$modal.msgSuccess("新增成功"); this.open = false; this.getList(); }); } } }); }, /** 删除按钮操作 */ handleDelete(row) { const reserveIds = row.reserveId || this.ids; this.$modal.confirm('是否确认删除预定编号为"' + reserveIds + '"的数据项?').then(function() { return delReserve(reserveIds); }).then(() => { this.getList(); this.$modal.msgSuccess("删除成功"); }).catch(() => {}); }, /** 导出按钮操作 */ handleExport() { this.download('data/reserve/export', { ...this.queryParams }, `reserve_${new Date().getTime()}.xlsx`) }, // 房间列表数据 async getAllRoomData(){ let res = await getAllRoom() this.roomList = res.data }, //对房间数组进行处理 async roomListSelect(){ var that = this let response = await getAllRoomType() this.roomTypeList = response.data this.roomList.map( (item)=>{ var newObj={} newObj.value=item.roomNumber var data = that.roomList.find(ele=>{ return ele.roomNumber===item.roomNumber }) var result = that.roomTypeList.find(roomType=>{ return roomType.roomTypeId === data.roomTypeId }) newObj.label=item.roomNumber+'('+result.roomTypeName+')' that.roomNumberList.push(newObj) }) } } }; </script>
年少轻狂,总以为天下事竭力有为。人事尽时,终感力不能及。