<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="80px"
          label-suffix=":"
        >
          <el-form-item label="物料查询">
            <el-input
              v-model="query.material_code"
              clearable
              size="mini"
              placeholder="物料编码、名称"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>
          <el-form-item label="批次号">
            <el-input
              v-model="query.pcsn"
              clearable
              size="mini"
              placeholder="批次"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>
          <el-form-item label="载具编码">
            <el-input
              v-model="query.storagevehicle_code"
              clearable
              size="mini"
              placeholder="载具编码"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>
          <el-form-item label="状态">
            <el-select
              v-model="query.status"
              clearable
              size="mini"
              placeholder="状态"
              class="filter-item"
              @change="crud.toQuery"
            >
              <el-option
                v-for="item in dict.GROUP_STATUS"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <rrOperation />
        </el-form>
      </div>
      <rrOperation />
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        size="mini"
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column prop="storagevehicle_code" label="载具编码" :min-width="flexWidth('storagevehicle_code',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="pcsn" label="批次" :min-width="flexWidth('pcsn',crud.data,'批次')" />
        <el-table-column prop="status" label="状态" :formatter="formattStatus" :min-width="flexWidth('status',crud.data,'状态')" />
        <el-table-column prop="qty" label="组盘数量" :formatter="crud.formatNum3" :min-width="100" />
        <el-table-column prop="remark" label="备注" :min-width="flexWidth('remark',crud.data,'备注')" />
        <el-table-column prop="create_name" label="组盘人" :min-width="flexWidth('create_name',crud.data,'组盘人')" />
        <el-table-column prop="create_time" label="组盘时间" :min-width="flexWidth('create_time',crud.data,'组盘时间')" />
        <el-table-column
          v-permission="['admin','Supplierbase:edit','Supplierbase:del']"
          label="操作"
          width="150px"
          lign="center"
        >
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :is-visiable-edit="false"
              :disabled-dle="scope.row.status === '02'"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudGroup from '@/views/wms/basedata/group/group'
import CRUD, { crud, form, header, presenter } from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import rrOperation from '@crud/RR.operation'

const defaultForm = {
  group_id: null,
  storagevehicle_code: null,
  material_id: null,
  pcsn: null,
  qty_unit_id: null,
  qty_unit_name: null,
  qty: null,
  remark: null,
  status: null,
  create_id: null,
  create_name: null,
  create_time: null,
  ext_code: null,
  ext_type: null
}
export default {
  name: 'Group',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  // 数据字典
  dicts: ['is_used', 'GROUP_STATUS'],
  cruds() {
    return CRUD({
      title: '组盘记录',
      url: 'api/group',
      optShow: {
        add: false,
        reset: true
      },
      idField: 'group_id',
      sort: 'group_id,desc',
      crudMethod: { ...crudGroup }
    })
  },
  data() {
    return {
      permission: {},
      classes: [],
      rules: {
      }
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    formattStatus(row) {
      return this.dict.label.GROUP_STATUS[row.status]
    }
  }
}
</script>

<style scoped>

</style>
