<template>
  <div class="feed-summary-container">
    <div class="feed-summary-inner">
      <div class="left-side-menu">
        <project-side-menu ref="profitloss" :menuTree="menuTreeList" :menuOptions="menuOptions" :unique-opened="false" :default-active="defaultActive" >
          <template slot="盈亏分析对比-1">
            <img src="@/assets/images/projectCostLedger/icon_cost_detail_7.svg" alt="">
            <div class="project-sub-menu-title-text">盈亏分析对比</div>
          </template>
        </project-side-menu>
      </div>
      <div class="profitloss">
        <div class="search">
          <el-date-picker
            v-model="expenseDate"
            type="month"
            placeholder="选择月"
            :picker-options="pickerOptions">
          </el-date-picker>
        </div>

      </div>
    </div>
  </div>
</template>
<script>
  import ProjectSideMenu from "@/views/projectCostLedger/detail/components/ProjectSideMenu";
  import { getProfitLossMenuTreeApi,getAnalysislist } from "@/api/projectCostLedger";
  export default {
    name: "orifitloss",
    props: {
      // 项目ID
      projectId: {
        type: String,
        required: true,
        default: ""
      },
      // 详情信息
      projectDetailInfo: {
        type: Object,
        default: () => ({})
      }
    },
    watch: {
      projectDetailInfo: {
        handler(newValue) {
          this.comProjectDetailInfo = newValue ? newValue : {};
          this.init(this.comProjectDetailInfo);
        },
        deep: true,
        immediate: true
      },
      projectId: {
        handler(newValue) {
          this.comProjectId = newValue;
        },
        immediate: true
      }
    },
    components: {
      ProjectSideMenu
    },
    data() {
      return {
        pickerOptions: {
          disabledDate(time) {
            let istrue = true
            let month = new Date().getMonth()+1
            let year = new Date().getFullYear()
            let times = (year+5)+'-'+ month + '-01 ' + '00:00:00'
            istrue =  new Date().getTime() < time.getTime() && time.getTime() < new Date(times).getTime()
            return !istrue
          },
        },
        menuOptions: {
          nodeName: "cbName",
          nodeValue: "id",
        },
        comProjectDetailInfo: {},
        comProjectId: "",
        defaultActive: "",
        menuTreeList: [
          // {
          //   nodeName: "房建类成本科目",
          //   id: "1",
          //   children: [
          //     {
          //       nodeName: "劳务分包工程",
          //       id: "1-1",
          //       children: [
          //         {
          //           nodeName: "主体工程-结构劳务",
          //           id: "1-1-1",
          //           children: [
          //             {
          //               nodeName: "结构劳务分包",
          //               id: "1-1-1-1",
          //             }
          //           ]
          //         },
          //         {
          //           nodeName: "二次结构及粗装修劳务",
          //           id: "1-2-1",
          //           children: [
          //             {
          //               nodeName: "二次机构及粗装修劳务",
          //               id: "1-2-1",
          //             }
          //           ]
          //         },
          //         {
          //           nodeName: "拆除、修缮、清理、改造劳...",
          //           id: "1-3-1",
          //           children: [
          //             {
          //               nodeName: "拆除、修缮、清理、改造劳...",
          //               id: "1-3-1",
          //             }
          //           ]
          //         }
          //       ]
          //     },
          //     {
          //       nodeName: "专业分包工程",
          //       id: "2-1",
          //     },
          //     {
          //       nodeName: "实体工程材料（土建）",
          //       id: "3-1",
          //     },
          //     {
          //       nodeName: "其他直接费成本",
          //       id: "4-1",
          //     },
          //   ]
          // },
          // {
          //   nodeName: "未归类项目",
          //   id: "2",
          //   children: []
          // }
        ],
        id: 0,
        expenseDate:'',
      };
    },
    //可访问data属性
    created() {
      let month = new Date().getMonth() +1
      let year = new Date().getFullYear()
      this.expenseDate = year + '-' + (month>= 9? month:'0'+ month)

    },
    //计算集
    computed: {

    },
    //方法集
    methods: {
      select(menuPath){
        this.id = menuPath
        let param = {
          id:this.id,
          expenseDate:this.expenseDate
        }
        getAnalysislist(param).then(res=>{

        })
      },
      async init(detail = {}) {
        try {
          const { projectId, cbStage,cbType} = detail;
          if (!projectId) return;
          await this.getFeedSummaryMenuTree({
            projectId,
            cbStage,
            cbType
          });
        } catch (error) {

        }
      },
      async getFeedSummaryMenuTree(params) {
        try {
          const result = await getProfitLossMenuTreeApi(params);
          if (result.code == 200) {
            let arr = {}
            arr.cbName = '盈亏分析对比'
            arr.id = 0
            arr.children = result.data
            const _tempArray = [arr];
            this.menuTreeList = _tempArray;
            await this.$nextTick()
            this.$refs['profitloss'].$refs['customElMenu'].open(_tempArray[0].id)
            this.defaultActive = result.data[0].id
            this.select(result.data[0].id)
          }
        } catch (error) {
          console.log(error)
        }
      }
    },
  }
</script>
<style lang="scss" scoped>
  .feed-summary-container {
    width: 100%;
    height: 100%;

    .feed-summary-inner {
      width: 100%;
      height: 100%;
      display: flex;
      align-items: center;

      .left-side-menu {
        width: 220px;
        min-width: 220px;
        height: 100%;
      }
      .profitloss{
        width: calc(100% - 220px);
        height: 100%;
        background: #fff;
      }
    }
  }
</style>
