<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-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="500px">
        <el-form ref="form" :model="form" :rules="rules" size="mini" label-width="100px">
          <el-form-item label="区域编码" prop="region_code">
            <el-input v-model="form.region_code" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="缓存线编码" prop="cacheline_code">
            <el-input v-model="form.cacheline_code" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="是否可用" prop="is_active">
            <el-select
              v-model="form.is_active"
              placeholder=""
              style="width: 370px"
            >
              <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="region_code" label="区域编码" />
        <el-table-column prop="cacheline_code" label="缓存线编码" />
        <el-table-column prop="create_time" label="创建时间" />
        <el-table-column prop="update_time" label="更新时间" />
        <el-table-column prop="is_active" label="是否可用" >
          <template slot-scope="scop">
            {{scop.row.is_active ? '是' : '否'}}
          </template>
        </el-table-column>
        <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 crudCachelineRegionRelation from '@/api/wms/cacheline/region/cachelineRegionRelation'
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 = {
  relation_id: null,
  region_code: null,
  cacheline_code: null,
  create_time: null,
  update_time: null,
  is_active: null,
  is_delete: null
}
export default {
  name: 'CachelineRegionRelation',
  dicts: ['IS_OR_NOT'],
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '个缓存线区域关系', url: 'api/cachelineRegionRelation', idField: 'relation_id', sort: 'relation_id,desc', crudMethod: { ...crudCachelineRegionRelation }})
  },
  data() {
    return {
      permission: {
      },
      rules: {
        region_code: [
          { required: true, message: '区域编码不能为空', trigger: 'blur' }
        ],
        cacheline_code: [
          { 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>
