<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="800px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="150px">
          <el-form-item label="科研项目编号" prop="projectNo">
            <el-input v-model="form.projectNo" />
          </el-form-item>
          <el-form-item label="科研项目名称" prop="projectName">
            <el-input v-model="form.projectName" />
          </el-form-item>
          <el-form-item label="项目预算" prop="projectFee">
            <el-input v-model="form.projectFee" />
          </el-form-item>
          <el-form-item label="项目负责人" prop="projectUserId">
            <!--            <el-input v-model="form.projectUserId"  />-->
            <user-select v-model="form.projectUser.id" />
            <!--              <el-select-->
            <!--                v-model="form.projectUser.id"-->
            <!--                filterable-->
            <!--                remote-->
            <!--                placeholder="请输入项目负责人名字"-->
            <!--              >-->
            <!--                <el-option-->
            <!--                    v-for="item in options"-->
            <!--                    :key="item.value"-->
            <!--                    :label="item.label"-->
            <!--                    :value="item.value">-->
            <!--                </el-option>-->

            <!--              </el-select>-->
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remark" />
          </el-form-item>

          <el-form-item label="创建者">
            <el-input v-model="form.createBy" />
          </el-form-item>
          <!-- <el-form-item label="更新者">
            <el-input v-model="form.updateBy"  />
          </el-form-item>
          <el-form-item label="创建日期">
            <el-input v-model="form.createTime"  />
          </el-form-item>
          <el-form-item label="更新时间">
            <el-input v-model="form.updateTime"  />
          </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="projectNo" label="科研项目编号" />
        <el-table-column prop="projectName" label="科研项目名称" />
        <el-table-column prop="projectFee" label="预算余额(万)" />
        <el-table-column prop="projectUser.nickName" label="项目负责人" />
        <el-table-column prop="remark" 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 v-if="checkPer(['admin','project:edit','project: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 crudProject from '@/api/system/project'
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 UserSelect from '@/views/system/user/user-select.vue'

const defaultForm = { projectUser: {}, projectId: null, projectNo: null, projectName: null, projectFee: null, projectUserId: null, remark: null, createBy: null, updateBy: null, createTime: null, updateTime: null }
export default {
  name: 'Project',
  components: { UserSelect, pagination, crudOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '科研信息', url: 'api/project', idField: 'projectId', sort: 'projectId,desc', crudMethod: { ...crudProject }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'project:add'],
        edit: ['admin', 'project:edit'],
        del: ['admin', 'project:del']
      },
      rules: {
        projectNo: [
          { required: true, message: '科研项目编号不能为空', trigger: 'blur' }
        ],
        projectName: [
          { required: true, message: '科研项目名称不能为空', trigger: 'blur' }
        ],
        projectFee: [
          { required: true, message: '项目预算不能为空', trigger: 'blur' }
        ]
      }}
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
