<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， 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="500px">
        <el-form ref="form" :model="form" :rules="rules" size="mini" label-width="80px">
          <el-form-item label="载具编码" prop="vehicle_code">
            <el-input v-model="form.vehicle_code" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="载具类型">
            <el-select
              v-model="form.vehicle_type"
              clearable
              filterable
              size="mini"
              class="filter-item"
              style="width: 370px;"
            >
              <el-option
                v-for="item in dict.vehicle_type"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </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 type="selection" width="55" />
        <el-table-column prop="vehicle_code" label="载具编码" />
        <el-table-column prop="vehicle_type" label="载具类型" >
          <template slot-scope="scope">
            {{ dict.label.vehicle_type[scope.row.vehicle_type] }}
          </template>
        </el-table-column>
        <el-table-column prop="update_optname" label="修改人" />
        <el-table-column prop="update_time" label="修改时间" />
        <el-table-column v-permission="[]" label="操作" width="120px" align="center" fixed="right">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudVehicle from './vehicle'
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 = { vehicle_id: null, vehicle_code: null, vehicle_name: null, one_code: null, two_code: null, rfid_code: null, vehicle_type: null, vehicle_width: null, vehicle_long: null, vehicle_height: null, overstruct_type: null, occupystruct_qty: null, ext_id: null, create_id: null, create_name: null, create_time: null, update_optid: null, update_optname: null, update_time: null }
export default {
  name: 'Vehicle',
  dicts:['vehicle_type'],
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '载具维护', url: 'api/vehicle', idField: 'vehicle_id', sort: 'vehicle_id,desc', crudMethod: { ...crudVehicle }})
  },
  data() {
    return {
      permission: {
      },
      rules: {
        vehicle_code: [
          { required: true, message: '载具编码不能为空', trigger: 'blur' }
        ],
        vehicle_type: [
          { required: true, message: '载具类型不能为空', trigger: 'blur' }
        ],
        overstruct_type: [
          { required: true, message: '载具超仓位类型不能为空', trigger: 'blur' }
        ],
        occupystruct_qty: [
          { required: true, message: '占仓位数不能为空', trigger: 'blur' }
        ]
      }}
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
