<template>
  <div class="main-contain">
     <div class="app-container "
     style="padding-left:0px;margin:0px;" v-loading="loading"
        element-loading-text="拼命加载中">
        <div style="justify-content: space-between;margin: 0px 0 12px 0;display: flex;align-items: center;">
         <div>
          <span style="font-size:14px;color:#606266">操作时间:</span>
          <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"
            :picker-options="pickerOptions"
            :clearable="false"
           ></el-date-picker>
            <span>-</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"
              :picker-options="pickerOptions"
              :clearable="false"
          ></el-date-picker>
          <el-button  type="primary" icon="el-icon-search" @click="getDrugQuery">查询</el-button>
          <span style="font-size:14px;color:#606266">药品类型:</span>
          <el-select v-model="good_type" style="width:200px;margin-right:10px;" placeholder="请选择"
          filterable
           @change="changeGoodTypeName">
            <el-option
              v-for="item in drugTypeList"
              :key="item.value"
              :label="item.name"
              :value="item.value">
            </el-option>
          </el-select>
          <el-input v-model="keyword" style="width:200px" placeholder="请输入药品名称或生产厂商" ></el-input>
          <el-button  type="primary" icon="el-icon-search" @click="seach">搜索</el-button>
         </div>
         <div>
          <!-- <el-button  type="primary" @click="toOverCount">调试</el-button> -->
           <el-button  type="primary" @click="toPrint">打印</el-button>
           <el-button  type="primary" @click="exportList">导出</el-button>
         </div>
        </div>

           <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">
                 {{getDrugTypeName(scope.row.drug_type)}}
              </template>
            </el-table-column>
            <el-table-column label="药品名称" align="center">
              <template slot-scope="scope">
                 {{scope.row.drug_name}}
              </template>
            </el-table-column>
            <el-table-column label="规格&单位" align="center">
                <template slot-scope="scope">
                  {{scope.row.dose}}{{scope.row.dose_unit}}*{{scope.row.min_number}}{{scope.row.min_unit}}/{{scope.row.max_unit}}
                </template>
            </el-table-column>
            <el-table-column label="生产厂商" align="center">
              <template slot-scope="scope">
                 {{getManufacturName(scope.row.manufacturer)}}
              </template>
            </el-table-column>
            <el-table-column label="经销商" align="center">
              <template slot-scope="scope">
                 {{getDearName(scope.row.dealer)}}
              </template>
            </el-table-column>
            <el-table-column label="期初结余" align="center">

                 <el-table-column prop="drugIn" label="数量" width="100" align="center">

                 </el-table-column>

                <el-table-column prop="drugInMoney" label="进货金额" width="100" align="center">

                </el-table-column>
                <el-table-column prop="drugSaleMoney" label="销售金额" width="100" align="center">

                </el-table-column>

            </el-table-column>
            <el-table-column label="本期增加" align="center">

                <el-table-column prop="drugAdd" label="数量" width="100" align="center">

                </el-table-column>

                <el-table-column prop="drugAddPrice" label="进货金额" width="100" align="center">

                </el-table-column>
                <el-table-column  prop="drugAddSalePrice" label="销售金额"  width="100" align="center">
                </el-table-column>

            </el-table-column>

            <el-table-column label="本期减少" align="center">
               <el-table-column prop="drugOut" label="数量" width="100" align="center">
                </el-table-column>
                <el-table-column  prop="drugOutPrice"  label="进货金额" width="100" align="center">
                </el-table-column>
                <el-table-column prop="drugOutSalePrice" label="销售金额" width="100" align="center">
                </el-table-column>
            </el-table-column>

            <el-table-column label="期末结余" align="center">
              <el-table-column prop="overDrug" label="数量" width="100" align="center">
              </el-table-column>
              <el-table-column prop="overDrugPrice" label="进货金额" width="100" align="center">
              </el-table-column>
              <el-table-column prop="oveDrugSaleMoney" label="销售金额" width="100" align="center">
              </el-table-column>
            </el-table-column>


          </el-table>
           <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :page-sizes="[10, 50, 100,200,300,400,500,1000]"
            :page-size="10"
            background
            align="right"
            style="margin-top:20px;"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          >
            </el-pagination>
     </div>





  </div>
