<template>
  <div class="app-container">
    <div class="title-container">
      <breadcrumb id="breadcrumb-container" class="breadcrumb-container" />
    </div>
    <y-page-list-layout :page-list="pageData" :page-para="listQuery" :get-page-list="getList"> 
      <template slot="left">
        <el-switch v-model="warehouseDialog" style="margin-top: 5px;margin-left: 20px;" active-text="开启出入库" inactive-text="关闭出入库"></el-switch>
        <el-input v-model="listQuery.reportNo" placeholder="产品号" clearable
          style="margin-left: 20px;width: 300px;float: left;">
        </el-input>
        <el-select style="margin-left: 20px;width: 170px;float: left;" v-model="listQuery.production" clearable placeholder="产品类型">
          <el-option value="价值意见书" label="价值意见书">价值意见书</el-option>
          <el-option value="报告" label="报告">报告</el-option>
          <el-option value="复评函" label="复评函">复评函</el-option>
          <el-option value="技术报告" label="价值意见书">技术报告</el-option>
          <el-option value="结果报告" label="报告">结果报告</el-option>
          <el-option value="咨询报告" label="复评函">咨询报告</el-option>
        </el-select>
        <el-date-picker
          style="margin-left: 20px;float: left;"
          v-model="warehouseInDate"
          type="daterange"
          align="center"
          unlink-panels
          range-separator="至"
          start-placeholder="入库时间（开始）"
          end-placeholder="入库时间（结束）"
          :picker-options="pickerOptions" value-format="yyyy-MM-dd">
        </el-date-picker>
        <el-button class="filter-item" style="margin-left: 10px;float: left;" type="primary" @click="searchList" round>搜索
        </el-button>
        <el-button class="filter-item" style="float: left;" round type="success" @click="resetSearch()">重置
        </el-button>
      </template>
      <parentTable  :data="pageData.records" slot="table" style="width: 100%;" :isBoard=600>
        <el-table-column label="业务类型" align="center"  >
          <template slot-scope="{row}">
            <span>{{ row.businessType }}</span>
          </template>
        </el-table-column>
        <el-table-column label="产品号" align="center"  >
          <template slot-scope="{row}">
            <span>{{ row.reportNo }}</span>
          </template>
        </el-table-column>
        <el-table-column label="产品类型" align="center"   >
          <template slot-scope="{row}">
            <span>{{ row.production}}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户经理" align="center"   >
          <template slot-scope="{row}">
            <span>{{ row.clientManager}}</span>
          </template>
        </el-table-column>
        <el-table-column label="库存状态" align="center">
          <template slot-scope="{row}">
            <span>{{ row.repertoryState==null?'未入库':(row.repertoryState == false?'已入库':'已出库')}}</span>
          </template>
        </el-table-column>
        <el-table-column label="入库时间" align="center">
          <template slot-scope="{row}">
            <span>{{ row.repertoryInTime}}</span>
          </template>
        </el-table-column>
      </parentTable>
    </y-page-list-layout>
    <el-dialog :visible.sync="warehouseDialog" width="25%" center top="35vh" custom-class="doWarehouseClass"
      @closed="cleanWareHouseProduction()">
      <ScanEntry ref="scanEntry" @scanEntryFun="handleScanEntry" label="请扫描二维码或输入产品号" :onFocus="warehouseDialog"/>
      <span slot="footer" class="dialog-footer">
        <el-button @click="warehouseDialog = false">取 消</el-button>
        <el-button type="primary" @click="doWareHouse()" :disabled="holdOn">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import YPageListLayout from '@/components/YPageListLayout'
import Breadcrumb from '@/components/Breadcrumb'
import ScanEntry from '@/components/ScanEntry'


export default {
  name: 'productionIn',
  components: {
    Breadcrumb,
    YPageListLayout,
    ScanEntry
  },
  filters: {
    
  },
  data() {
    return {
      pageData: { records: [] },
      listQuery: {
        page: 1,
        size: 10,
        descs: 'id',
      },
      warehouseInDate:'',
      pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
      },
      warehouseDialog:false,
      scanEntryData:null,
      holdOn:false
    }
  },
  created() {
    this.warehouseDialog = this.$route.query.openDialog === 'true';
    this.getList();
  },
  methods: {
  
    resetSearch() {
      this.$router.push({ query: {} });
      this.warehouseInDate = '';
      this.listQuery = {
        current: 1,
        size: 10,
        descs: 'id',
      }
      this.getList()
    },
   
    searchList() {
      // 重置分页
      this.listQuery.page = 1
      this.listQuery.size = 10
      if (this.warehouseInDate){
        this.listQuery.startDate = this.warehouseInDate[0]+' 00:00:00';
        this.listQuery.endDate = this.warehouseInDate[1]+ ' 23:59:59';
      }
      this.getList()
    },
    getList() {
      this.$api.majorProduction.house(Object.assign({}, this.listQuery)).then(res=>{
        if (res.code ===200){
            this.pageData = res.data;
        }
      })
    },
    aliasProductionType(code){
        if (code === 'STATEMENT'){
            return '价值意见书';
        }
        if (code === 'LETTER'){
            return '复评函';
        }
        return '报告';
    },
    cleanWareHouseProduction() {
      this.scanEntryData = null;
      this.$refs.scanEntry.clearData();
    },
    handleScanEntry(scanData) {
      this.scanEntryData = scanData;
    },
    doWareHouse(){
      this.holdOn = true;
      let productionNo = this.scanEntryData;
      if (!productionNo){
        productionNo = this.$refs.scanEntry.scanEntryData;
      }
      if (productionNo){
        
        this.$api.businessProduction.commonWareHouse(productionNo).then(res=>{
          if (res.code === 200 && res.data){
              this.$message({type:'success',message:"操作成功"});
              this.$refs.scanEntry.clearData();
          }
        })
      }else{
        this.$message({type:'error',message:"未获取到报告号"});
      }
      //解决在一秒内完成入库、出库的操作引起的bug
      setTimeout(()=>{
        this.holdOn = false;
      },1200)
    }
  },
  
}
</script>
<style lang="scss" scoped>
/deep/.doWarehouseClass {
  border-radius: 10px;
}
</style>
