<template>
  <el-dialog
    title="物料选择"
    append-to-body
    :visible.sync="dialogVisible"
    destroy-on-close
    :show-close="false"
    width="1000px"
    @close="close"
    @open="open"
  >
    <div class="head-container">
      <div>
        <!-- 搜索 -->
        <date-range-picker v-model="query.createTime" class="date-item" />
        <el-input
          v-model="query.material_code"
          clearable
          size="mini"
          placeholder="物料编码、名称"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-input
          v-model="query.pcsn"
          clearable
          size="mini"
          placeholder="子卷号"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-input
          v-model="query.sap_pcsn"
          clearable
          size="mini"
          placeholder="sap批次"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-input
          v-model="query.package_box_sn"
          clearable
          size="mini"
          placeholder="箱号"
          style="width: 250px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <rrOperation />
      </div>
    </div>
    <!--表格渲染-->
    <el-table
      ref="multipleTable"
      v-loading="crud.loading"
      :data="crud.data"
      style="width: 100%;"
      border
      :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column prop="instorage_time" label="入库日期" :min-width="flexWidth('instorage_time',crud.data,'入库日期')" />
      <el-table-column prop="material_code" label="物料编码" :min-width="flexWidth('material_code',crud.data,'物料编码')" />
      <el-table-column prop="material_name" label="物料名称" :min-width="flexWidth('material_name',crud.data,'物料名称')" />
      <el-table-column prop="struct_name" label="仓位" :min-width="flexWidth('struct_name',crud.data,'仓位')" />
      <el-table-column prop="box_no" label="箱号" :min-width="flexWidth('box_no',crud.data,'箱号')" />
      <el-table-column prop="pcsn" label="子卷号" :min-width="flexWidth('pcsn',crud.data,'子卷号')" />
      <el-table-column prop="sap_pcsn" label="sap批次" :min-width="flexWidth('sap_pcsn',crud.data,'sap批次')" />
      <el-table-column show-overflow-tooltip prop="plan_qty" :formatter="crud.formatNum3" label="重量" />
      <el-table-column show-overflow-tooltip prop="qty_unit_name" label="重量单位" />
    </el-table>
    <!--分页组件-->
    <pagination />
    <span slot="footer" class="dialog-footer">
      <el-button slot="left" type="info" @click="dialogVisible = false">关闭</el-button>
      <el-button slot="left" type="primary" @click="submit">保存</el-button>
    </span>
  </el-dialog>
</template>

<script>

import CRUD, { header, presenter } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import pagination from '@crud/Pagination'
import DateRangePicker from '@/components/DateRangePicker/index'

export default {
  name: 'AddDtl',
  components: { rrOperation, pagination, DateRangePicker },
  cruds() {
    return CRUD({
      title: '用户', url: 'api/checkoutbill/addDtl',
      optShow: {
        add: false,
        edit: false,
        del: false,
        reset: true,
        download: false
      },
      query: {

      }
    })
  },
  mixins: [presenter(), header()],
  props: {
    dialogShow: {
      type: Boolean,
      default: false
    },
    openParam: {
      type: String
    },
    storId: {
      type: String
    }
  },
  data() {
    return {
      dialogVisible: false,
      opendtlParam: '',
      rows: [],
      openShow: true
    }
  },
  watch: {
    dialogShow: {
      handler(newValue, oldValue) {
        this.dialogVisible = newValue
      }
    },
    openParam: {
      handler(newValue, oldValue) {
        this.opendtlParam = newValue
      }
    }
  },
  methods: {
    [CRUD.HOOK.beforeRefresh]() {
      this.crud.query.mater_type = this.opendtlParam
      this.crud.query.stor_id = this.storId
      if (this.openShow) {
        this.openShow = false
        return false
      } else {
        return true
      }
    },
    close() {
      this.crud.resetQuery(false)
      // 清空grid数据
      this.crud.data = undefined
      this.$emit('update:dialogShow', false)
    },
    open() {
      debugger
      this.crud.query.mater_type = this.opendtlParam
    },
    submit() {
      this.rows = this.$refs.multipleTable.selection
      if (this.rows.length <= 0) {
        this.$message('请先勾选物料')
        return
      }
      this.crud.resetQuery(false)
      this.$emit('update:dialogShow', false)
      this.$emit('tableChanged', this.rows)
    }
  }
}
</script>

