<template>
  <!-- 展示万州港港存库库存列表 -->
  <div class="homeworkPath">
    <div class="top">
      <el-input
        v-model="input"
        placeholder="请输入物资名称或者外轮船名"
        style="width: 260px"
        clearable
      ></el-input>
      <el-button type="primary" class="btn" @click="onclick">
        <i class="el-icon-search"></i>查询
      </el-button>
      <div class="totalNumber" style="margin-left:10px">
      <span
        style="
          color: IndianRed;
          font-family: FANGSONG;
          font-size: 15px;
          font-weight: bold;
        "
        >万州港合计吨位（截止至：{{now}}）</span
      >
      <el-input
        v-model="totalNumber"
        :disabled="true"
        style="width: 120px"
      ></el-input>
      <el-button style="margin-left: 12px" type="primary" @click="exportData()"
        ><i class="el-icon-download"></i>导出Excel</el-button
      >
      <el-button type="primary" @click="refresh">
        <i class="el-icon-refresh"></i>
      </el-button>
      </div>
    </div>
    
    <!-- <span
      class="el-input"
      style="
        color: red;
        margin-left: 45%;
        font-family: FANGSONG;
        font-size: 20px;
        font-weight: bold;
      "
      >万州港实时库存详情</span
    > -->
    <mergeRowTable
      ref="excelDom"
      v-bind.sync="option"
      :isHeigth="isHeigth"
      :shiyHeigth="shiyHeigth"
      @func="func"
      :pageSize="pageSize"
      :expandRowKeys="expandRowKeys"
    >
    <el-table-column fixed="right" label="点后出入库详情" width="120">
          <template slot-scope="scope">
              <el-button @click="detailclick1(scope.row)" type="text" size="small">
                入库详情
              </el-button>
              <el-button @click="detailclick2(scope.row)" type="text" size="small">
                出库详情
              </el-button>
          </template>
    </el-table-column>
    <el-table-column type="expand" width="1">
          <template slot-scope="props">
            <el-form label-position="center" inline class="demo-table-expand" style="margin-left:30%">
              <div v-if="false">{{ props }}</div>
              <div>
                <el-table :data="inbounds" border v-show="tableStatus==1">
                  <el-table-column
                    v-for="(item, i) in tableHead1"
                    :key="i"
                    :prop="item.prop"
                    :label="item.label"
                    :width="item.width"
                  ></el-table-column>
                </el-table>
                 <el-table :data="outbounds" border v-show="tableStatus==2">
                 <el-table-column
                    v-for="(item, i) in tableHead2"
                    :key="i"
                    :prop="item.prop"
                    :label="item.label"
                    :width="item.width"
                  ></el-table-column>
                </el-table>
              </div>
            </el-form>
          </template>
    </el-table-column>
    </mergeRowTable>
  </div>
</template>

<script>
export default {
  name: "homeworkPath",
  data() {
    return {
      tableTitle: "万州港港存库物资明细报表",
      shiyHeigth: 130,
      isHeigth: true,
      input: null,
      text: null,
      pageSize: 1000,
      state: "",
      //合计净重
      totalNumber: 0,
      option: {
        // 表格请求数据的地址
        requestUrl: "/api/v1/wmsh/getLoadPortStockList?apiId=158",
        comparison:"materialName",
        columnIndexs:[0,1,2]
      },
      option2: {
        requestUrl: "/api/v1/wmsh/getLoadPortStockByMaterialName?apiId=493",
      },
      tableStatus:0,
      focusRow:null,
      inbounds:[],
      outbounds:[],
      expandRowKeys:[],
      now:null,
      tableHead1:[
        {
          prop: "resultMaterialNumber",
          label: "入库吨位",
          width: 150
        },
        {
          prop: "insertTime",
          label: "入库时间",
          width: 150
        }
      ],
      tableHead2:[
         {
          prop: "resultMaterialNumber",
          label: "出库吨位",
          width: 150
        },
        {
          prop: "wagonNumber",
          label: "出库车皮数",
          width: 150
        },
        {
          prop: "insertTime",
          label: "出库时间",
          width: 150
        }
      ]
    };
  },
  created() {
    this.option.requestUrl =
      "/api/v1/wmsh/getLoadPortStockList?apiId=158&i=" + new Date();
    let now=new Date();
    let hour=now.getHours()
    if(hour>=8 && hour < 18){
      now.setHours(8);
    }else{
      now.setHours(18);
    }
    now.setMinutes(0);
    now.setSeconds(0);
    this.now=now.toLocaleString();
  },
  methods: {
    detailclick1(row){
      console.log("row",row);
      let flag=this.focusRow==row && this.tableStatus==1;//是否关闭
       this.axios.post("/api/v1/wmsh/findInboundDetail", row).then(res => {
        console.log("res", res);
        this.inbounds = res.data.data;
        this.expandRowKeys=[];//清空
      }).then(()=>{
        this.tableStatus=1;
        if(!flag){
          this.$refs.excelDom.toggleRowExpansion(row);
          this.focusRow=row;
        }else{
          this.focusRow=null;
        }
      });
    },
    detailclick2(row){
      console.log("row",row);
      let flag=this.focusRow==row && this.tableStatus==2;
      console.log(flag);
      this.axios.post("/api/v1/wmsh/findOutboundDetail", row).then(res => {
        console.log("res", res);
        this.outbounds = res.data.data;
        this.expandRowKeys=[]
      }).then(()=>{
        this.tableStatus=2;
        if(!flag){
          this.$refs.excelDom.toggleRowExpansion(row);
          this.focusRow=row;
        }else{
          this.focusRow=null;
        }
      });
    },
    func(res) {
      console.log("aaa" + res);
      var resultActualInstallations = 0;
      res.list.forEach((e) => {
        resultActualInstallations = resultActualInstallations + e.gmTonnage;
      });
      this.totalNumber = resultActualInstallations.toFixed(2) + " 吨";
    },
    // 点击查询查看
    onclick() {
      this.option.requestUrl =
        "/api/v1/wmsh/getLoadPortStockList?apiId=158&i=" +
        new Date() +
        "&con=" +
        this.input;
    },
    onclick1() {
      this.option2.requestUrl =
        "/api/v1/wmsh/getLoadPortStockByMaterialName?apiId=493&i=" +
        new Date() +
        "&con=" +
        this.text;
    },
    refresh() {
      this.$router.go(0);
    },
  },
};
</script>
<style lang='scss' scoped>
.homeworkPath {
  .top {
    padding: 1.25rem 0.375rem;
    display: flex;
    .my-autocomplete {
      width: 20%;
      margin-right: 40rpx;
    }
  }
}
</style>