<template>
  <el-dialog
    title="载具明细"
    append-to-body
    :visible.sync="dialogVisible"
    destroy-on-close
    width="1000px"
    @close="close"
  >
    <!--表格渲染-->
    <el-table
      ref="table2"
      :data="this.bucketParam"
      style="width: 100%;"
      border
      :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
      @select="handleSelectionChange"
      @select-all="onSelectAll"
    >
      <el-table-column prop="bucketunique" label="桶号" min-width="100" show-overflow-tooltip/>
      <el-table-column prop="label" label="桶类别"/>
      <el-table-column prop="material_code" label="物料编码" width="120px"/>
      <el-table-column prop="material_name" label="物料名称" min-width="120"/>
      <el-table-column prop="pcsn" label="批次" min-width="100" show-overflow-tooltip/>
      <el-table-column prop="storage_qty" label="数量">
        <template slot-scope="scope">
          {{ fun(scope.row.storage_qty) }}
        </template>
      </el-table-column>
      <el-table-column prop="qty_unit_name" label="单位"/>
      <el-table-column prop="quality_scode" :formatter="qualityFormat" label="品质类型"/>
      <el-table-column prop="ivt_level" :formatter="ivtFormat" label="库存等级"/>
      <el-table-column prop="is_active" :formatter="activeFormat" label="是否可用"/>
      <el-table-column prop="storagevehicle_code" label="载具号"/>
      <el-table-column prop="record_order" label="顺序号"/>
      <el-table-column prop="bag_qty" label="袋数"/>
    </el-table>
    <!--分页组件-->
    <pagination/>
  </el-dialog>
</template>

<script>

import CRUD, {crud} from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'

export default {
  name: 'BucketDtlDiv',
  components: {crudOperation, pagination},
  mixins: [crud()],
  props: {
    dialogShow: {
      type: Boolean,
      default: false
    },
    bucketParam: {
      type: Array,
      default: () => { return [] }
    }
  },
  dicts: ['MD_BUCKET_TYPE', 'bucket_status', 'ST_QUALITY_SCODE', 'ST_IVT_LEVEL', 'IS_OR_NOT'],
  data() {
    return {
      sects: [],
      classes: [],
      dialogVisible: false,
      checkrow: {},
      rows: []
    }
  },
  watch: {
    dialogShow: {
      handler(newValue, oldValue) {
        this.dialogVisible = newValue
      }
    }
  },
  methods: {
    fun(val) {
      return Number(val).toFixed(3)
    },
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    handleSelectionChange(val, row) {
      if (val.length > 1) {
        this.$refs.table.clearSelection()
        this.$refs.table.toggleRowSelection(val.pop())
      } else {
        this.checkrow = row
      }
    },
    onSelectAll() {
      this.$refs.table.clearSelection()
    },
    close() {
      this.$emit('update:dialogShow', false)
    },
    qualityFormat(row, column) {
      return this.dict.label.ST_QUALITY_SCODE[row.quality_scode]
    },
    ivtFormat(row, column) {
      return this.dict.label.ST_IVT_LEVEL[row.ivt_level]
    },
    activeFormat(row, column) {
      return this.dict.label.IS_OR_NOT[row.is_active]
    }
  }
}
</script>

