<template>
  <div class="housemange">
    <div class="form">
      <div
        class="closIcon"
        @click="searchStatus = false"
        v-if="searchStatus == true"
      >
        <van-icon name="arrow-up" />
      </div>
      <div
        class="openIcon"
        @click="searchStatus = true"
        v-if="searchStatus == false"
      >
        <van-icon name="arrow-down" />
      </div>
      <!-- <van-row>
        <van-col :span="4">
          <div class="yuanqu_label">园区</div>
        </van-col>
        <van-col :span="20" class="labelcolmt26">
          <uni-data-checkbox
            v-model="form.groupIds"
            mode="tag"
            :localdata="yuanqu_loacldata"
            selectedTextColor="#1D18BC"
            selectedColor="rgba(29,24,188,0.05);"
            @change="getSelectedYuanqu"
          >
          </uni-data-checkbox>
        </van-col>
      </van-row> -->
      <van-row v-if="form.groupIds != null">
        <van-col :span="4">
          <div>楼盘</div>
        </van-col>
        <van-col class="labelcolmt26" :span="20">
          <uni-data-checkbox
            v-model="form.parkFloorDiscIds"
            mode="tag"
            :localdata="loupan_loacldata"
            selectedTextColor="#1D18BC"
            selectedColor="rgba(29,24,188,0.05);"
            @change="getSelectedLoupan"
          >
          </uni-data-checkbox>
        </van-col>
      </van-row>
      <van-row>
        <van-col class="labelcolmt26" :span="4">
          <div style="height: 37rpx; line-height: 37rpx">状态</div>
        </van-col>
        <van-col class="labelcolmt26 status" :span="20">
          <uni-data-checkbox
            :map="{ text: 'label', value: 'value' }"
            v-model="form.statusArray"
            :localdata="dic_SelectList.INVESTMENT_STATUS"
            :multiple="true"
            selectedTextColor="#1D18BC"
            selectedColor="#1D18BC"
            @change="getSelectedStatus"
          >
          </uni-data-checkbox>
        </van-col>
      </van-row>
      <van-row v-if="searchStatus">
        <van-col class="labelcolmt26" :span="4">
          <div class="yuanqu_label" style="height: 37rpx; line-height: 37rpx">
            朝向
          </div>
        </van-col>
        <van-col class="labelcolmt26 status" :span="20">
          <uni-data-checkbox
            v-model="form.chaoxiangArray"
            :localdata="fangxiangList"
            :multiple="true"
            selectedTextColor="#1D18BC"
            selectedColor="#1D18BC"
            @change="getChaoxiang"
          >
          </uni-data-checkbox>
        </van-col>
      </van-row>
      <van-row v-if="searchStatus">
        <van-col class="labelcolmt26" :span="4">
          <div class="yuanqu_label">性质</div>
        </van-col>
        <van-col class="labelcolmt26" :span="16">
          <uni-data-checkbox
            v-model="form.zaitiTypeArray"
            mode="tag"
            :localdata="xinzhiList"
            selectedTextColor="#1D18BC"
            selectedColor="rgba(29,24,188,0.05);"
            @change="getSelectedXingZhi"
          >
          </uni-data-checkbox>
        </van-col>
      </van-row>
      <van-row v-if="searchStatus">
        <van-col class="labelcolmt26" :span="4">
          <div class="yuanqu_label">指导价</div>
        </van-col>
        <van-col class="labelcolmt26" :span="9">
          <input
            v-model="form.guidePrice1"
            type="number"
            placeholder="元/㎡/月"
          />
        </van-col>
        <van-col :span="1">
          <div class="width100 txt_center">-</div>
        </van-col>
        <van-col class="labelcolmt26" :span="9">
          <input
            v-model="form.guidePrice2"
            type="number"
            placeholder="元/㎡/月"
          />
        </van-col>
      </van-row>
      <van-row v-if="searchStatus">
        <van-col class="labelcolmt26" :span="4">
          <div class="yuanqu_label">面积</div>
        </van-col>
        <van-col class="labelcolmt26" :span="9">
          <input v-model="form.roomSize1" type="number" placeholder="㎡" />
        </van-col>
        <van-col :span="1">
          <div class="width100 txt_center">-</div>
        </van-col>
        <van-col class="labelcolmt26" :span="9">
          <input v-model="form.roomSize2" type="number" placeholder="㎡" />
        </van-col>
      </van-row>
      <div style="margin-top: 16rpx">
        <van-row>
          <van-col class="labelcolmt26" :span="6">
            <van-button
              color="#F1F2F9"
              custom-class="reset_btn"
              @click="reast()"
              >重置</van-button
            >
          </van-col>
          <van-col class="labelcolmt26" :span="18">
            <van-button
              style="margin-top: 16rpx"
              color="#2527AA"
              custom-class="search_btn"
              @click="search()"
            >
              <van-icon name="search" />
              搜索
            </van-button>
          </van-col>
        </van-row>
      </div>
    </div>
    <div class="list">
      <div v-if="vamTabStatus">
        <van-tabs
          id="resizeID"
          ref="vantTabs"
          :active="form.mnpBuildingIds"
          @change="getSelectedLoudong"
          line-width="80rpx"
          title-active-color="#1D18BC"
        >
          <van-tab
            v-for="(item, index) in loudongList"
            :title="item.ldmc"
            :name="item.id"
            :key="index"
          >
          </van-tab>
        </van-tabs>
      </div>
      <div class="total" v-if="roomList.length != 0">
        共
        <span style="color: #1d18bc">{{ form.total }}</span>
        间
      </div>

      <div
        class="list-row"
        v-if="roomList.length != 0"
        v-for="(item, index) in roomList"
        :key="index"
        @click="jumpPage(item.id, item.currentState)"
      >
        <div class="statusTag">
          <div class="tagText">
            {{ getCurrentState(item.currentState) }}
          </div>
        </div>
        <div class="cell_1">
          <div class="width100 height44rpx mb8rpx">
            <div class="first_title">
              {{
                item.yuanquName + item.quyuName + item.loudongName + item.roomNo
              }}
            </div>
          </div>
          <div class="width100 height40rpx mb8rpx">
            <div class="second_title">
              用途：{{
                getDicType("roomUse", item.roomUse) == undefined
                  ? "未知"
                  : getDicType("roomUse", item.roomUse)
              }}
            </div>
            <div class="second_title_1 width50 chaochuyincang">
              装修情况：
              {{
                !item.decorationSituation && item.decorationSituation != "暂无"
                  ? "未知"
                  : dic_SelectList.DECORATION_SITUATION[
                      item.decorationSituation - 1
                    ].label
              }}
            </div>
          </div>
          <div class="width100 height36rpx mb14rpx">
            <div class="third_title" v-if="item.roomSize">
              面积(㎡)：{{ item.roomSize }}平米
            </div>
            <div class="third_title" v-if="!item.roomSize">面积(㎡)：未知</div>

            <div class="third_title_1">
              朝向：{{ item.roomDirection ? item.roomDirection : "未知" }}
            </div>
          </div>
          <div class="width100 height36rpx">
            <div class="float_left chuzu_label">出租指导价（元/㎡/月）：</div>
            <span class="float_left chuzu_vlaue">{{
              !item.guidePrice ? "未知" : item.guidePrice
            }}</span>
          </div>
        </div>
        <div class="cell_2" findDeptList>
          <img src="../../../../static/mine/youjiantou.png" alt="" />
        </div>
      </div>
      <div class="list-row" v-if="roomList.length == 0">
        <van-empty
          class="disblock marginauto"
          style="background: white"
          description="暂无数据"
        />
      </div>
    </div>
  </div>
