<template>
  <el-dialog
    title="库存明细桶查询"
    append-to-body
    :visible.sync="dialogVisible"
    destroy-on-close
    width="1000px"
    @close="close"
    @open="open"
  >
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation />
      <!--表格渲染-->
      <el-table
        ref="deviceTable"
        v-loading="crud.loading"
        :data="crud.data"
        style="width: 100%;"
        size="mini"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column show-overflow-tooltip prop="struct_code" label="货位" />
        <el-table-column show-overflow-tooltip prop="storagevehicle_code" label="托盘号" />
        <el-table-column show-overflow-tooltip prop="bucketunique" label="桶号" width="150px">
          <template slot-scope="scope">
            <el-link type="warning" @click="openBag(scope.row)">{{ scope.row.bucketunique }}</el-link>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip min-width="130" prop="material_code" label="物料编码" />
        <el-table-column show-overflow-tooltip min-width="130" prop="material_name" label="物料名称" />
        <el-table-column show-overflow-tooltip prop="material_spec" label="规格" />
        <el-table-column show-overflow-tooltip prop="material_model" label="型号" />
        <el-table-column show-overflow-tooltip min-width="130" prop="pcsn" label="批次" />
        <el-table-column show-overflow-tooltip prop="quality_scode" label="品质类型" :formatter="format_quality_scode"/>
        <el-table-column show-overflow-tooltip prop="ivt_level" label="库存等级" :formatter="format_ivt_level"/>
        <el-table-column show-overflow-tooltip prop="is_active" label="是否可用" :formatter="format_is_active"/>
        <el-table-column show-overflow-tooltip prop="storage_qty" label="重量" :formatter="crud.formatNum3"/>
        <el-table-column show-overflow-tooltip prop="record_order" label="顺序号" />
        <el-table-column show-overflow-tooltip prop="bag_qty" label="袋数" />
        <el-table-column show-overflow-tooltip prop="unit_name" label="单位" />
        <el-table-column show-overflow-tooltip min-width="150" prop="instor_time" label="入库时间" />
      </el-table>
      <!--分页组件-->
      <pagination />
      <BagDialog :dialog-show.sync="bagDialog" :open-param-one="openParamOne"/>
    </div>
  </el-dialog>
</template>

<script>

import CRUD, { presenter, header } from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import crudOrderproc from '@/api/wms/pcs/orderproc'
import BagDialog from '@/views/wms/statistics/ivtQuery/BagDialog'

export default {
  name: 'ReceiveDialog',
  dicts: ['ST_QUALITY_SCODE', 'ST_IVT_LEVEL', 'is_usable'],
  components: { crudOperation, pagination, BagDialog },
  mixins: [presenter(), header()],
  cruds() {
    return CRUD({
      url: 'api/ivtQuery/bucketQuery',
      idField: 'id',
      sort: 'id,desc',
      crudMethod: { ... crudOrderproc },
      optShow: {
        add: false,
        edit: false,
        del: false,
        download: false,
        reset: false
      }
    })
  },
  props: {
    dialogShow: {
      type: Boolean,
      default: false
    },
    openParam: {
      type: String
    }
  },
  data() {
    return {
      dialogVisible: false,
      openParamOne: null,
      bagDialog: false
    }
  },
  watch: {
    dialogShow: {
      handler(newValue, oldValue) {
        this.dialogVisible = newValue
        this.crud.query.storagevehicle_code = this.openParam
      }
    }
  },
  methods: {
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done()
        })
        .catch(_ => {
        })
    },
    close() {
      this.$emit('update:dialogShow', false)
    },
    open() {
      this.crud.toQuery()
    },
    format_quality_scode(row, column) {
      return this.dict.label.ST_QUALITY_SCODE[row.quality_scode]
    },
    format_ivt_level(row, column) {
      return this.dict.label.ST_IVT_LEVEL[row.ivt_level]
    },
    format_is_active(row, column) {
      return this.dict.label.is_usable[row.is_active]
    },
    openBag(row) {
      this.openParamOne = row.bucketunique
      this.bagDialog = true
    }
  }
}
</script>

<style scoped>

</style>
