<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" @select="select">
          <template slot="措施费-1">
            <img src="@/assets/images/projectCostLedger/icon_cost_detail_4.svg" alt="">
            <div class="project-sub-menu-title-text">措施费</div>
          </template>
        </project-side-menu>
      </div>
      <div class="profitloss">
        <div class="search">
          <el-date-picker size="small" style="width: 140px"
            v-model="expenseDate"
            type="month"
            placeholder="选择月" @change="changetime"
            :picker-options="pickerOptions">
          </el-date-picker>
        </div>
        <div class="table-item">
          <el-table
            element-loading-text="Loading"
            :data="tableData"
            :row-class-name="tableRowClassName"
            row-key="id"
            v-horizontal-scroll="'hover'"
            default-expand-all
            :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
            border
            highlight-current-row
          >
            <el-table-column label="序号" width="60" align="left" prop="index" fixed="left"></el-table-column>
            <el-table-column label="清单内容" width="130" prop="itemContent" fixed="left">
              <template slot-scope="scope">{{scope.row.itemContent || '--'}}</template>
            </el-table-column>
            <el-table-column label="工作内容、做法/规格型号/施工现场配置说明" width="300" prop="workContent">
              <template slot-scope="scope">{{scope.row.workContent || '--'}}</template>
            </el-table-column>
            <el-table-column label="单位" width="130" prop="unit">
              <template slot-scope="scope">{{scope.row.unit || '--'}}</template>
            </el-table-column>
            <el-table-column label="工程量" width="130" prop="quantity">
              <template slot-scope="scope">{{scope.row.quantity || '--'}}</template>
            </el-table-column>
            <el-table-column label="不含税单价" width="130" prop="unitPriceExcludingTax">
              <template slot-scope="scope">{{scope.row.unitPriceExcludingTax || '--'}}</template>
            </el-table-column>
            <el-table-column label="使用时间" width="130" prop="usageTime">
              <template slot-scope="scope">{{scope.row.usageTime || '--'}}</template>
            </el-table-column>
          </el-table>
        </div>

      </div>
    </div>
  </div>
</template>
<script>
  import ProjectSideMenu from "@/views/projectCostLedger/detail/components/ProjectSideMenu";
  import { getMeasureslist,getCostMeasureslist ,getSummarydata} from "@/api/projectCostLedger";
  export default {
    name: "MeasureItems",
    props: {
      // 项目ID
      projectId: {
        type: String,
        required: true,
        default: ""
      },
      // 详情信息
      projectDetailInfo: {
        type: Object,
        default: () => ({})
      }
    },
    watch: {
      projectDetailInfo: {
        handler(newValue) {
          this.comProjectDetailInfo = newValue ? newValue : {};
          this.init(this.projectId);
        },
        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: "itemContent",
          nodeValue: "id",
        },
        comProjectDetailInfo: {},
        comProjectId: "",
        defaultActive: "",
        menuTreeList: [
        ],
        id: 0,
        expenseDate:'',
        tableData:[],
      };
    },
    //可访问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 month = this.expenseDate.replace(/-/ig, "");
        let param = {
          projectId:this.projectId,
          id:this.id,
          month:month
        }
        getCostMeasureslist(param).then(res=>{
          this.tableData = res.data
        })
      },
      async init(detail = '') {
        try {
          const  projectId = detail;
          if (!projectId) return;
          await this.getFeedSummaryMenuTree(projectId);
        } catch (error) {

        }
      },
      async getFeedSummaryMenuTree(params) {
        try {
          const result = await getMeasureslist(params);
          if (result.code == 200) {
            let arr = {}
            arr.itemContent = '措施费'
            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)
        }
      },
      changetime(){
        this.select(this.id)
      },
    },
  }
</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;
        padding: 16px;
        .table-item{
          margin-top: 16px;
        }
      }
    }
  }
</style>
