<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-form
          :inline="true"
          class="demo-form-inline"
          label-position="right"
          label-width="110px"
          label-suffix=":"
        >
          <el-form-item label="所属库区">
            <el-cascader
              placeholder="所属库区"
              :options="sects"
              :props="{ checkStrictly: true }"
              clearable
              class="filter-item"
              size="mini"
              style="width: 185px;"
              @change="sectQueryChange"
            />
          </el-form-item>

          <el-form-item label="库龄天数">
            <el-input-number
              v-model="query.sid_day_start"
              :min="1"
              clearable
              :precision="0"
              placeholder="起始"
              :controls="false"
              style="width: 90px;"
            />
            -
            <el-input-number
              v-model="query.sid_day_end"
              :min="1"
              clearable
              :precision="0"
              placeholder="结束"
              :controls="false"
              style="width: 90px;"
            />
          </el-form-item>

          <el-form-item label="物料编码">
            <el-input
              v-model="query.material_code"
              clearable
              size="mini"
              placeholder="输入物料编码、名称"
              style="width: 185px;"
              class="filter-item"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>

          <el-form-item label="木箱码">
            <el-input
              v-model="query.package_box_sn"
              clearable
              placeholder="输入木箱码"
              size="mini"
              style="width: 185px;"
              class="filter-item"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>

          <el-form-item label="子卷号">
            <el-input
              v-model="query.container_name"
              clearable
              placeholder="输入子卷号"
              size="mini"
              style="width: 185px;"
              class="filter-item"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>

          <el-form-item label="sap批次">
            <el-input
              v-model="query.sap_pcsn"
              clearable
              placeholder="输入sap批次"
              size="mini"
              style="width: 185px;"
              class="filter-item"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>

          <!--       <el-form-item label="制造完成日期">
            <el-date-picker
              v-model="query.date_of_production"
              type="date"
              placeholder="选择日期时间"
              size="mini"
              style="width: 185px;"
              value-format="yyyy-MM-dd"
              @change="hand"
            >
            </el-date-picker>
          </el-form-item>-->
          <el-form-item label="入库日期">
            <el-date-picker
              v-model="query.date_of_FG_inbound"
              type="date"
              placeholder="选择日期时间"
              size="mini"
              style="width: 185px;"
              value-format="yyyy-MM-dd"
              @change="hand"
            />
          </el-form-item>

          <el-form-item label="订单号">
            <el-input
              v-model="query.sale_order_name"
              clearable
              placeholder="输入订单号"
              size="mini"
              style="width: 185px;"
              class="filter-item"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>
          <el-form-item label="生产日期">
            <el-date-picker
              v-model="query.createTime"
              type="daterange"
              value-format="yyyy-MM-dd HH:mm:ss"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :default-time="['00:00:00', '23:59:59']"
              @change="crud.toQuery"
            />
          </el-form-item>

          <el-form-item label="客户编码">
            <el-input
              v-model="query.customer_name"
              clearable
              placeholder="输入客户编码、名称"
              size="mini"
              style="width: 185px;"
              class="filter-item"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>

          <el-form-item label="是否超期">
            <el-switch
              v-model="query.is_sid"
              active-value="1"
              inactive-value="0"
              active-color="#ff4949"
              inactive-color="#13ce66"
              @change="hand"
            >
            </el-switch>
          </el-form-item>
          <rrOperation />
        </el-form>
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission">
        <el-button
          slot="right"
          class="filter-item"
          type="success"
          icon="el-icon-thumb"
          size="mini"
          :loading="showDtlLoading"
          @click="downdtl"
        >
          导出
        </el-button>
      </crudOperation>
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        size="mini"
        :data="crud.data"
        highlight-current-row
        style="width: 100%;"
      >
        <el-table-column show-overflow-tooltip prop="stor_name" label="仓库" :min-width="flexWidth('stor_name',crud.data,'仓库')" />
        <el-table-column show-overflow-tooltip prop="sect_name" label="库区" :min-width="flexWidth('sect_name',crud.data,'库区')" />
        <el-table-column show-overflow-tooltip prop="struct_code" label="仓位" :min-width="flexWidth('struct_code',crud.data,'仓位')" />
        <el-table-column show-overflow-tooltip prop="package_box_sn" label="木箱码" :min-width="flexWidth('package_box_sn',crud.data,'木箱码')" />
        <el-table-column show-overflow-tooltip prop="quanlity_in_box" label="箱内子卷数量" :min-width="flexWidth('quanlity_in_box',crud.data,'箱内子卷数量')" />
        <el-table-column show-overflow-tooltip prop="customer_name" label="客户编码" :min-width="flexWidth('customer_name',crud.data,'客户编码')" />
        <el-table-column show-overflow-tooltip prop="customer_description" label="客户名称" :min-width="flexWidth('customer_description',crud.data,'客户名称')" />
        <el-table-column show-overflow-tooltip prop="sales_owner" label="业务员" :min-width="flexWidth('sales_owner',crud.data,'业务员')" />
        <el-table-column show-overflow-tooltip prop="sale_order_name" label="销售订单及行号" :min-width="flexWidth('sale_order_name',crud.data,'销售订单及行号')" />
        <el-table-column show-overflow-tooltip prop="pcsn" label="子卷号" :min-width="flexWidth('pcsn',crud.data,'子卷号')" />
        <el-table-column show-overflow-tooltip prop="sap_pcsn" label="sap批次" :min-width="flexWidth('sap_pcsn',crud.data,'sap批次')" />
        <el-table-column show-overflow-tooltip prop="sid_day" label="库龄(天)" :min-width="flexWidth('sid_day',crud.data,'库龄(天)')" />
        <el-table-column show-overflow-tooltip prop="product_name" label="产品编码" :min-width="flexWidth('product_name',crud.data,'产品编码')" />
        <el-table-column show-overflow-tooltip prop="product_description" label="产品描述" :min-width="flexWidth('product_description',crud.data,'产品描述')" />
        <el-table-column show-overflow-tooltip prop="width" label="产品规格(幅宽)" :min-width="flexWidth('width',crud.data,'产品规格(幅宽)')" />
        <el-table-column show-overflow-tooltip prop="thickness" label="产品厚度" :min-width="flexWidth('thickness',crud.data,'产品厚度')" />
        <el-table-column show-overflow-tooltip prop="mass_per_unit_area" label="单位面积质量" :min-width="flexWidth('mass_per_unit_area',crud.data,'单位面积质量')" />
        <el-table-column show-overflow-tooltip prop="canuse_qty" label="净重" :min-width="flexWidth('canuse_qty',crud.data,'净重')" />
        <el-table-column show-overflow-tooltip prop="length" label="长度" :min-width="flexWidth('length',crud.data,'长度')" />
        <el-table-column show-overflow-tooltip prop="date_of_production" label="制造完成日期" :min-width="flexWidth('date_of_production',crud.data,'制造完成日期')" />
        <el-table-column show-overflow-tooltip prop="date_of_fg_inbound" label="入库日期" :min-width="flexWidth('date_of_fg_inbound',crud.data,'入库日期')" />
        <el-table-column show-overflow-tooltip prop="box_weight" label="木箱自身重量" :min-width="flexWidth('box_weight',crud.data,'木箱自身重量')" />
        <el-table-column show-overflow-tooltip prop="quality_guaran_period" label="保质期" :min-width="flexWidth('quality_guaran_period',crud.data,'保质期')" />
        <el-table-column show-overflow-tooltip prop="un_plan_product_property1" label="子卷的悟性值1" :min-width="flexWidth('un_plan_product_property1',crud.data,'子卷的悟性值1')" />
        <el-table-column show-overflow-tooltip prop="un_plan_product_property2" label="子卷的悟性值2" :min-width="flexWidth('un_plan_product_property2',crud.data,'子卷的悟性值2')" />
        <el-table-column show-overflow-tooltip prop="un_plan_product_property3" label="子卷的悟性值3" :min-width="flexWidth('un_plan_product_property3',crud.data,'子卷的悟性值3')" />
        <el-table-column show-overflow-tooltip prop="box_type" label="木箱料号" :min-width="flexWidth('box_type',crud.data,'木箱料号')" />
        <el-table-column show-overflow-tooltip prop="box_length" label="长" :min-width="flexWidth('box_length',crud.data,'长')" />
        <el-table-column show-overflow-tooltip prop="box_width" label="宽" :min-width="flexWidth('box_width',crud.data,'宽')" />
        <el-table-column show-overflow-tooltip prop="box_high" label="高" :min-width="flexWidth('box_high',crud.data,'高')" />
        <el-table-column show-overflow-tooltip prop="remark" label="备注" :min-width="flexWidth('remark',crud.data,'备注')" />
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import CRUD, { crud, header, presenter } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import DateRangePicker from '@/components/DateRangePicker/index'
import crudUserStor from '@/views/wms/basedata/st/userStor/userStor'
import crudPastivtquery from '@/views/wms/stat/pastivt/pastivtquery'
import { download } from '@/api/data'
import { downloadFile } from '@/utils'

