<template>
  <div class="main-contain">
    <div class="position">
      <bread-crumb :crumbs="crumbs"></bread-crumb>
    </div>
    <div class="app-container">
      <el-table
        :row-style="changColor"
        :header-cell-style="{
          backgroundColor: 'rgb(245, 247, 250)',
          color: '#606266',
        }"
        :data="tableList"
        border
      >
        >
        <el-table-column align="center">
          <template slot="header" slot-scope="scope">
            商品名称<span style="color: red">*</span>
          </template>
          <template slot-scope="scope">
           {{scope.row.project_name}}
          </template>
        </el-table-column>
        <el-table-column label="商品类型" align="center">
          <template slot-scope="scope">
           {{scope.row.project_type}}
          </template>
        </el-table-column>
        <el-table-column label="规格" align="center">
          <template slot-scope="scope">
             {{scope.row.second_specification_name}}
          </template>
        </el-table-column>
        <el-table-column label="调拨数量" align="center">
          <template slot-scope="scope">
            {{scope.row.count}}{{scope.row.sencond_unit}}
          </template>
        </el-table-column>
        <el-table-column label="调出仓库" align="center">
          <template slot-scope="scope">
           {{getHouseName(scope.row.storehouse_out_id)}}
          </template>
        </el-table-column>
        <el-table-column label="调入仓库" align="center">
          <template slot-scope="scope">
           {{getHouseName(scope.row.storehouse_in_id)}}
          </template>
        </el-table-column>
        <el-table-column label="库存总数" align="center">
          <template slot-scope="scope">
            {{scope.row.second_total}}
          </template>
        </el-table-column>
        <el-table-column label="制单人" align="center">
          <template slot-scope="scope">
            {{getDocName(warehouse.creater)}}
          </template>
        </el-table-column>
        <el-table-column label="审核人" align="center">
          <template slot-scope="scope">
            {{getDocName(warehouse.checker)}}
          </template>
        </el-table-column>
        <el-table-column label="审核时间" align="center">
          <template slot-scope="scope">
           <span v-if="warehouse.check_time >0">{{getTimes(warehouse.check_time)}}</span>  
          </template>
        </el-table-column>
        <el-table-column label="备注" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.remake ? scope.row.remake : "" }}</span>
          </template>
        </el-table-column>
      </el-table>
     
    </div>
  </div>
</template>

<script>
import BreadCrumb from "@/xt_pages/components/bread-crumb";
import {getSecondOrderDetailList} from "@/api/seconde";
import { uParseTime } from "@/utils/tools";
export default {
  components: {
    BreadCrumb,
  },
  data() {
    return {
      crumbs: [
        { path: false, name: "库房管理" },
        { path: "/stock/warehousequery", name: "调拨详情" },
      ],
      value1: "",
      total: 0,
      page: 1,
      limit: 10,
      tableData: [{}, {}],
      formInline: {
        user: "",
        region: "",
      },
      rules: {
        region: [
          { required: true, message: "请选择活动区域", trigger: "change" },
        ],
      },
      supplyList: [],
      check_id: 0,
      doctorList: [],
      houseList:[],
      warehouse:{},
      tableList:[],
    };
  },

  methods: {
    // 初始化数据
    init() {},

    // 反审核
    approval() {},

    // 审核
    examine() {},

    // 保存
    save() {},

    // 表单添加
    toAdd() {},

    // 删除
    toDelete() {},

    // 详情查看
    toDetails() {},

    // 表单全选
    handleSelectionChange() {},

    // 页表操作
    handleSizeChange(val) {
      this.limit = val;
      this.init();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.init();
    },

    // 表格样式
    changColor({ rowIndex }) {
      if (rowIndex % 2 == 1) {
        return {
          backgroundColor: "#C4E1FF",
          color: "#303133",
        };
      } else {
        return {
          backgroundColor: "#ACD6FF",
          color: "#303133",
        };
      }
    },
       getTimes(time) {
      if (time === "") {
        return "";
      }
      return uParseTime(time, "{y}-{m}-{d}");
    },
    getlist() {
       var id = parseInt(this.$route.query.id)
      getSecondOrderDetailList(id).then((response) => {
        if (response.data.state == 1) {
          var list = response.data.data.list;
          this.tableList = list;
          this.houseList = response.data.data.houseList
          this.doctorList = response.data.data.doctorList
          var warehouse = response.data.data.warehouse
          this.warehouse = warehouse
        }
      });
    },
    getHouseName(id){
      var storehouse_name = ""
      for(let i=0;i<this.houseList.length;i++){
         if(id == this.houseList[i].id){
           storehouse_name = this.houseList[i].storehouse_name
         }
      }
      return storehouse_name
    },
    getDocName(id) {
      var user_name = "";
      for (let i = 0; i < this.doctorList.length; i++) {
        if (id == this.doctorList[i].admin_user_id) {
          user_name = this.doctorList[i].user_name;
        }
      }
      return user_name;
    }
  },
  created(){
    var now = new Date(); //当前日期
    var nowMonth = now.getMonth(); //当前月
    var nowYear = now.getFullYear(); //当前年
    //本月的开始时间
    var monthStartDate = new Date(nowYear, nowMonth, 1);
    this.start_time = this.getTimes(monthStartDate);
    this.end_time = this.getTimes(new Date());

    this.org_id = this.$store.getters.xt_user.org_id;
    // var start_time =  window.sessionStorage.getItem('purchase_start_time')
    
    // var end_time =  window.sessionStorage.getItem('purchase_end_time')
  
    // if(start_time !=null){
    //   this.start_time = ""
    //   this.start_time = start_time
    // }
    // if(end_time!=null){
    //   this.end_time = ""
    //   this.end_time = end_time
    // }
    // window.sessionStorage.removeItem('purchase_start_time')
    // window.sessionStorage.removeItem('purchase_end_time')
  
    this.getlist();
  }
};
</script>

<style rel="stylesheet/css" lang="scss" scoped>
</style>