<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">页面的url</label>
        <el-input v-model="query.vueUrl" clearable placeholder="页面的url" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">字段展示名</label>
        <el-input v-model="query.labelName" clearable placeholder="字段展示名" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" :tableKey="this.$options.name"/>
      <!--表单组件-->
      <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="页面的url">
            <el-input v-model="form.vueUrl" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="tag的样式">
            <el-input v-model="form.tagStyle" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="文字的样式">
            <el-input v-model="form.vueStyle" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="页面存储路径">
            <el-input v-model="form.vuePath" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="排序" prop="sort">
            <el-input v-model="form.sort" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="没有数据时显示的内容">
            <el-input v-model="form.defaultContent" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="字段名">
            <el-input v-model="form.propName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="字段展示名">
            <el-input v-model="form.labelName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="字段的存储类型">
            <el-input v-model="form.fieldType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="ioc图片">
            <el-input v-model="form.iIcon" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="ioc图片是否展示" prop="tfIcon">
            <el-input v-model="form.tfIcon" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="内容过度使用这个开关" prop="tfShowOverflowTooltip">
            <el-input v-model="form.tfShowOverflowTooltip" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="排序开关|自定义自己加" prop="tfSortable">
            <el-input v-model="form.tfSortable" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="tag开关" prop="tfElTag">
            <el-input v-model="form.tfElTag" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="tag属性">
            <el-input v-model="form.tagType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="用户id">
            <el-input v-model="form.userId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="是否展示" prop="tfShow">
            <el-input v-model="form.tfShow" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remarks" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="创建者">
            <el-input v-model="form.createBy" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="更新者">
            <el-input v-model="form.updateBy" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="创建日期">
            <el-input v-model="form.createTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="更新时间">
            <el-input v-model="form.updateTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="宽" prop="width">
            <el-input v-model="form.width" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="页面号" prop="pageNo">
            <el-input v-model="form.pageNo" 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.status.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="vueUrl" label="页面的url" />
        <el-table-column prop="tagStyle" label="tag的样式" />
        <el-table-column prop="vueStyle" label="文字的样式" />
        <el-table-column prop="vuePath" label="页面存储路径" />
        <el-table-column prop="sort" label="排序" />
        <el-table-column prop="defaultContent" label="没有数据时显示的内容" />
        <el-table-column prop="propName" label="字段名" />
        <el-table-column prop="labelName" label="字段展示名" />
        <el-table-column prop="fieldType" label="字段的存储类型" />
        <el-table-column prop="iIcon" label="ioc图片" />
        <el-table-column prop="tfIcon" label="ioc图片是否展示" />
        <el-table-column prop="tfShowOverflowTooltip" label="内容过度使用这个开关" />
        <el-table-column prop="tfSortable" label="排序开关|自定义自己加" />
        <el-table-column prop="tfElTag" label="tag开关" />
        <el-table-column prop="tagType" label="tag属性" />
        <el-table-column prop="userId" label="用户id" />
        <el-table-column prop="tfShow" label="是否展示" />
        <el-table-column prop="remarks" label="备注" />
        <el-table-column prop="createBy" label="创建者" />
        <el-table-column prop="updateBy" label="更新者" />
        <el-table-column prop="createTime" label="创建日期" />
        <el-table-column prop="updateTime" label="更新时间" />
        <el-table-column prop="width" label="宽" />
        <el-table-column prop="pageNo" label="页面号" />
        <el-table-column v-if="checkPer(['admin','elTableConfig:edit','elTableConfig: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 crudElTableConfig from '@/api/elTableConfig'
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 = { id: null, vueUrl: null, tagStyle: null, vueStyle: null, vuePath: null, sort: null, defaultContent: null, propName: null, labelName: null, fieldType: null, iIcon: null, tfIcon: null, tfShowOverflowTooltip: null, tfSortable: null, tfElTag: null, tagType: null, userId: null, tfShow: null, remarks: null, createBy: null, updateBy: null, createTime: null, updateTime: null, width: null, pageNo: null }
export default {
  name: 'ElTableConfig',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: 'elTableConfig', url: 'api/elTableConfig', idField: 'id', sort: 'id,desc', crudMethod: { ...crudElTableConfig }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'elTableConfig:add'],
        edit: ['admin', 'elTableConfig:edit'],
        del: ['admin', 'elTableConfig:del']
      },
      rules: {
        sort: [
          { required: true, message: '排序不能为空', trigger: 'blur' }
        ],
        tfIcon: [
          { required: true, message: 'ioc图片是否展示不能为空', trigger: 'blur' }
        ],
        tfShowOverflowTooltip: [
          { required: true, message: '内容过度使用这个开关不能为空', trigger: 'blur' }
        ],
        tfSortable: [
          { required: true, message: '排序开关|自定义自己加不能为空', trigger: 'blur' }
        ],
        tfElTag: [
          { required: true, message: 'tag开关不能为空', trigger: 'blur' }
        ],
        tfShow: [
          { required: true, message: '是否展示不能为空', trigger: 'blur' }
        ],
        width: [
          { required: true, message: '宽不能为空', trigger: 'blur' }
        ],
        pageNo: [
          { required: true, message: '页面号不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'vueUrl', display_name: '页面的url' },
        { key: 'labelName', display_name: '字段展示名' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
