<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.ruleType" clearable placeholder="规则类型" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">SQL内容</label>
        <el-input v-model="query.sqlContent" clearable placeholder="SQL内容" 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="550px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="120px">
          <el-form-item label="规则类型" prop="ruleType">
            <el-select v-model="form.ruleType" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.rule_type"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="SQL内容" prop="sqlContent">
            <el-input v-model="form.sqlContent" :rows="3" type="textarea" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="是否发邮件" >
            <el-checkbox v-model="form.beyj"/>
          </el-form-item>
          <el-form-item label="邮件备注">
            <el-input v-model="form.yjDes" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="邮件收件人">
            <el-input v-model="form.yjSjr" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="是否弹窗">
            <el-checkbox v-model="form.betc"/>
          </el-form-item>
          <el-form-item label="弹窗消息">
            <el-input v-model="form.tcMsg" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="颜色标记">
            <el-checkbox v-model="form.beys"/>
          </el-form-item>
          <el-form-item label="标记颜色值">
            <el-input v-model="form.ysFlg" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="标记颜色字段">
            <el-input v-model="form.ysField" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="校验正则表达式">
            <el-input v-model="form.gsContent" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="描述">
            <el-input v-model="form.description" 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" :height="crud.tableHeight" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="id" />
        <el-table-column prop="ruleType" label="规则类型">
          <template slot-scope="scope">
            {{ dict.label.rule_type[scope.row.ruleType] }}
          </template>
        </el-table-column>
        <el-table-column prop="sqlContent" label="SQL内容" />
        <el-table-column prop="description" label="描述" />
        <el-table-column prop="yjDes" label="邮件备注" />
        <el-table-column prop="yjSjr" label="邮件收件人" />
        <el-table-column prop="tcMsg" label="弹窗消息" />
        <el-table-column prop="beys" label="颜色标记" />
        <el-table-column prop="ysFlg" label="标记颜色值" />
        <el-table-column prop="ysField" label="标记颜色字段" />
        <el-table-column prop="gsContent" label="格式校验正则表达式" />
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column prop="updateTime" label="更新时间" />
        <el-table-column v-if="checkPer(['admin','ruleConfigure:edit','ruleConfigure: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 crudRuleConfigure from '@/api/ruleConfigure'
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, ruleType: null, sqlContent: null, description: null, beyj: null, yjDes: null, yjSjr: null, betc: null, tcMsg: null, beys: null, ysFlg: null, ysField: null, gsContent: null, bekz1: null, kz1Msg: null, kz1Content: null, bekz2: null, kz2Msg: null, kz2Content: null, bekz3: null, kz3Msg: null, kz3Content: null, bekz4: null, kz4Msg: null, kz4Content: null, bekz5: null, kz5Msg: null, kz5Content: null, createBy: null, updateBy: null, createTime: null, updateTime: null }
export default {
  name: 'RuleConfigure',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['rule_type'],
  cruds() {
    return CRUD({ title: '配置规则', url: 'api/ruleConfigure', idField: 'id', sort: 'id,desc', crudMethod: { ...crudRuleConfigure }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'ruleConfigure:add'],
        edit: ['admin', 'ruleConfigure:edit'],
        del: ['admin', 'ruleConfigure:del']
      },
      rules: {
        ruleType: [
          { required: true, message: '规则类型不能为空', trigger: 'blur' }
        ],
        sqlContent: [
          { required: true, message: 'SQL内容不能为空', trigger: 'blur' }
        ],
        beyj: [
          { required: true, message: '是否发邮件不能为空', trigger: 'blur' }
        ],
        bekz5: [
          { required: true, message: '扩展5标记不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'ruleType', display_name: '规则类型' },
        { key: 'sqlContent', display_name: 'SQL内容' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
