<template>
  <div class="content-main">
    <el-form
      ref="searchForm"
      :inline="true"
      :model="searchForm"
      class="demo-form-inline search-form"
      label-position="left"
    >
      <el-row>
        <el-form-item label="编号:" prop="bh">
          <el-input
            v-model="searchForm.bh"
            clearable
            placeholder="请输入编号"
          ></el-input>
        </el-form-item>
        <el-form-item label="会议室名称:" prop="hysmc">
          <el-select
            v-model="searchForm.hysmc"
            style="width: 170px"
            clearable
            placeholder="请选择会议室名称"
            >
            <el-option
              v-for="item in hysmcOptions"
              :key="item.name"
              :label="item.name"
              :value="item.name"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="使用单位:" prop="sydw">
          <el-select
            v-model="searchForm.sydw"
            style="width: 170px"
            clearable
            placeholder="请选择使用单位"
			@change="ChangeSydw"
            >
            <el-option
              v-for="item in sydwOptions"
              :key="item.unitName"
              :label="item.unitName"
              :value="item.unitName"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <div class="search-button">
            <span class="search-line"></span>
            <div
              class="search-select"
              @click="searchShowMoreBool = !searchShowMoreBool"
            >
              更多条件
              <i class="el-icon-arrow-up" v-show="searchShowMoreBool"></i>
              <i class="el-icon-arrow-down" v-show="!searchShowMoreBool"></i>
            </div>
            <el-button
              type="primary"
              size="small"
              class="iconfont iconchaxun"
              @click="searchInfo"
              >查询</el-button
            >
            <el-button
              type="primary"
              @click="resetInfo('searchForm')"
              size="small"
              class="iconfont iconzhongzhi"
            >
              重置</el-button
            >
          </div>
        </el-form-item>
      </el-row>
      <el-row v-show="searchShowMoreBool">
        <el-form-item label="使用部门:" prop="sybm">
          <el-select
            v-model="searchForm.sybm"
            style="width: 170px"
            clearable
            placeholder="请选择使用部门"
          >
            <el-option
              v-for="item in sybmOptions"
              :key="item.departName"
              :label="item.departName"
              :value="item.departName"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="使用时间:" prop="sysj">
          <el-date-picker
            v-model="searchForm.sysj"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            format="yyyy-MM-dd HH:ss"
            value-format="yyyy-MM-dd HH:ss"
          >
          </el-date-picker>
        </el-form-item>
      </el-row>
    </el-form>
    <el-row class="addBtnBg">
		<el-button
		  type="primary"
		  class="iconfont iconxinzeng"
		  size="mini"
		  @click="handleClick('','add')"
		  >新增</el-button
		>
      <el-button
        type="primary"
        class="iconfont icondaochu11"
        size="mini"
        @click="handleExport"
        >导出</el-button
      >
    
    </el-row>
    <el-row>
      <el-table
        :data="tableData"
        stripe
        border
        fit
        highlight-current-row
        style="width: 100%"
      >
        <el-table-column align="center" label="序号" width="60">
          <template slot-scope="scope">
            <span>{{ scope.$index + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column
		  width="120"
          align="center"
          prop="bh"
          show-overflow-tooltip
          label="编号"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="hysmc"
          label="会议室名称"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          align="center"
          prop="sydw"
          label="使用单位"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          align="center"
          prop="sybm"
          label="使用部门"
          show-overflow-tooltip
        >
        </el-table-column>
		<el-table-column
		  align="center"
		  prop="hyzt"
		  label="会议主题"
		  show-overflow-tooltip
		>
		</el-table-column>
		<el-table-column
		  width="240px"
		  align="center"
		  prop="sysj"
		  label="使用时间"
		  show-overflow-tooltip
		>
		<template slot-scope="scope">
			{{scope.row.sysjks+' - '+scope.row.sysjjs}}
		</template>
		</el-table-column>
        <el-table-column
          align="center"
          prop="spzt"
          label="状态"
          show-overflow-tooltip
        >
		<template slot-scope="scope">
		  <span>{{ getHysglStatusName(scope.row.spzt,satusList) }}</span>
		</template>
		</el-table-column>
        <el-table-column align="center" label="操作" width="120">
          <template slot-scope="scope">
            <el-tooltip effect="light" content="查看" placement="top">
              <el-button
                @click="handleClick(scope.row, 'ck')"
                type="primary"
                size="small"
                class="operate_show_btn iconfont iconchakan2"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              effect="light"
              content="审核"
              placement="top"
              v-if="buttonNameList.indexOf('审核') > -1"
            >
              <el-button
                @click="handleClick(scope.row, 'sh')"
                type="primary"
                class="operate_edit_btn iconfont iconshenhe"
                v-show="scope.row.spzt == '9200000'"
                size="small"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              effect="light"
              content="编辑"
              placement="top"
              v-if="buttonNameList.indexOf('编辑') > -1"
            >
              <!--  -->
              <el-button
                @click="handleClick(scope.row, 'bj')"
                type="primary"
                class="operate_edit_btn iconfont iconxiugai1"
                v-show="scope.row.spzt == '9300000' || scope.row.spzt == '9000000'"
                size="small"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              effect="light"
              content="确认"
              placement="top"
              v-if="buttonNameList.indexOf('确认') > -1"
            >
              <!--  -->
              <el-button
                @click="handleClick(scope.row, 'ywqr')"
                type="primary"
                class="operate_edit_btn iconfont iconqueren"
                v-show="
                  scope.row.spzt == '9100000' || scope.row.spzt == '9400000'
                "
                size="small"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              effect="light"
              content="删除"
              placement="top"
              v-if="buttonNameList.indexOf('删除') > -1"
            >
              <el-button
                @click="deleteRow(scope.row)"
                type="primary"
                v-show="scope.row.spzt == '9000000' || scope.row.spzt == '9300000'"
                size="small"
                class="operate_delete_btn iconfont iconshanchu"
              ></el-button>
            </el-tooltip>
			<!-- <el-tooltip
			  class="item"
			  effect="light"
			  content="导出"
			  placement="top"
			>
			  <el-button
			    @click="handleClick(scope.row, 'dc')"
			    type="primary"
			    size="small"
			    class="operate_edit_btn iconfont icondaochu11"
			  ></el-button>
			 </el-tooltip> -->
          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <el-row>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="pageForm.pageNum"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageForm.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageForm.total"
      ></el-pagination>
    </el-row>
  </div>
</template>

<script>
import { authorityControl } from "@/api/login/login";
import {
  selectMeetingRoomManagePage,
  selectUnitList,
  exportMeetingRoomManage,
  deleteMeetingRoomApply
} from "@/api/operationServices/meetingRoomManage/index.js";
import {
	hySpztStatus,
  getHysglStatusName
} from "@/utils/statusList";
export default {
  data() {
    return {
	  getHysglStatusName:getHysglStatusName,
	  satusList:hySpztStatus,
      searchShowMoreBool: false,
      buttonNameList: [],
      searchForm: {
        bh:'',
		hysmc:'',
		sydw:'',
		sybm:'',
        spztList: "",
        sysj: [],
      },
	  hysmcOptions:[
		  {
			 name:'三楼应急指挥大厅',
			 value:'1',
		  },
		  {
			 name:'五楼视频会议室',
			 value:'2',
		  }
	  ],
      sydwOptions:[],
	  sybmOptions:[],
      pageForm: {
        pageNum: 1,
        pageSize: 10,
        total: 0,
      },
      tableData: [],
    };
  },
  created() {
	  console.log(hySpztStatus,'hfffffffff------')
    this.getButtonList(
      sessionStorage.getItem("resourceCode"),
      sessionStorage.getItem("userCode")
    );
	this.GetSydwList()
  },
  methods: {
	  //获取使用单位list
	  GetSydwList(){
		  selectUnitList().then(res =>{
			  console.log(res,'')
			  this.sydwOptions=res.data
			  console.log(this.sydwOptions,'fer66666666')
		  })
	  },
	  //选择使用单位
	  ChangeSydw(e){
		  console.log(e,'kkhhgd-----')
		  this.sydwOptions.forEach((item) =>{
			  if(e == item.unitName){
				  this.sybmOptions=item.departList
			  }
		  })
	  },
	//导出
	handleExport() {
		let arrList=[]
		if(this.buttonNameList.indexOf("新增") > -1){
		  // if(this.buttonNameList.indexOf("审核") > -1){
			 //  // this.pageType=2
		  // }else{
			 //  this.pageType=undefined
		  // }
		  this.satusList.forEach((item,index)=>{
				arrList.push(item.dictCode)
			})
		  this.searchForm.spztList=arrList
		}else if (this.buttonNameList.indexOf("确认") > -1) {
		  this.satusList.forEach((item,index)=>{
			if(index > 0){
				arrList.push(item.dictCode)
			   }
			})
		  this.searchForm.spztList=arrList
		}else if (this.buttonNameList.indexOf("审核") > -1) {
		    this.pageType=2
		//   this.searchForm.spztList=arrList
		}
	  let data = {
	    bh: this.searchForm.bh,
	    hysmc: this.searchForm.hysmc,
	    sydw: this.searchForm.sydw,
	    sybm: this.searchForm.sybm,
	    spztList: this.searchForm.spztList,
	    pageSize: this.pageForm.pageSize,
	    pageNum: this.pageForm.pageNum,
	    pageType:this.pageType,
	    sysjks:
	      this.searchForm.sysj.length > 0
	        ? this.searchForm.sysj[0]
	        : "",
	    sysjjs:
	      this.searchForm.sysj.length > 0
	        ? this.searchForm.sysj[1]
	        : "",
	  };
	  exportMeetingRoomManage(data)
	    .then((response) => {
	      let exportName = "会议室管理";
	      let blob = new Blob([response], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8" });
	      if (!!window.ActiveXObject || "ActiveXObject" in window) {
	        window.navigator.msSaveOrOpenBlob(blob, exportName);
	      } else {
	        const link = document.createElement("a");
	        link.style.display = "none";
	        link.href = URL.createObjectURL(blob);
	        link.setAttribute("download", exportName);
	        document.body.appendChild(link);
	        link.click();
	        document.body.removeChild(link);
	      }
	    })
	    .catch();
	},
    searchShowMore() {
      this.searchShowMoreBool = !this.searchShowMoreBool;
    },
    //获取按钮权限
    getButtonList(menuCode, userCode) {
      let codeData = {
        resourceCode: menuCode,
        userId: userCode,
      };
      authorityControl(codeData).then((res) => {
		  let arrList=[]
        let buttonNameList = [];
        res.data.forEach((item) => {
          this.buttonNameList.push(item.resourceName);
        });

        // 1:区粮办 2:市储备粮处 3:市储备公司 4:运维部门5.信息重信，7其他业务处室
        this.$nextTick((info) =>{
			this.getList("start");
		})
		
      });
    },
    getList(type) {
      if (type != "start") {
        //非初始化调用：查询、分页
        sessionStorage.setItem("searchData", JSON.stringify(this.searchForm));
        sessionStorage.setItem("pageData", JSON.stringify(this.pageForm));
      } else {
        //初始化分两种情况，详情页等返回后的初始化，以及第一次进入此菜单的初始化
        if (JSON.parse(sessionStorage.getItem("searchData"))) {
          //详情页返回后，将对应查询条件和分页的字段赋值，页面回显参数
          this.searchForm = JSON.parse(sessionStorage.getItem("searchData"));
          this.pageForm = JSON.parse(sessionStorage.getItem("pageData"));
        } else {
          //第一次进去此菜单时，保存上方默认的data
          sessionStorage.setItem("searchData", JSON.stringify(this.searchForm));
          sessionStorage.setItem("pageData", JSON.stringify(this.pageForm));
        }
      }
	  let arrList=[]
	  if(this.buttonNameList.indexOf("新增") > -1){
		  // if(this.buttonNameList.indexOf("审核") > -1){
			 //  // this.pageType=2
		  // }else{
			 //  this.pageType=undefined
		  // }
		  this.satusList.forEach((item,index)=>{
				arrList.push(item.dictCode)
			})
		  this.searchForm.spztList=arrList
	  }else if (this.buttonNameList.indexOf("确认") > -1) {
	    this.satusList.forEach((item,index)=>{
			if(index > 0){
				arrList.push(item.dictCode)
			   }
			})
	    this.searchForm.spztList=arrList
	  }else if (this.buttonNameList.indexOf("审核") > -1) {
		  this.pageType=2
	  //   this.searchForm.spztList=arrList
	  }
      let data = {
        bh: this.searchForm.bh,
        hysmc: this.searchForm.hysmc,
        sydw: this.searchForm.sydw,
        sybm: this.searchForm.sybm,
        spztList: this.searchForm.spztList,
        pageSize: this.pageForm.pageSize,
        pageNum: this.pageForm.pageNum,
		pageType:this.pageType,
        sysjks:
          this.searchForm.sysj.length > 0
            ? this.searchForm.sysj[0]
            : "",
        sysjjs:
          this.searchForm.sysj.length > 0
            ? this.searchForm.sysj[1]
            : "",
      };
      selectMeetingRoomManagePage(data).then((res) => {
        if (res.infoCode == 200) {
          this.pageForm.total = res.data.total;
          this.tableData = res.data.items;
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    //查询
    searchInfo() {
      this.pageForm.pageNum = 1;
      this.getList();
    },

    //重置
    resetInfo(searchForm) {
      this.$refs[searchForm].resetFields();
	  // this.searchForm.spztList=[]
      this.pageForm.pageNum = 1;
      this.getList();
    },
    //查看
    handleClick(row, type) {
      this.$router.push({
        name: "meetingRoomManageDetail",
        query: {
          spzt:row ? row.spzt : undefined,
          id: row ? row.bh :undefined,
          type: type,
		  ywdwqryj:row ? row.ywdwqryj ? row.ywdwqryj : undefined :undefined,
		  shdwshyj:row ? row.shdwshyj ? row.shdwshyj : undefined :undefined,
        },
      });
    },
    // //新增会议
    // addclick() {
    //   this.$router.push({
    //     name: "meetingRoomManageDetail",
    //     query: {
    //       shzt: "add",
    //     },
    //   });
    // },
    handleSizeChange(val) {
      this.pageForm.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.pageForm.pageNum = val;
      this.getList();
    },
    deleteRow(row) {
      let data = {
        id: row.bh,
      };
	  // this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
	  //           confirmButtonText: '确定',
	  //           cancelButtonText: '取消',
	  //           type: 'warning'
	  //         }).then(() => {
	  //           this.$message({
	  //             type: 'success',
	  //             message: '删除成功!'
	  //           });
	  //         }).catch(() => {
	  //           this.$message({
	  //             type: 'info',
	  //             message: '已取消删除'
	  //           });          
	  //         });
      this.$confirm("是否确认删除？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        deleteMeetingRoomApply(data)
          .then((response) => {
            if (response.infoCode == 200) {
              this.getList();
              this.$message({
                showClose: true,
                message: "删除成功！",
                type: "success",
              });
            }
          })
          .catch(function (error) {
            console.log(error);
          });
      });
    },
  },
  beforeCreate() {},
  mounted() {},
};
</script>

<style lang="scss" scoped>
.line {
  border-bottom: 1px solid #000;
}
.iconfont {
  color: white;
}
.title {
  margin-bottom: 20px;
  text-align: center;
  font-size: 16px;
}

.text {
  text-align: center;
}

.iconfont {
  font-size: 13px;
}
.addTable {
  text-align: right;
  margin-right: 50px;
}

.addTable span {
  font-size: 20px;
  font-weight: bold;
  color: #4588db;
  cursor: pointer;
}
</style>
<style>
</style>