export default {
  name: 'Pastivt',
  components: { crudOperation, rrOperation, udOperation, pagination, DateRangePicker },
  cruds() {
    return CRUD({
      title: '',
      optShow: { add: false, reset: true },
      idField: 'iostorinv_id',
      url: '/api/pastivt',
      query: {
        is_sid: '0'
      },
      crudMethod: { ...crudPastivtquery }
    })
  },
  mixins: [presenter(), header(), crud()],
  // 数据字典
  dicts: [],
  data() {
    return {
      height: document.documentElement.clientHeight - 180 + 'px;',
      sects: [],
      showDtlLoading: false
    }
  },
  mounted: function() {
    const that = this
    window.onresize = function temp() {
      that.height = document.documentElement.clientHeight - 180 + 'px;'
    }
  },
  created() {
    crudUserStor.getSect({ 'stor_id': '' }).then(res => {
      this.sects = res.content
    })
  },
  methods: {
    hand(value) {
      this.crud.toQuery()
    },
    sectQueryChange(val) {
      if (val.length === 1) {
        this.query.stor_id = val[0]
        this.query.sect_id = ''
      }
      if (val.length === 0) {
        this.query.sect_id = ''
        this.query.stor_id = ''
      }
      if (val.length === 2) {
        this.query.stor_id = val[0]
        this.query.sect_id = val[1]
      }
      this.crud.toQuery()
    },
    downdtl() {
      if (this.currentRow !== null) {
        crud.downloadLoading = true
        const data = {
          'stor_id': this.crud.query.stor_id,
          'sect_id': this.crud.query.sect_id,
          'sid_day_start': this.crud.query.sid_day_start,
          'sid_day_end': this.crud.query.sid_day_end,
          'material_code': this.crud.query.material_code,
          'package_box_sn': this.crud.query.package_box_sn,
          'container_name': this.crud.query.container_name,
          'sap_pcsn': this.crud.query.sap_pcsn,
          'date_of_production': this.crud.query.date_of_production,
          'sale_order_name': this.crud.query.sale_order_name,
          'customer_name': this.crud.query.customer_name
        }
        if (this.crud.query.createTime !== undefined) {
          data.begin_time = this.crud.query.createTime[0]
          data.end_time = this.crud.query.createTime[1]
        }
        this.showDtlLoading = true
        download('/api/pastivt/download', data).then(result => {
          downloadFile(result, '临期库存查询', 'xlsx')
          crud.downloadLoading = false
          this.showDtlLoading = false
        }).catch(() => {
          crud.downloadLoading = false
          this.showDtlLoading = false
        })
      }
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
::v-deep .el-dialog__body {
  padding-top: 10px;
}
</style>