</template>

<script>
import vanTab from "../../../../wxcomponents/weapp/dist/tab/index";
import vanTabs from "../../../../wxcomponents/weapp/dist/tabs/index";
import common from "../../../utils/common";
import vanEmpty from "../../../../wxcomponents/weapp/dist/empty/index";
import {
  findYuanQuList,
  findLongPanList,
  findLouDongList,
  findRoomByCondition,
  getByCodes,
} from "@/js_sdk/http.js";
const form = {
  status: [],
  chaoxiang: [],
  statusArray: ["1"],
  chaoxiangArray: [],
  zaitiTypeArray: [],
  zaitiType: "",
  roomSize1: "",
  roomSize2: "",
  guidePrice1: "",
  guidePrice2: "",
  parkFloorDiscIds: null,
  groupIds: null,
  pageNum: 1,
  pageSize: 10,
  total: 0,
  currentState: "1",
  mnpBuildingIds: "",
};

export default {
  components: {
    vanTab,
    vanTabs,
    vanEmpty,
  },
  name: "housemanger.vue",
  data() {
    return {
      searchStatus: false,
      tabsStatus: true,
      dic_key: [
        "PROPERTY_NATURE",
        "HOUSE_USAGE",
        "project_status",
        "INVESTMENT_STATUS",
        "DECORATION_SITUATION",
      ],
      dic_SelectList: {},
      loudongList: [],
      activezhaoshang: "0",
      form: {
        ...form,
      },
      active: 0,
      formData: {},
      value: 0,
      vamTabStatus: false,
      yuanqu_loacldata: [],
      loupan_loacldata: [],
      range: [
        {
          value: 0,
          text: "科教产业园",
        },
        {
          value: 1,
          text: "安居",
        },
        {
          value: 2,
          text: "胡埭",
        },
      ],
      loupanList: [
        {
          value: 0,
          text: "一期",
        },
        {
          value: 1,
          text: "二期",
        },
        {
          value: 2,
          text: "三期",
        },
        {
          value: 3,
          text: "四期",
        },
        {
          value: 4,
          text: "五期",
        },
        {
          value: 5,
          text: "六期",
        },
        {
          value: 6,
          text: "七期",
        },
        {
          value: 7,
          text: "八期",
        },
        {
          value: 8,
          text: "九期",
        },
      ],
      statusList: [
        {
          value: 1,
          text: "空置",
        },
        {
          value: 2,
          text: "预约",
        },
        // {
        //   value: 3,
        //   text: "预约",
        // },
        {
          value: 4,
          text: "临期",
        },
        {
          value: 5,
          text: "已租",
        },
        {
          value: 6,
          text: "到期",
        },
      ],
      roomList: [],
      fangxiangList: [
        {
          value: "朝东",
          text: "东",
        },
        {
          value: "朝南",
          text: "南",
        },
        {
          value: "朝西",
          text: "西",
        },
        {
          value: "朝北",
          text: "北",
        },
      ],
      xinzhiList: [
        {
          value: 1,
          text: "自有物业",
        },
        {
          value: 2,
          text: "社会物业",
        },
      ],
    };
  },
  mounted() {
    this.findYuanQuList();
    this.getByCodes1();
  },
  methods: {
    getCurrentState(currentState) {
      if (
        this.dic_SelectList.INVESTMENT_STATUS &&
        this.dic_SelectList.INVESTMENT_STATUS.length > 0
      ) {
        let data = this.dic_SelectList.INVESTMENT_STATUS.find(
          (e) => e.value == currentState
        );
        // console.log("datadatadatadatadatadata", data);
        return data.label;
      }
    },
    reast() {
      this.loudongList = [];
      this.roomList = [];
      this.form = { ...form };
      this.findYuanQuList();
      this.getByCodes1();
    },
    async search() {
      if (!this.form.groupIds && !this.form.parkFloorDiscIds) {
        return this.$showToast("请选择园区和楼盘后重试");
      }
      if (!this.form.groupIds) {
        return this.$showToast("请选择园区后重试");
      }
      if (!this.form.parkFloorDiscIds) {
        return this.$showToast("请选择楼盘后重试");
      }
      this.form.pageNum = 1;
      this.form.pageSize = 10;
      this.form.total = 0;
      let data = await findRoomByCondition(this.form);
      this.roomList = data.rows;
      this.form.total = data.total;
    },

    onReachBottom() {
      console.log("滑动到距离底部100px的时候触发,可以放 。。业务逻辑");
    }, //下拉执行的时候触发 （下拉刷新）

    getDicType(type, value) {
      if (!value) return;
      if (type == "zaiti") {
        let PROPERTY_NATURE = this.dic_SelectList.PROPERTY_NATURE;

        let index = PROPERTY_NATURE.findIndex((e) => e.value == value);
        return PROPERTY_NATURE[index].label;
      }
      if (type == "roomUse") {
        let HOUSE_USAGE = this.dic_SelectList.HOUSE_USAGE;
        let index = HOUSE_USAGE.findIndex((e) => e.value == value);
        return HOUSE_USAGE[index].label;
      }
    },
    async getByCodes1() {
      let data = await getByCodes(
        JSON.stringify([
          "PROPERTY_NATURE",
          "HOUSE_USAGE",
          "project_status",
          "INVESTMENT_STATUS",
          "DECORATION_SITUATION",
        ])
      );
      console.log("1111111111111111", data);
      this.dic_SelectList = this.$common.handleDicList(data);
      console.log("this.dic_SelectList", this.dic_SelectList);
    },
    async getSelectedLoudong(event) {
      console.log(event);
      this.form.mnpBuildingIds =
        event.detail.title == "全部" ? "" : event.detail.name;
      let data = await findRoomByCondition(this.form);
      console.log(data);
      this.roomList = data.rows;
      this.form.total = data.total;
    },
    async getSelectedYuanqu() {
      let data = await findLongPanList(this.form.groupIds);
      this.roomList = [];
      this.loudongList = [];
      if (data.length > 0) {
        this.loupan_loacldata = data.map((e) => {
          return {
            value: e.id,
            text: e.name,
          };
        });
        this.form.parkFloorDiscIds = this.loupan_loacldata[0].value;
      } else {
        this.loupan_loacldata = [{ value: null, text: "暂无" }];
      }
      this.getSelectedLoupan();
    },
    async getSelectedLoupan() {
      try {
        let data = await findLouDongList(this.form.parkFloorDiscIds);
        this.vamTabStatus = false;
        console.log(data);
        if (data.length == 0) {
          this.loudongList = [];
          this.roomList = [];
          this.tabsStatus = !this.tabsStatus;
          return;
        } else {
          this.loudongList = [{ ldmc: "全部", id: "" }, ...data];
          this.roomList = [];
          this.form.mnpBuildingIds = "";
        }
        let row = await findRoomByCondition(this.form);
        console.log("我是row", row);
        this.roomList = row.rows;
        this.form.total = row.total;
        this.vamTabStatus = true;
        console.log(row);
      } catch (e) {
        console.log("e这天真热", e);
      }
    },
    findYuanQuList() {
      findYuanQuList().then((data) => {
        let yuanqu_list = [...data];
        let yuanqu_loacldata = yuanqu_list.map((e) => {
          return {
            value: e.id,
            text: e.groupName,
          };
        });
        this.yuanqu_loacldata = yuanqu_loacldata;
        this.form.groupIds = this.yuanqu_loacldata[0].value;
        this.getSelectedYuanqu();
      });

      // console.log(yuanqu_loacldata)
    },
    jumpPage(id, currentState) {
      console.log(id);
      uni.navigateTo({
        url:
          "/pages/subPackages/housedetails/housedetails?id=" +
          id +
          "&currentState=" +
          currentState,
      });
    },
    onLoadMore() {},
    getChaoxiang() {
      this.form.roomDirection = this.form.chaoxiangArray.join(",");
    },
    getSelectedStatus(e) {
      console.log(this.form.statusArray.join(","));
      this.form.currentState = this.form.statusArray.join(",");
    },
    getSelectedXingZhi() {
      console.log(this.form.zaitiTypeArray);
      this.form.zaitiType = this.form.zaitiTypeArray;
    },
    onChange() {},
    getMoreList() {
      let that = this;
      that.form.pageNum += 1;
      findRoomByCondition(that.form).then((e) => {
        console.log(that.roomList);
        if (that.roomList.length == e.total) {
          this.$showToast("没有更多数据");
        }
        that.roomList = [...that.roomList, ...e.rows];

        console.log(that.roomList);
        that.$forceUpdate();
      });
    },
  },

  onPullDownRefresh: function () {
    // 加载数据
  },
  onReachBottom() {
    console.log("滑动到距离底部100px的时候触发,可以放 。。业务逻辑");
  }, //下拉执行的时候触发 （下拉刷新）
};
</script>

