<template>
  <view class="content">
		<view class="title">请选择楼栋</view>
    <view class="search-keyword">
      <scroll-view class="keyword-list-box" scroll-y>
        <!-- <checkbox-group @change="checkboxChange">
          <label v-for="(row, index) in dataList" :key="row.id">
            <view class="keyword-entry" hover-class="keyword-entry-tap">
              <view class="keyword-text">
                <checkbox color="#42b983" :value="row.id" :checked="row.checked" />
                <rich-text :nodes="row.buildingName"></rich-text>
              </view>
              <view class="keyword-img">
                <image src="/static/HM-search/back.png"></image>
              </view>
            </view>
          </label>
        </checkbox-group> -->
				<label v-for="(row, index) in dataList" :key="row.id" @click="itemClick(row)">
				  <view class="keyword-entry" hover-class="keyword-entry-tap">
				    <view class="keyword-text">
				      {{row.buildingName}}
				    </view>
				  </view>
				</label>
      </scroll-view>
    </view>
    <view class="toolbar" @click="determine()" hover-class="seimin-btn-hover">
      返回
    </view>
    <!-- 弹窗 -->
    <showModel :title="models.title" :icon="models.icon" :disjunctor="models.disjunctor" :content="models.content" @know="know" :operate="models.operate"></showModel>
  </view>
</template>

<script>
  import {
    post,
    webHandle
  } from "../../http/http.js";
  export default {
    data() {
      return {
        type: "", //进入该页面的类型
        configName: "", //快速组合名称
        id: "", //快速组合id
        changedept: 0, //是否从列表过来的切换负责科室
        hosId: "",
        dataList: [],
        //系统设置的科室类型
        sysDeptType: 0,
        quickCombinationDeptType: 0,
        // 弹窗model
        models: {
          disjunctor: false,
        },
      };
    },
    onLoad(options) {
      this.hosId = uni.getStorageSync("userData").user.currentHospital.id;
      console.log(options, 'options');
      this.type = options.type;
      if (this.type == "setBuilding") {
        this.configName = options.configName;
        this.id = options.id;
        this.changedept = options.changedept;

        options.quickCombinationId && this.getQuickCombinationDeptType(+options.quickCombinationId);
      } else {
        this.getSysDeptType();
      }
      // this.init();
      // #ifdef APP-PLUS
      webHandle("no", "app");
      // #endif
      // #ifdef H5
      webHandle("no", "wx");
      // #endif
    },
    methods: {
      //返回
      know() {
        this.models.disjunctor = false;
      },
      //获取系统设置的科室类型
      getQuickCombinationDeptType(quickCombinationId) {
        let postData = {
          "idx": 0,
          "sum": 1,
          workAllocationQuickConfig: {
            id: quickCombinationId
          }
        }
        post("/simple/data/fetchDataList/workAllocationQuickConfig", postData).then((res) => {
          if (res.status == 200) {
            let workAllocationQuickConfig = res.list[0] || {};
            // 科室绑定人员
            if(workAllocationQuickConfig.ruleType == 3){
              if(workAllocationQuickConfig.deptTypeList){
                this.quickCombinationDeptType = workAllocationQuickConfig.deptTypeList.map(v => v.id).toString();
              }else{
                // 没有获取到配置,则获取之前的
                this.getSysDeptType();
              }
              this.getBuildings();
            }else{
              this.getSysDeptType();
            }
          }
        })
      },
      // 确认
      determine() {
				uni.navigateBack({
					delta: 1,
				})
      },
			// 选择楼栋
			itemClick(item){
				console.log(3333,item)
				let postData = {
				  "idx": 0,
				  "sum": 9999,
				  department: {
				    buildIds: item.id,
						groupByFloor: true
				  }
				}

				if(this.quickCombinationDeptType){
				  postData.department.deptTypeIds = this.quickCombinationDeptType;
				} else if (this.sysDeptType === 0) {
				  return;
				} else {
				  postData.department.type = {
				    id: this.sysDeptType
				  }
				}

				uni.showLoading({
				  title: "加载中",
				});
				post("/data/fetchDataList/department", postData).then((res) => {
				  uni.hideLoading();
				  if (res.status == 200) {
						console.log(2222,res.list)
				    uni.setStorageSync("floorList", res.list)
						uni.navigateTo({
						  url: `../searchFloor/searchFloor?name=${item.buildingName}&configName=${this.configName}&id=${this.id}&changedept=${this.changedept}`
						});
				  } else {
				    uni.showToast({
				      icon: "none",
				      title: res.msg || "接口获取数据失败！",
				    });
				  }
				})
			},
      // 选择楼栋
      checkboxChange: function(e) {
        var dataList = this.dataList,
            values = e.detail.value;
        for (var i = 0, lenI = dataList.length; i < lenI; ++i) {
          const item = dataList[i]
          if (values.includes(item.id)) {
            this.$set(item, 'checked', true)
          } else {
            this.$set(item, 'checked', false)
          }
        }
      },
      //获取系统设置的科室类型
      getSysDeptType() {
        uni.showLoading({
          title: "加载中",
        });
        let postData = {
          "idx": 0,
          "sum": 1,
          systemConfiguration: {
            keyconfig: "busiViewDeptId"
          }
        }
        post("/simple/data/fetchDataList/systemConfiguration", postData).then((res) => {
          this.getBuildings();
          if (res.status == 200) {
            this.sysDeptType = res.list[0].valueconfig
          } else {
            uni.showToast({
              icon: "none",
              title: res.msg || "接口获取数据失败！",
            });
          }
        })
      },
      //获取楼栋列表
      getBuildings() {
        let postData = {
          "idx": 0,
          "sum": 100,
          building: {
            cascadeHosId: this.hosId
          }
        }
        post("/simple/data/fetchDataList/building", postData).then((res) => {
          uni.hideLoading();
          if (res.status == 200) {
            this.dataList = res.list || [];
          } else {
            uni.showToast({
              icon: "none",
              title: res.msg || "接口获取数据失败！",
            });
          }
        })
      },
    },
  };
