<template>
  <div class="main-contain">
    <div class="position">
      <bread-crumb :crumbs="crumbs"></bread-crumb>
    </div>
    <div class="app-container">
      <el-table
        :row-style="{ color: '#303133' }"
        :header-cell-style="{
          backgroundColor: 'rgb(245, 247, 250)',
          color: '#606266',
        }"
        :data="tableList"
        :class="signAndWeighBoxPatients"
        border
      >
        <el-table-column label="商品名称" align="center">
          <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" width="150">
          <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}}
          </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>
      
    </div>
  </div>
</template>

<script>
import BreadCrumb from "@/xt_pages/components/bread-crumb";
import {getSecondOrderDetailList} from "@/api/seconde";
import { uParseTime } from "@/utils/tools";
export default {
  name: "stockIn",
  components: {},
  components: {
    BreadCrumb,
  },
  data() {
    return {
      isActive: false,
      Color_txt: true,
      crumbs: [
        { path: false, name: "采购管理" },
        { path: "/supply/query", name: "采购订单" },
      ],
      keywords: "",
      total: 0,
      multipleSelection: [],
      signAndWeighBoxPatients: "sign-and-weigh-box-patients",
      start_time: "",
      end_time: "",
      page: 1,
      limit: 10,
      goodType: [],
      goodInfo: [],
      org_id: 0,
      types: [],
      tableList: [],
      type_name: "",
      checkList: [
        { id: 0, name: "请选择" },
        { id: 1, name: "已审核" },
        { id: 2, name: "未审核" },
      ],
      supplyList: [],
      check_id: 0,
      doctorList: [],
      houseList:[],
      warehouse:{},
    };
  },
  methods: {
    toAdd() {
      this.$router.push({ path: "/purchase/order/add" });
    },
    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
        }
      });
    },
    getName(id) {
      var name = "";
      for (let i = 0; i < this.supplyList.length; i++) {
        if (id == this.supplyList[i].id) {
          name = this.supplyList[i].supplier_name;
        }
      }
      return 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;
    },
    getAllBuyPrice(arr) {
      var buy_price = 0;
      if (arr != undefined && arr.length > 0) {
        for (let i = 0; i < arr.length; i++) {
          buy_price += arr[i].count * arr[i].price;
        }
      }
      return buy_price.toFixed(2);
    },
    getAllCount(arr) {
      var count = 0;
      if (arr != undefined && arr.length > 0) {
        for (let i = 0; i < arr.length; i++) {
          count += parseInt(arr[i].count);
        }
      }
      if (count == 0) {
        return "";
      }
      if (count > 0) {
        return count;
      }
    },
    toClick(id) {
      window.sessionStorage.setItem('purchase_start_time',this.start_time)
      window.sessionStorage.setItem('purchase_end_time',this.end_time)
      this.$router.push({ path: "/stock/in/test/edit?id=" + id });
    },
    toDetail(id){
      this.$router.push({ path: "/stock/in/test/detail?id=" + id });
    },
    toDelete(val, index) {
      if (val.is_check == 1) {
        this.$message.error("已审核单据，不能删除!");
        return false;
      }
      if (val.orderOut.length > 0) {
        this.$message.error("已关联单据，不能删除!");
        return false;
      }
      this.$confirm("确认删除吗?", "删除", {
        confirmButtonText: "确 定",
        cancelButtonText: "取 消",
        type: "warning",
      }).then(() => {
          deletePurchaseOrder(val.id).then((response) => {
            if (response.data.state == 1) {
              var msg = response.data.data.msg;
              this.tableList.splice(index, 1);
              this.getlist()
              this.$message.success("删除成功");
            } else {
              this.$message.error("删除失败");
            }
          });
        })
        .catch(() => {});
    },
    // 动态改变表格样式
    Color_Change() {
      this.Color_txt = true;
      console.log(this.Color_txt, "op");
    },

    Color_Changeleave() {
      this.Color_txt = false;
      console.log(this.Color_txt, "false");
    },
    getTime(time) {
      if (time === '') {
      return ''
      }
      return uParseTime(time, '{y}-{m}-{d}')
     },
    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 lang="scss">
.cluster-rs {
  text-align: center;
}
.annotation-rs {
  width: 100%;
  height: 100%;
  border: none;
  td {
    width: 155px;
    padding: 5px;
    border-right: none;
    text-align: center;
    vertical-align: middle;
  }
}
tr:last-child {
  td {
    border-bottom: none;
  }
}
</style>

<style rel="stylesheet/css" lang="scss" scoped>
.information {
  border: 1px #dcdfe6 solid;
  padding: 30px 20px 30px 20px;

  .border {
    border-bottom: 1px #dcdfe6 solid;
    margin: 0px 0 20px 0;
  }
}

.title {
  background: #409eff;
  height: 44px;
  line-height: 44px;
  padding: 0 0 0 10px;
  color: #fff;
  margin: 0 0 10px 0;
}

.edit_separater {
  border-top: 1px solid rgb(233, 233, 233);
  margin-top: 15px;
  margin-bottom: 15px;
}
/deep/ .el-table__body-wrapper::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
</style>

<style>
.sign-and-weigh-box .sign-and-weigh-box-patients .cell {
  font-size: 12px;
}

.sign-and-weigh-box .sign-and-weigh-box-patients .current-row > td {
  background: #6fb5fa;
}

.count {
  color: #bd2c00;
}
.el-table td,
.el-table th.is-leaf,
.el-table--border,
.el-table--group {
  border-color: #d0d3da;
}
.el-table--border::after,
.el-table--group::after,
.el-table::before {
  background-color: #d0d3da;
}

.color {
  background: none !important;
  display: flex;
  flex-direction: column;
}
</style>
