// 进厂作业
<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 label="操作" fixed="right" width="80">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="detailclick(scope.row)">
              物资详情
            </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>
                <el-table :data="tableData" border >
                  <el-table-column
                    v-for="(item, i) in tableHead"
                    :key="i"
                    :prop="item.prop"
                    :label="item.label"
                    :width="item.width"
                  ></el-table-column>
                </el-table>
              </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=210&orderType=2",
      },
      //记录旧的row对象
      oldRow: "",
      //记录上一个展开的点击次数，单数为展开状态，复数为闭合状态
      oldRowCount: 1,
      tableHead: [
        {
          prop: "materialName",
          label: "物资名称",
          width: 150,
        },
        {
          prop: "specificationModel",
          label: "规格型号",
          width: 150,
        },
        {
          prop: "orderMaterialNumber",
          label: "物资件数",
          width: 100,
        },
        {
          prop: "orderMaterialWeight",
          label: "物资重量",
          width: 100,
        },
      ],
      tableData: [],
    };
  },
  methods: {
    //   时间查询
    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=210&orderType=2&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()
      }
    },
    // 查看物资详情
    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);
    },
    // 根据运输订单id查询物资信息
    getMaterial(orderId) {
      this.axios
        .get("/api/v1/tms/getMaterial?orderId=" + orderId)
        .then((res) => {
          res.data.data.forEach(e => {
            if(e.specificationModel == "()"){
              e.specificationModel = null;
            } 
          });
          this.tableData = res.data.data;
        });
    },
  },
};
</script>
<style lang="scss" scoped>
.sale {
  .top {
    padding: 1.25rem 0.375rem;
			.el-input {
			width: 20%;
			margin-right: 1.25rem;
			}
  }
}
</style>