</script>
<style scoped lang="less">
  view {
    display: block;
  }
	.title{
		padding: 30rpx;
		font-size: 32rpx;
		text-align: center;
		font-weight: bold;
	}
  // 底部
  .toolbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 30rpx;
		width: 96%;
		margin-left: 2%;
    z-index: 9999;
    height: 88rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    border-radius: 10rpx;
    background-color: #8F939C;
		color: #fff;
  }

  .search-box {
    width: 95%;
    background-color: rgb(242, 242, 242);
    padding: 15upx 2.5%;
    display: flex;
    justify-content: space-between;
    position: sticky;
    top: 0;
  }

  .search-box .mSearch-input-box {
    width: 100%;
  }

  .search-box .input-box {
    width: 85%;
    flex-shrink: 1;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .search-box .search-btn {
    width: 15%;
    margin: 0 0 0 2%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    font-size: 28upx;
    color: #fff;
    background: linear-gradient(to right, #ff9801, #ff570a);
    border-radius: 60upx;
  }

  .search-box .input-box>input {
    width: 100%;
    height: 60upx;
    font-size: 32upx;
    border: 0;
    border-radius: 60upx;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    padding: 0 3%;
    margin: 0;
    background-color: #ffffff;
  }

  .placeholder-class {
    color: #9e9e9e;
  }

  .search-keyword {
    width: 100%;
    background-color: rgb(242, 242, 242);
  }

  .keyword-list-box {
    height: calc(100vh - 230rpx);
    padding-top: 10upx;
    border-radius: 20upx 20upx 0 0;
    background-color: #fff;
  }

  .keyword-entry-tap {
    background-color: #eee;
  }

  .keyword-entry {
    width: 94%;
    height: 80rpx;
    margin: 0 3%;
    font-size: 30rpx;
    color: #333;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: solid 1rpx #DEDEDE;
  }

  .keyword-entry image {
    width: 60upx;
    height: 60upx;
  }

  .keyword-entry .keyword-text,
  .keyword-entry .keyword-img {
    height: 80upx;
    display: flex;
    align-items: center;
  }

  .keyword-entry .keyword-text {
    // width: 90%;
  }

  .keyword-entry .keyword-img {
    width: 10%;
    justify-content: center;
  }

  .keyword-box {
    height: calc(100vh - 110upx);
    border-radius: 20upx 20upx 0 0;
    background-color: #fff;
  }

  .keyword-box .keyword-block {
    padding: 10upx 0;
  }

  .keyword-box .keyword-block .keyword-list-header {
    width: 94%;
    padding: 10upx 3%;
    font-size: 27upx;
    color: #333;
    display: flex;
    justify-content: space-between;
  }

  .keyword-box .keyword-block .keyword-list-header image {
    width: 40upx;
    height: 40upx;
  }

  .keyword-box .keyword-block .keyword {
    width: 94%;
    padding: 3px 3%;
    display: flex;
    flex-flow: wrap;
    justify-content: flex-start;
  }

  .keyword-box .keyword-block .hide-hot-tis {
    display: flex;
    justify-content: center;
    font-size: 28upx;
    color: #6b6b6b;
  }

  .keyword-box .keyword-block .keyword>view {
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 60upx;
    padding: 0 20upx;
    margin: 10upx 20upx 10upx 0;
    height: 60upx;
    font-size: 28upx;
    background-color: rgb(242, 242, 242);
    color: #6b6b6b;
  }
</style>
