<template>
  <!-- 系统问题 -->
  <box-content v-loading="loading">
    <!-- 搜索框 -->
    <div class="search">
      <el-form
        :inline="true"
        size="mini"
        class="base-search-form"
      >
        <!-- 审核问题 -->
        <el-form-item
          :label="$t('trials:qcCfg:table:questionName')"
        >
          <el-input
            v-model="searchData.QuestionName"
            clearable
            style="width:120px;"
          />
        </el-form-item>
        <!-- 语言类型 -->
<!--        <el-form-item-->
<!--          :label="$t('common:title:languageType')"-->
<!--        >-->
<!--          <el-select-->
<!--            v-model="searchData.LanguageType"-->
<!--            clearable style="width:120px;"-->
<!--          >-->
<!--            <el-option-->
<!--              v-for="item of $d.LanguageType"-->
<!--              :key="item.value"-->
<!--              :value="item.value"-->
<!--              :label="item.label"-->
<!--            />-->
<!--          </el-select>-->
<!--        </el-form-item>-->
        <!-- 类型 -->
        <el-form-item
          :label="$t('trials:medicalFeedbackCfg:title:taskType')"
        >
          <el-select
            v-model="searchData.ReadingCategory"
            clearable
            style="width:120px;"
          >
            <el-option
              v-for="item of $d.ReadingCategory"
              :key="item.value"
              :value="item.value"
              :label="item.label"
            />
          </el-select>
        </el-form-item>
        <!-- 是否通用 -->
        <el-form-item :label="$t('trials:medicalFeedbackCfg:title:isGeneral')">
          <el-select clearable style="width:120px;" v-model="searchData.IsGeneral" @change="(v) => {
            if (v) {
              searchData.CriterionTypeEnum = null
            }
          }">
            <el-option v-for="item of $d.YesOrNo" :key="item.id" :value="item.value" :label="item.label" />
          </el-select>
        </el-form-item>
        <!-- 阅片标准 -->
        <el-form-item v-if="searchData.IsGeneral === false" :label="$t('trials:medicalFeedbackCfg:title:criterion')">
          <el-select v-model="searchData.CriterionTypeEnum"  clearable style="width:120px;">
            <el-option v-for="item of $d.CriterionType" :key="item.id" :value="item.value" :label="item.label" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="handleSearch"
          >{{ $t('common:button:search') }}</el-button>
          <el-button
            type="primary"
            @click="handleReset"
          >{{ $t('common:button:reset') }}</el-button>
        </el-form-item>
      </el-form>
      <span style="margin-left:auto">
        <el-button
          type="primary"
          size="mini"
          :disabled="selectArr.length<=0"
          @click="handleSubmit"
        >
          {{ $t('common:button:submit') }}
        </el-button>
      </span>
    </div>

    <el-table
      :data="list"
      stripe
      size="small"
      height="400"
      @selection-change="handleSelectChange"
    >
      <el-table-column
        type="selection"
        align="left"
        width="45"
      />
      <el-table-column type="index" width="60" />
      <!-- 审核问题 -->
      <el-table-column
        prop="QuestionName"
        :label="$t('trials:qcCfg:table:questionName')"
        show-overflow-tooltip
      />
