<template>
  <div>
    <el-button
      style="float: right"
      size="small"
      icon="el-icon-printer"
      @click="PrintAction"
      type="primary"
      >打印
    </el-button>
     <el-button
      style="float: right;margin-right:10px"
      size="small"
      @click="exportListDetail"
      type="primary"
      >明细导出
    </el-button>
     <el-button
      style="float: right;margin-right:10px"
      size="small"
      @click="exportList"
      type="primary"
      >汇总导出
    </el-button>
    <div class="cell clearfix">
      <label class="title"><span class="name">仓库</span> :</label>
      <el-select size="small" v-model="storehouse_id" filterable placeholder="请选择仓库" style="width:200px" @change="changeHouseList">
          <el-option
            v-for="(option, index) in houseList"
            :key="index"
            :label="option.storehouse_name"
            :value="option.id">
          </el-option>
      </el-select>
      <el-input
        size="small"
        style="width:180px;"
        class="filter-item"
        v-model.trim="searchKey"
        placeholder="单据编码/制单人/规格名称/耗材名称"
      />
      <el-button
        size="small"
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="search"
        >搜索</el-button
      >

        <label class="title"><span class="name">日期查询</span> : </label>
        <el-date-picker
          size="small"
          v-model="start_time"
          prefix-icon="el-icon-date"
          :editable="false"
          style="width: 150px;"
          type="date"
          placeholder="选择日期时间"
          align="right"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          @change="startTimeChange"
        ></el-date-picker>
        <span class="cellLine"> - </span>
        <el-date-picker
          size="small"
          v-model="end_time"
          prefix-icon="el-icon-date"
          :editable="false"
          style="width: 150px;"
          type="date"
          placeholder="选择日期时间"
          align="right"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          @change="endTimeChange"
        ></el-date-picker>

    </div>

    <el-row :gutter="12" style="margin-top: 10px">
      <el-table
        :data="cancelStockDate"
        :class="signAndWeighBoxPatients"
        border
        highlight-current-row
        ref="multipleTable"
        @selection-change="select"
        :row-style="{ color: '#303133' }"
        :header-cell-style="{
          backgroundColor: 'rgb(245, 247, 250)',
          color: '#606266'
        }"
      >
        <el-table-column label="单据编号" align="center" width="200">
          <template slot-scope="scope">
            {{ scope.row.warehouse_out_order_number }}
          </template>
        </el-table-column>

        <el-table-column label="耗材类型" align="center">
          <template slot-scope="scope">
            {{ typeName(scope.row.good_type_id) }}
          </template>
        </el-table-column>

         <el-table-column label="耗材名称" align="center">
          <template slot-scope="scope">
            {{ typeNameOne(scope.row.good_id) }}
          </template>
        </el-table-column>

        <el-table-column label="规格型号" align="center">
          <template slot-scope="scope">
            {{ specificationName(scope.row.good_id) }}
          </template>
        </el-table-column>

        <!-- <el-table-column label="单据类型" align="center">
          <template slot-scope="scope">
            {{ getTypeName(scope.row) }}
          </template>
        </el-table-column> -->

        <el-table-column label="操作时间" align="center">
          <template slot-scope="scope">
            {{ getTime(scope.row.WarehouseOut.warehouse_out_time) }}
          </template>
        </el-table-column>
        <el-table-column label="制单人" align="center">
          <template slot-scope="scope">
            {{ getXuserName(scope.row.WarehouseOut.creater) }}
          </template>
        </el-table-column>
         <el-table-column label="仓库名称" align="center">
          <template slot-scope="scope">
            {{ getStorehouseName(scope.row.storehouse_id) }}
          </template>
        </el-table-column>
        <el-table-column label="出货价" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.is_total == 0 && (orgId == 9919)">{{scope.row.GoodInfo.buy_price}}</span>
            <span v-else>
              <span v-if="scope.row.price > 0"> {{ scope.row.price }} </span>
               <span v-if="scope.row.price == 0"> {{ scope.row.GoodInfo.packing_price }} </span>
            </span>
          </template>
        </el-table-column>
        <el-table-column label="数量" align="center">
          <template slot-scope="scope">
            <span v-if="orgId!=9583">{{ scope.row.count }}</span>
            <span v-if="orgId ==9583">{{getStockCount(scope.row.good_id) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="总价" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.is_total == 0 && scope.row.price > 0">{{getTotal(scope.row.price, scope.row.count)}}</span>
             <span v-if="scope.row.is_total == 0 && scope.row.price == 0">{{getTotal(scope.row.GoodInfo.packing_price, scope.row.count)}}</span>
            <span v-else>{{ scope.row.total }}</span>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[10, 50, 100,1000,1500,3000]"
        :page-size="10"
        background
        style="margin-top:20px;float: right"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-row>
  </div>
</template>

<script>
import { uParseTime } from "@/utils/tools";
import { fetchAllAdminUsers, fetchAllDoctorAndNurse } from "@/api/doctor";
import { deleteCancelStock, GetAllConfig, getStockDetail,getPrintStockGood,getGoodInfoList,getGoodDetailPrintList } from "@/api/stock";

export default {
  name: "stockOutDetail",

  created() {
    var nowDate = new Date();
    var nowYear = nowDate.getFullYear();
    var nowMonth = nowDate.getMonth() + 1;
    var nowDay = nowDate.getDate();
    this.end_time =
      nowYear +
      "-" +
      (nowMonth < 10 ? "0" + nowMonth : nowMonth) +
      "-" +
      (nowDay < 10 ? "0" + nowDay : nowDay);
    nowDate.setMonth(nowDate.getMonth() - 1);
    nowYear = nowDate.getFullYear();
    nowMonth = nowDate.getMonth() + 1;
    nowDay = nowDate.getDate();
    this.start_time =
      nowYear +
      "-" +
      (nowMonth < 10 ? "0" + nowMonth : nowMonth) +
      "-" +
      (nowDay < 10 ? "0" + nowDay : nowDay);
    var start_time =  window.sessionStorage.getItem('start')
    var end_time =  window.sessionStorage.getItem('end')
    if(start_time !=null){
      this.start_time = start_time
    }
    if(end_time!=null){
      this.end_time = end_time
    }
    window.sessionStorage.removeItem('start')
    window.sessionStorage.removeItem('end')
    this.getGoodDetailPrintList()
    this.GetCancelStock();
    this.GetConfigInfo();
    this.fetchAllAdminUsers();
    this.goodUnit = this.$store.getters.good_unit
    var org_id = this.$store.getters.xt_user.org.id
    this.orgId = org_id


  },
  data() {
    return {
      orderTypeArr: [
        { value: 1, label: "耗材入库单" },
        { value: 2, label: "其他入库单" }
      ],
      manufacturer_id: "",
      dealer_id: "",
      order_type:"",

      searchKey: "",
      type: 2,
      page: 1,
      limit: 10,
      checked: false,
      total: 0,
      pageTotal: 0,
      pageSelect: 0,
      adminUserOptions: [],
      multipleSelection: [],
      signAndWeighBoxPatients: "sign-and-weigh-box-patients",
      start_time: "",
      cancelStockDate: [],
      end_time: "",
      goodType: [],
      goodInfo: [],
      manufacturer: [],
      selectedTableData: [],
      dealer: [],
      goodUnit:[],
      tableList:[],
      stockTotal:[],
      goodInfoData:[],
      orgId:"",
      tableData:[],
      tableOut:[],
      tableDataList:[],
      storehouse_id:0,
      houseList:[],
      wareOutList:[],
    };
  },
  methods: {
    changeType: function(val) {
      this.order_type = val;
      this.GetCancelStock();
      this.getGoodDetailPrintList()

    },
    changeManufacturer: function(val) {
      this.manufacturer_id = val;
      this.GetCancelStock();
      this.getGoodDetailPrintList()
    },
    getTypeName: function(row) {
      let name = "";
      const name2 = "";
      if (row.type == 1) {
        name = "耗材出库单";
      } else if (row.type == 2) {
        name = "其他出库单";
      }

      return name;
    },
    specificationName: function(good_info_id) {
      let name = "";
      for (let i = 0; i < this.goodInfo.length; i++) {
        if (this.goodInfo[i].id == good_info_id) {
          name = this.goodInfo[i].specification_name;
        }
      }
      return name;
    },
    typeName: function(good_type_id) {
      let name = "";
      for (let i = 0; i < this.goodType.length; i++) {
        if (this.goodType[i].id == good_type_id) {
          name = this.goodType[i].type_name;
        }
      }
      return name;
    },
    typeNameOne:function(good_id){
       let name = "";
      for (let i = 0; i < this.goodInfo.length; i++) {
        if (this.goodInfo[i].id == good_id) {
          name = this.goodInfo[i].good_name;
        }
      }
      return name;
    },
    search: function() {
      const Params = {
        page: this.page,
        limit: this.limit,
        start_time: this.start_time,
        end_time: this.end_time,
        type: this.type,
        keywords: this.searchKey
      };
      this.cancelStockDate = [];
      this.tableData = []
      getStockDetail(Params).then(response => {
        if (response.data.state == 0) {

          this.$message.error(response.data.msg);
          return false;
        } else {

          this.total = response.data.data.total;
          var total = 0
          for (let i = 0; i < response.data.data.list.length; i++) {
            this.tableData.push(response.data.data.list[i])

            var obj = response.data.data.list[i];
            total += response.data.data.list[i].price * response.data.data.list[i].count
            obj["is_total"] = 0;
            this.cancelStockDate.push(obj);

          }
          this.cancelStockDate.push({
            warehouse_out_order_number: "合计",
            is_total: 1,
            total:total.toFixed(2),
            WarehouseOut: {
              warehouse_out_time: 0
            }
          });

        }
      });
    },
    AddNewOrder: function() {
      this.$router.push({
        name: "cancelStockOrderAdd",
        query: { type: this.type }
      });
    },
    GetCancelStock: function() {
      const Params = {
        page: this.page,
        limit: this.limit,
        start_time: this.start_time,
        end_time: this.end_time,
        type: this.type,
        manufacturer: this.manufacturer_id,
        order_type: this.order_type,
        dealer: this.dealer_id,
        keywords: this.searchKey,
        storehouse_id:this.storehouse_id,
      };
      this.cancelStockDate = [];
      getStockDetail(Params).then(response => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg);
          return false;
        } else {

          this.total = response.data.data.total;
          var obj = {id:0,storehouse_name:"全部"}
          this.houseList = []
          this.houseList.push(obj)
          for(let i=0;i<response.data.data.houseList.length;i++){
           this.houseList.push(response.data.data.houseList[i])
          }
          this.wareOutList =  response.data.data.list
          var total = 0
          for (let i = 0; i < response.data.data.list.length; i++) {
            this.tableData.push(response.data.data.list[i])
            var obj = response.data.data.list[i];
            if(response.data.data.list[i].price > 0){
               total += response.data.data.list[i].price * response.data.data.list[i].count
            }
            if(response.data.data.list[i].price == 0){
               total += response.data.data.list[i].GoodInfo.packing_price * response.data.data.list[i].count
            }

            obj["is_total"] = 0;
            this.cancelStockDate.push(obj);
          }

          this.tableDataList = response.data.data.list

          this.cancelStockDate.push({
            warehouse_out_order_number: "合计",
            is_total: 1,
            total: total.toFixed(2),
            WarehouseOut: {
              warehouse_out_time: 0
            }
          });

        }
      });
    },
    getXuserName(id) {
      if (id <= 0) {
        return "";
      }
      var name = "";
      if (
        this.adminUserOptions == null ||
        typeof this.adminUserOptions.length === "undefined"
      ) {
        return name;
      }
      var leng = this.adminUserOptions.length;
      if (leng == 0) {
        return name;
      }
      for (let index = 0; index < leng; index++) {
        if (this.adminUserOptions[index].id == id) {
          name = this.adminUserOptions[index].name;
          break;
        }
      }
      return name;
    },
    fetchAllAdminUsers() {
      fetchAllAdminUsers().then(response => {
        if (response.data.state == 1) {
          this.adminUserOptions = response.data.data.users;
          var alen = this.adminUserOptions.length;
          for (let index = 0; index < alen; index++) {
            if (this.adminUserOptions[index].user_type == 2) {
              // this.doctorOptions.push(this.adminUserOptions[index]);
            }
          }
        }
      });
    },
    handleSelectionChange: function(val) {
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      this.limit = val;
      this.GetCancelStock();
      // this.getPrintStockGood()
    },
    handleCurrentChange(val) {
      this.page = val;
      this.GetCancelStock();
      // this.getPrintStockGood()
    },
    startTimeChange(val) {
      var time = this.getTimestamp(val) - this.getTimestamp(this.end_time);
      if (time > 0) {
        this.$message.error("结束时间不能小于开始时间");
        this.start_time = "";
      } else {
        window.sessionStorage.removeItem('start')
        this.cancelStockDate = []
        this.GetCancelStock();
        this.getGoodDetailPrintList()

      }
    },
    endTimeChange(val) {
      var time = this.getTimestamp(val) - this.getTimestamp(this.start_time);
      if (time < 0) {
        this.$message.error("结束时间不能小于开始时间");
        this.end_time = "";
      } else {
        window.sessionStorage.removeItem('end')
        this.cancelStockDate = []
        this.GetCancelStock();
        this.getGoodDetailPrintList()
      }
    },
    getTimestamp(time) {
      // 把时间日期转成时间戳
      return new Date(time).getTime() / 1000;
    },
    calculate: function(val) {
      return Math.round(parseFloat(val) * 100) / 100;
    },
    GetConfigInfo: function() {
      GetAllConfig().then(response => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg);
          return false;
        } else {
          this.manufacturer = response.data.data.manufacturer;
          this.dealer = response.data.data.dealer;
          this.goodInfo = response.data.data.goodInfo;
          this.goodType = response.data.data.goodType;
        }
      });
    },
    getManufactuerName: function(manufacturer_id) {
      for (let i = 0; i < this.manufacturer.length; i++) {
        if (this.manufacturer[i].id == manufacturer_id) {
          return this.manufacturer[i].manufacturer_name;
        }
      }
    },
    getDealerName: function(dealer_id) {
      for (let i = 0; i < this.dealer.length; i++) {
        if (this.dealer[i].id == dealer_id) {
          return this.dealer[i].dealer_name;
        }
      }
    },
    handleEdit: function(index, row) {
      this.$router.push({
        name: "cancelStockDetail",
        query: { id: row.id, type: this.type }
      });
    },
    handleDelete: function(index, row) {
      const ids = [];
      ids.push(row.id);
      const idStr = ids.join(",");

      const params = {
        ids: idStr
      };

      this.$confirm("确认删除出库退库单记录?", "删除出库退库单记录", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          deleteCancelStock(params).then(response => {
            if (response.data.state == 0) {
              this.$message.error(response.data.msg);
              return false;
            } else {
              this.$notify({
                title: "成功",
                message: "删除成功",
                type: "success",
                duration: 2000
              });
              for (let i = 0; i < ids.length; i++) {
                for (let y = 0; y < this.cancelStockDate.length; y++) {
                  if (ids[i] == this.cancelStockDate[y].id) {
                    this.cancelStockDate.splice(y, 1);
                  }
                }
              }
            }
          });
        })
        .catch(() => {});
    },
    changeAllSelected: function(val) {
      if (val) {
        this.$refs.multipleTable.toggleAllSelection();
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    select(selection) {
      this.selectedTableData = selection;
    },
    batchDelete() {
      if (this.selectedTableData.length <= 0) {
        this.$message.error("请选择要删除的记录");
        return;
      }
      const ids = [];
      for (let i = 0; i < this.selectedTableData.length; i++) {
        ids.push(this.selectedTableData[i].id);
      }
      const idStr = ids.join(",");
      const params = {
        ids: idStr
      };
      this.$confirm("确认删除出库退库单记录?", "删除出库退库单记录", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          deleteCancelStock(params).then(response => {
            if (response.data.state == 0) {
              this.$message.error(response.data.msg);
              return false;
            } else {
              this.$notify({
                title: "成功",
                message: "删除成功",
                type: "success",
                duration: 2000
              });

              for (let i = 0; i < ids.length; i++) {
                for (let y = 0; y < this.cancelStockDate.length; y++) {
                  if (ids[i] == this.cancelStockDate[y].id) {
                    this.cancelStockDate.splice(y, 1);
                  }
                }
              }
            }
          });
        })
        .catch(() => {});
    },
    getTotal: function(price, total) {
      var m = 0,
        r1,
        r2;
      var s1 = price.toString();
      var s2 = total.toString();
      try {
        m += s1.split(".")[1].length;
      } catch (e) {}
      try {
      } catch (e) {
        m += s2.split(".")[1].length;
      }
      r1 = Number(price.toString().replace(".", ""));
      r2 = Number(total.toString().replace(".", ""));
      return (r1 * r2) / Math.pow(10, m);
    },
    getTime: function(val) {
      if (val == 0) {
        return "";
      } else {
        return uParseTime(val, "{y}-{m}-{d}");
      }
    },
    PrintAction: function() {
      window.sessionStorage.setItem('start',this.start_time)
      window.sessionStorage.setItem('end',this.end_time)
      this.$router.push({
        path: "/stock/print",
        query: {
          type: 2,
          start_time: this.start_time,
          end_time: this.end_time,
          limit:this.limit,
          page:this.page,
        }
      });
    },
    // getPrintStockGood(){
    //   const params = {
    //     start_time:this.start_time,
    //     end_time:this.end_time,
    //     type:3,
    //   }
    //   getPrintStockGood(params).then(response=>{
    //       if(response.data.state == 1){
    //         var stockTotal =  response.data.data.stockTotal

    //         this.stockTotal = stockTotal
    //         var list =  response.data.data.list
    //         this.tableList = []
    //         for(let i=0;i<list.length;i++){
    //           if (list[i].query_warehouseout_info.length > 0) {
    //             this.tableList.push(list[i])
    //           }
    //         }
    //       }
    //   })
    // },
     calCount(stock) {
        let total = 0
        var array = []
        array = stock.query_warehousing_info
        for (let i = 0; i < array.length; i++) {
         total = total + array[i].warehousing_count
        }
        return total
      },

     calTotal(stock) {
       var array = []
       array = stock.query_warehousing_info
        let total_price = 0.0
        for (let i = 0; i < array.length; i++) {
         total_price = total_price + array[i].warehousing_count * array[i].price
        }
        return  Math.floor(total_price * 100) / 100
      },
      calTotalPrice() {
        var amountPrice = 0
        for (let i = 0; i < this.tableList.length; i++) {
          var obj = this.tableList[i]
          var len = 0
          len = obj.query_warehouseout_info.length
          let total_price = 0.0
          for (let a = 0; a < len; a++) {
           total_price = total_price + obj.query_warehouseout_info[a].total_price
          }

          amountPrice = amountPrice +  Math.floor(total_price* 100) / 100
        }
        return Math.floor(amountPrice* 100) / 100
      },
      getTotal: function(price, total) {
        var m = 0, r1, r2
        var s1 = price.toString()
        var s2 = total.toString()
        try {
          m += s1.split('.')[1].length
        } catch (e) {

        }
        try {
        } catch (e) {
          m += s2.split('.')[1].length
        }
        r1 = Number(price.toString().replace('.', ''))
        r2 = Number(total.toString().replace('.', ''))
        return r1 * r2 / Math.pow(10, m)
      },
      unique(arr) {
        const res = new Map();
        return arr.filter((arr) => !res.has(arr.id) && res.set(arr.id, 1));
      },
      getList() {
        let params = {
          page: 1,
          limit: 1000,
          keyword: "",
          is_use:"",
          good_kind:"",
          is_charge: "",
          is_mark:"",
          manufacturer:"",
        }

        getGoodInfoList(params).then(response => {
          if (response.data.state == 0) {
            this.$message.error(response.data.msg)
            return false
          } else {
            this.goodInfoData = []
            for (let i = 0; i < response.data.data.list.length; i++) {
              this.goodInfoData.push(response.data.data.list[i])
            }

          }
        })
      },

    exportList(){
      console.log("shij232333",this.tableOut)
     
       for(let i=0;i<this.tableOut.length;i++){
        this.tableOut[i].index = i+1
        this.tableOut[i].good_name = this.tableOut[i].good_name
        this.tableOut[i].specification_name = this.tableOut[i].specification_name
        this.tableOut[i].packing_unit = this.tableOut[i].packing_unit
        this.tableOut[i].ctime = this.getTime(this.tableOut[i].ctime)
        if(this.orgId == 9919){
          this.tableOut[i].total_price = (this.tableOut[i].count * this.tableOut[i].buy_price).toFixed(2)
          this.tableOut[i].packing_price = this.tableOut[i].buy_price
        }else if(this.orgId == 10265){
          this.tableOut[i].total_price = (this.getMySelfCount(this.tableOut[i].good_id) * this.tableOut[i].retail_price).toFixed(2)
        }else if(this.orgId == 10215){
          this.tableOut[i].total_price = (this.getMySelfCount(this.tableOut[i].good_id) * this.tableOut[i].retail_price).toFixed(2)
        }else if(this.orgId == 10210){
          this.tableOut[i].total_price = (this.getWarehouseOut(this.tableOut[i].good_id) * this.tableOut[i].retail_price).toFixed(2)
        }else if(this.orgId == 9671){
          this.tableOut[i].total_price = (this.getWarehouseOut(this.tableOut[i].good_id) * this.tableOut[i].retail_price).toFixed(2)
        }else if(this.orgId == 9956){
          this.tableOut[i].total_price = (this.getWarehouseOut(this.tableOut[i].good_id) * this.tableOut[i].retail_price).toFixed(2)
        }else if(this.orgId == 10217){
          this.tableOut[i].total_price = (this.getWarehouseOut(this.tableOut[i].good_id) * this.tableOut[i].retail_price).toFixed(2)
        }else if(this.orgId == 10191){
          this.tableOut[i].total_price = (this.getWarehouseOut(this.tableOut[i].good_id) * this.tableOut[i].retail_price).toFixed(2)
        }else if(this.orgId == 10188){
          this.tableOut[i].total_price = (this.getWarehouseOut(this.tableOut[i].good_id) * this.tableOut[i].retail_price).toFixed(2)
        }else{
          this.tableOut[i].total_price = (this.getStockCount(this.tableOut[i].good_id) * this.tableOut[i].retail_price).toFixed(2)
        }

        if(this.orgId  == 10265 || this.orgId ==10215){

         this.tableOut[i].out_count = this.getMySelfCount(this.tableOut[i].good_id)
        }
        if(this.orgId == 10210 || this.orgId == 9671 || this.orgId == 10210 || this.orgId == 9956 || this.orgId == 10217 || this.orgId == 10188 || this.orgId == 10191){
          this.tableOut[i].out_count = this.getWarehouseOut(this.tableOut[i].good_id)
          console.log("out_count232233232332",this.tableOut[i].out_count)
        }
        if(this.orgId!=10265 && this.orgId !=10215 && this.orgId!=10210&&this.orgId!=9671 && this.orgId!=9956&& this.orgId!=10217 && this.orgId!=10188 && this.orgId!=10191){
          this.tableOut[i].out_count = this.getStockCount(this.tableOut[i].good_id)
        }
       }
       import('@/vendor/Export2Excel').then(excel => {
       const tHeader = ['序号','耗材名称', '规格型号', '单位','数量','出货价','总价','出库时间','备注']

       const filterVal = ['index','good_name', 'specification_name', 'packing_unit','out_count','packing_price','total_price','ctime','remark']

       const data = this.formatJson(filterVal, this.tableOut)


        excel.export_json_to_excel({
           header: tHeader,
           data,
           filename: '耗材出库明细'
         })
          this.downloadLoading = false
        })
     },
     exportListDetail(){

        var obj = {index:"合计",total_price:0}
        var total = 0
        for(let i=0;i<this.tableDataList.length;i++){
          this.tableDataList[i].index = i + 1
          this.tableDataList[i].good_type_name = this.typeName(this.tableDataList[i].good_type_id)
          this.tableDataList[i].good_name = this.typeNameOne(this.tableDataList[i].good_id)
          this.tableDataList[i].specification_name = this.specificationName(this.tableDataList[i].good_id)
          this.tableDataList[i].time = this.getTime(this.tableDataList[i].WarehouseOut.warehouse_out_time)
          this.tableDataList[i].user_name = this.getXuserName(this.tableDataList[i].WarehouseOut.creater)
          this.tableDataList[i].out_count = this.tableDataList[i].count
          if(this.orgId == 9919){
             this.tableDataList[i].total_price = (this.tableDataList[i].count * this.tableDataList[i].GoodInfo.buy_price).toFixed(2)
             total += this.tableDataList[i].count * this.tableDataList[i].buy_price
          }
          if(this.orgId != 9919){
            this.tableDataList[i].total_price = (this.tableDataList[i].count * this.tableDataList[i].price).toFixed(2)
            total += this.tableDataList[i].count * this.tableDataList[i].price
          }

        }
        obj.total_price = total.toFixed(2)

        this.tableDataList.push(obj)
       import('@/vendor/Export2Excel').then(excel => {
       const tHeader = ['序号','单据编号', '耗材类型', '耗材名称','规格型号','操作时间','制单人','出货价','数量','总价']
       const filterVal = ['index','warehouse_out_order_number', 'good_type_name', 'good_name','specification_name','time','user_name','price','out_count','total_price']

       const data = this.formatJson(filterVal, this.tableDataList)


        excel.export_json_to_excel({
           header: tHeader,
           data,
           filename: '耗材出库明细'
         })
          this.downloadLoading = false
        })
     },
     formatJson(filterVal, jsonData) {
        return jsonData.map(v => filterVal.map(j => v[j]));
     },
     getUnit(id){
      var name = ""
      for(let i=0;i<this.goodUnit.length;i++){
       if(this.goodUnit[i].id == id){
          name = this.goodUnit[i].name
         }
       }
      return name
     },
    getTotalPrice(){
       var total_price = 0
       for(let i=0;i<this.tableList.length;i++){
         total_price += this.getStockCount(this.tableList[i].id) * this.tableList[i].retail_price
       }
       return total_price
     },

     getGoodDetailPrintList(){
        const params = {
          start_time:this.start_time,
          end_time:this.end_time,
          type:2,
        }
      this.tableOut = []
      getGoodDetailPrintList(params).then(response=>{
        if(response.data.state == 1){
          var list = response.data.data.list

          this.tableOut = list
          var stockTotal = response.data.data.stockTotal

          this.stockTotal = stockTotal
        }
      })
     },
     getStockCount(id){

        var count = ""
        for(let i=0;i<this.stockTotal.length;i++){
            if(id == this.stockTotal[i].good_id){
              count = this.stockTotal[i].count
            }
        }
        return count
    },
    getMySelfCount(good_id){
       var total = 0
       for(let i=0;i<this.tableOut.length;i++){
         if(good_id == this.tableOut[i].good_id){
            total+= this.tableOut[i].count
         }
       }
       return total
     },
     getWareOutTotalSix(){
       var total = 0
       for(let i=0;i<this.tableOut.length;i++){
         total+= this.getMySelfCount(this.tableOut[i].good_id) * this.tableOut[i].packing_price
       }
       return total
     },
    getStorehouseName(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
         }
       }
       if(storehouse_name == "全部"){
          return ""
       }else{
         return storehouse_name
       }
     },
     changeHouseList(){
       this.houseList = []
       this.GetCancelStock()
     },
     getWarehouseOut(good_id){
      var total = 0
      for(let i=0;i<this.wareOutList.length;i++){
         if(this.wareOutList[i].good_id == good_id){
            total += this.wareOutList[i].count
         }
      }
      return total
    }
  }
};
</script>

<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;
  }
}

.edit_separater {
  border-top: 1px solid rgb(233, 233, 233);
  margin-top: 15px;
  margin-bottom: 15px;
}
</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;
}
</style>
