<template>
  <div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="140px" class="nghfs">
		    <p class="lqw" style="font-weight: 700;font-size: 15px;"> <img src="../../../assets/images/icon_yq_htgl_btzs.png" alt="" style="width:10px;height: 10px;margin-right: 10px;"> 搜索条件</p>
		     <el-row>
		       <!-- <el-col :span="24"> -->
		         <el-col :span="8">
		          <el-form-item label="会议室名称" prop="conferenceRoomName">
		            <el-input
		              v-model="queryParams.conferenceRoomName"
		              placeholder="请输入会议室名称"
		              clearable
		              @keyup.enter.native="handleQuery"
		            />
		          </el-form-item>
		         </el-col>
		         <el-col :span="8">
		           <el-form-item label="会议室地址" prop="conferenceRoomAddress">
		             <el-input
		               v-model="queryParams.conferenceRoomAddress"
		               placeholder="请输入会议室地址"
		               clearable
		               @keyup.enter.native="handleQuery"
		             />
		           </el-form-item>
		         </el-col>
						 <el-col :span="8">
						   <el-form-item label="会议开始时间" prop="startTime">
						     <el-date-picker clearable
						       v-model="queryParams.startTime"
						       type="datetime"
						       value-format="yyyy-MM-dd HH:mm:ss"
						       placeholder="请选择会议开始时间">
						     </el-date-picker>
						   </el-form-item>
						 </el-col>
						 <el-col :span="8">
						   <el-form-item label="会议结束时间" prop="endTime">
						     <el-date-picker clearable
						       v-model="queryParams.endTime"
						       type="datetime"
						       value-format="yyyy-MM-dd HH:mm:ss"
						       placeholder="请选择会议结束时间">
						     </el-date-picker>
						   </el-form-item>
						 </el-col>
		
		         <el-col :span="4"  style="margin-top: 3px;">
		           <el-button type="primary" style="background-color: #5974E0; border-color: #5974E0;" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
		          <el-button style="background-color: #fff; border-color: #3464EB; color: #3464EB;" icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
		         </el-col>
		     </el-row>
		    </el-form>


    <div class="ntgs" >
    <div style="display: flex;align-items: center; margin-bottom: 10px;">
      <p class="lqw" style="font-weight: 700;font-size: 15px; margin: 0; margin-bottom: 0;"> <img src="../../../assets/images/icon_yq_htgl_btzs.png" alt="" style="width:10px;height: 10px;margin-right: 10px;"> 会议室预约</p>
      <el-row :gutter="10" class="mb8"  style=" margin-bottom: 0;">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:order: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="['system:order: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="['system:order: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="['system:order:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
	</div>

    <el-table stripe v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="预约人员名称" align="center" prop="orderUser" width="160"/>
      <el-table-column label="会议室名称" align="center" prop="conferenceRoomName" />
      <el-table-column label="会议室地址" align="center" prop="conferenceRoomAddress" />
      <el-table-column label="会议名称" align="center" prop="conferenceName" />
      <el-table-column label="会议人数" align="center" prop="conferenceNumber" />
      <el-table-column label="会议开始时间" align="center" prop="startTime" width="180">
        <template slot-scope="scope">
          <span>{{ scope.row.startTime}}</span>
        </template>
      </el-table-column>
      <el-table-column label="会议结束时间" align="center" prop="endTime" width="180">
        <template slot-scope="scope">
          <span>{{scope.row.endTime }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="创建部门" align="center" prop="createDept" /> -->
      <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
       <template slot-scope="scope">
         <el-button
           size="mini"
           type="text"
           @click="handleUpdate(scope.row)"
       	style="color:#28C529"
           v-hasPermi="['system:order:edit']"
         >修改</el-button>
         <el-button
           size="mini"
           type="text"
       	  style="color:#F7052B"
           @click="handleDelete(scope.row)"
           v-hasPermi="['system:order: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"
    />
	</div>

    <!-- 添加或修改会议室预约对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
		  <el-row>
			  <!-- <el-col :span="12">
			  	 <el-form-item label="会议室名称" prop="conferenceRoomName">
			  	 <el-select style="width:100%"  v-model="form.conferenceRoomName" placeholder="请选择会议室名称" clearable>
			  	   <el-option
			  	   @click.native="ishsue(dict)"
			  	     v-for="dict in orderListg"
			  	     :key="dict.conferenceRoomId"
			  	     :label="dict.conferenceRoomName"
			  	     :value="dict.conferenceRoomName"
			  	   />
			  	 </el-select>
			  	 </el-form-item> 
			  </el-col> -->
			  
			  <el-col :span="24" style="margin-bottom: 20px;" class="ingq" v-if="isnshe">
				<el-form-item label="会议室名称" prop="conferenceRoomName">
				  <div style="display: flex; flex-wrap: wrap;" >
					  <div style="width: 33%;display: flex; align-items: center;cursor:pointer; " v-for="(item,index) in orderListg" :key="index" @click="iskbw(item)">
						  <img src="../../../assets/images/icon_mjqx_xz_normal.png" alt="" style="width: 14px;height: 14px;" v-if="issid != item.conferenceRoomId">
						  <img src="../../../assets/images/icon_mjqx_xz_selected.png" alt="" style="width: 14px;height: 14px;" v-if="issid == item.conferenceRoomId">
						  <el-tooltip class="item" effect="dark" :content="item.conferenceRoomName" placement="top">
						  <p style="margin: 0; margin-left: 10px; overflow: hidden;text-overflow:ellipsis;display: -webkit-box;
                          -webkit-line-clamp: 1;-webkit-box-orient: vertical;font-weight: 500;font-size: 14px;color: #161616;">
							  {{item.conferenceRoomName}}
						  </p>
						  </el-tooltip>
					  </div>
					  
				  </div>
				  <div style="background: #F0F8FE;border-radius: 10px; padding: 10px; margin-top: 20px;">
					  <p style="font-weight: bold;font-size: 14px;color: #161616;"> <img src="../../../assets/images/icon_htgl_hyyy_3y.png" alt="" style="width: 16px;height: 16px; margin-right: 10px;">已预约时间段,以下时间段不可预约。</p>
					  <div style="display: flex; flex-wrap: wrap;" v-if="lisget != null && lisget.length != 0 " >
						  <div style="width: 50%; display: flex;align-items: center;"  v-for="(item,index) in lisget" :key="index">
						  						  <p style="width: 6px;height: 6px;background: #FFB132;border-radius: 3px;margin-right: 10px;"></p>
						  						  <p style="font-weight: bold;font-size: 14px;color: #161616;">{{item.startTime}}  </p>
						  						  <span style="font-weight: bold;font-size: 14px;color: #666666; margin: 0 5px;">至 </span>
						  						  <p style="font-weight: bold;font-size: 14px;color: #161616;">{{item.endTime}}</p>
						  </div>
					  </div>
					  <div v-if="lisget == null || lisget.length == 0">
						  暂无数据,可以预约任意时间段。
					  </div>
				  </div>
				</el-form-item>   
			  </el-col>
		  			  <!-- <el-col :span="24">
		  				 <el-form-item label="会议室名称" prop="conferenceRoomName">
		  				 <el-select style="width:100%"  v-model="form.conferenceRoomName" placeholder="请选择会议室名称" clearable>
		  				   <el-option
						   @click.native="ishsue(dict)"
		  				     v-for="dict in orderListg"
		  				     :key="dict.conferenceRoomId"
		  				     :label="dict.conferenceRoomName"
		  				     :value="dict.conferenceRoomName"
		  				   />
		  				 </el-select>
						 </el-form-item> 
		  			  </el-col> -->
		  			  <!-- <el-col :span="12">
		  			  	<el-form-item label="会议室地址" prop="conferenceRoomAddress">
		  			  	  <el-input v-model="form.conferenceRoomAddress" placeholder="请输入会议室地址" />
		  			  	</el-form-item>			  
		  			  </el-col> -->
					  <el-col :span="12">
					  	<el-form-item label="会议名称" prop="conferenceName">
					  	  <el-input v-model="form.conferenceName"  placeholder="请输入内容" />
					  	</el-form-item>			  
					  </el-col>
					  <el-col :span="12">
					  	<el-form-item label="会议人数" prop="conferenceNumber">
					  	  <el-input v-model="form.conferenceNumber" placeholder="请输入会议人数" />
					  	</el-form-item>			  
					  </el-col>
					  <el-col :span="12">
					  	<el-form-item label="会议开始时间" prop="startTime">
					  	  <el-date-picker clearable
						  @change="nghwest"
					  	    v-model="form.startTime"
					  	    type="datetime"
							style="width:100%;"
					  	    value-format="yyyy-MM-dd HH:mm:ss"
					  	    placeholder="请选择会议开始时间">
					  	  </el-date-picker>
					  	</el-form-item>			  
					  </el-col>
					  <el-col :span="12">
					  	<el-form-item label="会议结束时间" prop="endTime">
					  	  <el-date-picker clearable
						  @change="nghwe"
					  	    v-model="form.endTime"
					  	    type="datetime"
					  	    value-format="yyyy-MM-dd HH:mm:ss"
							style="width:100%;"
					  	    placeholder="请选择会议结束时间">
					  	  </el-date-picker>
					  	</el-form-item>			  
					  </el-col>
					  <el-col :span="12">
					  	<el-form-item label="是否需要席卡" prop="useXk">
					  					<el-select style="width: 100%;" v-model="form.useXk" placeholder="是否需要席卡">
					  					  <el-option
					  					    v-for="dict in dict.type.sys_yes_no"
					  					    :key="dict.value"
					  					    :label="dict.label"
					  					    :value="dict.value"
					  					  />
					  					</el-select>
					  	</el-form-item>			  
					  </el-col>
		  			  <el-col :span="12">
		  			  	<el-form-item label="会议说明" prop="remark">
		  			  	  <el-input v-model="form.remark" placeholder="请输入会议说明" />
		  			  	</el-form-item>			  
		  			  </el-col>
					  <el-col :span="24">
					  	<el-form-item label="席卡详情" prop="xkDetail">
					  	  <el-input v-model="form.xkDetail" placeholder="请输入席卡详情" />
					  	</el-form-item>			  
					  </el-col>
					  
		  </el-row>
      </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 { listOrder, listOrderf, getOrder, delOrder, addOrder, updateOrder } from "@/api/system/order";

export default {
  name: "Order",
  dicts: ['sys_yes_no', 'sys_user_sex','usertype'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 会议室预约表格数据
      orderList: [],
	  orderListg:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 7,
        orderUser: null,
        orderUserId: null,
        conferenceRoomId: null,
        conferenceRoomName: null,
        conferenceRoomAddress: null,
        conferenceName: null,
        conferenceNumber: null,
        startTime: null,
        endTime: null,
        createDept: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
		conferenceName: [
		  { required: true, message: "不能为空", trigger: "blur" }
		],
		conferenceNumber: [
		  { required: true, message: "不能为空", trigger: "blur" }
		],
		startTime: [
		  { required: true, message: "不能为空", trigger: "blur" }
		],
		endTime: [
		  { required: true, message: "不能为空", trigger: "blur" }
		],
      },
	  issid:0,
	  lisget:[],
	  conferenceRoomName:null,
	  conferenceRoomAddress:null,
	  isnshe:false
    };
  },
  created() {
    this.getList();
	// console.log(this.$store.state.user.name)
	this.getlisno()
  },
  methods: {
	  xuanze(val){
		  
	  },
    /** 查询会议室预约列表 */
    getList() {
      this.loading = true;
	  this.queryParams.orderUserId = this.$store.state.user.id
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
	getlisno(){
	this.loading = true;
	this.isnshe = false
	listOrderf().then(response => {
	  this.orderListg = response.rows;
	  
	  if(this.orderListg.length != 0 && this.orderListg != null ){
		this.issid = this.orderListg[0].conferenceRoomId  
		if(this.orderListg[0].conferenceRoomOrderList == null){
			this.orderListg[0].conferenceRoomOrderList = []	  
			this.lisget = []
		}else{
			this.lisget = this.orderListg[0].conferenceRoomOrderList 
		}
		this.conferenceRoomName = this.orderListg[0].conferenceRoomName
		this.conferenceRoomAddress = this.orderListg[0].conferenceRoomAddress
	  }
	   this.isnshe = true
	  this.total = response.total;
	  this.loading = false;
	});
	},
	nghwest(val){
	  	 
	},
	nghwe(val){
		if(this.form.startTime == null || this.form.startTime == ''){
			this.$message.error("请选择开始时间");
			this.form.endTime = null
			return
		}else{
       const time3 = Date.parse(val)
	   const time4 = Date.parse(this.form.startTime)
	   if(time3 < time4){
		   this.$message.error("请选择大于开始时间");
		   this.form.endTime = null
		   return
	   }
	   console.log(3,time3,time4)
		}
		
	},
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        conferenceRoomOrderId: null,
        orderUser: null,
        orderUserId: null,
        conferenceRoomId: null,
        conferenceRoomName: null,
        conferenceRoomAddress: null,
        conferenceName: null,
        conferenceNumber: null,
        startTime: null,
        endTime: null,
        createDept: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
		useXk:'Y',
		xkDetail:null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
	iskbw(val){
		this.issid = val.conferenceRoomId
		if(val.conferenceRoomOrderList == null){
			val.conferenceRoomOrderList = []	  
		}
		this.lisget = val.conferenceRoomOrderList
		this.conferenceRoomName = val.conferenceRoomName
		this.conferenceRoomAddress = val.conferenceRoomAddress
	},
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.conferenceRoomOrderId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加会议室预约";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const conferenceRoomOrderId = row.conferenceRoomOrderId || this.ids
      getOrder(conferenceRoomOrderId).then(response => {
        this.form = response.data;
		this.issid = this.form.conferenceRoomId
		 this.conferenceRoomName = this.form.conferenceRoomName
		this.conferenceRoomAddress = this.form.conferenceRoomAddress
		if(this.orderListg.length != 0){
		  this.orderListg.filter( rou=>{
			 if(this.issid == this.form.conferenceRoomId){
				 if(rou.conferenceRoomOrderList == null){
				 	rou.conferenceRoomOrderList = []	  
				 }
				this.lisget = rou.conferenceRoomOrderList  
			 }		 
		   })	
		}
        this.open = true;
        this.title = "修改会议室预约";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
			this.form.orderUserId = this.$store.state.user.id
			this.form.orderUser = this.$store.state.user.name
			this.form.conferenceRoomId = this.issid
			this.form.conferenceRoomName = this.conferenceRoomName
			this.form.conferenceRoomAddress = this.conferenceRoomAddress
          if (this.form.conferenceRoomOrderId != null) {
            updateOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const conferenceRoomOrderIds = row.conferenceRoomOrderId || this.ids;
      this.$modal.confirm('是否确认删除会议室预约编号为"' + conferenceRoomOrderIds + '"的数据项？').then(function() {
        return delOrder(conferenceRoomOrderIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/order/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    },
	ishsue(row){
	 this.form.conferenceRoomAddress = row.conferenceRoomAddress
	 this.form.conferenceRoomId = row.conferenceRoomId
	}
  }
};
</script>
<style lang="scss">
	.nhgrls{
		.el-dialog__body{
			padding: 0;
		}
	}
  .hyr{
    span{
      text-decoration:underline;
    }
  }
</style>
<style scoped lang="scss">
	.ingq{
		p{
			margin: 0;
		}
	}
	
  .iuer{
    display: flex;
    justify-content: space-between;
    align-items: center;
    .ite{
      display: flex;
      justify-content: space-between;
      align-items: center;
      p{
        margin: 0;
        font-size: 15px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #AAAAAA;
        padding: 4px 12px;
        background: #F7F8FA;
        border-radius: 4px;
        margin-right: 20px;
      }
      .actt{
        background: #E6EBFF;
        border: 1px solid #5974E0;
        border-radius: 4px;
        color: #5974E0;
      }

    }
  }
  .lqw{
    padding: 0 10px;
    margin: 0;
    margin-bottom: 20px;
  }
.nhgel{
  height: 170px;
  background-color: #313b61;
  width: 100%;
  position: absolute;
  top:0;
  left:0;
  z-index: 0;
}
	.app-container{
		background-color: #f3f4f6;
		padding-top: 10px;
	   
	}
	.ntgs{
	position: relative;
		background-color: #fff;
		padding: 5px;
		// border-radius: 5px;
		padding-top: 10px;
	     padding: 10px 20px;
		 padding-left: 10px;
		.pagination-container{
			height: 50px;
		}
	}
	.nghfs{
	position: relative;
		background-color: #fff;
		padding-top: 18px !important;
		padding: 5px;
		// border-radius: 5px;
		// margin-bottom: 20px;
	}
	.ksf{
		img{
			width:100%;
			height: 100%;
		}
	}

</style>
