<template>
    <div>
        <div style="display: flex;align-items: center;justify-content: space-between;margin-bottom:10px;">
            <div>
                <el-select v-model="inventory_status" size="small" placeholder="请选择" @change="changeInventory">
                    <el-option
                    v-for="item in inventoryList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
                    </el-option>
                </el-select>
                <el-input
                size="small"
                style="width: 200px;margin-left:10px;"
                class="filter-item"
                v-model.trim="searchKey"
                placeholder="请输入单据编号或操作人姓名"
                />
                <el-button
                size="small"
                class="filter-item"
                type="primary"
                icon="el-icon-search"
                @click="search"
                >搜索</el-button
                >
                <el-date-picker
                @change="changeStartTime"
                size="small"
                v-model="start_time"
                type="date"
                style="margin-left:5px;width:140px;"
                placeholder="选择日期">
                </el-date-picker>
                <el-date-picker
                size="small"
                v-model="end_time"
                type="date"
                style="margin-left:5px;width:140px;"
                placeholder="选择日期"
                @change="changeEndTime">
                </el-date-picker>
            </div>
            <div>
                <el-button size="small" type="primary" @click="dialogVisible = true">新增</el-button>
                <el-button size="small" type="primary" @click="toCheck">核对</el-button>
                <!-- <el-button size="small" type="primary" @click="print">打印</el-button>
                <el-button size="small" type="primary" @click="exportList">导出</el-button> -->
            </div>
        </div>
        <el-table :data="tableList" border :header-cell-style="{ backgroundColor: 'rgb(245, 247, 250)' }"  @selection-change="changePrice">
            <el-table-column type="selection" width="55" align="center"> </el-table-column>
            <el-table-column prop="date" label="盘点编号"  align="center">
              <template slot-scope="scope">
                {{scope.row.warehousing_order}}
              </template>  
            </el-table-column>
            <el-table-column  prop="date" label="盘点日期" align="center">
              <template slot-scope="scope" >
                {{getTime(scope.row.start_time)}}
              </template>  
            </el-table-column>
             <el-table-column  prop="date" label="盘点数量" align="center">
              <template slot-scope="scope" >
                {{scope.row.count}}
              </template>  
            </el-table-column>
            <el-table-column prop="name" label="库存" width="100" align="center">
                  <template slot-scope="scope">
                   {{scope.row.total}}
                 </template> 
            </el-table-column>
            <el-table-column prop="name" label="批次" width="100" align="center">
                <template slot-scope="scope">
                  {{scope.row.number}}
                </template> 
            </el-table-column>
            <el-table-column prop="name" label="盘点人" align="center">
             <template slot-scope="scope" >
              {{scope.row.user_name}}
             </template>
            </el-table-column>
            <el-table-column prop="name"  label="审核日期" align="center">
              <template slot-scope="scope" >
               {{getTime(scope.row.checker_time)}}
             </template>
            </el-table-column>
            <el-table-column prop="name" label="审核人" align="center">
              <template slot-scope="scope" >
              {{getChecker(scope.row.checker)}}
             </template>
            </el-table-column>
            <el-table-column prop="name" label="状态"  align="center">
              <template slot-scope="scope">
                <span v-if="scope.row.checker_status == 1">盘点完成</span>
                <span v-if="scope.row.checker_status == 2">正在盘点</span>
             </template>
            </el-table-column>
            <el-table-column label="操作" align="center" width="300">
                <template slot-scope="scope">
                  <el-button type="primary" size="small" @click="getInventory(scope.row.id,scope.row.checker_status)">校对</el-button>
                  <el-button type="primary" size="small" @click="getInventoryDetail(scope.row.id,scope.row.checker_status)">编辑</el-button>
                  <el-button type="danger" size="small" @click="deleteInventory(scope.row.id,scope.row.checker_status,scope.$index)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :page-sizes="[10, 20, 40, 100]"
            :page-size="10"
            background
            style="margin-top:20px;text-align: right"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
        >
        </el-pagination>
        <el-dialog
        title="耗材盘点"
        :visible.sync="dialogVisible"
        width="1200px">
            <el-form :model="form" class="modifyDialog" label-width="120px">
                <el-form-item label="耗材ID">
                    <el-input v-model="form.good_id"></el-input>
                </el-form-item>
                <el-form-item label="耗材名称">
                   <el-autocomplete
                    class="checkSearch"
                    popper-class="my-autocomplete"
                    v-model="form.good_name"
                    :fetch-suggestions="querySearchAsync"
                    :trigger-on-focus="true"
                    placeholder="请输入耗材名称"
                    @select="handleSelect"
                    @input="changeGoodName(scope.$index)"
                    style="width:160px;"
                  >
                    <i class="el-icon-search el-input__icon" slot="suffix"></i>
                  <template slot-scope="{ item }">
                    <div class="name">{{ item.good_name +"  " +item.specification_name + "  "+item.manufacturer }}</div>
                  </template>
                 </el-autocomplete>
                </el-form-item>
                <el-form-item label="规格">
                    <el-input v-model="form.specification_name"></el-input>
                </el-form-item>
                <el-form-item label="批号">
                  <el-select v-model="form.number" filterable placeholder="请选择">
                      <el-option
                        v-for="(item,index) in numberList"
                        :key="index"
                        :label="item.number"
                        :value="item.number">
                      </el-option>
                  </el-select>
                </el-form-item>

                <el-form-item label="单位">
                    <el-input v-model="form.warehousing_unit"></el-input>
                </el-form-item>
                <el-form-item label="进货价">
                    <el-input v-model="form.buy_price"></el-input>
                </el-form-item>
                <el-form-item label="零售价">
                    <el-input v-model="form.packing_price"></el-input>
                </el-form-item>
                <el-form-item label="盘点数量">
                    <el-input v-model="form.count"></el-input>
                </el-form-item>
                <el-form-item label="库存">
                    <el-input v-model="form.total"></el-input>
                </el-form-item>
                <el-form-item label="产地">
                    <el-input v-model="form.good_origin_place"></el-input>
                </el-form-item>
                <el-form-item label="批准文号">
                    <el-input v-model="form.license_number"></el-input>
                </el-form-item>
                <el-form-item label="生产厂商">
                    <el-input v-model="form.manufacturer"></el-input>
                </el-form-item>
                <el-form-item label="备注">
                    <div style="display:flex;">
                        <el-input v-model="form.remark"></el-input>
                        <el-button style="margin-left:5px;" type="primary" @click="addInventory">添加</el-button>
                    </div>
                </el-form-item>
            </el-form>
            <el-table :data="tableData" border :header-cell-style="{ backgroundColor: 'rgb(245, 247, 250)' }">
                <el-table-column prop="date" label="耗材ID" width="100" align="center">
                 <template slot-scope="scope">
                   {{scope.row.good_id}}
                 </template>
                </el-table-column>
                <el-table-column prop="date" label="耗材名称" width="100" align="center">
                 <template slot-scope="scope">
                   {{scope.row.good_name}}
                 </template>
                </el-table-column>
                <el-table-column prop="name" label="规格" width="100" align="center">
                 <template slot-scope="scope">
                   {{scope.row.specification_name}}
                 </template>
                </el-table-column>
                <el-table-column prop="name" label="单位" width="100" align="center">
                  <template slot-scope="scope">
                   {{scope.row.warehousing_unit}}
                 </template> 
                </el-table-column>
                <el-table-column prop="name" label="盘点数量" width="100" align="center">
                  <template slot-scope="scope">
                   {{scope.row.count}}
                 </template> 
                </el-table-column>
              
                <el-table-column prop="name" label="原进货价" width="100" align="center">
                    <template slot-scope="scope">
                    {{scope.row.buy_price}}
                    </template> 
                </el-table-column>
                <el-table-column prop="name" label="原零售价" width="100" align="center">
                    <template slot-scope="scope">
                    {{scope.row.packing_price}}
                    </template> 
                </el-table-column>
                <el-table-column prop="name" label="生产厂商" width="100" align="center">
                    <template slot-scope="scope">
                        {{scope.row.manufacturer}}
                     </template> 
               </el-table-column>
                <el-table-column  prop="name"  label="产地" width="100" align="center">
                    <template slot-scope="scope">
                    {{scope.row.good_origin_place}}
                    </template> 
                </el-table-column>
                <el-table-column prop="name" label="批准文号" width="100" align="center">
                   <template slot-scope="scope">
                    {{scope.row.license_number}}
                    </template> 
                </el-table-column>
                <el-table-column  prop="name" label="备注" width="100" align="center">
                     <template slot-scope="scope">
                      {{scope.row.remark}}
                    </template> 
                </el-table-column>
                <el-table-column
                fixed="right"
                width="100"
                label="操作">
                    <template slot-scope="scope">
                        <el-button type="text" size="small" @click="toEdit(scope.row)">编辑</el-button>
                        <el-button type="text" size="small" @click="toDelete(scope.$index)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="saveInventory">确 定</el-button>
            </span>
        </el-dialog>

      <el-dialog
        title="耗材盘点核对"
        :visible.sync="checkDialogVisible"
        width="30%"
        >
        <span>
          <el-form :model="form">
            <el-row>
              <el-col>
                <el-form-item label="核对时间">
                 <el-date-picker
                    size="small"
                    v-model="check_time"
                    type="date"
                    style="margin-left:5px;width:140px;"
                    placeholder="选择日期">
                  </el-date-picker>
                </el-form-item>  
              </el-col>
            </el-row>  
             <el-row>
              <el-col>
                <el-form-item label="核对人">
                  <el-select v-model="checker" placeholder="请选择">
                    <el-option
                    v-for="item in doctorList"
                    :key="item.admin_user_id"
                    :label="item.user_name"
                    :value="item.admin_user_id">
                    </el-option>
                 </el-select>
                </el-form-item>  
              </el-col>
            </el-row>  
          </el-form>  
        </span>
        <span slot="footer" class="dialog-footer">
            <el-button @click="checkDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="SaveCheckedInventory">保 存</el-button>
        </span>
    </el-dialog>


     <el-dialog
        title="编辑"
        :visible.sync="editPriceDialogVisible"
        width="50%">
        <span>
          <el-form  :model="form">
            <el-row>
               <el-col>
                <el-form-item label="耗材名称:">
                    <el-autocomplete
                        class="checkSearch"
                        popper-class="my-autocomplete"
                        v-model="form.good_name"
                        :fetch-suggestions="querySearchAsync"
                        :trigger-on-focus="true"
                        placeholder="请输入耗材名称"
                        @select="handleSelect"
                        @input="changeGoodName(scope.$index)"
                        style="width:160px;"
                    >
                        <i class="el-icon-search el-input__icon" slot="suffix"></i>
                    <template slot-scope="{ item }">
                        <div class="name">{{ item.good_name +"  " +item.specification_name + "  "+item.manufacturer }}</div>
                    </template>
                    </el-autocomplete>
                </el-form-item>
               <el-form-item label="盘点数量：">
                 <el-input v-model="form.count" style="width:200px"></el-input>
               </el-form-item>
             </el-col> 
            </el-row>
            <el-row>
             <el-col>
                <el-form-item label="备注：">
                    <div style="display:flex;">
                        <el-input v-model="form.remark"  style="width:200px"></el-input>
                    </div>
                </el-form-item>
              </el-col>  
            </el-row>
          </el-form>
        </span>
        <span slot="footer" class="dialog-footer">
            <el-button @click="editPriceDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="upateInventory">保存</el-button>
        </span>
    </el-dialog>


       <el-dialog
        title="编辑"
        :visible.sync="modefiyePriceDialogVisible"
        width="50%">
        <span>
          <el-form  :model="form">
            <el-row>
               <el-col>
               <el-form-item label="盘点数量：">
                 <el-input v-model="form.count" style="width:200px"></el-input>
               </el-form-item>
             </el-col> 
            </el-row>
            <el-row>
             <el-col>
                <el-form-item label="备注：">
                    <div style="display:flex;">
                        <el-input v-model="form.remark"  style="width:200px"></el-input>
                    </div>
                </el-form-item>
              </el-col>  
            </el-row>
          </el-form>
        </span>
        <span slot="footer" class="dialog-footer">
            <el-button @click="modefiyePriceDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="modifyInventory">保存</el-button>
        </span>
      </el-dialog>


      <el-dialog
        title="校对"
        :visible.sync="proofPriceDialogVisible"
        width="50%">
        <span>
          <el-form  :model="form">
            <el-row>
               <el-col>
                 <el-form-item label="耗材名称:">
                 <el-autocomplete
                        class="checkSearch"
                        popper-class="my-autocomplete"
                        v-model="form.good_name"
                        :fetch-suggestions="querySearchAsync"
                        :trigger-on-focus="true"
                        placeholder="请输入耗材名称"
                        @select="handleSelect"
                        @input="changeGoodName(scope.$index)"
                        style="width:160px;"
                        :disabled="true"
                    >
                        <i class="el-icon-search el-input__icon" slot="suffix"></i>
                    <template slot-scope="{ item }">
                        <div class="name">{{ item.good_name +"  " +item.specification_name + "  "+item.manufacturer }}</div>
                    </template>
                    </el-autocomplete>
                </el-form-item>   
               <el-form-item label="规格">
                    <el-input v-model="form.specification_name" style="width:200px" :disabled="true"></el-input>
              </el-form-item>  
               <el-form-item label="盘点数量：">
                 <el-input v-model="form.count" style="width:200px" :disabled="true"></el-input>
               </el-form-item>
               <el-form-item label="库存数量：">
                 <el-input v-model="form.total" style="width:200px" :disabled="true"></el-input>
               </el-form-item>
               <el-form-item label="校对数量：">
                 <el-input v-model="form.proof_count" style="width:200px"></el-input>
               </el-form-item>
             </el-col> 
            </el-row>
          </el-form>
        </span>
        <span slot="footer" class="dialog-footer">
            <el-button @click="proofPriceDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="proofInventory">保存</el-button>
        </span>
      </el-dialog>
    </div>
