<template>
  <el-card shadow="never" class="aui-card--fill">
    <el-form
      :inline="true"
      :model="dataForm"
      @submit.native.prevent
      @keyup.enter.native="getDataList()"
    >
      <el-form-item>
        <el-button type="primary" @click="addOrUpdateHandle(null,null,'新增表单')">{{ $t('add') }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="dataListLoading" :data="dataList" row-key="id" border style="width: 100%;">
      <!-- 名称 -->
      <el-table-column prop="name" :label="'名称'" />
      <!-- 描述 -->
      <el-table-column prop="description" :label="'描述'" />
      <!-- 创建时间 -->
      <el-table-column prop="createDate" :label="'创建时间'" />
      <!-- 操作 -->
      <el-table-column prop="operation" :label="$t('handle')">
        <template slot-scope="scope">
          <!-- <el-button type="text" size="small" @click="testClick1(scope.row.id,...scope.row)">{{ '测试1' }}</el-button> -->
          <!-- <el-button type="text" size="small" @click="testClick2(scope.row.id,...scope.row)">{{ '测试2' }}</el-button> -->
          <el-button
            type="text"
            size="small"
            @click="preview(scope.row.id,scope.row)"
          >{{ $t('preview') }}</el-button>
          <el-button
            type="text"
            size="small"
            @click="addOrUpdateHandle(scope.row.id,scope.row)"
          >{{ $t('update') }}</el-button>
          <el-button
            type="text"
            size="small"
            style="color:red"
            @click="deleteCrfItem(scope.row.id)"
          >{{ $t('delete') }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 添加分页组件 -->
    <el-pagination
      background
      layout="prev, pager, next"
      :total="total"
      @current-change="pageCurrentChangeHandle"
    />
    <!-- <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      /> -->
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList" />
    <!-- 弹窗, 预览 -->
    <preview v-if="previewVisible" ref="preview" :type="'preview'" />

  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './add-or-update'
import preview from '@/components/ecrf/dialog-load'

export default {
  components: { AddOrUpdate, preview },
  mixins: [mixinViewModule],
  data() {
    return {
      previewVisible: false,
      mixinViewModuleOptions: {
        getDataListURL: '/project/crf/template/page',
        getDataListIsPage: true,
        deleteURL: '/project/crf/template'
      },
      dataForm: {
        projectId: window.SITE_CONFIG['projectId']
      }
    }
  },
  methods: {
    preview(id, params, title) {
      this.previewVisible = true
      this.$nextTick(() => {
        this.$refs.preview.id = id
        this.$refs.preview.init()
      })
    },
    deleteCrfItem(id) {
      this.$confirm('确认删除吗？').then(() => {
        this.$http.delete('/project/crf/template', { params: { id }}).then(() => {
          this.$message.success('删除成功')
          this.getDataList()
        })
      })
    }
  }
}
</script>
