<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="账号">
            <el-input v-model="form.username" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="用户名">
            <el-input v-model="form.person_name" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="记录时间">
            <el-input v-model="form.record_time" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="设备号">
            <el-input v-model="form.device_code" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="动作">
            <el-input v-model="form.device_action" 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 prop="username" label="账号" :min-width="flexWidth('username',crud.data,'账号')"/>
        <el-table-column prop="person_name" label="用户名" :min-width="flexWidth('person_name',crud.data,'用户名')"/>
        <el-table-column prop="record_time" label="记录时间" :min-width="flexWidth('record_time',crud.data,'记录时间')"/>
        <el-table-column prop="device_code" label="设备号" :min-width="flexWidth('device_code',crud.data,'设备号')"/>
        <el-table-column prop="device_action" label="动作" :min-width="flexWidth('device_action',crud.data,'动作')">
          <template slot-scope="scope">
            {{ dict.label.device_action[scope.row.device_action] }}
          </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 crudDasDeviceOperationRecord from './dasDeviceOperationRecord'
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 = {
  record_id: null,
  username: null,
  person_name: null,
  record_time: null,
  device_code: null,
  device_action: null
}
export default {
  name: 'DeviceOperation',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({
      title: '设备动作操作记录',
      dicts: ['device_action'],
      url: 'api/dasDeviceOperationRecord',
      idField: 'record_id',
      sort: 'record_id,desc',
      crudMethod: { ...crudDasDeviceOperationRecord },
      optShow: {
        add: false,
        edit: false,
        del: false,
        download: false,
        reset: false
      }
    })
  },
  data() {
    return {
      permission: {
      },
      rules: {
      }    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