</template>
<script>
import { getStorehouseList,getPurchaseNewDrugQuery,getDrugOverCount } from "@/api/drug/drug"
const moment = require('moment')
import { uParseTime } from '@/utils/tools'
export default {

  data(){
    return{
     tableList:[],
     goodList:[
      {id:1,name:"全部药品"},
      {id:2,name:"库存预警"},
     ],
     houseList:[],
     storehouse_id:0,
     good_type:0,
     multipleSelection: [],
     signAndWeighBoxPatients: "sign-and-weigh-box-patients",
     manufacturerList:[],
     limit:10,
     page:1,
     total:0,
     keyword:"",
     drugTypeList:[],
     start_time:"",
     end_time:"",
     countList:[],
     outCountList:[],
     autoCountList:[],
     cancelCountList:[],
     org_id:this.$store.getters.xt_user.org_id,
     dialogVisible:false,
     start_first_time:"",
     end_first_time:"",
     tableData:[],
     good_id:0,
     patientList:[],
     good_name:"",
     specification_name:"",
     loading:false,
     pickerOptions:{ //禁用当前日期之前的日期
           disabledDate(v) {
            return v.getTime() < 1667491200000
          },
      },
     dealerList:[]
    }

  },
  methods:{
    changeStorehouseName(){

    },
    changeGoodTypeName(){
      this.drugTypeList = []
      this.getlist()
    },
    getStorehouseList(){
      getStorehouseList().then(response=>{
         if(response.data.state == 1){
           var houseList = response.data.data.list
           var obj = {id:0,storehouse_name:"全部"}
           this.houseList.push(obj)
           for(let i=0;i<houseList.length;i++){
             this.houseList.push(houseList[i])
           }
           this.manufacturerList = response.data.data.manufacturerList

           this.patientList = response.data.data.patientList
           this.dealerList = response.data.data.dealerList
         }
      })
    },
    getlist(){
        this.loading = true
        var params = {
          good_type:this.good_type,
          keyword:this.keyword,
          page:this.page,
          limit:this.limit,
          start_time:this.start_time,
          end_time:this.end_time,
        }
      getPurchaseNewDrugQuery(params).then(response=>{
         if(response.data.state == 1){
            this.loading = false
            var list = response.data.data.list
            for (let i = 0; i < list.length; i++) {

              //期初结余入库
              if(list[i].DrugWarehouseInfoStart!=null && list[i].DrugWarehouseInfoStart.length > 0){
                for(let j=0;j<list[i].DrugWarehouseInfoStart.length;j++){
                  if(list[i].max_unit == list[i].DrugWarehouseInfoStart[j].max_unit){
                     list[i].DrugWarehouseInfoStart[j].count =list[i].min_number * list[i].DrugWarehouseInfoStart[j].count
                  }
                }
              }

             //期初结余出库
              if(list[i].DrugWarehouseOutInfoStart!=null && list[i].DrugWarehouseOutInfoStart.length>0){
                for(let j=0;j<list[i].DrugWarehouseOutInfoStart.length;j++){
                  if(list[i].max_unit == list[i].DrugWarehouseOutInfoStart[j].max_unit){
                    list[i].DrugWarehouseOutInfoStart[j].count =  list[i].DrugWarehouseOutInfoStart[j].count*list[i].min_number
                  }
                }
              }

              //期初结余退库
               if(list[i].WareStartStockCancelInfo!=null && list[i].WareStartStockCancelInfo.length>0){
                for(let j=0;j<list[i].WareStartStockCancelInfo.length;j++){
                  if(list[i].max_unit == list[i].WareStartStockCancelInfo[j].max_unit){
                    list[i].WareStartStockCancelInfo[j].count =  list[i].WareStartStockCancelInfo[j].count*list[i].min_number
                  }
                }
              }


              //期末结余入库
              if(list[i].DrugWarehouseInfoEnd!=null && list[i].DrugWarehouseInfoEnd.length > 0){
                for(let j=0;j<list[i].DrugWarehouseInfoEnd.length;j++){
                   if(list[i].max_unit == list[i].DrugWarehouseInfoEnd[j].max_unit){
                     list[i].DrugWarehouseInfoEnd[j].count = list[i].min_number * list[i].DrugWarehouseInfoEnd[j].count
                   }
                }
              }

              //期末结余出库
               if(list[i].DrugWarehouseOutInfoEnd!=null && list[i].DrugWarehouseOutInfoEnd.length>0){
                for(let j=0;j<list[i].DrugWarehouseOutInfoEnd.length;j++){
                  if(list[i].max_unit == list[i].DrugWarehouseOutInfoEnd[j].max_unit){
                    list[i].DrugWarehouseOutInfoEnd[j].count =  list[i].DrugWarehouseOutInfoEnd[j].count*list[i].min_number
                  }
                }
              }

              //期末结余退库
               if(list[i].WareEndStockCancelInfo!=null && list[i].WareEndStockCancelInfo.length>0){
                for(let j=0;j<list[i].WareEndStockCancelInfo.length;j++){
                  if(list[i].max_unit == list[i].WareEndStockCancelInfo[j].max_unit){
                    list[i].WareEndStockCancelInfo[j].count =  list[i].WareEndStockCancelInfo[j].count*list[i].min_number
                  }
                }
              }

              //期中增加
              if(list[i].DrugWarehouseInfoStartEnd!=null && list[i].DrugWarehouseInfoStartEnd.length > 0){
                for(let j=0;j<list[i].DrugWarehouseInfoStartEnd.length;j++){
                   if(list[i].max_unit == list[i].DrugWarehouseInfoStartEnd[j].max_unit){
                     list[i].DrugWarehouseInfoStartEnd[j].count =list[i].min_number * list[i].DrugWarehouseInfoStartEnd[j].count
                   }
                }
              }

              //期中减少
              if(list[i].DrugWarehouseOutInfoStartEnd!=null && list[i].DrugWarehouseOutInfoStartEnd.length > 0){
                for(let j=0;j<list[i].DrugWarehouseOutInfoStartEnd.length;j++){
                   if(list[i].max_unit == list[i].DrugWarehouseOutInfoStartEnd[j].max_unit){
                     list[i].DrugWarehouseOutInfoStartEnd[j].count =list[i].min_number * list[i].DrugWarehouseOutInfoStartEnd[j].count
                   }
                }
              }

              //期中退库
              if(list[i].WareStartEndStockCancelInfo!=null && list[i].WareStartEndStockCancelInfo.length > 0){
                for(let j=0;j<list[i].WareStartEndStockCancelInfo.length;j++){
                   if(list[i].max_unit == list[i].WareStartEndStockCancelInfo[j].max_unit){
                     list[i].WareStartEndStockCancelInfo[j].count =list[i].min_number * list[i].WareStartEndStockCancelInfo[j].count
                   }
                }
              }



              //期初盘盈
              if(list[i].WareStartStockInventoryProfit!=null && list[i].WareStartStockInventoryProfit.length > 0){
                for(let j=0;j<list[i].WareStartStockInventoryProfit.length;j++){
                  if(list[i].max_unit == list[i].WareStartStockInventoryProfit[j].max_unit){
                     list[i].WareStartStockInventoryProfit[j].count = list[i].WareStartStockInventoryProfit[j].count * list[i].min_number
                  }
                }
              }

              //期初盘亏
              if(list[i].WareStartStockInventoryLosses!=null && list[i].WareStartStockInventoryLosses.length > 0){
                 for(let j=0;j<list[i].WareStartStockInventoryLosses.length;j++){
                   if(list[i].max_unit == list[i].WareStartStockInventoryLosses[j].max_unit){
                      list[i].WareStartStockInventoryLosses.count = list[i].WareStartStockInventoryLosses[j].count * list[i].min_number
                   }
                 }
              }



             //期中盘盈
             if(list[i].WareStartEndStockInventoryProfit!=null && list[i].WareStartEndStockInventoryProfit.length > 0){
                for(let j=0;j<list[i].WareStartEndStockInventoryProfit.length;j++){
                  if(list[i].max_unit == list[i].WareStartEndStockInventoryProfit[j].max_unit){
                    list[i].WareStartEndStockInventoryProfit[j].count = list[i].WareStartEndStockInventoryProfit[j].count * list[i].min_number
                  }
                }
             }

             //期中盘亏
             if(list[i].WareStartEndStockInventoryLosses!=null && list[i].WareStartEndStockInventoryLosses.length > 0){
               for(let j=0;j<list[i].WareStartEndStockInventoryLosses.length;j++){
                 if(list[i].max_unit == list[i].WareStartEndStockInventoryLosses[j].max_unit){
                    list[i].WareStartEndStockInventoryLosses[j].count = list[i].WareStartEndStockInventoryLosses[j].count * list[i].min_number
                 }
               }
             }
             //期末盘盈
             if(list[i].WareEndStockInventoryProfit!=null && list[i].WareEndStockInventoryProfit.length >0){
               for(let j=0;j<list[i].WareEndStockInventoryProfit.length;j++){
                 if(list[i].max_unit == list[i].WareEndStockInventoryProfit[j].max_unit){
                    list[i].WareEndStockInventoryProfit[j].count = list[i].WareEndStockInventoryProfit[j].count * list[i].min_number
                 }
               }
             }
             //期末盘亏
             if(list[i].WareEndStockInventoryLosses!=null && list[i].WareEndStockInventoryLosses.length > 0){
               for(let j=0;j<list[i].WareEndStockInventoryLosses.length;j++){
                if(list[i].max_unit == list[i].WareEndStockInventoryLosses[j].max_unit){
                   list[i].WareEndStockInventoryLosses[j].count = list[i].WareEndStockInventoryLosses[j].count * list[i].min_number
                }
               }
             }

            if(this.org_id !=10210 && this.org_id!=0 && this.org_id !=10402 && this.org_id !=10215){

               //  新版
             if(list[i].new_drug_in_flow_info!=null && list[i].new_drug_in_flow_info.length>0){
                for(let j=0;j<list[i].new_drug_in_flow_info.length;j++){
                   if(list[i].max_unit == list[i].new_drug_in_flow_info[j].max_unit){
                        list[i].new_drug_in_flow_info[j].count = list[i].new_drug_in_flow_info[j].count * list[i].min_number
                   }
                }
             }

             if(list[i].new_drug_cancel_flow_info!=null && list[i].new_drug_cancel_flow_info.length>0){
                for(let j=0;j<list[i].new_drug_cancel_flow_info.length;j++){
                   if(list[i].max_unit == list[i].new_drug_cancel_flow_info[j].max_unit){
                        list[i].new_drug_cancel_flow_info[j].count = list[i].new_drug_cancel_flow_info[j].count * list[i].min_number
                   }
                }
             }

             if(list[i].new_drug_no_profit_flow_info!=null && list[i].new_drug_no_profit_flow_info.length>0){
                for(let j=0;j<list[i].new_drug_no_profit_flow_info.length;j++){
                   if(list[i].max_unit == list[i].new_drug_no_profit_flow_info[j].max_unit){
                        list[i].new_drug_no_profit_flow_info[j].count = list[i].new_drug_no_profit_flow_info[j].count * list[i].min_number
                   }
                }
             }

             if(list[i].new_drug_out_flow_info!=null && list[i].new_drug_out_flow_info.length>0){
                for(let j=0;j<list[i].new_drug_out_flow_info.length;j++){
                   if(list[i].max_unit == list[i].new_drug_out_flow_info[j].max_unit){
                        list[i].new_drug_out_flow_info[j].count = list[i].new_drug_out_flow_info[j].count * list[i].min_number
                   }
                }
             }

             if(list[i].new_drug_profit_flow_info!=null && list[i].new_drug_profit_flow_info.length>0){
                for(let j=0;j<list[i].new_drug_profit_flow_info.length;j++){
                   if(list[i].max_unit == list[i].new_drug_profit_flow_info[j].max_unit){
                        list[i].new_drug_profit_flow_info[j].count = list[i].new_drug_profit_flow_info[j].count * list[i].min_number
                   }
                }
             }


            }
           
            }

            console.log("list23323223322332232323322323wode",list)
            for(let i=0;i<list.length;i++){
              list[i].last_price_in = 0
              list[i].drugAddOne= 0
              list[i].drugOutOne =0
              
              if(this.org_id ==10210  || this.org_id ==10402 || this.org_id ==10215 || this.org_id == 0 || this.org_id ==10191){
                 list[i].drugIn = this.GetDrugStartFlow(list[i].DrugStatFlow.over_count,list[i].min_number,list[i].min_unit,list[i].max_unit) 
              }else{
                list[i].drugIn = this.GetInitStartFlow(list[i].new_drug_in_flow_info,list[i].new_drug_profit_flow_info,list[i].new_drug_out_flow_info,list[i].new_drug_no_profit_flow_info,list[i].new_drug_cancel_flow_info,list[i].min_number,list[i].min_unit,list[i].max_unit)
              }
             

           
              list[i].over_count_one = this.GetInitStartFlowOne(list[i].new_drug_in_flow_info,list[i].new_drug_profit_flow_info,list[i].new_drug_out_flow_info,list[i].new_drug_no_profit_flow_info,list[i].new_drug_cancel_flow_info,list[i].min_number,list[i].min_unit,list[i].max_unit) 
              list[i].drugInMoney = list[i].last_price
              if(this.org_id == 0 || this.org_id == 10697){
                list[i].drugSaleMoney =  (list[i].over_count_one * list[i].last_price).toFixed(2)
              }else{
                list[i].drugSaleMoney = "/"
              }
             

              list[i].drugAdd = this.drugAddInfo(list[i].DrugWarehouseInfoStartEnd,list[i].min_number,list[i].min_unit,list[i].max_unit,list[i].WareStartEndStockInventoryProfit)
              list[i].drugAddOne = this.drugAddInfoOne(list[i].DrugWarehouseInfoStartEnd,list[i].min_number,list[i].min_unit,list[i].max_unit,list[i].WareStartEndStockInventoryProfit)
              
              if(this.org_id == 0 || this.org_id == 10697){
                 list[i].drugAddPrice = list[i].last_price
                 list[i].drugAddSalePrice = (list[i].last_price *list[i].drugAddOne).toFixed(2)
              }else{
                list[i].drugAddPrice = "/"
                list[i].drugAddSalePrice = "/"
              }
             

              list[i].drugOut=  this.getDrugOut(list[i].DrugWarehouseOutInfoStartEnd,list[i].min_number,list[i].min_unit,list[i].max_unit,list[i].WareStartEndStockInventoryLosses,list[i].WareStartEndStockCancelInfo)
              list[i].drugOutOne =this.getDrugOutOne(list[i].DrugWarehouseOutInfoStartEnd,list[i].min_number,list[i].min_unit,list[i].max_unit,list[i].WareStartEndStockInventoryLosses,list[i].WareStartEndStockCancelInfo)
           
              if(this.org_id == 0 || this.org_id == 10697){
                list[i].drugOutPrice = list[i].retail_price
                list[i].drugOutSalePrice = (list[i].drugOutOne * list[i].retail_price).toFixed(2)
              }else{
                list[i].drugOutPrice = "/"
                list[i].drugOutSalePrice = "/"
              }
            

         
            if(this.org_id == 10265 || this.org_id ==10210 || this.org_id==10402 || this.org_id ==10215){
              list[i].overDrug = this.GetDrugEndFlow(list[i].DrugEndFlow.over_count,list[i].min_number,list[i].min_unit,list[i].max_unit)
            }else{
              list[i].overDrug = this.GetDrugOver(list[i].over_count_one,list[i].drugAddOne,list[i].drugOutOne,list[i].min_number,list[i].min_unit,list[i].max_unit)
            }
             
            list[i].overDrugOne = this.GetDrugOverOne(list[i].over_count_one,list[i].drugAddOne,list[i].drugOutOne,list[i].min_number,list[i].min_unit,list[i].max_unit)
            if(this.org_id == 0 || this.org_id == 10697){
                list[i].overDrugPrice = list[i].retail_price
                list[i].oveDrugSaleMoney = (list[i].overDrugOne * list[i].retail_price).toFixed(2)
            }else{
             list[i].overDrugPrice = "/"
             list[i].oveDrugSaleMoney = "/"
            }
           
            }
            this.tableList = list;
            this.total = response.data.data.total
            this.manufacturerList = response.data.data.manufacturerList
            var drugTypeList = response.data.data.drugTypeList
            var obj = {value:0,name:"全部"}
            this.drugTypeList.push(obj)
            for(let i=0;i<drugTypeList.length;i++){
               this.drugTypeList.push(drugTypeList[i])
            }

         }
      })
    },
    getManufacturName(id){
      var manufacturer_name = ""
      for(let i=0;i<this.manufacturerList.length;i++){
        if(id == this.manufacturerList[i].id){
           manufacturer_name = this.manufacturerList[i].manufacturer_name
        }
      }
      return manufacturer_name
    },
    handleSizeChange(val) {
      this.drugTypeList = []
      this.limit = val;
      this.getlist()
    },
    handleCurrentChange(val) {
      this.page = val;
      this.drugTypeList = []
      this.getlist()
    },
   seach(){
    this.drugTypeList = []
    this.houseList= []
    this.getlist()
   },
   getDrugTypeName(id){
     var type_name = ""
     for(let i=0;i<this.drugTypeList.length;i++){
       if(id == this.drugTypeList[i].value){
         type_name = this.drugTypeList[i].name
       }
     }
     return type_name
   },
   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
   },
  getTime(val) {
    if(val < 0){
      return ""
    }
   if(val == ""){
     return ""
   }else {
    return uParseTime(val, '{y}-{m}-{d}')
   }
   },
  getName(id){
    var name = ""
    for(let i=0;i<this.patientList.length;i++){
      if(id == this.patientList[i].id){
        name = this.patientList[i].name
      }
    }
    return name
  },
  endTimeChange(){
     this.drugTypeList = []
    this.getlist()
  },
  startTimeChange(){
     this.drugTypeList = []
    this.getlist()
  },
  getDrugWarehouseInfoOne(arr,min_number,min_unit,max_unit,arr2,arr3,arr4,arr5){
   var total = 0
   var totalOne =0
   var totalTwo = 0
   var totalthree= 0
   var totalfour = 0
   var totalfive = 0
   var max_str = "";
   var min_str = "";
   if(arr!=null && arr.length > 0){
    for(let i=0;i<arr.length;i++){
      totalOne += arr[i].count
     }
   }
   if(arr2!=null && arr2.length > 0){
    for(let i=0;i<arr2.length;i++){
      totalTwo += arr2[i].count
     }
   }
   if(arr3!=null && arr3.length > 0){
    for(let i=0;i<arr3.length;i++){
      totalthree += arr3[i].count
     }
   }
  if(arr4!=null && arr4.length > 0){
    for(let i=0;i<arr4.length;i++){
      totalfour += arr4[i].count
     }
  }

  if(arr5!=null && arr5.length > 0){
    for(let i=0;i<arr5.length;i++){
      totalfive += arr5[i].count
     }
  }
  // console.log("totalONE223323232323232",totalOne)
  // console.log("totalTwo2oo2o32o3o32o23",totalTwo)
  // console.log("totalfive",totalfive)
  // console.log("00-------------------------")
  total = totalOne - totalTwo + totalthree - totalfour + totalfive
  if (total < min_number) {
     min_str = total + min_unit;
   }
  if (total == 0) {
     min_str = "";
     max_str = "";
  }
  if (total >= min_number) {
    if (parseInt(total / min_number) != 0) {
      max_str = parseInt(total / min_number) + max_unit;
    }
    if (total % min_number != 0) {
      min_str = (total % min_number) + min_unit;
    }
   }
  console.log("max_str",max_str)
  console.log("min_str",min_str)
  if(max_str == "" && min_str == ""){
    return "0"
  }else{
   return max_str + min_str
  }


  },
  getDrugWarehouseInfo(arr,arr4,min_number,min_unit,max_unit,arr2,arr3,arr5){
   var total = 0
   var total_one= 0
   var total_two = 0
   var total_three = 0
   var total_four = 0
   var total_five = 0
   var max_str = "";
   var min_str = "";
   if(arr!=null && arr.length > 0){
    for(let i=0;i<arr.length;i++){
      total_one += arr[i].count
     }
   }
   if(arr4!=null && arr4.length > 0){
    for(let i=0;i<arr4.length;i++){
      total_four += arr4[i].count
     }
   }
   if(arr2!=null && arr2.length > 0){
     for(let i=0;i<arr2.length;i++){
       total_two+= arr2[i].count
     }
   }
   if(arr3!=null && arr3.length >0){
     for(let i=0;i<arr3.length;i++){
       total_three +=arr3[i].count
     }
   }

    if(arr5!=null && arr5.length >0){
     for(let i=0;i<arr5.length;i++){
       total_five +=arr5[i].count
     }
   }

  total = total_one - total_four +total_two - total_three + total_five
  if(total < 0){
    total = 0
  }
  if (total < min_number) {
     min_str = total + min_unit;
   }
  if (total == 0) {
     min_str = "";
     max_str = "";
  }
  if (total >= min_number) {
    if (parseInt(total / min_number) != 0) {
      max_str = parseInt(total / min_number) + max_unit;
    }
    if (total % min_number != 0) {
      min_str = (total % min_number) + min_unit;
    }
   }
   if(max_str == "" && min_str == ""){
     return "0"
   }else{
     return max_str + min_str;
   }

  },
  getDrugWarehouseInfoStart(arr,min_number,min_unit,max_unit,outArr){
   var total = 0
   var add_total = 0
   var out_total = 0
   var max_str = "";
   var min_str = "";
   if(arr!=null &&arr.length > 0){
    for(let i=0;i<arr.length;i++){
      add_total += arr[i].warehousing_count
     }
   }
   if(outArr.length > 0){
     for(let i=0;i<outArr.length;i++){
      out_total+= outArr[i].count
     }
   }
   total = add_total - out_total
  if (total < min_number) {
    min_str = total + min_unit;
   }
  if (total == 0) {
     min_str = "";
     max_str = "";
  }
  if (total >= min_number) {
    if (parseInt(total / min_number) != 0) {
      max_str = parseInt(total / min_number) + max_unit;
    }
    if (total % min_number != 0) {
      min_str = (total % min_number) + min_unit;
    }
   }
  return max_str + min_str;

  },
 getDrugWarehouseInfoMoneyStart(arr,min_number,min_unit,max_unit,last_price,outArr){
   var total = 0
   var min_str = 0
   var max_str = 0
   var addTotal = 0
   var outTotal = 0
   var total_price = 0
   if(arr.length > 0){
    for(let i=0;i<arr.length;i++){
      addTotal += arr[i].warehousing_count
     }
   }
   if(outArr.length > 0){
     for(let i=0;i<outArr.length;i++){
      outTotal += outArr[i].count
     }
   }

   total = addTotal - outTotal
   if (total < min_number) {
      min_str = total
   }
   if (total >= min_number) {
    if (parseInt(total / min_number) != 0) {
      max_str = parseInt(total / min_number);
    }
    if (total % min_number != 0) {
      min_str = (total % min_number);
    }
   }

   total_price = (max_str * last_price + min_str*(last_price/min_number)).toFixed(2)

   return total_price
  },
  getDrugWarehouseInfoMoney(arr,min_number,min_unit,max_unit,last_price){
   var total = 0
   var min_str = 0
   var max_str = 0
   var total_price = 0
   if(arr.length > 0){
    for(let i=0;i<arr.length;i++){
      total += arr[i].stock_max_number + arr[i].stock_min_number
     }
   }
   if (total < min_number) {
      min_str = total
   }
   if (total >= min_number) {
    if (parseInt(total / min_number) != 0) {
      max_str = parseInt(total / min_number);
    }
    if (total % min_number != 0) {
      min_str = (total % min_number);
    }
   }

   total_price = (max_str * last_price + min_str*(last_price/min_number)).toFixed(2)

   return total_price
  },
  getDrugWarehouseInfoStockAdd(arr,min_number,min_unit,max_unit){

   var total = 0
   var max_str = "";
   var min_str = "";
   if(arr.length > 0){
    for(let i=0;i<arr.length;i++){
      total += arr[i].warehousing_count
     }
   }
  if (total < min_number) {
    min_str = total + min_unit;
   }
  if (total == 0) {
     min_str = "";
     max_str = "";
  }
  if (total >= min_number) {
    if (parseInt(total / min_number) != 0) {
      max_str = parseInt(total / min_number) + max_unit;
    }
    if (total % min_number != 0) {
      min_str = (total % min_number) + min_unit;
    }
   }
  return max_str + min_str;
  },
  getDrugWarehouseInfoaddMoney(arr,min_number,min_unit,max_unit,last_price){
   var total = 0
   var min_str = 0
   var max_str = 0
   var total_price = 0
   if(arr.length > 0){
    for(let i=0;i<arr.length;i++){
      total += arr[i].warehousing_count
     }
   }
   if (total < min_number) {
      min_str = total
   }
   if (total >= min_number) {
    if (parseInt(total / min_number) != 0) {
      max_str = parseInt(total / min_number);
    }
    if (total % min_number != 0) {
      min_str = (total % min_number);
    }
   }

   total_price = (max_str * last_price + min_str*(last_price/min_number)).toFixed(2)
   return total_price
  },
  getDrugInMoneyOne(arr,min_number,min_unit,max_unit,arr2,arr3,arr4,arr5){

   var totalOne = 0
   var totalTwo =0
   var total_three = 0
   var total_four = 0
   var totalFive = 0
   var total_price = 0
   if(arr!=null&&arr.length > 0){
    for(let i=0;i<arr.length;i++){
      totalOne += (arr[i].count/min_number*arr[i].price) + arr[i].count*(arr[i].price%min_number)
     }
   }

  if(arr2!=null&&arr2.length > 0){
    for(let i=0;i<arr2.length;i++){
      totalTwo += ((arr2[i].count/min_number) * arr2[i].price) + ((arr2[i].count%min_number)*(arr2[i].price/min_number))
     }
   }


  if(arr3!=null&&arr3.length > 0){
    for(let i=0;i<arr3.length;i++){
      total_three+=arr3[i].count* arr3[i].xt_drug_warehouse_info.retail_price
     }
   }

  if(arr4!=null&&arr4.length > 0){
    for(let i=0;i<arr4.length;i++){
      total_four+=arr4[i].count * arr4[i].xt_drug_warehouse_info.retail_price
     }
   }

  if(arr5!=null&&arr5.length > 0){
    for(let i=0;i<arr5.length;i++){
      totalFive += ((arr5[i].count/min_number) * arr5[i].price) + ((arr5[i].count%min_number)*(arr5[i].price/min_number))
     }
   }

   total_price =(totalOne - totalTwo + total_three - total_four + totalFive).toFixed(2)
 
   if(total_price >0){
    return total_price
   }else{
    return "0.00"
   }

  },
  getDrugInMoney(arr,arr4,min_number,min_unit,max_unit,arr2,arr3,arr5){

   var total_price = 0
   var total_one_price = 0
   var total_two_price = 0
   var total_four_price =0
   var total_three_price = 0
   var total_five_price = 0
   if(arr!=null&&arr.length > 0){
    for(let i=0;i<arr.length;i++){
      total_one_price += arr[i].count * (arr[i].price/min_number) + arr[i].count * (arr[i].price%min_number)
     }
   }

   if(arr4!=null && arr4.length > 0){
     for(let i=0;i<arr4.length;i++){
      //  total_four_price +=arr4[i].count * arr4[i].xt_drug_warehouse_info.price/min_number
      total_four_price+= ((arr4[i].count/min_number) * arr4[i].price) + ((arr4[i].count%min_number)*(arr4[i].price/min_number))
     }
   }

   if(arr2!=null && arr2.length > 0){
     for(let i=0;i<arr2.length;i++){
       total_two_price += arr2[i].count * arr2[i].xt_drug_warehouse_info.price/min_number
     }
   }

  if(arr3!=null && arr3.length > 0){
     for(let i=0;i<arr3.length;i++){
       total_three_price += arr3[i].count * arr3[i].xt_drug_warehouse_info.price/min_number
     }
   }

   if(arr5!=null && arr5.length > 0){
     for(let i=0;i<arr5.length;i++){
       total_five_price += arr5[i].count * arr5[i].xt_drug_warehouse_info.price/min_number
     }
   }

   total_price = total_one_price - total_four_price + total_two_price - total_three_price + total_five_price
   if(total_price > 0){
     return total_price.toFixed(2)
   }else{
    return "0.00"
   }
  },
  getSaleMoney(arr,arr4,min_number,min_unit,max_unit,arr2,arr3,arr5){

   var total_price = 0
   var total_price_one = 0
   var total_price_two = 0
   var total_price_four = 0
   var total_price_three =0
   var total_price_five = 0
   if(arr!=null&&arr.length > 0){
    for(let i=0;i<arr.length;i++){
      total_price_one += arr[i].count * arr[i].xt_drug_warehouse_info.retail_price
     }
   }
   if(arr4!=null && arr4.length>0){
    for(let i=0;i<arr4.length > 0;i++){
      total_price_four += arr4[i].count * arr4[i].xt_drug_warehouse_info.retail_price
    }
   }
   if(arr2!=null && arr2.length > 0){
    for(let i=0;i<arr2.length;i++){
     total_price_two += arr2[i].count * arr2[i].xt_drug_warehouse_info.retail_price
    }

   }

  if(arr3!=null && arr3.length > 0){
    for(let i=0;i<arr3.length;i++){
      total_price_three += arr3[i].count * arr3[i].xt_drug_warehouse_info.retail_price
    }

   }

  if(arr5!=null && arr5.length > 0){
    for(let i=0;i<arr5.length;i++){
      total_price_five += arr5[i].count * arr5[i].xt_drug_warehouse_info.retail_price
    }

   }

  total_price = total_price_one - total_price_four + total_price_two - total_price_three + total_price_five
   if(total_price >0){
     return total_price.toFixed(2)
   }else{
    return "0.00"
   }

  },
  getSaleMoneyOne(arr,min_number,min_unit,max_unit,arr2,arr3,arr4,arr5){
  var totalOne = 0
   var totalTwo =0
   var total_price = 0
   var total_three= 0
   var total_four = 0
   var total_five = 0
   if(arr!=null&&arr.length > 0){
    for(let i=0;i<arr.length;i++){
      totalOne += arr[i].count*arr[i].xt_drug_warehouse_info.retail_price
     }
   }

  if(arr2!=null&&arr2.length > 0){
    for(let i=0;i<arr2.length;i++){
      totalTwo += arr2[i].count * arr2[i].xt_drug_warehouse_info.retail_price
     }
   }

  if(arr3!=null&&arr3.length > 0){
    for(let i=0;i<arr3.length;i++){
      total_three+=arr3[i].count* arr3[i].xt_drug_warehouse_info.retail_price
     }
   }

  if(arr4!=null&&arr4.length > 0){
    for(let i=0;i<arr4.length;i++){
      total_four+=arr4[i].count * arr4[i].xt_drug_warehouse_info.retail_price
     }
   }

   if(arr5!=null&&arr5.length > 0){
    for(let i=0;i<arr5.length;i++){
      total_five+=arr5[i].count * arr5[i].xt_drug_warehouse_info.retail_price
     }
   }
  //  console.log("total_one",totalOne)
  //  console.log("totalTwo",totalTwo)
  //  console.log("total_three",total_three)
  //  console.log("total_four",total_four)

  //  console.log("total_pricewode",(totalOne - totalTwo+total_three - total_four).toFixed(2))
   total_price =(totalOne - totalTwo+total_three - total_four + total_five).toFixed(2)
   if(total_price > 0){
      return total_price
   }else{
     return "0.00"
   }

  },
  getDrugWarehouseOutInfo(arr,min_number,min_unit,max_unit){
   var total = 0
   var max_str = "";
   var min_str = "";
   if(arr.length > 0){
    for(let i=0;i<arr.length;i++){
      total += arr[i].count
     }
   }
  if (total < min_number) {
    min_str = total + min_unit;
   }
  if (total == 0) {
     min_str = "";
     max_str = "";
  }
  if (total >= min_number) {
    if (parseInt(total / min_number) != 0) {
      max_str = parseInt(total / min_number) + max_unit;
    }
    if (total % min_number != 0) {
      min_str = (total % min_number) + min_unit;
    }
   }
  return max_str + min_str;
  },
  getDrugWarehouseOutMoney(arr,min_number,min_unit,max_unit,last_price){
   var total = 0
   var min_str = 0
   var max_str = 0
   var total_price = 0
   if(arr.length > 0){
    for(let i=0;i<arr.length;i++){
      total += arr[i].count
     }
   }
   if (total < min_number) {
      min_str = total
   }
   if (total >= min_number) {
    if (parseInt(total / min_number) != 0) {
      max_str = parseInt(total / min_number);
    }
    if (total % min_number != 0) {
      min_str = (total % min_number);
    }
    total_price = (max_str * last_price + min_str*(last_price/min_number)).toFixed(2)
    return total_price
   }
  },
   open(){
   
    // this.start_time = moment().year(2022).month(10).date(4).format('YYYY-MM-DD')
    this.start_time = moment().startOf('month').format('YYYY-MM-DD')
    this.end_time = moment(new Date()).add('year',0).format("YYYY-MM-DD")
    this.houseList= []
    this.drugTypeList = []
    this.getStorehouseList()
    this.getlist()
   },

  drugAddInfo(arr,min_number,min_unit,max_unit,arr2){
    var total = 0
    var totalone = 0
    var totaltwo = 0
    var max_str = "";
    var min_str = "";
    if(arr!=null && arr.length > 0){
      for(let i=0;i<arr.length;i++){
        totalone += arr[i].count
      }
    }
    if(arr2!=null && arr2.length >0){
      for(let i=0;i<arr2.length;i++){
        totaltwo += arr2[i].count
      }
    }
    total = totalone + totaltwo

    if (total < min_number) {
      min_str = total + min_unit;
    }
    if (total == 0) {
      min_str = "";
      max_str = "";
    }
    if (total >= min_number) {
      if (parseInt(total / min_number) != 0) {
        max_str = parseInt(total / min_number) + max_unit;
      }
      if (total % min_number != 0) {
        min_str = (total % min_number) + min_unit;
      }
    }
    if(max_str == "" && min_str == ""){
      return "0"
    }else{
      return max_str + min_str
    }

   },
   drugAddInfoOne(arr,min_number,min_unit,max_unit,arr2){
    var total = 0
    var totalone = 0
    var totaltwo = 0
    var max_str = "";
    var min_str = "";
    if(arr!=null && arr.length > 0){
      for(let i=0;i<arr.length;i++){
        totalone += arr[i].count
      }
    }
    if(arr2!=null && arr2.length >0){
      for(let i=0;i<arr2.length;i++){
        totaltwo += arr2[i].count
      }
    }
    total = totalone + totaltwo

    
    return total

   },
   getdrugAddPrice(arr,min_number,min_unit,max_unit,arr2){
    var total = 0
    var totalone =0
    var totaltwo = 0
    var total_price = 0

    if(arr!=null&&arr.length > 0){
      for(let i=0;i<arr.length;i++){
        totalone += arr[i].count * arr[i].xt_drug_warehouse_info.price/min_number
      }
    }

    if(arr2!=null && arr2.length > 0){
     for(let i=0;i<arr2.length;i++){
       totaltwo +=arr2[i].count * arr2[i].xt_drug_warehouse_info.price/min_number
      }
    }
    total = totalone + totaltwo
    total_price =total.toFixed(2)
    return total_price
   },
   drugAddSalePrice(arr,min_number,min_unit,max_unit,arr2){
    var total = 0
    var total_one = 0
    var total_two = 0
    var total_price = 0
    if(arr!=null&&arr.length > 0){
      for(let i=0;i<arr.length;i++){
        total_one += arr[i].count * arr[i].xt_drug_warehouse_info.retail_price
      }
    }

   if(arr2!=null&&arr2.length > 0){
      for(let i=0;i<arr2.length;i++){
       total_two +=arr2[i].count * arr2[i].xt_drug_warehouse_info.retail_price
      }
    }

    total = total_one + total_two

    total_price = total.toFixed(2)
    return total_price
   },
   getDrugOut(arr,min_number,min_unit,max_unit,arr2,arr3){
    var total = 0
    var totalone = 0
    var totaltwo = 0
    var totalthree = 0
    var min_str = ""
    var max_str = ""
    if(arr!=null&&arr.length > 0){
      for(let i=0;i<arr.length;i++){
         totalone +=arr[i].count
      }
    }
    if(arr2!=null && arr2.length>0){
      for(let i=0;i<arr2.length;i++){
        totaltwo +=arr2[i].count
      }
    }
    if(arr3!=null && arr3.length>0){
      for(let i=0;i<arr3.length;i++){
        totalthree +=arr3[i].count
      }
    }
    console.log("出库ssssssssssssssss",totalone)
    console.log("盘亏",totaltwo)
    console.log("退库22222222222",totalthree)
    total = totalone + totaltwo - totalthree
    console.log("剩余阿道夫阿道夫阿道夫",total)
    if (total < min_number) {
      min_str = total + min_unit;
    }
    if (total == 0) {
      min_str = "";
      max_str = "";
    }
    if (total >= min_number) {
      if (parseInt(total / min_number) != 0) {
        max_str = parseInt(total / min_number) + max_unit;
      }
      if (total % min_number != 0) {
        min_str = (total % min_number) + min_unit;
      }
   }
   if(max_str == "" && min_str == ""){
     return "0"
   }else{
    return max_str + min_str;
   }

   },
   getDrugOutOne(arr,min_number,min_unit,max_unit,arr2,arr3){
    var total = 0
    var totalone = 0
    var totaltwo = 0
    var totalthree = 0
    var min_str = ""
    var max_str = ""
    if(arr!=null&&arr.length > 0){
      for(let i=0;i<arr.length;i++){
         totalone +=arr[i].count
      }
    }
    if(arr2!=null && arr2.length>0){
      for(let i=0;i<arr2.length;i++){
        totaltwo +=arr2[i].count
      }
    }
    if(arr3!=null && arr3.length>0){
      for(let i=0;i<arr3.length;i++){
        totalthree +=arr3[i].count
      }
    }
    total = totalone + totaltwo - totalthree
    
    return total

   },
   getDrugOutPrice(arr,min_number,min_unit,max_unit,arr2,arr3){

    var total_price = 0
    var total_one_price =0
    var total_two_price = 0
    var total_three_price = 0
    var total = 0
    var total_two = 0
    var total_three = 0
    if(arr!=null&&arr.length > 0){
      for(let i=0;i<arr.length;i++){
        total_one_price += arr[i].count * (arr[i].xt_drug_warehouse_info.price/min_number)
        total += arr[i].count
      }
    }
    if(arr2!=null && arr2.length>0){
      for(let i=0;i<arr2.length;i++){
        total_two_price +=arr2[i].count * arr2[i].xt_drug_warehouse_info.price/min_number
        total_two +=arr2[i].count
      }
    }

    if(arr3!=null && arr3.length>0){
      for(let i=0;i<arr3.length;i++){
        total_three_price +=arr3[i].count * arr3[i].xt_drug_warehouse_info.price/min_number
        total_three +=arr3[i].count
      }
    }

    total_price = total_one_price + total_two_price - total_three_price
    if(total_price > 0){
      return total_price.toFixed(2)
    }else{
     return "0.00"
    }

   },
   getDrugOutSaleprice(arr,min_number,min_unit,max_unit,arr3,arr4){
    var total_price = 0
    var total_price_one = 0
    var total_price_two = 0
    var total_price_three = 0
    if(arr!=null&&arr.length > 0){
      for(let i=0;i<arr.length;i++){
        total_price_one += arr[i].count * arr[i].xt_drug_warehouse_info.retail_price
      }
    }

    if(arr3!=null && arr3.length >0){
      for(let i=0;i<arr3.length;i++){
         total_price_two +=arr3[i].count * arr3[i].xt_drug_warehouse_info.retail_price
      }
    }

    if(arr4!=null && arr4.length >0){
      for(let i=0;i<arr4.length;i++){
         total_price_three +=arr4[i].count * arr4[i].xt_drug_warehouse_info.retail_price
      }
    }

   total_price = total_price_one + total_price_two - total_price_three

    if(total_price > 0){
      return total_price.toFixed(2)
    }else{
     return "0.00"
    }

   },
   toPrint(){
    this.$router.push({path:"/drugs/purchase/new/query/print?start_time="+this.start_time+"&end_time="+this.end_time+"&page="+this.page+"&limit="+this.limit+"&keyword="+this.keyword+"&good_type="+this.good_type})
   },
    exportList: function() {
       for(let i=0;i<this.tableList.length;i++){
          this.tableList[i].index = i+1
          this.tableList[i].query_date = this.start_time+"~"+this.end_time
          this.tableList[i].good_type = this.getDrugTypeName(this.tableList[i].drug_type)
          this.tableList[i].manufacturer_name = this.getManufacturName(this.tableList[i].manufacturer)
          this.tableList[i].dealer_name = this.getDearName(this.tableList[i].dealer)
          this.tableList[i].specification_name = this.tableList[i].dose + this.tableList[i].dose_unit +"*"+this.tableList[i].min_number + this.tableList[i].min_unit+"/"+this.tableList[i].max_unit
          // this.tableList[i].drugInMoney = this.tableList[i].last_price

        }
        import('@/vendor/Export2Excel').then(excel => {
           const multiHeader = [['序号', '查询日期','  药品类型','药品名称','规格&单位','生产产商','经销商', '期初结余' , '', '', '本期增加', '', '', '本期减少' , '', '', '期末结余' , '', '']]
           const header = ['', '','','','','','', '数量', '进货金额', '销售金额', '数量', '进货金额', '销售金额', '数量', '进货金额', '销售金额', '数量', '进货金额', '销售金额']
           const merges = ['A1:A2', 'B1:B2','C1:C2','D1:D2','E1:E2','F1:F2','G1:G2','H1:J1', 'K1:M1', 'N1:P1', 'Q1:S1']
           const filterVal = ['index', 'query_date', 'good_type','drug_name','specification_name','manufacturer_name','dealer_name','drugIn','drugInMoney','drugSaleMoney','drugAdd','drugAddPrice','drugAddSalePrice','drugOut','drugOutPrice','drugOutSalePrice','overDrug','overDrugPrice','oveDrugSaleMoney']

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

           const filename = '药品进销存查询'


            excel.export_json_to_excel({
              multiHeader,
              header,
              merges,
              data,
              filename
            })
        })
     },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]));
    },
    GetDrugStartFlow(total,min_number,min_unit,max_unit){
      var min_str = ""
      var max_str = ""
      if (total < min_number) {
        min_str = total + min_unit;
      }
      if (total == 0) {
        min_str = "";
        max_str = "";
      }
      if (total >= min_number) {
        if (parseInt(total / min_number) != 0) {
            max_str = parseInt(total / min_number) + max_unit;
        }
        if (total % min_number != 0) {
            min_str = (total % min_number) + min_unit;
        }
      }
        if(max_str == "" && min_str == ""){
            return "0"
        }else{
            return max_str + min_str;
        }
    },

  
    GetDrugEndFlow(total,min_number,min_unit,max_unit){

     var min_str = ""
     var max_str = ""    
     if (total < min_number) {
        min_str = total + min_unit;
      }
      if (total == 0) {
        min_str = "";
        max_str = "";
      }
      if (total >= min_number) {
        if (parseInt(total / min_number) != 0) {
            max_str = parseInt(total / min_number) + max_unit;
        }
        if (total % min_number != 0) {
            min_str = (total % min_number) + min_unit;
        }
      }
     if(max_str == "" && min_str == ""){
            return "0"
        }else{
            return max_str + min_str;
       }
    },
    toOverCount(){
      getDrugOverCount().then(response=>{
        if(response.data.state == 1){
          var msg = response.data.data.msg
          this.$message.success("调试成功")
        }
      })  
    },
    getDearName(id){
      var dear_name = ""
      for(let i=0;i<this.dealerList.length;i++){
        if(id == this.dealerList[i].id){
          dear_name = this.dealerList[i].dealer_name
        }
      }
      return dear_name
    },
    GetDrugOver(totalone,totaltwo,totalthree,min_number,min_unit,max_unit){
      var total = 0
      var min_str = ""
      var max_str = ""  
       total = totalone + totaltwo - totalthree
      //  console.log("totoalone---------------",totalone)
      //  console.log("totaltwo------------",totaltwo)
      //  console.log("totalthree----------",totalthree)
        if (total < min_number) {
          min_str = total + min_unit;
        }
        if (total == 0) {
          min_str = "";
          max_str = "";
        }
        if (total >= min_number) {
          if (parseInt(total / min_number) != 0) {
            max_str = parseInt(total / min_number) + max_unit;
          }
          if (total % min_number != 0) {
            min_str = (total % min_number) + min_unit;
          }
      }
      if(max_str == "" && min_str == ""){
        return "0"
      }else{
        return max_str + min_str;
      }
    },
    GetDrugOverOne(totalone,totaltwo,totalthree,min_number,min_unit,max_unit){
      var total = 0
      
      total = totalone + totaltwo - totalthree
       
      return total
       
    },
    GetInitStartFlow(val1,val2,val3,val4,val5,min_number,min_unit,max_unit){
      var total_one =0
      var total_two = 0
      var total_three =0
      var total_four =0
      var total_five = 0
      var total =0
      var min_str = ""
      var max_str = ""  
      if(val1!=null && val1.length>0){
         for(let i=0;i<val1.length;i++){
           total_one +=val1[i].count
         }
      }  

      if(val2!=null && val2.length>0){
         for(let i=0;i<val2.length;i++){
          total_two +=val2[i].count
         }
      }  
    
      console.log("val3",val3)
      if(val3!=null && val3.length>0){
         for(let i=0;i<val3.length;i++){
          total_three +=val3[i].count
         }
      }  
      if(val4!=null && val4.length>0){
         for(let i=0;i<val4.length;i++){
          total_four +=val4[i].count
         }
      }  

      if(val5!=null && val5.length>0){
         for(let i=0;i<val5.length;i++){
          total_five +=val5[i].count
         }
      }  
      console.log("入库",total_one)
      console.log("盘盈",total_two)
      console.log("出库",total_three)
      console.log("盘亏",total_four)
      console.log("退库",total_five)
      var total = total_one + total_two -total_three-total_four + total_five
      if (total <=0) {
        return 0
      }else{
        if (total < min_number) {
          min_str = total + min_unit;
        }
          if (total == 0) {
            min_str = "";
            max_str = "";
          }
          if (total >= min_number) {
            if (parseInt(total / min_number) != 0) {
              max_str = parseInt(total / min_number) + max_unit;
            }
            if (total % min_number != 0) {
              min_str = (total % min_number) + min_unit;
            }
        }
        if(max_str == "" && min_str == ""){
          return "0"
        }else{
          return max_str + min_str;
        }
      }
     
    },
    GetInitStartFlowOne(val1,val2,val3,val4,val5,min_number,min_unit,max_unit){
      var total_one =0
      var total_two = 0
      var total_three =0
      var total_four =0
      var total_five = 0
      var total =0
      var min_str = ""
      var max_str = ""  
      if(val1!=null && val1.length>0){
         for(let i=0;i<val1.length;i++){
           total_one +=val1[i].count
         }
      }  

      if(val2!=null && val2.length>0){
         for(let i=0;i<val2.length;i++){
          total_two +=val2[i].count
         }
      }  
    
      console.log("val3",val3)
      if(val3!=null && val3.length>0){
         for(let i=0;i<val3.length;i++){
          total_three +=val3[i].count
         }
      }  
      if(val4!=null && val4.length>0){
         for(let i=0;i<val4.length;i++){
          total_four +=val4[i].count
         }
      }  

      if(val5!=null && val5.length>0){
         for(let i=0;i<val5.length;i++){
          total_five +=val5[i].count
         }
      }  
      console.log("入库",total_one)
      console.log("盘盈",total_two)
      console.log("出库",total_three)
      console.log("盘亏",total_four)
      console.log("退库",total_five)
      var total = total_one + total_two -total_three-total_four + total_five
      if(total>0){
        return total
      }else{
        return 0
      }
     
    },
    getDrugQuery(){
      this.getlist()
    }
  }
}
</script>