<!--      &lt;!&ndash; 审核问题 &ndash;&gt;-->
<!--      <el-table-column-->
<!--        prop="LanguageType"-->
<!--        :label="$t('common:title:languageType')"-->
<!--        show-overflow-tooltip-->
<!--      >-->
<!--        <template slot-scope="scope">-->
<!--          {{ $fd('LanguageType', scope.row.LanguageType) }}-->
<!--        </template>-->
<!--      </el-table-column>-->
      <!-- 类型 -->
      <el-table-column
        prop="Type"
        :label="$t('trials:qcCfg:table:type')"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          {{ $fd('QcType', scope.row.Type) }}
        </template>
      </el-table-column>
      <!-- 选项 -->
      <el-table-column
        prop="TypeValue"
        :label="$t('trials:qcCfg:table:typeValue')"
        show-overflow-tooltip
        min-width="110"
      />
      <!-- 任务类型 -->
      <el-table-column
        prop="ReadingCategory"
        :label="$t('trials:medicalFeedbackCfg:title:taskType')"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.ReadingCategory === 1" type="primary">
            {{ $fd('ReadingCategory', scope.row.ReadingCategory) }}
          </el-tag>
          <el-tag v-if="scope.row.ReadingCategory === 2" type="info">
            {{ $fd('ReadingCategory', scope.row.ReadingCategory) }}
          </el-tag>
          <el-tag v-if="scope.row.ReadingCategory === 4" type="danger">
            {{ $fd('ReadingCategory', scope.row.ReadingCategory) }}
          </el-tag>
          <el-tag v-if="scope.row.ReadingCategory === 5" type="warning">
            {{ $fd('ReadingCategory', scope.row.ReadingCategory) }}
          </el-tag>
        </template>
      </el-table-column>
      <!-- 阅片标准 -->
      <el-table-column
        prop="CriterionTypeEnum"
        :label="$t('trials:medicalFeedbackCfg:title:criterion')"
        width="120"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <div>
            {{ $fd('CriterionType', scope.row.CriterionTypeEnum) }}
          </div>
        </template>
      </el-table-column>
      <!-- 是否通用 -->
      <el-table-column
        prop="IsGeneral"
        :label="$t('trials:medicalFeedbackCfg:title:isGeneral')"
        width="80"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <div>
            {{ $fd('YesOrNo', scope.row.IsGeneral) }}
          </div>
        </template>
      </el-table-column>
      <!-- 父问题 -->
      <el-table-column
        prop="ParentShowOrder"
        :label="$t('trials:qcCfg:table:parentQs')"
        show-overflow-tooltip
      />
      <!-- 父问题触发值 -->
      <el-table-column
        prop="ParentTriggerValue"
        :label="$t('trials:qcCfg:table:parentTriggerValue')"
        show-overflow-tooltip
      />
      <!-- 序号 -->
      <el-table-column
        prop="ShowOrder"
        :label="$t('trials:qcCfg:table:order')"
        min-width="70"
      />
      <!-- 是否必填 -->
      <el-table-column
        prop="IsRequired"
        :label="$t('trials:qcCfg:table:isRequired')"
        min-width="90"
      >
        <template slot-scope="scope">
          {{ $fd('YesOrNo', scope.row.IsRequired) }}
        </template>
      </el-table-column>
<!--      &lt;!&ndash; 启用状态 &ndash;&gt;-->
<!--      <el-table-column-->
<!--        prop="IsEnable"-->
<!--        :label="$t('trials:qcCfg:table:isEnable')"-->
<!--        min-width="120"-->
<!--      >-->
<!--        <template slot-scope="scope">-->
<!--          {{ $fd('YesOrNo', scope.row.IsEnable) }}-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>
    <Pagination class="page" :total="total" :page.sync="searchData.PageIndex" :limit.sync="searchData.PageSize" @pagination="getList" />
  </box-content>
</template>
<script>
import { getReadingMedicineSystemQuestionList } from '@/api/dictionary'
import Pagination from '@/components/Pagination'
import { addTrialDataFromSystem } from '@/api/trials'
import BoxContent from '@/components/BoxContent'
const searchDataDefault = () => {
  return {
    PageIndex: 1,
    PageSize: 20,
    QuestionName: '',
    Type: '',
    CriterionTypeEnum: null,
    IsGeneral: false
  }
}
export default {
  name: 'AddDefaultQS',
  components: { BoxContent, Pagination },
  props: {
    trialReadingCriterionId: {
      type: String,
      default() {
        return ''
      }
    },
    currentCriterionType: {
      type: Number,
      default() {
        return 0
      }
    }
  },
  data() {
    return {
      trialId: '',
      searchData: searchDataDefault(),
      list: [],
      loading: false,
      selectArr: [],
      total: 0
    }
  },
  mounted() {
    this.trialId = this.$route.query.trialId
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      this.searchData.TrialId = this.trialId
      this.searchData.CurrentCriterionType = this.CurrentCriterionType
      getReadingMedicineSystemQuestionList(this.searchData).then(res => {
        this.loading = false
        this.list = res.Result.CurrentPageData
        this.total = res.Result.TotalCount
      }).catch(() => { this.loading = false })
    },
    handleSelectChange(val) {
      console.log(val)
      const arr = []
      for (let index = 0; index < val.length; index++) {
        arr.push(val[index].Id)
      }
      console.log(arr)
      this.selectArr = arr
    },
    handleSubmit() {
      this.loading = true
      var param = {
        trialId: this.trialId,
        systemQuestionIds: this.selectArr,
        TrialReadingCriterionId: this.trialReadingCriterionId
      }
      addTrialDataFromSystem(param).then(res => {
        this.loading = false
        if (res.IsSuccess) {
          this.$message.success(this.$t('common:message:savedSuccessfully'))
          this.$emit('getList')
          this.$emit('close')
        }
      }).catch(() => { this.loading = false })
    },
    // 查询
    handleSearch() {
      this.getList()
    },
    // 重置
    handleReset() {
      this.searchData = searchDataDefault()
      this.getList()
    }
  }
}
</script>
