<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="small" label-width="80px">
          <el-form-item label="项标识" prop="item_id">
            <el-input v-model="form.item_id" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="项编码" prop="item_code">
            <el-input v-model="form.item_code" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="项名字" prop="item_name">
            <el-input v-model="form.item_name" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="DB块编码">
            <el-input v-model="form.db_code" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="DB块值">
            <el-input v-model="form.db_value" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="DB块值类型">
            <el-input v-model="form.value_type" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="采集类型">
            <el-input v-model="form.collect_type" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="设备标识" prop="device_id">
            <el-input v-model="form.device_id" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remark" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="是否启用" prop="is_active">
            <el-input v-model="form.is_active" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="是否删除" prop="is_delete">
            <el-input v-model="form.is_delete" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="创建者" prop="create_by">
            <el-input v-model="form.create_by" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="创建时间" prop="create_time">
            <el-input v-model="form.create_time" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="更新者">
            <el-input v-model="form.update_by" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="更新时间">
            <el-input v-model="form.update_time" 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="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="item_id" label="项标识" />
        <el-table-column prop="item_code" label="项编码">
          <template slot-scope="scope">
            {{ dict.label.user_status[scope.row.item_code] }}
          </template>
        </el-table-column>
        <el-table-column prop="item_name" label="项名字">
          <template slot-scope="scope">
            {{ dict.label.user_status[scope.row.item_name] }}
          </template>
        </el-table-column>
        <el-table-column prop="db_code" label="DB块编码" />
        <el-table-column prop="db_value" label="DB块值" />
        <el-table-column prop="value_type" label="DB块值类型" />
        <el-table-column prop="collect_type" label="采集类型" />
        <el-table-column prop="remark" label="备注" />
        <el-table-column prop="is_active" label="是否启用" />
        <el-table-column prop="is_delete" label="是否删除" />
        <el-table-column prop="create_by" label="创建者" />
        <el-table-column prop="create_time" label="创建时间" />
        <el-table-column prop="update_by" label="更新者" />
        <el-table-column prop="update_time" label="更新时间" />
        <el-table-column v-permission="['admin','deviceDbitem:edit','deviceDbitem:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudDeviceDbitem from '@/views/acs/device/deviceDbitem/deviceDbitem'
import CRUD, { presenter, header, form, crud } 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 = { item_id: null, item_code: null, item_name: null, db_code: null, db_value: null, value_type: null, collect_type: null, device_id: null, remark: null, is_active: null, is_delete: null, create_by: null, create_time: null, update_by: null, update_time: null }
export default {
  name: 'DeviceDbitem',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['user_status', 'user_status'],
  cruds() {
    return CRUD({ title: '设备采集项', url: 'api/deviceDbitem', idField: 'item_id', sort: 'item_id,desc', crudMethod: { ...crudDeviceDbitem }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'deviceDbitem:add'],
        edit: ['admin', 'deviceDbitem:edit'],
        del: ['admin', 'deviceDbitem:del']
      },
      rules: {
        item_id: [
          { required: true, message: '项标识不能为空', trigger: 'blur' }
        ],
        item_code: [
          { required: true, message: '项编码不能为空', trigger: 'blur' }
        ],
        item_name: [
          { required: true, message: '项名字不能为空', trigger: 'blur' }
        ],
        device_id: [
          { required: true, message: '设备标识不能为空', trigger: 'blur' }
        ],
        is_active: [
          { required: true, message: '是否启用不能为空', trigger: 'blur' }
        ],
        is_delete: [
          { required: true, message: '是否删除不能为空', trigger: 'blur' }
        ],
        create_by: [
          { required: true, message: '创建者不能为空', trigger: 'blur' }
        ],
        create_time: [
          { required: true, message: '创建时间不能为空', trigger: 'blur' }
        ]
      }}
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
