<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.search"
              clearable
              size="mini"
              style="width: 230px;"
              placeholder="木箱号、物料编码、物料名称"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>

          <rrOperation />
        </el-form>
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <!--<el-dialog
        :close-on-click-modal="false"
        :before-close="crud.cancelCU"
        :visible.sync="crud.status.cu > 0"
        :title="crud.status.title"
        width="800px"
      >
        <el-form ref="form" :model="form" :rules="rules" size="mini" label-width="120px">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="木箱类型:" prop="box_type">
                <el-input v-model="form.box_type" style="width: 200px;" :disabled="crud.status.edit > 0" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="木箱描述:" prop="box_name">
                <el-input v-model="form.box_name" style="width: 200px;" :disabled="crud.status.edit > 0" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="捆扎模版:" prop="lash_num">
                <el-input v-model="form.lash_num" style="width: 200px;" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="叉车取货宽度:" prop="expend_width">
                <el-input-number :precision="2" :step="0.1" :min="0" :max="100" v-model="form.expend_width" size="mini" :controls="false" style="width: 200px" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="一次捆扎次数:" prop="lash_num_one">
                <el-input-number :precision="0" :step="1" :min="0" :max="9" v-model="form.lash_num_one" size="mini" :controls="false" style="width: 200px" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="二次捆扎次数:" prop="lash_num_tow">
                <el-input-number :precision="0" :step="1" :min="0" :max="9" v-model="form.lash_num_tow" size="mini" :controls="false" style="width: 200px" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="是否一次捆扎:" prop="need_lash_one">
                <el-radio v-model="form.need_lash_one" label="1" style="width: 79px;" border>是</el-radio>
                <el-radio v-model="form.need_lash_one" label="0" style="width: 79px;" border>否</el-radio>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="是否二次捆扎:" prop="need_lash_two">
                <el-radio v-model="form.need_lash_two" label="1" style="width: 79px;" border>是</el-radio>
                <el-radio v-model="form.need_lash_two" label="0" style="width: 79px;" border>否</el-radio>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>-->
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        size="mini"
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column prop="box_no" sortable label="木箱号" :min-width="flexWidth('box_no',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="num" label="最大子卷数" :min-width="flexWidth('num',crud.data,'最大子卷数')" />
        <el-table-column prop="box_length" label="木箱长度" :min-width="flexWidth('box_length',crud.data,'木箱长度')" />
        <el-table-column prop="box_width" label="木箱宽度" :min-width="flexWidth('box_width',crud.data,'木箱宽度')" />
        <el-table-column prop="box_high" label="木箱高度" :min-width="flexWidth('box_high',crud.data,'木箱高度')" />
        <el-table-column prop="vehicle_type" label="载具类型" :min-width="flexWidth('vehicle_type',crud.data,'载具类型')" :formatter="formattTwo"/>
        <el-table-column prop="is_packing" label="是否装箱" :min-width="flexWidth('is_packing',crud.data,'是否装箱')" :formatter="formatOne" />
        <el-table-column prop="box_weight" label="木箱重量" :min-width="flexWidth('box_weight',crud.data,'木箱重量')" />
        <el-table-column prop="insert_time" label="创建时间" :min-width="flexWidth('insert_time',crud.data,'创建时间')" />
       <!-- <el-table-column
          v-permission="['admin','sectattr:edit','sectattr:del']"
          label="操作"
          width="120px"
          fixed="right"
          align="center"
        >
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>-->
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudBoxinfo from '@/views/wms/basedata/st/boxInfo/boxinfo'
import CRUD, { crud, form, 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'

const defaultForm = {
  box_id: null,
  box_no: null,
  material_code: null,
  material_name: null,
  num: null,
  box_length: null,
  box_width: null,
  box_high: null,
  insert_time: null,
  lash_num: null,
  vehicle_type: null,
  is_packing: null,
  box_weight: null
}
export default {
  name: 'BoxInfo',
  dicts: ['IS_OR_NOT'],
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({
      title: '木箱信息',
      optShow: { add: false, reset: true },
      url: 'api/boxinfo',
      idField: 'box_id',
      sort: 'box_no,desc',
      crudMethod: { ...crudBoxinfo }
    })
  },
  data() {
    return {
      stors: [],
      permission: {
        add: ['admin', 'user:add'],
        edit: ['admin', 'user:edit'],
        del: ['admin', 'user:del']
      },
      rules: {
      }
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    formatOne(row) {
      return this.dict.label.IS_OR_NOT[row.is_packing]
    },
    formattTwo(row) {
      if (row.vehicle_type === '1') {
        return '小托盘'
      }

      if (row.vehicle_type === '2') {
        return '大托盘'
      }
    }
  }
}
</script>

<style scoped>

</style>
