<template>
  <BaseContainer>
    <!-- 搜索框 -->
    <template slot="search-container">
      <el-form :inline="true" size="mini">
<!--        <el-form-item label="靶病灶">-->
<!--          <el-select v-model="searchData.TargetLesion" size="mini">-->
<!--            <el-option-->
<!--              v-for="item of $d.TargetAssessment"-->
<!--              :key="item.id"-->
<!--              :value="item.value"-->
<!--              :label="item.label"-->
<!--            />-->
<!--          </el-select>-->
<!--        </el-form-item>-->

<!--        <el-form-item label="非靶病灶">-->

<!--          <el-select v-model="searchData.NonTargetLesions" size="mini">-->
<!--            <el-option-->
<!--              v-for="item of $d.NoTargetAssessment"-->
<!--              :key="item.id"-->
<!--              :value="item.value"-->
<!--              :label="item.label"-->
<!--            />-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="新病灶">-->
<!--          <el-select v-model="searchData.NewLesion" size="mini">-->
<!--            <el-option-->
<!--              v-for="item of $d.NewLesionAssessment"-->
<!--              :key="item.id"-->
<!--              :value="item.value"-->
<!--              :label="item.label"-->
<!--            />-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="整体疗效">-->
<!--          <el-select v-model="searchData.OverallEfficacy" size="mini">-->
<!--            <el-option-->
<!--              v-for="item of $d.OverallAssessment"-->
<!--              :key="item.id"-->
<!--              :value="item.value"-->
<!--              :label="item.label"-->
<!--            />-->
<!--          </el-select>-->
<!--        </el-form-item>-->
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleSearch">
            {{ $t('common:button:search') }}
          </el-button>
          <el-button type="primary" icon="el-icon-refresh-left" size="mini" @click="handleReset">
            {{ $t('common:button:reset') }}
          </el-button>
        </el-form-item>
      </el-form>
      <!-- <span style="margin-left:auto">
        <el-button
          v-if="!isCompleteConfig"
          type="primary"
          size="mini"
          @click="handleAdd"
        >
          {{ $t('common:button:new') }}
        </el-button>
      </span> -->

    </template>

    <template slot="main-container">
      <!-- 受试者列表 -->
      <el-table
        ref="organList"
        v-loading="loading"
        v-adaptive="{bottomOffset:80}"
        :data="list"
        width="100%"
        style="width: 100%;min-width: 300px"
        stripe
        height="100"
        @sort-change="handleSortByColumn"
      >
        <el-table-column type="index" min-width="90" />
        <el-table-column
          :prop="item.ColumnKey"
          v-for="item of headList"
          :key="item.ColumnName"
          :label="item.ColumnName"
          show-overflow-tooltip
          sortable="custom"
        >
          <template slot-scope="scope">
            {{ $fd(item.DictionaryKey ,Number(scope.row[item.ColumnKey])) }}
          </template>
        </el-table-column>
<!--        <el-table-column-->
<!--          v-if="!isCompleteConfig"-->
<!--          :label="$t('common:action:action')"-->
<!--          width="200"-->
<!--          fixed="right"-->
<!--        >-->
<!--          <template slot-scope="scope">-->
<!--            <el-button-->
<!--              circle-->
<!--              title="编辑"-->
<!--              icon="el-icon-edit-outline"-->
<!--              @click="handleEdit(scope.row)"-->
<!--            />-->
<!--            <el-button-->
<!--              circle-->
<!--              title="删除"-->
<!--              icon="el-icon-delete"-->
<!--              @click="handleDelete(scope.row)"-->
<!--            />-->
<!--          </template>-->
<!--        </el-table-column>-->
      </el-table>
      <!-- 分页组件 -->
      <pagination class="page" :total="total" :page.sync="searchData.PageIndex" :limit.sync="searchData.PageSize" @pagination="getList" />
    </template>

    <!-- 新增/编辑 -->
    <el-dialog
      v-if="editDialog.visible"
      :visible.sync="editDialog.visible"
      :close-on-click-modal="false"
      :title="editDialog.title"
      width="500px"
      custom-class="base-dialog-wrapper"
      append-to-body
    >
      <EfficacyAssessmentForm
        :data="rowData"
        :criterion-id="criterionId"
        @close="editDialog.visible = false"
        @getList="getList"
      />
    </el-dialog>

  </BaseContainer>
</template>
<script>
import { getTumorAssessmentPageList, deleteTumorAssessment } from '@/api/dictionary'
import BaseContainer from '@/components/BaseContainer'
import Pagination from '@/components/Pagination'
import EfficacyAssessmentForm from './EfficacyAssessmentForm'
const searchDataDefault = () => {
  return {
    CriterionId: '',
    TargetLesion: null,
    NonTargetLesions: null,
    NewLesion: null,
    OverallEfficacy: null,
    PageIndex: 1,
    PageSize: 20
  }
}
export default {
  name: 'EfficacyAssessmentList',
  components: { BaseContainer, Pagination, EfficacyAssessmentForm },
  props: {
    criterionId: {
      type: String,
      required: true
    },
    isCompleteConfig: {
      type: Boolean,
      required: true
    },
    criterionType: {
      type: Number,
      required: true
    },
  },
  data() {
    return {
      searchData: searchDataDefault(),
      loading: false,
      list: [],
      total: 0,
      rowData: {},
      editDialog: { title: '', visible: false },
      criterions: [],
      headList: []
    }
  },
  watch: {
    list() {
      this.$nextTick(() => {
        this.$refs.organList.doLayout()
      })
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    // 获取受试者列表
    getList() {
      this.loading = true
      this.searchData.CriterionId = this.criterionId
      this.searchData.CriterionType = this.criterionType
      getTumorAssessmentPageList(this.searchData).then(res => {
        this.loading = false
        // this.list = res.Result
        this.headList = res.OtherInfo
        this.list = res.Result.CurrentPageData
        this.total = res.Result.TotalCount
      }).catch(() => { this.loading = false })
    },
    // 新增
    handleAdd() {
      this.rowData = { CriterionId: this.criterionId }
      this.editDialog.title = '新增'
      this.editDialog.visible = true
    },
    // 编辑
    handleEdit(row) {
      this.rowData = { ...row }
      this.editDialog.title = '编辑'
      this.editDialog.visible = true
    },
    // 删除
    handleDelete(row) {
      this.$confirm('是否确认删除', {
        type: 'warning',
        distinguishCancelAndClose: true
      })
        .then(() => {
          this.loading = true
          deleteTumorAssessment(row.Id)
            .then(res => {
              this.loading = false
              if (res.IsSuccess) {
                this.getList()
                this.$message.success('删除成功！')
              }
            }).catch(() => { this.loading = false })
        })
    },
    // 查询
    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()
    }
  }
}
</script>
