<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <el-form
        :inline="true"
        class="demo-form-inline"
        label-position="right"
        label-width="90px"
        label-suffix=":"
      >
        <el-form-item label="生产区域">
          <el-select
            v-model="query.product_area"
            filterable
            size="mini"
            placeholder="区域类型"
            class="filter-item"
            @change="crud.toQuery()"
          >
            <el-option
              v-for="item in dict.product_area"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="模糊搜索">
          <el-input
            v-model="query.search"
            clearable
            size="small"
            placeholder="请输入位置编码或名称"
            class="filter-item"
          />
        </el-form-item>
        <rrOperation :crud="crud" />
      </el-form>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， 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="710px">
        <el-form ref="form" :inline="true" :model="form" :rules="rules" size="mini" label-width="120px">
          <el-form-item label="生产区域" prop="product_area">
            <el-select
              v-model="form.product_area"
              placeholder=""
              style="width: 200px"
            >
              <el-option
                v-for="item in dict.product_area"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="缓存线位置编码" prop="position_code">
            <el-input v-model="form.position_code" style="width: 200px;" :disabled="crud.status.edit == 1"/>
          </el-form-item>
          <el-form-item label="缓存线位置名字" prop="position_name">
            <el-input v-model="form.position_name" style="width: 200px;" />
          </el-form-item>
          <el-form-item label="位置顺序号" prop="positionOrder_no">
            <el-input v-model="form.positionOrder_no" style="width: 200px;" />
          </el-form-item>
          <el-form-item label="缓存线编码" prop="cacheline_code">
            <el-input v-model="form.cacheline_code" style="width: 200px;" />
          </el-form-item>
          <el-form-item label="缓存线层数" prop="layer_num">
            <el-input v-model="form.layer_num" style="width: 200px;" />
          </el-form-item>
          <el-form-item label="优先层顺序" prop="priority_layer_no">
            <el-input v-model="form.priority_layer_no" style="width: 200px;" />
          </el-form-item>
          <el-form-item label="料箱展示顺序号" prop="order_no">
            <el-input v-model="form.order_no" style="width: 200px;" />
          </el-form-item>
          <el-form-item label="载具编码">
            <el-input v-model="form.vehicle_code" style="width: 200px;" />
          </el-form-item>
          <el-form-item label="是否空位" prop="is_empty">
            <el-select
              v-model="form.is_empty"
              placeholder=""
              style="width: 200px"
            >
              <el-option
                v-for="item in dict.IS_OR_NOT"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="是否展示" prop="is_show">
            <el-select
              v-model="form.is_show"
              placeholder=""
              style="width: 200px"
            >
              <el-option
                v-for="item in dict.IS_OR_NOT"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="是否可用" prop="is_active">
            <el-select
              v-model="form.is_active"
              placeholder=""
              style="width: 200px"
            >
              <el-option
                v-for="item in dict.IS_OR_NOT"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="是否删除" prop="is_delete">
            <el-select
              v-model="form.is_delete"
              placeholder=""
              style="width: 200px"
            >
              <el-option
                v-for="item in dict.IS_OR_NOT"
                :key="item.id"
                :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="position_code" label="位置编码" width="120"/>
        <el-table-column prop="position_name" label="名字" width="120"/>
        <el-table-column prop="positionOrder_no" label="顺序号" />
        <el-table-column prop="cacheline_code" label="缓存线编码" />
        <el-table-column prop="layer_num" label="层数" />
        <el-table-column prop="priority_layer_no" label="优先层顺序" />
        <el-table-column prop="order_no" label="料箱展示顺序号" width="120"/>
        <el-table-column prop="vehicle_code" label="载具编码" />
        <el-table-column prop="product_area" label="生产区域" />
        <el-table-column prop="is_empty" label="是否空位" />
        <el-table-column prop="is_show" label="是否展示" />
        <el-table-column prop="is_active" 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 crudCachelinePosition from '@/api/wms/cacheline/position/cachelinePosition'
import CRUD, { crud, form, header, presenter } from '@crud/crud'
import rrOperation from '@crud/RR.operation.vue'
import crudOperation from '@crud/CRUD.operation.vue'
import udOperation from '@crud/UD.operation.vue'
import pagination from '@crud/Pagination.vue'

const defaultForm = {
  position_code: null,
  position_name: null,
  positionOrder_no: null,
  cacheline_code: null,
  layer_num: null,
  priority_layer_no: null,
  order_no: null,
  vehicle_code: null,
  product_area: 'A1',
  is_empty: '1',
  is_show: '1',
  is_active: '1',
  is_delete: '0'
}
export default {
  name: 'CachelinePosition',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['product_area', 'IS_OR_NOT'],
  cruds() {
    return CRUD({
      title: '缓存线位置',
      url: 'api/cachelinePosition',
      idField: 'position_code',
      sort: 'position_code,desc',
      crudMethod: { ...crudCachelinePosition },
      query: {
        product_area: 'A1'
      }
    })
  },
  data() {
    return {
      permission: {
      },
      rules: {
        position_code: [
          { required: true, message: '缓存线位置编码不能为空', trigger: 'blur' }
        ],
        position_name: [
          { required: true, message: '缓存线位置名字不能为空', trigger: 'blur' }
        ],
        positionOrder_no: [
          { required: true, message: '位置顺序号不能为空', trigger: 'blur' }
        ],
        cacheline_code: [
          { required: true, message: '缓存线编码不能为空', trigger: 'blur' }
        ],
        layer_num: [
          { required: true, message: '缓存线层数不能为空', trigger: 'blur' }
        ],
        priority_layer_no: [
          { required: true, message: '优先层顺序不能为空', trigger: 'blur' }
        ],
        order_no: [
          { required: true, message: '料箱展示顺序号不能为空', trigger: 'blur' }
        ],
        product_area: [
          { required: true, message: '生产区域不能为空', trigger: 'blur' }
        ],
        is_empty: [
          { required: true, message: '是否空位不能为空', trigger: 'blur' }
        ],
        is_show: [
          { required: true, message: '是否展示不能为空', trigger: 'blur' }
        ],
        is_active: [
          { required: true, message: '是否可用不能为空', trigger: 'blur' }
        ],
        is_delete: [
          { required: true, message: '是否删除不能为空', trigger: 'blur' }
        ]
      }    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
