<template>
  <view class="supplier_main">
    <headers themeType="white" iconType showBack @select="toDept">
      <view class="headerName" @click="toDept">
        {{ projectDetail.projectName }}
      </view>
    </headers>
    <view class="blockList">
      <view class="blockItem" v-for="(item,index) in blockList" :key="index" @click="clickBlock(item)">
        <image :src="require('@/static/supplierImg/' + item.moduleIcon + '.png')" mode="aspectFill"></image>
        <view class="name">{{ item.moduleName }}</view>
      </view>
    </view>
    <footers activeTab="supplierHome"></footers>
  </view>
</template>

<script>
  import headers from '@/components/headers/headers.vue'
  import footers from '@/components/footers/footers.vue'
  import {
    getBottomLevelData
  } from "@/utils/tool.js"
  export default {
    components: {
      headers,
      footers
    },
    data() {
      return {
        userInfo: {},
        blockList: [],
        projectDetail: {
          projectName: ""
        }
      };
    },
    onLoad() {
      let userInfo = uni.getStorageSync("userInfoObj");
      this.userInfo = userInfo;
      this.getProjectSn(() => {
        uni.setStorageSync('userInfo', JSON.stringify({
          ...userInfo,
          sn: this.searchsn
        }))
        uni.setStorageSync('userInfoObj', {
          ...userInfo,
          sn: this.searchsn
        })
        this.getProjectDetail()
      })
    },
    methods: {
      clickBlock(item) {
        // 点击块
        console.log(item);
        let url = ""
        switch (item.moduleName) {
          case "我的资质":
            url = "/pages/supplier/qualifications/qualifications"
            break;
          case "进度管理":
            url = "/pages/projectEnd/standardSchedule/index"
            break;
          case "人员管理":
            url = "/pages/projectEnd/laborManage/index"
            break;
          case "车辆管理":
            url = "/pages/projectEnd/carManage/index?type=supplier"
            break;
          case "质量管理":
            url = "/pages/projectEnd/supplyQualityManage/supplyQualityManage"
            break;
        }
        uni.navigateTo({
          url
        })
        //
      },
      getProjectSn(next) {
        var userInfo = uni.getStorageSync('userInfoObj');
        this.sendRequest({
          url: "xmgl/company/getTenantOrgTreeList",
          data: {
            userId: userInfo.userId,
            headquartersSn: uni.getStorageSync("company").headquartersSn
          },
          method: "POST",
          success: (res) => {
            let three = getBottomLevelData(res.result)[0];
            let dept = uni.getStorageSync("dept");
            let projectDetail = uni.getStorageSync("projectDetailObj");

            console.log(three);

            if (!dept) {
              uni.setStorageSync('projectDetail', JSON.stringify(three))
              uni.setStorageSync('projectDetailObj', three)
              dept = three.projectSn;
              projectDetail = three;
              uni.setStorageSync("dept", dept)
            }
            this.projectDetail = projectDetail;
            this.searchsn = dept;
            next()
          }
        })
      },
      getProjectDetail() {
        // 获取项目详情
        let _this = this;
        this.sendRequest({
          url: 'xmgl/baseModule/getModuleAndMenuList',
          data: {
            projectSn: this.searchsn,
            userId: this.userInfo.userId,
            moduleType: 6 // 供应商传6
          },
          method: 'POST',
          success(res) {
            console.log(res.result);
            console.log("=-=-=-==-=-=-=-=-==---==-=--=")
            _this.blockList = res.result.moduleList;
          }
        })
      },
      toDept() {
        uni.navigateTo({
          url: "/pages/deptList/deptList"
        })
      },
    },

  }
</script>

<style lang="scss" scoped>
  .blockList {
    display: flex;
    flex-wrap: wrap;

    .blockItem {
      width: calc(100% / 3);
      display: flex;
      flex-direction: column;
      padding: 30rpx;
      text-align: center;
      align-items: center;

      image {
        width: 100rpx;
        height: 100rpx;
      }

      &:active {
        background-color: rgba(0, 0, 0, .01);
      }

      &:last-child {
        border: none;
      }

      .name {
        color: #333;
        padding: 20rpx 0;
      }
    }
  }
</style>

<style lang="scss">
  page {
    background-color: #fff;
  }
</style>