<style lang="scss">
.chaochuyincang {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.statusTag {
  position: absolute;
  background: #2527aa;
  text-align: center;
  color: white;
  // clip-path: polygon(100% 100%, 100% 0%, 0% 0%);
  // height: 100rpx;
  right: 0rpx;
  font-size: 20rpx;
  top: 0rpx;
  padding: 5rpx 20rpx;
  .tagText {
    // transform: rotate(38deg);
    // position: absolute;
    // right: 10rpx;
    // top: 25rpx;
    font-size: 24rpx;
  }
}
.closIcon {
  width: 40px;
  height: 40px;
  background: white;
  position: absolute;
  bottom: -40rpx;
  z-index: 100;
  right: 0;
  left: 0;
  margin: auto;
  border-radius: 50%;
  text-align: center;
  line-height: 40px;
}
.openIcon {
  width: 40px;
  height: 40px;
  background: white;
  position: absolute;
  bottom: -40rpx;
  z-index: 100;
  right: 0;
  left: 0;
  margin: auto;
  border-radius: 50%;
  text-align: center;
  line-height: 40px;
}
/deep/.van-cell {
  padding: 0 0 0 28rpx !important;
}
.inputClass {
  padding: 0 0 0 28rpx !important;
}
.yuanqu_label {
  height: 55rpx;
  line-height: 55rpx;
}
.loupan_label {
  padding: 0rpx 10rpx;
}
.housemange {
  /deep/.checklist-box {
    margin: 0 !important;
    margin-right: 16rpx !important;
  }
  .search_btn {
    margin-left: 18rpx;
    width: calc(100% - 18rpx);
    height: 60rpx;
  }
  .reset_btn {
    color: #2628a9 !important;
    width: 100%;
    height: 60rpx;
  }
  .list-row {
    width: calc(100% - 64rpx);
    padding: 16rpx 32rpx 18rpx 32rpx;
    background: #ffffff;
    margin-bottom: 16rpx;
    display: flex;
    //height: 278rpx;
    border-radius: 8rpx 8rpx 8rpx 8rpx;
    align-items: center;
    position: relative;
  }
  .second_title {
    float: left;
    width: 50%;

    font-size: 28rpx;
    font-family: PingFang SC-Medium, PingFang SC;
    font-weight: 500;
    color: #777777;
  }

  .cell_1 {
    float: left;
    width: 90%;
  }
  .cell_2 {
    float: left;
    width: 10%;
    img {
      height: 60rpx;
      width: 60rpx;
      float: right;
      margin: 0;
    }
  }
  .list {
    width: calc(100% - 64rpx);

    margin: 32rpx;
  }

  .form {
    width: calc(100% - 128rpx);
    margin: 32rpx;
    background: #ffffff;
    padding: 32rpx;
    position: relative;
    .label {
      height: 53rpx;
      line-height: 53rpx;
    }
  }

  .labelcolmt26 {
    input {
      font-size: 24rpx;
      border-radius: 8rpx 8rpx 8rpx 8rpx;
      border: 2rpx solid #cccccc;
      text-align: center;
    }
    .van-col {
      margin-top: 26rpx !important;
    }

    label {
      color: #333333;
      font-size: 30rpx;
      margin: 0;
      margin-top: 0 !important;
    }

    .uni-data-checklist {
      margin-top: -10rpx !important;
    }
  }

  .status {
    .uni-data-checklist {
      margin-top: 0rpx !important;
    }

    label {
      color: #333333;
      font-size: 30rpx;
      padding-right: 0rpx !important;
    }
  }
}
</style>
