<template>
  <div class="oYeRealTimeInventory">
    <div class="search">
      <el-form :inline="true">
        <el-form-item>
          <el-select
            v-model="screen"
            placeholder="选择条件"
            style="width:180px"
            clearable
          >
            <el-option
              v-for="(item, index) in selectOptions"
              :label="item.label"
              :key="index"
              :value="item.value"
            ></el-option>
          </el-select>
          <el-input v-model="con" style="width:200px" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="screen1"
            placeholder="选择条件"
            style="width:180px"
            clearable
          >
            <el-option
              v-for="(item, index) in selectOptions"
              :label="item.label"
              :key="index"
              :value="item.value"
            ></el-option>
          </el-select>
          <el-input v-model="con1" style="width:200px" clearable></el-input>
        </el-form-item>
        <el-button type="primary" @click="search">查询</el-button>
        <el-form-item></el-form-item>
      </el-form>
    </div>
    <div class="table">
      <dilTable v-bind.sync="options"></dilTable>
    </div>
  </div>
</template>
<script>
import { getCookie, formatDate } from '@/utils/util.js'

export default {
  data() {
    const generateStartDate = _ => {
      let startDate = new Date()
      let startDateStr = formatDate(startDate, 'yyyy-MM-dd')
      let startTimeStr = startDateStr + ' 00:00:00'
      let startTime = new Date(startTimeStr)
      return startTime.getTime()
    }
    const generateEndDate = _ => {
      let endDate = new Date()
      let endDateStr = formatDate(endDate, 'yyyy-MM-dd')
      let endTimeStr = endDateStr + ' 23:59:59'
      let endTime = new Date(endTimeStr)
      return endTime.getTime()
    }
    return {
      options: {
        requestUrl: '',
        requestQuery: {}
      },
      selectOptions: [
        {
          value: 'consigneeName',
          label: '客户'
        },
        {
          value: 'saleArea',
          label: '直发'
        },
        {
          value: 'inboundArea',
          label: '仓库大类'
        },
        {
          value: 'inboundWarehouse',
          label: '具体仓库'
        },
        {
          value: 'materialName',
          label: '物资名称'
        },
        {
          value: 'materialSpe',
          label: '规格'
        }
      ],
      con: '',
      con1: '',
      screen: '',
      screen1: '',
      startTime: generateStartDate(),
      endTime: generateEndDate(),
      apiId: '531',
      orgCode: null,
      loginName: null
    }
  },
  created() {
    this.getInfo()
    this.getRequestUrl()
  },
  methods: {
    getInfo() {
      this.orgCode = getCookie('orgCode')
      if (this.orgCode == 'shouhuokehu') {
        this.apiId = 534
        this.loginName = getCookie('loginName')
      } else if (this.orgCode == 'ouyechangwaiku') {
        this.apiId = 531
        this.loginName = null
        this.inboundWarehouse = getCookie('loginName')
      } else {
        this.apiId = 531
        this.loginName = null
      }
    },
    getRequestUrl() {
      this.options.requestUrl =
        '/api/v1/wms/getOyeRealTimeResult?apiId=' +
        this.apiId +
        '&con=' +
        this.con +
        '&i=' +
        new Date()
      let queryMap = {}
      queryMap[this.screen] = this.con
      queryMap[this.screen1] = this.con1
      queryMap['consigneeName'] = this.loginName
      queryMap['inboundWarehouse'] = this.inboundWarehouse
      this.options.requestQuery = JSON.parse(JSON.stringify(queryMap))
    },
    search() {
      this.getRequestUrl()
    }
  }
}
</script>
<style lang="scss" scoped>
.oYeRealTimeInventory {
  .search {
    margin-left: 10px;
    margin-top: 10px;
  }
  .table {
    margin-left: 10px;
    margin-top: 10px;
  }
}
</style>