</template>

<script> 
import { uParseTime } from '@/utils/tools'
import { postSearchGoodWarehouseList,saveInventory,getInventoryList,SaveCheckedInventory,getInventoryDetail,modifyInventory,deleteInventory,getStockBatchNumber,getGoodWarehouseList,proofInventory } from "@/api/stock"
export default {
    name: "inventory",
    data() {
        return{
            searchKey:'',
            value1:'',
            value2:'',
            tableData: [],
            dialogVisible:false,
            total: 0,
            inventoryList:[
              {id:0,name:"全部"},
              {id:1,name:"盘点完成"},
              {id:2,name:"正在盘点"},
            ],
            start_time:"",
            end_time:"",
           form: {
                id:"",
                good_name: '',
                packing_price:'',
                new_price:"",
                count:"",
                remark:"",
                warehousing_order:"",
                manufacturer:"",
                dealer:"",
                license_number:"",
                warehousing_unit:"",
                specification_name:"",
                buy_price:"",
                good_id:"",
                packing_unit:"",
                good_origin_place:"",
                report_count:"",
                total:"",
                expiry_date:"",
                product_date:"",
                number:"",
                proof_count:"",
            },
         manufacturerList:[],
         dealerList:[],
         goodList:[],
         currentIndex: 0,
         inventory_status:"",
         limit:10,
         page:1,
         doctorList:[],
         total:0,
         tableList:[],
         ids:"",
         checker:this.$store.getters.xt_user.user.id,
         check_time:new Date(),
         checkDialogVisible:false,
         editPriceDialogVisible:false,
         modefiyePriceDialogVisible:false,
         proofPriceDialogVisible:false,
         id:0,
         numberList:[],
        }
    },
    methods:{
         querySearchAsync(keyword, cb) {
            let key = '';
            if (keyword != undefined) {
                key = keyword
            }
            postSearchGoodWarehouseList(key).then(response => {
            if (response.data.state == 1) {
            
                var list = response.data.data.list
                console.log("列表数据",list)
                this.goodList = list
                var manufacturerList = response.data.data.manufacturerList
                this.manufacturerList = manufacturerList
                var dealer =  response.data.data.dealerList
                this.dealerList = dealer
                for(let i=0;i<this.goodList.length;i++){
                    for(let j=0;j<this.manufacturerList.length;j++){
                    if(this.goodList[i].manufacturer == this.manufacturerList[j].id){
                        this.goodList[i].manufacturer = this.manufacturerList[j].manufacturer_name
                    }
                    }
                }

                for(let i=0;i<this.goodList.length;i++){
                    for(let j=0;j<this.dealerList.length;j++){
                        if(this.goodList[i].dealer == this.dealerList[j].id){
                        this.goodList[i].dealer = this.dealerList[j].dealer_name
                        }
                    }
                }
            
                cb(this.goodList)
            } else {
                cb([])
             }
          })
         },
        changeGoodName(val){
          this.currentIndex = val
        },
         handleSelect(val){
            console.log("val232323223",val)
            this.getStockBatchNumber(val.good_id)
            this.getGoodWarehouseList(val.good_id)
            this.form.id = val.id
            this.form.good_id = val.good_id,
            this.form.good_name = val.good_name
            this.form.packing_price = val.packing_price
            this.form.warehousing_order = val.warehousing_order
            this.form.license_number = val.license_number
            this.form.dealer = val.dealer
            this.form.manufacturer = val.manufacturer
            this.form.specification_name = val.specification_name
            this.form.remark = val.remark
            this.form.buy_price = val.buy_price
            this.form.warehousing_unit = val.packing_unit  
            this.form.total = val.total
            this.form.number = val.number
            this.form.expiry_date = val.expiry_date
            this.form.product_date = val.product_date
        },
        search(){
          this.getlist()
        },
        print(){
          if(this.ids == ""){
            this.$message.error("请勾选打印数据")
            return
          }else{
           this.$router.push({path:'/stock/inventoryPrint?ids='+this.ids})   
          } 
        },
       getTime(val) {
         if(val < 0){
            return ""
          }
         if(val == ""){
            return ""
          }else {
            return uParseTime(val, '{y}-{m}-{d}')
         }
        },
        handleSizeChange(val){
          this.limit = val
          this.getlist()
        },
        handleCurrentChange(val){
          this.page = val
          this.getlist()
        },
        addInventory(){
           var obj = {
            good_id:this.form.good_id,
            good_name:this.form.good_name,
            specification_name:this.form.specification_name,
            warehousing_unit:this.form.warehousing_unit,
            count:this.form.count,
            buy_price:this.form.buy_price.toString(),
            packing_price:this.form.packing_price.toString(),
            manufacturer:this.form.manufacturer,
            good_origin_place:this.form.good_origin_place,
            license_number:this.form.license_number,
            remark:this.form.remark,
            warehousing_order:this.form.warehousing_order,
            dealer:this.form.dealer,
            start_time:this.getTime(new Date()),
            product_date:this.form.product_date,
            expiry_date:this.form.expiry_date,
            number:this.form.number,
            warehousing_info_id:0,
            total:this.form.total,

           } 
           this.tableData.push(obj)
        },
      saveInventory(){
        for(let i=0;i<this.tableData.length;i++){
           for(let j=0;j<this.numberList.length;j++){
              if(this.tableData[i].number == this.numberList[j].number){
                this.tableData[i].warehousing_info_id = this.numberList[j].id
              }
              this.tableData[i].expiry_date = parseInt(this.tableData[i].expiry_date)
              this.tableData[i].product_date = parseInt(this.tableData[i].product_date)
           }
          
          this.tableData[i].count = parseInt(this.tableData[i].count)
          this.tableData[i].total = parseInt(this.tableData[i].total)
          if(this.tableData[i].manufacturer == 0){
            this.tableData[i].manufacturer = ""
          }
          if(this.tableData[i].dealer == 0){
            this.tableData[i].dealer = ""
          }
        }
        var params = {
         tableData:this.tableData,
        } 
        console.log("params",params)
       
       saveInventory(params).then(response=>{
         if(response.data.state == 1){
           var msg = response.data.data.msg
           this.$message.success("保存成功")
           this.dialogVisible = false
           this.getlist()
         }
       })
      },
   getlist(){
    var params = {
          keyword:this.searchKey,
          start_time:this.start_time,
          end_time:this.end_time,
          inventory_status:this.inventory_status, 
          page:this.page,
          limit:this.limit,
         }
        console.log("parasm",params)
       getInventoryList(params).then(response=>{
          if(response.data.state ==1 ){
           var list =  response.data.data.list
           console.log("列表23232323232",list)
           this.tableList = list
           var total = response.data.data.total
           this.total = total
           this.doctorList =  response.data.data.doctorlist
          }
       })
     },
     getChecker(id){
       var name = ""
       for(let i=0;i<this.doctorList.length;i++){
          if(id == this.doctorList[i].admin_user_id){
             name = this.doctorList[i].user_name
          }
       }
       return name
     },
    toCheck(){
      if(this.ids.length <=0){
         this.$message.error("请勾选核对数据")
         return
       }else{
         this.checkDialogVisible = true
       }
     },
    changePrice(val){  
       var arr = []
      
       for(let i=0;i<val.length;i++){
         arr.push(val[i].id)
       }
      var str = arr.join(",")
    
      console.log("str",str)
      this.ids = str
     
     },
     SaveCheckedInventory(){
         var params = {
            ids:this.ids,
            check_time:this.getTime(this.check_time),
            checker:this.checker,
         }
       console.log("params",params)
       SaveCheckedInventory(params).then(response=>{
         if(response.data.state == 1){
           this.$message.success("保存成功")
           var inventory = response.data.data.inventory
           this.checkDialogVisible = false
           this.getlist()
         }
       })
     },
      toDelete(index){
       this.tableData.splice(index,1)
     },
     toEdit(row){
      this.form.good_name = row.good_name
      this.form.count = row.count
      this.form.remark = row.remark
      this.form.id = row.id
      this.editPriceDialogVisible = true  
     },
     upateInventory(){
       for(let i=0;i<this.tableData.length;i++){
         if(this.form.id == this.tableData[i].id){
            this.tableData[i].good_name = this.form.good_name
            // this.tableData[i].packing_price = this.form.packing_price
            this.tableData[i].count = this.form.count
            this.tableData[i].remark = this.form.remark
         }
       }
       this.editPriceDialogVisible = false
       this.form.good_name = ""
      //  this.form.packing_price = ""
       this.form.count = ""
       this.form.remark = ""
     },
     getInventory(id){
       getInventoryDetail(id).then(response=>{
          if(response.data.state == 1){
            var detail =  response.data.data.detail
            console.log("detial",detail)
            this.form.good_name = detail.good_name
            this.form.specification_name = detail.specification_name
            this.form.count = detail.count
            this.form.remark = detail.remark
            this.form.total = detail.total
            this.form.warehousing_info_id = detail.warehousing_info_id
            this.form.good_id  = detail.good_id
            this.id = detail.id
            this.proofPriceDialogVisible = true

          }
       })
     },
     getInventoryDetail(id,check_status){
        if(check_status == 1){
          this.$message.error("已核对的不能编辑")
          return
        }
       getInventoryDetail(id).then(response=>{
          if(response.data.state == 1){
            var detail =  response.data.data.detail
            console.log("detial",detail)
            this.form.count = detail.count
            this.form.remark = detail.remark
            this.id = detail.id
            this.modefiyePriceDialogVisible = true

          }
       })
     },
     modifyInventory(){
         var params = {
           id:this.id,
           count:parseInt(this.form.count),
           remark:this.form.remark,
         }
       modifyInventory(params).then(response=>{
          if(response.data.state == 1){
            var inventory =  response.data.data.inventory
            this.$message.success("保存成功")
            this.modefiyePriceDialogVisible = false
            this.getlist()
          }
       })
     },
     deleteInventory(id,check_status,index){
        if(check_status == 1){
          this.$message.error("已核对的不能编辑")
          return
        }
        this.$confirm('是否删除所选内容?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let params = {
            id:id,
          }
       deleteInventory(params).then(response => {
            if (response.data.state == 1) {
              var msg = response.data.data.msg
              this.$message.success("保存成功")
              this.tableList.splice(index,1)
            } 
          })
        }).catch(() => {
          this.loading = false
        });
     },
      exportList(){
       
         import('@/vendor/Export2Excel').then(excel => {
         const tHeader = ['盘点编码', '盘点日期', '盘点数量','盘点人','审核日期','核对人','状态']
         const filterVal = ['warehousing_order', 'start_time', 'count','user_name','check_time','checker','checker_status']
       
          for(let i=0;i<this.tableList.length;i++){
           this.tableList[i].start_time = this.getTime(this.tableList[i].start_time)
           this.tableList[i].check_time =  this.getTime(this.tableList[i].check_time)
           this.tableList[i].checker = this.getChecker(this.tableList[i].checker)
           if(this.tableList[i].checker_status == 1){
             this.tableList[i].checker_status = "已核对"
           }
          if(this.tableList[i].checker_status == 2){
             this.tableList[i].checker_status = "未核对"
           }
         }
         const data = this.formatJson(filterVal, this.tableList)
      
         excel.export_json_to_excel({
           header: tHeader,
           data,
           filename: '耗材盘点'
         })
          this.downloadLoading = false
        })
       },
       formatJson(filterVal, jsonData) {
        return jsonData.map(v => filterVal.map(j => v[j]));
      },
     
     getStockBatchNumber(id){
       var params = {
         id:id
       }
      getStockBatchNumber(params).then(response=>{
        if(response.data.state == 1){
          var list = response.data.data.list
          console.log("批号列表",list)
          this.numberList = list
        }
      })
     },
     getGoodWarehouseList(id){
       var params = {
          id:id,
       }
      getGoodWarehouseList(params).then(response=>{
         if(response.data.state == 1){
           var list = response.data.data.list
           this.form.total =  list.stock_count
           console.log("list23232",list)
         }
      })
     },
     proofInventory(){
        var params = {
          id:this.id,
          good_id:this.form.good_id,
          warehousing_info_id:this.form.warehousing_info_id,
          proof_count:parseInt(this.form.proof_count),
          total:parseInt(this.form.total)
        }
        console.log("parasm",params)
       proofInventory(params).then(response=>{
          if(response.data.state == 1){
             var info = response.data.data.info
             this.$message.success("保存成功!")
             this.proofPriceDialogVisible = false
             this.form.good_name = ""
             this.form.specification_name = ""
             this.form.proof_count = ""
             this.form.total = ""
             this.form.good_id = ""
             this.getlist()
          }
       })
     },
     changeInventory(){
       this.getlist()
     },
     changeStartTime(val){
       this.start_time = this.getTime(val)
       this.getlist()
     },
     changeEndTime(val){
       this.end_time = this.getTime(val)
       this.getlist()
     }
    },
    created(){
      this.getlist()
    },
    mounted() {
    },
};
</script>