<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">模糊搜索</label>
        <el-input
          v-model="query.region_code"
          clearable
          placeholder="编码、名称"
          style="width: 185px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <rrOperation :crud="crud" />
      </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="550px"
      >
        <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="region_name">
            <el-input v-model="form.region_name" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="点位类型说明">
            <el-input v-model="form.point_type_explain" type="textarea" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="点位状态说明">
            <el-input v-model="form.point_status_explain" type="textarea" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remark" type="textarea" style="width: 370px;" />
          </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 v-if="false" prop="region_id" label="区域标识" />
        <el-table-column prop="region_code" label="区域编码" min-width="120" />
        <el-table-column prop="region_name" label="区域名称" min-width="130" />
        <el-table-column prop="point_type_explain" label="点位类型说明" min-width="150" />
        <el-table-column prop="point_status_explain" label="点位状态说明" min-width="120" />
        <el-table-column prop="remark" label="备注" />
        <el-table-column prop="create_name" label="创建人" />
        <el-table-column prop="create_time" label="创建时间" min-width="140" show-overflow-tooltip />
        <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 crudRegion, { changeActive } from '@/views/wms/sch/region'
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 = {
  region_id: null,
  region_code: null,
  region_name: null,
  remark: null,
  point_type_explain: null,
  point_status_explain: null,
  create_id: null,
  create_name: null,
  create_time: null,
  update_optid: null,
  update_optname: null,
  update_time: null
}
export default {
  name: 'Region',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({
      title: '区域管理',
      url: 'api/region',
      idField: 'region_id',
      sort: 'region_id,desc',
      crudMethod: { ...crudRegion },
      optShow: {
        add: true,
        edit: false,
        del: false,
        download: false,
        reset: true
      }
    })
  },
  data() {
    return {
      permission: {},
      rules: {
        region_code: [
          { required: true, message: '区域编码不能为空', trigger: 'blur' }
        ],
        region_name: [
          { required: true, message: '区域名称不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
