<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 v-if="false" label="方案标识" prop="plan_uuid">
            <el-input v-model="form.plan_uuid" style="width: 370px;" />
          </el-form-item>
          <el-form-item :label="$t('route.table_title.code')" prop="plan_code">
            <el-input v-model="form.plan_code" style="width: 370px;" />
          </el-form-item>
          <el-form-item :label="$t('route.table_title.name')" prop="plan_name">
            <el-input v-model="form.plan_name" style="width: 370px;" />
          </el-form-item>
          <el-form-item :label="$t('route.table_title.remark')" prop="description">
            <el-input v-model="form.remark" style="width: 380px;" rows="5" type="textarea" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">{{ $t('common.Cancel') }}</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">{{ $t('common.Confirm') }}</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 v-if="false" prop="plan_uuid" label="方案标识" />
        <el-table-column prop="plan_code" :label="$t('route.table_title.code')" />
        <el-table-column prop="plan_name" :label="$t('route.table_title.name')" />
        <el-table-column prop="remark" :label="$t('route.table_title.remark')" />
        <el-table-column prop="create_by" :label="$t('common.create_by')" />
        <el-table-column prop="create_time" :label="$t('common.create_time')" />
        <el-table-column prop="update_by" :label="$t('common.update_by')" />
        <el-table-column prop="update_time" :label="$t('common.update_time')" />
        <el-table-column
          v-permission="['admin','routePlan:edit','routePlan:del']"
          :label="$t('common.Update')"
          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 crudRoutePlan from '@/api/acs/route/routePlan'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import i18n from '@/i18n'

const defaultForm = {
  plan_uuid: null,
  plan_code: null,
  plan_name: null,
  remark: null,
  is_active: null,
  is_delete: null,
  create_by: null,
  create_time: null,
  update_by: null,
  update_time: null
}
export default {
  name: 'RoutePlan',
  components: { pagination, crudOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({
      title: i18n.t('route.title2'),
      url: 'api/routePlan',
      idField: 'plan_uuid',
      sort: 'plan_uuid,desc',
      crudMethod: { ...crudRoutePlan }
    })
  },
  data() {
    return {
      permission: {
        add: ['admin', 'routePlan:add'],
        edit: ['admin', 'routePlan:edit'],
        del: ['admin', 'routePlan:del']
      },
      rules: {
        plan_uuid: [
          { required: true, message: '方案标识不能为空', trigger: 'blur' }
        ],
        plan_code: [
          { required: true, message: '方案编码不能为空', trigger: 'blur' }
        ],
        plan_name: [
          { 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>
