<template>
    <div class="main-contain">
        <div class="position">
        <bread-crumb :crumbs="crumbs"></bread-crumb>
        <el-row style="float:right;">
            <el-col :span="24">
            <el-button size="small" icon="el-icon-printer" type="primary" @click="printAction">打印</el-button>
            </el-col>
        </el-row>
        </div>
        <div class="app-container" style="background-color: white;">
            <div id="print_content">
                <div class="print_main_content">
                    <div class="order_title_panl">
                        <span class="main_title">药品进销存查询表</span>
                    </div>
                    <div style="text-align:left;margin-bottom:20px;font-size: 14px;margin-bottom:-30px">
                      <span class="time_p">查询日期:{{start_time}} ~</span><span class="time_p">{{end_time}}</span>
                    </div>
                    <div style="text-align:right;margin-bottom:20px;font-size: 14px;">
                      <span class="time_p">打印时间：{{time_now}}</span>
                    </div>
                    <div class="table_panel">
                        <table class="table">
                            <thead>
                                <tr>
                                  <td rowspan="2" width="60">序号</td>
                                  <td rowspan="2" width="80">药品类型</td>
                                  <td rowspan="2" width="80">药品名称</td>
                                  <td rowspan="2" width="80">规格&单位</td>
                                  <td rowspan="2" width="80">国家编码</td>
                                  <td rowspan="2" width="80">生产厂商</td>
                                  <td rowspan="2" width="80">经销商</td>
                                  <td width="80" colspan="3">期初结余</td>
                                  <td width="80" colspan="3">本期增加</td>
                                  <td width="80" colspan="3">本期减少</td>
                                  <td width="80" colspan="3">期末结余</td>
                                </tr>
                                <tr>
                                  <td>数量</td>
                                  <td>进货金额</td>
                                  <td>销售金额</td>
                                  <td>数量</td>
                                  <td>进货金额</td>
                                  <td>销售金额</td>
                                  <td>数量</td>
                                  <td>进货金额</td>
                                  <td>销售金额</td>
                                  <td>数量</td>
                                  <td>进货金额</td>
                                  <td>销售金额</td>
                                </tr>

                            </thead>
                            <tbody>
                                <tr v-for="(item,index) in this.tableList" :key="index">
                                 <td>{{index + 1 }}</td>
                                 <td> {{getDrugTypeName(item.drug_type)}}</td>
                                 <td> {{item.drug_name}}</td>
                                 <td> {{item.dose}}{{item.dose_unit}}*{{item.min_number}}{{item.min_unit}}/{{item.max_unit}}</td>
                                 <td>{{item.medical_insurance_number}}</td>
                                 <td>{{getManufacturName(item.manufacturer)}}</td>
                                 <td>{{getDearName(item.dealer)}}</td>
                                 <td>{{item.drugIn}}</td>
                                 <td>{{item.drugInMoney}}</td>
                                 <td>{{item.drugSaleMoney}}</td>
                                 <td>{{item.drugAdd}}</td>
                                 <td>{{item.drugAddPrice}}</td>
                                 <td>{{item.drugAddSalePrice}}</td>
                                 <td>{{item.drugOut}}</td>
                                 <td>{{item.drugOutPrice}}</td>
                                 <td>{{item.drugOutSalePrice}}</td>
                                 <td>{{item.overDrug}}</td>
                                 <td>{{item.overDrugPrice}}</td>
                                 <td>{{item.oveDrugSaleMoney}}</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import BreadCrumb from '@/xt_pages/components/bread-crumb'
