<!-- 盘点记录 -->
<template>
  <div class="app-container takeStockRecord">
    <div class="page-container takeStockRecordPage" v-if="pageType === 1">
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm"
                 :inline="true" style="width:100%;">
          <el-form-item label="" prop="queryParamsData2">
            <el-select v-model="queryParams.queryParamsData2"
                       placeholder="请选择学院"
                       style="width: 180px">
              <el-option
                v-for="item in deptOptions"
                :key="item.deptId"
                :label="item.deptName"
                :value="item.deptId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="queryParamsData3">
            <el-cascader
              style="width: 180px"
              placeholder="请选择楼栋楼层"
              :props="{value: 'id', label: 'name',children:'buildFloorVoList'}"
              v-model="queryParams.queryParamsData3"
              :options="buildFloorOptions">
            </el-cascader>
          </el-form-item>
          <el-form-item label="" prop="state">
            <el-date-picker
              :clearable="false"
              v-model="dateRange"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="" prop="queryParamsData1">
            <el-input
              maxLength="30"
              v-model="queryParams.queryParamsData1"
              placeholder="标题/实验室/房间号/姓名/联系方式"
              style="width: 260px"
            />
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
          <div style="display: flex;float: right;cursor: pointer;margin-right:10px;">
            <p class="el-icon-refresh-left" style="transform: scaleX(-1);color:#0183FA;font-size:20px;font-weight:700;line-height:40px;"></p>
            <p style="line-height:40px;margin-left:10px;font-size:14px;">刷新</p>
          </div>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="dataList"
                  @sort-change="sortChange">
          <el-table-column label="序号" prop="name" width="50" show-overflow-tooltip/>
          <el-table-column label="标题" prop="name"  show-overflow-tooltip/>
          <el-table-column label="学院" prop="content" width="230" show-overflow-tooltip/>
          <el-table-column label="楼栋楼层" prop="content" width="200" show-overflow-tooltip/>
          <el-table-column label="实验室" prop="content" width="200" show-overflow-tooltip/>
          <el-table-column label="安全员" prop="content" width="200" show-overflow-tooltip/>
          <el-table-column label="盘点人" prop="state" width="100" show-overflow-tooltip/>
          <el-table-column label="盘点时间" prop="createTime" sortable="custom" width="200" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime,"{y}-{m}-{d} {h}:{i}") }}</span>
            </template>
          </el-table-column>
        </el-table>
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-show="total>0"
                    :total="total"
                    :page.sync="queryParams.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
    <!--<add-page :propsData="propsData" v-if="pageType === 2"></add-page>-->
  </div>
</template>
<script>
  //import { getDicts } from "@/api/commonality/noPermission";
  //import { systemUserSelect } from "@/api/commonality/permission";
  //import { getInfo } from "@/api/basicsModules/index";
  //import addPage from "./addPage.vue";
  import { getDeptDropList,systemBuildingGetTreeList,} from "@/api/commonality/permission";
  export default {
    name: 'index',
    //components: {
    //  addPage
    //},
    data () {
      return {
        tableButtonType:this.hasPermiDom(['demo:demo:detail','demo:demo:edit','demo:demo:del',]),
        //页面状态
        pageType:1,
        //页面遮罩
        loading:false,
        //学院
        deptOptions:[],
        //楼栋楼层
        buildFloorOptions:[],
        //下拉列表数据
        optionList:[{value:true,label:'启用'},{value:false,label:'停用'}],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          queryParamsData1:"",
          queryParamsData2 :null,
        },
        //时间数据
        dateRange:[],
        //列表数据
        dataList:[{name:'1'},{name:'2'},],
        //数据数量
        total:0,
        //组件传参
        propsData:{},
      }
    },
    created () {

    },
    mounted () {
      this.getDeptDropList();
      this.systemBuildingGetTreeList();
      //this.getList();
    },
    methods: {
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'dateRange',[])
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          queryParamsData1:"",
          queryParamsData2 :null,
        });
        this.getList();
      },
      //时间排序方法
      sortChange(val){
        if(val.prop == 'checkTime'){
          this.$set(this.queryParams,'checkTimeOrder',val.order=='ascending'?'1':(val.order=='descending'?'2':''));
          this.handleQuery();
        }
      },
      //获取数据列表
      getList(){
        // this.$set(this,'loading',true);
        // let obj = JSON.parse(JSON.stringify(this.queryParams))
        // if(this.dateRange[0]){
        //   obj.startTime = this.dateRange[0]+'T00:00:00'
        //   obj.endTime = this.dateRange[1]+'T23:59:59'
        // }else{
        //   obj.startTime = "";
        //   obj.endTime = "";
        // }
        // getListFunction(obj).then(response => {
        //   this.$set(this,'loading',false);
        //   this.$set(this,'dataList',response.data.records);
        //   this.$set(this,'total',response.data.total);
        // });
      },
      //操作按钮
      tableButton(type,row){
        let self = this;
        if(type == 1){
          //新增
          this.$set(this,'pageType',2);
          this.$set(this,'propsData',{});
        }
      },
      //查询学院列表
      getDeptDropList(){
        getDeptDropList({deptName:"",level:2,deptType:1}).then(response => {
          this.$set(this, 'deptOptions', response.data)
        });
      },
      //查询楼栋楼层
      systemBuildingGetTreeList(){
        systemBuildingGetTreeList({}).then(response => {
          if (response.data[0]) {
            let list = this.forBuildFloor(response.data);
            let newList = [];
            for(let i=0;i<list.length;i++){
              if(list[i].buildFloorVoList){
                for(let o=0;o<list[i].buildFloorVoList.length;o++){
                  if(list[i].buildFloorVoList[o].buildFloorVoList){
                    newList.push(list[i].buildFloorVoList[o])
                  }
                }
              }
            }
            this.$set(this, 'buildFloorOptions', newList)
          }
        })
      },
      //处理楼栋楼层数据
      forBuildFloor(list){
        let self = this;
        for(let i=0;i<list.length;i++){
          if(list[i].buildFloorVoList){
            if(list[i].buildFloorVoList[0]){
              list[i].buildFloorVoList = self.forBuildFloor(list[i].buildFloorVoList);
            }else{
              delete list[i].buildFloorVoList;
            }
          }else{
            delete list[i].buildFloorVoList;
          }
        }
        return list
      },
    },
  }
</script>
<style scoped lang="scss">
  .takeStockRecord{
    .takeStockRecordPage{

    }
  }
</style>
