<template>
  <scroll-view class="content" scroll-y="true">
    <image src="/static/img/workBac1.png" class="bacImg1"></image>
    <image src="/static/img/workBac2.png" class="bacImg2"></image>
    <!-- 房源模块 -->
    <view class="conItem" style="margin-top: 100rpx" v-if="showCheckOut">
      <view class="conItem-title">房源</view>
      <view class="conItem-cont">
        <view
          class="conItem-cont-item"
          v-for="(item, index) in fyList"
          :key="index"
          @click="handelFyClick(item)"
        >
          <image :src="item.image" class="itemImg"></image>
          <text class="itemText">{{ item.text }}</text>
        </view>
      </view>
    </view>

    <!-- 巡检模块 -->
    <view
      class="conItem"
      :style="!showCheckOut && showInspection ? 'margin-top:100rpx' : ''"
      v-if="showInspection"
    >
      <view class="conItem-title">巡检</view>
      <view class="conItem-cont">
        <view
          class="conItem-cont-item"
          v-for="(item, index) in xjList"
          :key="index"
          @click="handelXjClick(item)"
        >
          <image :src="item.image" class="itemImg"></image>
          <text class="itemText">{{ item.text }}</text>
        </view>
      </view>
    </view>

    <view class="conItem">
      <view class="conItem-title">水电</view>
      <view class="conItem-cont">
        <view
          class="conItem-cont-item"
          v-for="(item, index) in sdList"
          :key="index"
          @click="handelSdClick(item)"
        >
          <image :src="item.image" class="itemImg"></image>
          <text class="itemText">{{ item.text }}</text>
        </view>
      </view>
    </view>

    <view class="conItem" style="display: none">
      <view class="conItem-title">报修</view>
      <view class="conItem-cont">
        <view
          class="conItem-cont-item"
          v-for="(item, index) in bxList"
          :key="index"
        >
          <image :src="item.image" class="itemImg"></image>
          <text class="itemText">{{ item.text }}</text>
        </view>
      </view>
    </view>

    <view class="conItem" style="display: none">
      <view class="conItem-title">报事</view>
      <view class="conItem-cont">
        <view
          class="conItem-cont-item"
          v-for="(item, index) in bsList"
          :key="index"
          @click="handleBsClick(item)"
        >
          <image :src="item.image" class="itemImg"></image>
          <text class="itemText">{{ item.text }}</text>
        </view>
      </view>
    </view>
  </scroll-view>
</template>

<script>
import { getRouters } from "../../../pages/api";
export default {
  data() {
    return {
      showCheckOut: false, // 控制房源模块显示
      showInspection: false, // 控制巡检模块显示
      fyList: [
        // { image: '/static/img/看房.png', text: '看房确认' },
        { image: "/static/img/退房检查.png", text: "退房检查" },
        { image: "/static/img/释放.png", text: "释放房源检查" },
        // { image: '/static/img/预约.png', text: '预约看房' },
        { image: "/static/img/强制清退.png", text: "强制清退" },
      ],
      xjList: [
        { image: "/static/img/巡查.png", text: "巡检上报" },
        { image: "/static/img/记录.png", text: "巡检记录" },
      ],
      sdList: [
        { image: "/static/img/水费.png", text: "水量上报" },
        { image: "/static/img/电费.png", text: "电量上报" },
      ],
      // bxList: [
      // { image: '/static/img/上报.png', text: '上报' },
      // { image: '/static/img/处理.png', text: '处理' },
      // ],
      // bsList: [
      // { image: '/static/img/上报.png', text: '上报' },
      // { image: '/static/img/处理.png', text: '处理' },
      // ],
    };
  },
  onLoad() {
    this.getRouter();
    if (!this.$store.state.user.token) {
      uni.redirectTo({
        url: "/pages/login/login",
      });
    }
  },
  methods: {
    // 获取路由
    async getRouter() {
      const res = await getRouters();
      // 递归查找
      function hasMenu(menu, name) {
        if (!menu) return false;
        if (Array.isArray(menu)) {
          return menu.some((item) => hasMenu(item, name));
        }
        if (menu.name === name) return true;
        if (menu.children) return hasMenu(menu.children, name);
        return false;
      }
      this.showCheckOut = hasMenu(res.data || res, "Check_out");
      this.showInspection = hasMenu(res.data || res, "Inspection");
    },
    handelFyClick(item) {
      if (item.text == "退房检查") {
        uni.navigateTo({
          url: "/pagesA/checkout/list/list",
        });
      } else if (item.text == "释放房源检查") {
        uni.navigateTo({
          url: "/pagesA/release/list/list",
        });
      } else if (item.text == "强制清退") {
        uni.navigateTo({
          url: "/pagesA/force/index/index",
        });
      }
    },
    handleBsClick(item) {
      if (item.text === "处理") {
        // 记录
        uni.navigateTo({
          url: "/pages/tabBar/bsPage/bsRecord",
        });
      } else {
        // 上报
        uni.navigateTo({
          url: "/pages/tabBar/bsPage/bsReport",
        });
      }
    },
    handelXjClick(item) {
      if (item.text === "巡检上报") {
        // 列表
        uni.navigateTo({
          url: "/pagesA/xjPage/xj",
        });
      } else {
        uni.navigateTo({
          url: "/pagesA/xjPage/xjRecord",
        });
      }
    },
    handelSdClick(item) {
      if (item.text === "水量上报") {
        uni.navigateTo({
          url: "/pagesA/sdPage/sfReport",
        });
      } else if (item.text === "电量上报") {
        uni.navigateTo({
          url: "/pagesA/sdPage/dfReport",
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.content {
  width: 100%;
  height: 100vh;
}

.conItem {
  width: calc(100% - 40rpx);
  border-radius: 10rpx;
  margin-left: 20rpx;
  background-color: rgba(255, 255, 255, 1);
  box-shadow: 2rpx 2rpx 4rpx rgba(0, 0, 0, 0.2);
  margin-bottom: 20rpx;
  padding: 20rpx;
  box-sizing: border-box;
}

.conItem-title {
  color: rgb(64, 64, 64);
  font-size: 32rpx;
  text-align: left;
  font-weight: bold;
}

.conItem-cont {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 20rpx;
}

.conItem-cont-item {
  width: 23%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  margin-right: 2%;
  margin-bottom: 20rpx;

  .itemImg {
    width: 100rpx;
    height: 100rpx;
  }

  .itemText {
    color: rgb(64, 64, 64);
    font-size: 28rpx;
    margin-top: 15rpx;
    white-space: nowrap;
  }
}

.conItem-cont-item:nth-child(4n) {
  margin-right: 0;
}

.bacImg1 {
  width: 100%;
  height: 17%;
  position: absolute;
  top: 0;
  z-index: -1;
}

.bacImg2 {
  width: 100%;
  height: 80%;
  position: absolute;
  top: 12%;
  z-index: -1;
}
</style>