import { getStorehouseList,getPurchaseNewDrugQuery } from "@/api/drug/drug"
import print from 'print-js'
const moment = require('moment')
export default {
    components:{
        BreadCrumb
    },
    data(){
        return{
          crumbs: [
            { path: false, name: '库存管理' },
            { path: false, name: '库存查询' },
            { path: false, name: '库存查询打印' },
          ],
          start_time:"",
          end_time:"",
          drug_name:"",
          drug_spec:"",
          keyword:"",
          tableData:[],
          time_now:moment(new Date()).add('year',0).format("YYYY-MM-DD"),
          type_name:"",
          limit:"",
          page:"",
          WarehouseInfo: {
          loading: false,
          warehouseInfoDate: [],
         },
          tableList:[],
          good_type:[],
          manufacturerList:[],
          countList:[],
          outCountList:[],
          autoCountList:[],
          cancelCountList:[],
          org_id:0,
          drugTypeList:[],
          dealerList:[],
          query_type:0,
        }
    },
    methods:{
      printAction: function() {
          const style = '@media print { .print_main_content { background-color: white; width:1500px;  margin:0 auto; padding: 0 0 20px 0; } .order_title_panl { text-align: center; } .time_p{font-size:16px;} .main_title { font-size: 18px; line-height: 40px; font-weight: 500; } .table_panel { } .table { width: 100%; border: 1px solid; border-collapse: collapse; padding: 2px; } thead tr td { border: 1px solid; text-align: center; font-size: 16px; padding: 15px 5px; } tbody tr td { border: 1px solid; text-align: center; font-size: 16px; padding: 10px 5px; white-space: pre-line;} .proj { padding: 5px 0; text-align: left; } .proj_title { font-size: 16px; font-weight: 500; line-height: 25px; } .proj_item { font-size: 15px; line-height: 20px; } .zone_name { font-weight: 500; } }'
          printJS({
          printable: 'print_content',
          type: 'html',
          documentTitle: '  ',
          style: style,
          scanStyles: false
          })
      },
    getStorehouseList(){
      getStorehouseList().then(response=>{
         if(response.data.state == 1){
           this.manufacturerList = response.data.data.manufacturerList
           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,
          query_type:this.query_type,
        }
      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(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
                   }
                }
             }


            }



            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 ==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) 
               
               if(this.org_id == 0 || this.org_id == 10644 || this.org_id == 10752){
                list[i].drugInMoney = ""
              }else{
                list[i].drugInMoney = list[i].last_price
              }

                if( this.org_id == 10697 || this.org_id == 9478){
                  list[i].drugSaleMoney =  (list[i].over_count_one * list[i].last_price).toFixed(2)
                }else if(this.org_id == 0 || this.org_id == 10644 || this.org_id == 10752){
                  list[i].drugAddPrice = ""
                  list[i].drugSaleMoney =  this.GetInitStartFlowPice(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)
                }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 == 10697 || this.org_id ==9478){
                 list[i].drugAddPrice = list[i].last_price
                 list[i].drugAddSalePrice = (list[i].last_price *list[i].drugAddOne).toFixed(2)
                }else if(this.org_id == 0 || this.org_id ==10644 || this.org_id == 10752){
                  list[i].drugAddPrice = "/"
                  list[i].drugAddSalePrice = this.drugAddInfoOnePirce(list[i].DrugWarehouseInfoStartEnd,list[i].min_number,list[i].min_unit,list[i].max_unit,list[i].WareStartEndStockInventoryProfit)
                  console.log("本期增加加淀粉",list[i].drugAddSalePrice)
                } 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 == 10697 || this.org_id == 9478){
                  list[i].drugOutPrice = list[i].last_price
                  list[i].drugOutSalePrice = (list[i].drugOutOne * list[i].last_price).toFixed(2)
                }else if(this.org_id == 0 || this.org_id == 10644 || this.org_id == 10752){
                  list[i].drugOutPrice = "/"
                  list[i].drugOutSalePrice= this.getDrugOutPriceOne(list[i].DrugWarehouseOutInfoStartEnd,list[i].min_number,list[i].min_unit,list[i].max_unit,list[i].WareStartEndStockInventoryLosses,list[i].WareStartEndStockCancelInfo)
                } 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 == 10697 || this.org_id == 9478){
                  list[i].overDrugPrice = list[i].last_price
                  list[i].oveDrugSaleMoney = (list[i].overDrugOne * list[i].last_price).toFixed(2)
                }else if(this.org_id == 0 || this.org_id ==10644 || this.org_id == 10752){
                  list[i].overDrugPrice = ""
                  list[i].oveDrugSaleMoney = this.GetDrugOverOnePrice(list[i].drugSaleMoney,list[i].drugAddSalePrice,list[i].drugOutSalePrice,list[i].min_number,list[i].min_unit,list[i].max_unit)
                } else{
                  list[i].overDrugPrice = "/"
                  list[i].oveDrugSaleMoney = "/"
                }
            }
            if(this.org_id == 10697 || this.org_id == 9478){
              if(list!=null && list.length>0){
                var obj = {drug_type:"",drug_name:"合计",dose:"",dose_unit:"",min_number:"",min_unit:"",max_unit:"",medical_insurance_number:"",manufacturer:"",dealer:"",drugIn:"",drugInMoney:"",drugSaleMoney:0,drugAdd:"",drugAddPrice:"",drugAddSalePrice:0,drugOut:"",drugOutPrice:"",drugOutSalePrice:0,overDrug:"",overDrugPrice:"",oveDrugSaleMoney:0}
                for(let i=0;i<list.length;i++){
                  obj.drugSaleMoney += parseFloat(list[i].drugSaleMoney)
                  obj.oveDrugSaleMoney += parseFloat(list[i].oveDrugSaleMoney)
                  obj.drugAddSalePrice += parseFloat(list[i].drugAddSalePrice)
                  obj.drugOutSalePrice +=parseFloat(list[i].drugOutSalePrice)
                }
                obj.drugSaleMoney  = obj.drugSaleMoney.toFixed(2)
                obj.oveDrugSaleMoney  = obj.oveDrugSaleMoney.toFixed(2)
                obj.drugAddSalePrice  = obj.drugAddSalePrice.toFixed(2)
                obj.drugOutSalePrice  = obj.drugOutSalePrice.toFixed(2)
                list.push(obj)

              }
            }
            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.limit = val;
      this.getlist()
    },
    handleCurrentChange(val) {
      this.page = val;
      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
       }
     }
     if (type_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
   },


   startFirstTimeChange(){
     this.getlist()
   },
   endEndTimeChange(){
     this.getlist()
   },
  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.getlist()
  },
  startTimeChange(){
    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
     }
  }

  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;
    }
   }
   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
     }
   }
   console.log("adw23223wode",addTotal)
   console.log("233232232tade",outTotal)
   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)
    console.log("total_price",total_price)
   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)
    console.log("total_price",total_price)
   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*(arr[i].price/min_number)+ 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/min_number*arr[i].price) + 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
     }
   }

   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
   }
  },
   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
      }
    }
    total = totalone + totaltwo - 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;
   }

   },
   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"
    }

   },
   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;
       }
    },
    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
        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
         }
      }  
    
      var total = total_one + total_two -total_three-total_four + total_five

      if (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;
        }
      }else{
        return 0
      }
    
    },
    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
         }
      }  
     
      var total = total_one + total_two -total_three-total_four + total_five
       if (total > 0) {
         return total
       }else{
         return 0
       }
     
    },
    
    GetInitStartFlowPice(val1,val2,val3,val4,val5,min_number,min_unit,max_unit){
      var total_one_price =0
      var total_two_price = 0
      var total_three_price =0
      var total_four_price =0
      var total_five_price = 0
      var total =0
   
      if(val1!=null && val1.length>0){
         for(let i=0;i<val1.length;i++){
          total_one_price +=val1[i].count/min_number*val1[i].price
         }
      }  

      if(val2!=null && val2.length>0){
         for(let i=0;i<val2.length;i++){
          total_two_price +=val2[i].count/min_number*val2[i].price
         }
      }  
    
      console.log("val3",val3)
      if(val3!=null && val3.length>0){
         for(let i=0;i<val3.length;i++){
          total_three_price +=val3[i].count*val3[i].price
         }
      }  
      if(val4!=null && val4.length>0){
         for(let i=0;i<val4.length;i++){
          total_four_price +=val4[i].count*val4[i].price
         }
      }  

      if(val5!=null && val5.length>0){
         for(let i=0;i<val5.length;i++){
          total_five_price +=val5[i].count*val5[i].price
         }
      }  
     
      if(total_one_price == ""){
        total_one_price = 0
      }
      if(total_two_price == ""){
        total_two_price = 0
      }
      if(total_three_price == ""){
        total_three_price = 0
      }
      if(total_four_price == ""){
        total_four_price = 0
      }
      if(total_five_price == ""){
        total_five_price = 0
      }

      var total = (total_one_price + total_two_price -total_three_price-total_four_price + total_five_price)
       
      if(total >1){
        return total.toFixed(2)
      }else{
        return ""
      }
       
    },
    drugAddInfoOnePirce(arr,min_number,min_unit,max_unit,arr2){
      
      var total = 0
      var totalone_price = 0
      var total_two_price = 0
      if(arr!=null && arr.length > 0){
        for(let i=0;i<arr.length;i++){
          totalone_price += arr[i].count/min_number * arr[i].price
        }
      }
      if(arr2!=null && arr2.length >0){
        for(let i=0;i<arr2.length;i++){ 
          total_two_price += arr2[i].count/min_number * arr2[i].price
        }
      }
      if(totalone_price== ""){
           totalone_price = 0
        }
      if(total_two_price== ""){
          total_two_price = 0
      }
      total = totalone_price + total_two_price

      if(total>0){
        return total.toFixed(2)
      }else{
        return ""
      }
      
   },
    getDrugOutPriceOne(arr,min_number,min_unit,max_unit,arr2,arr3){
      var total = 0
      var totalone_price = 0
      var total_two_price = 0
      var total_three_price = 0
    
      if(arr!=null&&arr.length > 0){
        for(let i=0;i<arr.length;i++){
          totalone_price +=arr[i].count * arr[i].price
        }
      }
      if(arr2!=null && arr2.length>0){
        for(let i=0;i<arr2.length;i++){
          total_two_price +=arr2[i].count * arr2[i].price
        }
      }
      if(arr3!=null && arr3.length>0){
        for(let i=0;i<arr3.length;i++){
          total_three_price +=arr3[i].count * arr3[i].price
        }
      }
      if(totalone_price==""){
        totalone_price=0
      }
      if(total_two_price == ""){
        total_two_price =0
      }
      if(total_three_price == ""){
        total_three_price =0
      }
 
  
      total = (totalone_price + total_two_price - total_three_price)
      if(total >0){
        return total.toFixed(2)
      }else{
        return ""
      }
    
   },
   GetDrugOverOnePrice(totalone,totaltwo,totalthree,min_number,min_unit,max_unit){
     
    if(totalone == ""){
        totalone =0
     }
     if(totaltwo == ""){
       totaltwo =0
     }
     if(totalone == ""){
        totalone =0
     }
     if(totalthree == ""){
      totalthree =0
     }
   
     var total = 0
      total = (parseFloat(totalone)  + parseFloat(totaltwo)  - parseFloat(totalthree))
     
      if(total >0){
        return total.toFixed(2)
      }else{
        return ""
      }
    },
   },
    created(){
      this.org_id =  this.$store.getters.xt_user.org_id

      var starttime =  this.$route.query.start_time
      this.start_time = starttime
      var endtime =  this.$route.query.end_time
      this.end_time = endtime
      var good_type = parseInt(this.$route.query.good_type)
      this.good_type = good_type

      var query_type = parseInt(this.$route.query.query_type)
      this.query_type= query_type
      var keyword = this.$route.query.keyword
      this.keyword = keyword
      this.page = parseInt(this.$route.query.page)
      this.limit = parseInt(this.$route.query.limit)
      this.getStorehouseList()
      this.getlist()
    }
}
</script>


<style rel="stylesheet/scss" lang="scss" scoped>
.print_main_content {
  background-color: white;
  max-width: 1500px;
  margin: 0 auto;
  padding: 0 0 20px 0;

  .order_title_panl {
    text-align: center;

    .main_title {
      font-size: 18px;
      line-height: 40px;
      font-weight: 500;
    }
  }
  .table_panel {
    .table {
      width: 100%;
      border: 1px solid;
      border-collapse: collapse;
      padding: 2px;


      thead {
        tr {
          td {
            border: 1px solid;
            text-align: center;
            font-size: 14px;
            padding: 15px 5px;
          }
        }
      }
      tbody {
        tr {
          td {
            border: 1px solid;
            text-align: center;
            font-size: 14px;
            padding: 10px 5px;
            white-space: pre-line;
            .proj {
              padding: 5px 0;
              text-align: left;

              .proj_title {
                font-size: 16px;
                font-weight: 500;
                line-height: 25px;
              }

              .proj_item {
                font-size: 15px;
                line-height: 20px;

                .zone_name {
                  font-weight: 500;
                }
              }
            }
          }
        }
      }
    }
  }
}
</style>
