<template>
  <box-content>
    <el-tabs v-model="activeTab" type="border-card">
      <!-- 通用 -->
      <el-tab-pane
        :label="$t('trials:emailManageCfg:title:commom')"
        name="0"
      >
        <EmailList v-if="activeTab === '0'" :is-distinguish-criteria="false"></EmailList>
      </el-tab-pane>
      <!-- 标准相关 -->
      <el-tab-pane
        :label="$t('trials:emailManageCfg:title:criterions')"
        name="1"
      >
        <EmailList v-if="activeTab === '1'" :is-distinguish-criteria="true"></EmailList>
      </el-tab-pane>
    </el-tabs>
  </box-content>
</template>
<script>
import { getEmailNoticeConfigList, deleteEmailNoticeConfig } from '@/api/dictionary'
import BoxContent from '@/components/BoxContent'
import Pagination from '@/components/Pagination'
import EmailList from './components/EmailList'
const searchDataDefault = () => {
  return {
    IsReturnRequired: '',
    IsUrgent: '',
    IsEnable: '',
    PageIndex: 1,
    PageSize: 20
  }
}
export default {
  name: 'EmailListIndex',
  components: { BoxContent, Pagination, EmailList },
  data() {
    return {
      activeTab: '0',
      searchData: searchDataDefault(),
      loading: false,
      list: [],
      total: 0,
      rowData: {},
      title: '',
      editVisible: false,
      attachmentVisible: false
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    // 获取受试者列表
    getList() {
      this.loading = true
      getEmailNoticeConfigList(this.searchData).then(res => {
        this.loading = false
        this.list = res.Result.CurrentPageData
        this.total = res.Result.TotalCount
      }).catch(() => { this.loading = false })
    },
    // 新增
    handleAdd() {
      this.rowData = {}
      this.title = '新增'
      this.editVisible = true
    },
    // 编辑
    handleEdit(row) {
      this.rowData = { ...row }
      this.title = '编辑'
      this.editVisible = true
    },
    // 删除
    handleDelete(row) {
      this.$confirm(this.$t('trials:staffResearch:message:confirmDel'), {
        type: 'warning',
        distinguishCancelAndClose: true
      })
        .then(() => {
          deleteEmailNoticeConfig(row.Id)
            .then(res => {
              if (res.IsSuccess) {
                this.getList()
                this.$message.success('删除成功!')
              }
            })
        })
    },
    handleDetail(row) {
      this.rowData = { ...row }
      this.attachmentVisible = true
    },
    // 查询
    handleSearch() {
      this.searchData.PageIndex = 1
      this.getList()
    },
    // 重置
    handleReset() {
      this.searchData = searchDataDefault()
      this.getList()
    },
    // 排序
    handleSortByColumn(column) {
      if (column.order === 'ascending') {
        this.searchData.Asc = true
      } else {
        this.searchData.Asc = false
      }
      this.searchData.SortField = column.prop
      this.searchData.PageIndex = 1
      this.getList()
    },
    // 关闭新增、编辑框
    closeDialog() {
      this.editVisible = false
    }
  }
}
</script>
