// 进厂作业
<template>
  <div class="sale">
    <div class="top">
      <!-- 框计算 -->
      <span class="text">进门时间：</span>
      <el-date-picker v-model="startTime" type="datetime" placeholder="选择日期">
      </el-date-picker>
      <span class="text">至</span>
      <el-date-picker v-model="endTime" type="datetime" placeholder="选择日期">
      </el-date-picker>
      <el-button type="primary" class="btn" @click="onclick">
        <i class="el-icon-search"></i>查询
      </el-button>
    </div>
    <div class="tab">
      <dilTable v-bind.sync="option" ref="table">
        <el-table-column fixed="right" label="操作" align="center" width="100">
          <template slot-scope="scope">
            <el-button @click="detailclick(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">
              <div v-if="false">{{ props }}</div>
              <div>
                <dilTable v-bind.sync="option1"></dilTable>
              </div>
            </el-form>
          </template>
        </el-table-column>
      </dilTable>
    </div>
  </div>
</template>
<script>
import { sjTime } from "@/utils/sharedJsFile";
export default {
  data() {
    return {
      inputText: "",
      startTime: null,
      endTime: null,
      option: {
        // 表格请求数据的地址
        requestUrl: "/api/v1/tms/getAllEnFactoryResult?apiId=261&orderType=4",
      },
      //记录旧的row对象
      oldRow: "",
      //记录上一个展开的点击次数，单数为展开状态，复数为闭合状态
      oldRowCount: 1,
      option1: {
        requestUrl: "",
      },
    };
  },
  methods: {
    // 查看物资详情
    detailclick(row) {
      // 记录重复点击次数
      if (this.oldRow === row) {
        this.oldRowCount += 1;
      }
      // 切换当前详情表
      this.$refs.table.toggleRowExpansion(row);
      // 打开前关闭上一个详情表
      if (this.oldRow != "") {
        if (this.oldRow != row) {
          if (this.oldRowCount % 2 === 1) {
            this.$refs.table.toggleRowExpansion(this.oldRow);
          } else {
            this.oldRowCount = 1;
          }
        } else {
          this.oldRow = null;
          return;
        }
      }
      // 重置上一个点击对象
      this.oldRow = row;
      this.getMaterial(row.orderId);
    },
    getMaterial(orderId) {
      this.option1.requestUrl =
        "/api/v1/uc/getMaterialMesByOrderId?apiId=352&orderId=" + orderId;
    },
    onclick() {
      let startTime = null;
      let endTime = null;
      if (this.startTime) {
        startTime = sjTime(this.startTime);
      }
      if (this.endTime) {
        endTime = sjTime(this.endTime);
      }
      if (startTime && endTime) {
        if (startTime < endTime) {
          // if(getCookie("orgCode") == "dagangadmin" || getCookie("orgCode") == "zidonghuabu"){
          this.option.requestUrl = "/api/v1/tms/getAllEnFactoryResult?apiId=261&orderType=4&startTime=" + startTime + "&endTime=" + endTime + "&i=" +new Date();

          // }else if(getCookie("orgCode") == "wuliuchuyunzhongxin"){
          // this.options.requestUrl = "/api/v1/wms/getWmsInboundResult?apiId=371&orderType=13&startTime=" + startTime + "&endTime=" + endTime + "&i=" +new Date(); 
          // }else{
          // this.options.requestUrl = '/api/v1/wms/getWmsInboundResult?apiId=371&userId=' + getCookie("orgCode") +"&startTime=" + startTime + "&endTime=" + endTime + "&i=" +new Date(); 
          // }
        } else {
          this.startTime = null;
          this.endTime = null;
          this.$message.warning("开始时间要比结束时间早");
        }
      } else {
        this.getRequestUrl()
      }
    },
  },
};
</script>
<style lang="scss">
.sale {
  .top {
    width: 100%;
    height: 5rem;
    display: flex;
    align-items: center;
    padding-left: 2.5rem;
  }
}
</style>