<template>
  <el-form ref="tableQsForm" v-loading="loading" :model="form" size="small" :rules="rules" :disabled="type === 'look'"
    label-width="130px">
    <div class="base-dialog-body" style="height: 550px; display:flex;flex-direction: column;">
      <div style="height: 100px;">
        <!-- 类型 -->
        <el-form-item :label="$t('trials:readingUnit:qsList:title:type')" prop="Type">
          <el-select v-model="form.Type" clearable @change="((val) => { qsTypeChange(val, form) })">
            <template v-for="item of $d.Criterion_Question_Type">
              <el-option
                v-if="item.value !== 'increment' && item.value !== 'table' && item.value !== 'basicTable' && item.value !== 'group' && item.value !== 'fixedTable' && item.value !== 'calculation'"
                :key="item.value" :value="item.value" :label="item.label" />
            </template>
          </el-select>
        </el-form-item>
        <!-- 问题名称 -->
        <el-form-item v-if="form.Type !== 'group' && $i18n.locale !== 'en'"
          :label="$t('trials:readingUnit:qsList:title:qsName')" prop="QuestionName" :rules="[
            { required: true, message: this.$t('common:ruleMessage:specify'), trigger: 'blur' },
            { max: form.Type === 'summary' ? 300 : 100, message: `${this.$t('common:ruleMessage:maxLength')} ${form.Type === 'summary' ? 300 : 100}` }
          ]">
          <el-input v-model="form.QuestionName" />
        </el-form-item>
        <!-- 问题名称（EN） -->
        <el-form-item v-if="form.Type !== 'group' && $i18n.locale !== 'zh'"
          :label="$t('trials:readingUnit:qsList:title:qsNameEn')" prop="QuestionEnName" :rules="[
            { required: true, message: this.$t('common:ruleMessage:specify'), trigger: 'blur' },
            { max: form.Type === 'summary' ? 300 : 100, message: `${this.$t('common:ruleMessage:maxLength')} ${form.Type === 'summary' ? 300 : 100}` }
          ]">
          <el-input v-model="form.QuestionEnName" />
        </el-form-item>
      </div>
      <div style="flex: 1;overflow-y:auto;">
        <!-- 公有属性 -->
        <el-divider content-position="left">{{ $t('trials:readingUnit:title:publicProperties') }}</el-divider>
        <!-- 是否显示 -->
        <el-form-item :label="$t('trials:readingUnit:baseDataCfg:title:isEnable')" prop="ShowQuestion">
          <el-radio-group v-model="form.ShowQuestion" @change="((val) => { isShowQuestionChange(val, form) })">
            <el-radio v-for="item of $d.ShowQuestion" :key="`ShowQuestion${item.value}`" :label="item.value">
              {{ item.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- 是否必填 -->
        <el-form-item v-if="form.Type !== 'group' && form.Type !== 'table' && form.Type !== 'summary'"
          :label="$t('trials:qcCfg:table:isRequired')" prop="IsRequired">
          <el-radio-group v-model="form.IsRequired" :disabled="form.IsJudgeQuestion === true || form.ShowQuestion === 2"
            @change="((val) => { isRequiredChange(val, form) })">
            <el-radio v-for="item of $d.QuestionRequired" :key="`QuestionRequired${item.value}`" :label="item.value">
              {{ item.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- 显示时依赖父问题 -->
        <el-form-item v-if="form.ShowQuestion === 1" :label="$t('trials:readingUnit:qsList:title:parentId')"
          prop="ParentId">
          <el-select v-model="form.ParentId" clearable @change="((val) => { parentQuestionChange(val, form) })">
            <el-option v-for="item of parentOptions" :key="`ParentId${item.QuestionId}`" :label="item.QuestionName"
              :value="item.QuestionId" />
          </el-select>
        </el-form-item>
        <!-- 显示时依赖父问题触发值 -->
        <el-form-item v-if="form.ParentId && form.ShowQuestion === 1"
          :label="$t('trials:qcCfg:table:parentTriggerValue')" prop="ParentTriggerValueList">
          <el-select v-model="form.ParentTriggerValueList" clearable multiple>
            <el-option v-for="item of parentTriggerValOptions" :key="item.id" :label="item.label"
              :value="String(item.value)" />
          </el-select>
        </el-form-item>
        <!-- 父问题 -->
        <el-form-item v-if="form.Type !== 'group' && form.IsRequired === 1"
          :label="$t('trials:readingUnit:qsList:title:relevanceId')" prop="RelevanceId">
          <el-select v-model="form.RelevanceId" clearable @change="((val) => { relevanceQuestionChange(val, form) })">
            <el-option v-for="item of parentOptions" :key="`RelevanceId${item.QuestionId}`" :label="item.QuestionName"
              :value="item.QuestionId" />
          </el-select>
        </el-form-item>
        <!-- 必填依赖的父问题触发值 -->
        <el-form-item v-if="form.RelevanceId && form.IsRequired === 1"
          :label="$t('trials:readingUnit:qsList:title:relevanceValueList')" prop="RelevanceValueList">
          <el-select v-model="form.RelevanceValueList" clearable multiple>
            <el-option v-for="item of reParentTriggerValOptions" :key="item.id" :label="item.label"
              :value="String(item.value)" />
          </el-select>
        </el-form-item>
        <!-- 导出标识 -->
        <!-- <el-form-item 
          :label="$t('trials:readingUnit:qsList:title:ExportIdentification')" prop="ExportIdentification"
          v-if="form.Type === 'radio' || form.Type === 'select' || form.Type === 'input' || form.Type === 'textarea' || form.Type === 'number' || form.Type === 'class' || form.Type === 'calculation'"
        >
          <el-radio-group 
            v-model="form.ExportIdentification"
            @change="
              (val) => {
                form.ExportResult = []
              }
            "
          >
            <el-radio
              v-for="item of $d.ExportIdentification"
              :key="`ExportIdentification${item.value}`"
              :label="item.value"
              >{{ item.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item> -->
        <!-- 导出结果 -->
        <el-form-item :label="$t('trials:readingUnit:qsList:title:ExportResult')"
          v-if="form.Type === 'radio' || form.Type === 'select' || form.Type === 'input' || form.Type === 'textarea' || form.Type === 'number' || form.Type === 'class' || form.Type === 'calculation'">
          <el-select v-model="form.ExportResult" multiple>
            <el-option v-for="item in $d.ExportResult" :key="`ExportResult${item.value}`" :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <!-- 限制编辑 -->
        <el-form-item :label="$t('trials:readingUnit:qsList:title:limitEdit')" v-if="form.Type !== 'summary'"
          prop="LimitEdit" :rules="[
            { required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }
          ]">
          <el-radio-group v-model="form.LimitEdit">
            <el-radio v-for="item of $d.LimitEdit" :label="item.value" :key="item.id">{{ item.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- 是否复制前值 -->
        <el-form-item :label="$t('trials:readingUnit:qsList:title:PrecopyValue')" v-if="form.Type !== 'summary'">
          <el-switch v-model="form.IsCopy" />
        </el-form-item>
        <!-- 注释 -->
        <el-form-item :label="$t('trials:readingUnit:qsList:title:Remark')" prop="Remark">
          <el-input v-model="form.Remark" />
        </el-form-item>
        <!-- 序号 -->
        <el-form-item :label="$t('trials:readingUnit:qsList:title:order')" prop="ShowOrder" :rules="[
          { required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }
        ]">
          <el-input-number v-model="form.ShowOrder" controls-position="right" :min="0" />
        </el-form-item>
        <!-- 重复出现最大次数 -->
        <el-form-item :label="$t('trials:readingUnit:qsList:title:MaxRowCount')"
          v-if="form.Type !== 'summary' && form.Type !== 'screenshot' && form.Type !== 'upload'" prop="MaxRowCount">
          <el-input-number v-model="form.MaxRowCount" controls-position="right" :min="0" :max="10" />
        </el-form-item>


        <!-- 私有属性 -->
        <el-divider content-position="left">{{ $t('trials:readingUnit:title:privateProperties') }}</el-divider>
        <!-- 下拉框单选或多选 -->
        <el-form-item v-if="form.Type === 'select'" :label="$t('trials:readingUnit:qsList:title:MultipleSelect')"
          prop="OptionTypeEnum" :rules="[
            { required: true, message: this.$t('common:ruleMessage:specify') }
          ]">
          <el-radio-group v-model="form.OptionTypeEnum">
            <el-radio v-for="item of $d.OptionType" :key="item.id" :label="item.value">
              {{ item.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- 问题数据来源 -->
        <el-form-item v-if="form.Type === 'number'" :label="$t('trials:readingUnit:qsList:title:dataSource')"
          prop="DataSource" :rules="[
            { required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }
          ]">
          <el-radio-group v-model="form.DataSource">
            <el-radio v-for="item of $d.DataSource" :key="`DataSource${item.value}`" :label="item.value">
              {{ item.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- 数值类型 -->
        <el-form-item v-if="form.Type === 'number'" :label="$t('trials:readingUnit:qsList:title:valueType')"
          prop="ValueType" :rules="[
            { required: true, message: $t('trials:researchForm:formRule:select') }
          ]">
          <el-radio-group v-model="form.ValueType">
            <template v-for="item of $d.ValueType">
              <el-radio v-if="item.value !== 3" :key="item.id" :label="item.value">
                {{ item.label }}
              </el-radio>
            </template>
          </el-radio-group>
        </el-form-item>

        <el-form-item v-if="form.Type === 'number' && form.ValueType === 1"
          :label="$t('trials:readingUnit:qsList:title:digitPlaces')" prop="ValueType" :rules="[
            { required: true, message: $t('trials:researchForm:formRule:select') }
          ]">
          <el-input :value="$fd('DigitPlaces', digitPlaces).toString()" :disabled="true" />
        </el-form-item>
        <!-- 单位 -->
        <el-form-item v-if="form.Type === 'number'" :label="$t('trials:readingUnit:qsList:title:unit')" prop="Unit"
          :rules="[
            { required: true, message: $t('trials:researchForm:formRule:select') }
          ]">
          <el-radio-group v-model="form.Unit">
            <el-radio v-for="item of $d.ValueUnit" :label="item.value" :key="item.id">{{ item.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- 自定义单位 -->
        <el-form-item v-if="form.Type === 'number' && form.Unit === 4"
          :label="$t('trials:readingUnit:qsList:title:customUnit')" prop="CustomUnit" :rules="[
            { required: true, message: $t('trials:researchForm:formRule:select') }
          ]">
          <el-input v-model="form.CustomUnit" />
        </el-form-item>
        <div v-if="form.Type === 'number' && form.DataSource === 1"
          style="background: #f8f8f8;padding: 10px 0px;border-radius: 10px;position: relative;margin-bottom: 10px;">
          <el-form-item :label="$t('trials:readingUnit:qsList:title:customCalculateMark')" prop="CustomCalculateMark"
            :rules="[
              { required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }
            ]">
            <el-radio-group v-model="form.CustomCalculateMark" style="line-height: 40px;"
              @change="(v) => CustomCalculateMarkChange(v)">
              <div>
                <el-radio v-for="item of $d.CustomCalculateMark" v-show="item.value <= 4 || item.value >= 15"
                  :key="`CustomCalculateMark${item.value}`" :label="item.value">
                  {{ item.label }}
                </el-radio>
              </div>
              <div>
                <el-radio v-for="item of $d.CustomCalculateMark" v-show="item.value > 6 && item.value < 10"
                  :key="`CustomCalculateMark${item.value}`" :label="item.value">
                  {{ item.label }}
                </el-radio>
              </div>
            </el-radio-group>
          </el-form-item>
          <el-table :data="form.CalculateQuestions" style="margin: 10px;width: calc(100% - 20px)" size="small">
            <el-table-column :label="$t('trials:readingUnit:qsList:title:order')" min-width="70">
              <template slot-scope="scope">
                {{ scope.$index + 1 }}
              </template>
            </el-table-column>
            <el-table-column :label="$t('trials:readingUnit:qsList:title:customCalculateMark')" show-overflow-tooltip
              min-width="70">
              <template slot-scope="scope">
                {{ scope.$index === 0 && [1, 2, 3, 4].includes(form.CustomCalculateMark) ? null :
                  $fd('CustomCalculateMark', form.CustomCalculateMark) }}
              </template>
            </el-table-column>
            <el-table-column :label="$t('trials:readingUnit:qsList:title:qsNameEn')" prop="TableQuestionId"
              show-overflow-tooltip min-width="180">
              <template slot-scope="scope">
                <el-select v-model="scope.row.TableQuestionId" clearable>
                  <el-option v-for="item of numberQuestions" :key="item.QuestionId" :label="item.QuestionName"
                    :value="item.QuestionId" />
                </el-select>
              </template>
            </el-table-column>
            <el-table-column :label="$t('common:action:action')" prop="TableQuestionId" show-overflow-tooltip>
              <template slot-scope="scope">
                <el-button icon="el-icon-plus" size="mini" circle :title="$t('common:button:add')"
                  @click="addCustomCalculateMark(scope.$index)" :disabled="form.CustomCalculateMark === 15" />
                <el-button icon="el-icon-minus" size="mini" circle
                  ::disabled="(form.CustomCalculateMark !== 15 && form.CalculateQuestions.length <= 2) || (form.CustomCalculateMark === 15 && form.CalculateQuestions.length <= 1)"
                  :title="$t('common:button:delete')" @click="deleteCustomCalculateMark(scope.$index)" />
              </template>
            </el-table-column>
          </el-table>
          <div style="font-size: 12px;color:#666;padding: 0 15px 0;text-align: right">
            <i class="el-icon-info" />{{ [1, 2, 3, 4].includes(form.CustomCalculateMark) ?
              $t('trials:readingUnit:qsList:message:msg1') : $t('trials:readingUnit:qsList:message:msg2') }}
          </div>
        </div>
        <!-- 是否预设 -->
        <el-form-item v-if="form.Type === 'select' || form.Type === 'radio'"
          :label="$t('trials:qcCfg:table:IsPreinstall')" prop="IsPreinstall">
          <el-radio-group v-model="form.IsPreinstall">
            <el-radio v-for="item of $d.YesOrNo" :key="`QuestionIsPreinstall${item.value}`" :label="item.value">
              {{ item.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- 图表展示-->
        <el-form-item v-if="(form.Type === 'number' || form.Type === 'calculation') && !isFromSystem"
          :label="$t('trials:readingUnit:qsList:title:ShowChartTypeEnum')" prop="ShowChartTypeEnum">
          <el-radio-group v-model="form.ShowChartTypeEnum">
            <el-radio v-for="item of $d.ShowChartType" :key="item.id" :label="item.value">{{ item.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- 影像标记:disabled="form.IsRequired === 0" -->
        <el-form-item v-if="form.Type === 'number' && !isFromSystem && readingVersionEnum"
          :label="$t('trials:readingUnit:qsList:title:imageMarkEnum')" prop="ImageMarkEnum">
          <el-radio-group v-model="form.ImageMarkEnum" @change="imageMarkEnumChange">
            <el-radio v-for="item of $d.ImageMark" :key="item.id" :label="item.value"
              :disabled="form.IsRequired === 2 && item.value === 1">{{ item.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <!--标记类型-->
        <el-form-item v-if="form.ImageMarkEnum === 1 || form.ImageMarkEnum === 2"
          :label="$t('trials:readingUnit:qsList:title:ImageMarkTypeEnum')" prop="ImageMarkTypeEnum">
          <el-radio-group v-model="form.ImageMarkTypeEnum" @change="ImageMarkTypeEnumChange">
            <el-radio v-for="item of $d.ImageMarkType" :key="item.id" :label="item.value">{{ item.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- 测量工具 ImageTool -->
        <el-form-item v-if="(form.ImageMarkEnum === 1 || form.ImageMarkEnum === 2) && form.ImageMarkTypeEnum === 0"
          :label="$t('trials:readingUnit:qsList:title:ImageTool')" prop="ImageTool" :rules="[
            { required: true, message: this.$t('common:ruleMessage:select') }
          ]">
          <el-radio-group v-model="form.ImageTool" @change="imageToolChange">
            <el-radio v-for="tool of readingTools" :key="tool.toolName" :label="tool.toolName">
              {{ $t(tool.i18nKey) }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- 分割工具 ImageTool -->
        <el-form-item v-if="(form.ImageMarkEnum === 1 || form.ImageMarkEnum === 2) && form.ImageMarkTypeEnum === 1"
          :label="$t('trials:readingUnit:qsList:title:ImageTool')" prop="ImageTool" :rules="[
            { required: true, message: this.$t('common:ruleMessage:select') }
          ]">
          <el-radio-group v-model="form.ImageTool" @change="imageSegmentToolChange">
            <el-radio v-for="tool of readingSegmentTools" :key="tool.toolName" :label="tool.toolName">
              {{ $t(tool.i18nKey) }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- 测量值 ImageToolAttribute -->
        <el-form-item v-if="form.ImageTool && imageToolAttributes.length > 0"
          :label="$t('trials:readingUnit:qsList:title:ImageToolAttribute')" prop="ImageToolAttribute" :rules="[
            { required: true, message: this.$t('common:ruleMessage:select') }
          ]">
          <el-radio-group v-model="form.ImageToolAttribute">
            <el-radio v-for="i of imageToolAttributes" :key="i" :label="i">
              {{ i }}
            </el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item v-if="(form.Type === 'select' || form.Type === 'radio' || form.Type === 'input') && isFromSystem"
          :label="$t('trials:readingUnit:label:QuestionGenre')" prop="TableQuestionType" :rules="[
            { required: form.Type !== 'input', message: $t('common:ruleMessage:select') }
          ]">
          <el-radio-group v-model="form.TableQuestionType" @change="((val) => { tableQuestionTypeChange(val, form) })">
            <el-radio v-for="item of $d.TableQuestionType" :key="item.id" :label="item.value"
              :disabled="form.Type === 'radio' && (item.value === 1 || item.value === 2)">
              {{ item.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          v-if="(!isFromSystem || form.TableQuestionType === 3) && (form.Type === 'select' || form.Type === 'radio' || form.Type === 'calculation' || form.Type === 'class' || form.Type === 'number')"
          :label="$t('trials:readingUnit:qsList:title:typeValue')" prop="TypeValue" :rules="[
            { required: form.Type !== 'number', message: this.$t('common:ruleMessage:specify'), trigger: ['blur', 'change'] },
            { validator: validateTypeVal, trigger: ['blur', 'change'] },
            { max: 200, message: `${this.$t('common:ruleMessage:maxLength')} 200` }]">
          <el-input v-model="form.TypeValue" :placeholder="$t('trials:readingUnit:qsList:message:msg3')"
            @change="typeValueChange" />
        </el-form-item>
        <el-form-item v-if="(form.Type === 'select' || form.Type === 'radio') && form.TypeValue"
          :label="$t('trials:readingUnit:qsList:title:defaultValue')">
          <el-select v-model="form.DefaultValue" clearable>
            <el-option v-for="item of form.TypeValue ? form.TypeValue.split('|') : []" :key="'TypeValue' + item"
              :label="item" :value="item" />
          </el-select>
        </el-form-item>
        <el-form-item v-if="form.Type === 'number' && !isFromSystem"
          :label="$t('trials:readingUnit:qsList:title:defaultValue')">
          <el-input :disabled="form.DataSource === 1" v-model="form.DefaultValue" />
        </el-form-item>
        <el-form-item v-if="form.TableQuestionType === 2 && isFromSystem"
          :label="$t('trials:readingUnit:qsList:title:DependParentId')" prop="DependParentId">
          <el-select v-model="form.DependParentId">
            <el-option v-for="item of parentOptions" :key="`DependParentId${item.QuestionId}`"
              :label="item.QuestionName" :value="item.QuestionId" />
          </el-select>
        </el-form-item>
        <el-form-item v-if="form.TableQuestionType === 1 || !!form.DependParentId && isFromSystem"
          :label="$t('trials:readingUnit:qsList:title:DataTableColumn')" prop="DataTableColumn">
          <el-select v-model="form.DataTableColumn">
            <el-option v-for="item of $d.OrganColumn" :key="item.id" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>

        <el-form-item v-if="form.TableQuestionType === 3 || form.TableQuestionType === 2 && isFromSystem"
          :label="$t('trials:readingUnit:label:DictionaryCode')" prop="DictionaryCode"
          :rules="[{ required: form.TableQuestionType === 3, message: $t('common:ruleMessage:select'), trigger: 'blur' }]">
          <el-select v-model="form.DictionaryCode">
            <el-option v-for="item of dicList" :key="item.Id" :label="item.Code" :value="item.Code" />
          </el-select>
        </el-form-item>

        <!-- 高亮标记值 -->
        <el-form-item v-if="(form.Type === 'select' || form.Type === 'radio' || form.Type === 'calculation')"
          :label="$t('trials:readingUnit:qsList:title:highlightAnswers')" prop="HighlightAnswerList">
          <el-select v-model="form.HighlightAnswerList" clearable multiple>
            <template v-if="form.TypeValue">
              <el-option v-for="item of form.TypeValue.split('|')" :key="'HighlightAnswerList' + item" :label="item"
                :value="item" />
            </template>
            <template v-else-if="form.DictionaryCode">
              <el-option v-for="item of highlightAnswers" :key="item.Id" :label="item.ValueCN" :value="item.Code" />
            </template>
          </el-select>
        </el-form-item>
        <!-- 最大字符数 -->
        <el-form-item v-if="form.Type === 'input' || form.Type === 'textarea'"
          :label="$t('trials:readingUnit:qsList:title:MaxAnswerLength')" prop="MaxAnswerLength" :rules="[
            { required: true, message: this.$t('common:ruleMessage:specify'), trigger: 'blur' }
          ]">
          <el-input-number v-model="form.MaxAnswerLength" :min="0"></el-input-number>
        </el-form-item>
        <!-- 最大上传个数 -->
        <el-form-item v-if="form.Type === 'upload'" :label="$t('trials:readingUnit:qsList:title:imageCount')"
          prop="ImageCount">
          <el-input-number v-model="form.ImageCount" controls-position="right" :min="0" :max="10" />
        </el-form-item>
        <!-- 文件类型 -->
        <el-form-item v-show="form.Type === 'upload'" :label="$t('trials:readingUnit:qsList:title:FileType')"
          prop="FileType"
          :rules="[{ type: 'array', required: form.Type === 'upload', message: this.$t('common:ruleMessage:specify'), trigger: ['change'] }]">
          <el-checkbox-group v-model="form.FileType" @change="(v) => {
            if (v.includes('-1')) {
              form.FileType = ['-1']
            } else {
            }
          }">
            <el-checkbox v-for="item of $d.fileType" :key="`fileType${item.value}`" :value="item.value + ''"
              :label="item.value" :disabled="form.FileType.includes('-1') && item.value !== '-1'">
              {{ item.label }}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>

        <!-- 分类 -->
        <el-form-item v-if="form.Type === 'class'" :label="$t('trials:readingUnit:qsList:title:ClassifyType')"
          prop="ClassifyType" :rules="[
            { required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }
          ]">
          <el-radio-group v-model="form.ClassifyType" @change="classifyTypeChange">
            <el-radio v-for="item of $d.ClassifyType" :key="item.id" :label="item.value">
              {{ item.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="form.Type === 'class' && form.ClassifyType === 0"
          :label="$t('trials:readingUnit:label:ClassifyQuestion')" prop="ClassifyTableQuestionId" :rules="[
            { required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }
          ]">
          <el-select v-model="form.ClassifyTableQuestionId" clearable>
            <el-option v-for="item of numberQuestions" :key="item.QuestionId" :label="item.QuestionName"
              :value="item.QuestionId" />
          </el-select>
        </el-form-item>
        <el-form-item v-if="form.Type === 'class' && form.ClassifyType === 1"
          :label="$t('trials:readingUnit:label:ClassifyQuestion')" prop="ClassifyTableQuestionId" :rules="[
            { required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }
          ]">
          <el-select v-model="form.ClassifyTableQuestionId" clearable @change="classifyTableQuestionChange">
            <el-option v-for="item in selectQuestions" :key="item.QuestionId" :label="item.QuestionName"
              :value="item.QuestionId" />
          </el-select>
        </el-form-item>
        <el-form-item v-if="form.Type === 'class' && form.ClassifyType === 0"
          :label="$t('trials:readingUnit:label:ClassifyAlgorithms')" prop="ClassifyAlgorithms" :rules="[
            { required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }
          ]">
          <div>
            <el-table ref="CalculateTable" :data="ClassifyAlgorithmsList" style="margin: 10px;width: calc(100% - 20px)"
              size="small">
              <!-- 运算类型 -->
              <el-table-column :label="$t('trials:readingUnit:label:label')" show-overflow-tooltip min-width="70">
                <template slot-scope="scope">
                  {{ scope.row.label }}
                </template>
              </el-table-column>
              <!-- 运算类型 -->
              <el-table-column :label="$t('trials:readingUnit:label:gt')" show-overflow-tooltip min-width="128">
                <template slot-scope="scope">
                  <el-input-number v-model="scope.row.gt"></el-input-number>
                </template>
              </el-table-column>
              <!-- 运算类型 -->
              <el-table-column :label="$t('trials:readingUnit:label:lt')" show-overflow-tooltip min-width="128">
                <template slot-scope="scope">
                  <el-input-number v-model="scope.row.lt"></el-input-number>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-form-item>
        <el-form-item v-if="form.Type === 'class' && form.ClassifyType === 1"
          :label="$t('trials:readingUnit:label:ClassifyAlgorithms')" prop="ClassifyAlgorithms" :rules="[
            { required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }
          ]">
          <div>
            <el-table ref="CalculateTable" :data="ClassifyAlgorithmsList" style="margin: 10px;width: calc(100% - 20px)"
              size="small">
              <!-- 运算类型 -->
              <el-table-column :label="$t('trials:readingUnit:label:label')" show-overflow-tooltip min-width="70">
                <template slot-scope="scope">
                  {{ scope.row.label }}
                </template>
              </el-table-column>
              <!-- 选项 -->
              <el-table-column :label="$t('trials:readingUnit:label:options')" show-overflow-tooltip min-width="128">
                <template slot-scope="scope">
                  <el-select v-model="scope.row.val" multiple>
                    <el-option v-for="item in classifyQuestionOptions" :key="item" :label="item" :value="item">
                    </el-option>
                  </el-select>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-form-item>
        <!-- 分类是否可编辑 -->
        <el-form-item v-if="form.Type === 'class'" :label="$t('trials:readingUnit:qsList:title:ClassifyEditType')"
          prop="ClassifyEditType" :rules="[
            { required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }
          ]">
          <el-radio-group v-model="form.ClassifyEditType">
            <el-radio v-for="item of $d.ClassifyEditType" :key="item.id" :label="item.value">
              {{ item.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- 分类显示类型 -->
        <el-form-item v-if="form.Type === 'class'" :label="$t('trials:readingUnit:qsList:title:ClassifyShowType')"
          prop="ClassifyShowType" :rules="[
            { required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }
          ]">
          <el-radio-group v-model="form.ClassifyShowType">
            <el-radio v-for="item of $d.ClassifyShowType" :key="item.id" :label="item.value">
              {{ item.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
      </div>

    </div>
    <div v-if="type !== 'look'" class="base-dialog-footer" style="text-align:right;margin-top:10px;">
      <!-- 取消 -->
      <el-button size="small" type="primary" @click="close">
        {{ $t('common:button:cancel') }}
      </el-button>
      <!-- 保存 -->
      <el-button size="small" type="primary" @click="save">
        {{ $t('common:button:save') }}
      </el-button>
    </div>
  </el-form>
</template>
<script>
import { addOrUpdateReadingTableQuestionTrial, getReadingTableOtherQuestionTrial, getCalculateTableQuestions } from '@/api/trials'
import { getBasicConfigSelect, getCriterionDictionaryList, getCriterionDictionary } from '@/api/dictionary'
export default {
  name: 'AddOrUpdateTableQs',
  props: {
    isFromSystem: {
      type: Boolean,
      required: true
    },
    digitPlaces: {
      type: Number,
      default() { return 0 }
    },
    list: {
      type: Array,
      default() { return [] }
    },
    data: {
      type: Object,
      default() { return {} }
    },
    readingQuestionId: {
      type: String,
      required: true
    },
    criterionId: {
      type: String,
      required: true
    },
    type: {
      type: String,
      required: true
    },
    readingTools: {
      type: Array,
      default() {
        return []
      }
    },
    readingSegmentTools: {
      type: Array,
      default() {
        return []
      }
    },
    readingVersionEnum: {
      type: Number,
      default: 0
    }
  },

  data() {
    return {
      ClassifyAlgorithmsList: [],
      form: {
        Id: '',
        ReadingQuestionId: '',
        QuestionName: '',
        QuestionEnName: '',
        Type: 'select',
        TypeValue: '',
        ParentId: '',
        ParentTriggerValueList: [],
        ShowOrder: 0,
        ShowQuestion: 0,
        IsRequired: 2,
        IsPreinstall: false,
        Remark: '',
        RelevanceId: '',
        RelevanceValueList: [],
        DataTableName: '',
        DataTableColumn: '',
        DictionaryCode: '',
        TableQuestionType: null,
        MaxRowCount: null,
        FileType: [],
        DependParentId: '',
        QuestionMark: null,
        CalculateQuestions: [],
        CustomCalculateMark: '',
        DataSource: 0,
        GlobalReadingShowType: 3,
        CustomUnit: null,
        ValueType: null,
        Unit: null,
        LimitEdit: 0,
        DefaultValue: null,
        IsCopy: false,
        HighlightAnswerList: [],
        MaxAnswerLength: null,
        ClassifyTableQuestionId: null,
        ClassifyAlgorithms: null,
        // ExportIdentification: 0,
        ExportResult: [],
        ImageCount: 0,
        ClassifyType: null,
        ClassifyEditType: null,
        ClassifyShowType: null,
        ImageMarkEnum: 0,
        ImageMarkTypeEnum: 0,
        ShowChartTypeEnum: 0,
        ImageTool: '',
        ImageToolAttribute: '',
        OptionTypeEnum: 0
        // IsEnable: true
      },
      imageToolAttributes: [],
      rules: {
        Type: [
          { required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }
        ],
        // QuestionName: [{ required: true, message: this.$t('common:ruleMessage:specify'), trigger: 'blur' },
        //   { max: 200, message: `${this.$t('common:ruleMessage:maxLength')} 200` }],
        // QuestionEnName:[{required: true, message: this.$t('common:ruleMessage:specify'), trigger: ['blur', 'change']},
        //   {max: 50, message: `${this.$t('common:ruleMessage:maxLength')} 50`}],
        // TypeValue: [{ required: form.Type !== 'number', message: this.$t('common:ruleMessage:specify'), trigger: 'blur' },
        //   { validator: validateTypeVal, trigger: 'blur' },
        //   { max: 200, message: `${this.$t('common:ruleMessage:maxLength')} 200` }],
        ShowQuestion: [{ required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }],
        IsRequired: [{ required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }],
        IsPreinstall: [{ required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }],
        ParentId: [{ required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }],
        ParentTriggerValueList: [
          { required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }
        ],
        RelevanceId: [{ required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }],
        RelevanceValueList: [{ required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }],
        DataTableName: [{ required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }],
        DataTableColumn: [{ required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }],
        DependParentId: [{ required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }],
        // ExportIdentification: [
        //   { required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' },
        // ],
        // ExportResult: [
        //   { required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' },
        // ]
      },
      loading: false,
      parentOptions: [],
      parentTriggerValOptions: [],
      reParentTriggerValOptions: [],
      tblOptions: [],
      colOptions: [],
      dicList: [],
      tableQuestions: [],
      LimitEdit: 0,
      highlightAnswers: [],
      validateTypeVal: null,
      numberQuestions: [],
      classQuestions: [],
      selectQuestions: [],
      classifyQuestionOptions: [],
      selectedClassifyOptions: []
    }
  },
  watch: {
    'form.DictionaryCode': {
      deep: true,
      immediate: true,
      async handler(v, oldv) {
        try {
          if (!v) {
            this.highlightAnswers = []
            return
          }
          let res = await getCriterionDictionary({
            ReadingCriterionId: this.data.ReadingQuestionCriterionSystemId,
            DictionaryCode: this.form.DictionaryCode
          })
          this.highlightAnswers = res.Result[this.form.DictionaryCode]
        } catch (e) {
          console.log(e)
        }
      }
    }
  },
  mounted() {
    console.log(this.$d.Criterion_Question_Type)
    this.validateTypeVal = (rule, value, callback) => {
      if (value === '' && this.form.Type !== 'number') {
        callback(new Error(this.$t('common:ruleMessage:specify')))
      } else {
        var arr = value.split('|')
        if (new Set(arr).size !== arr.length) {
          // '选项不允许存在相同值'
          callback(new Error(this.$t('trials:readingUnit:qsList:message:msg0')))
        } else if (value && this.form.Type === 'number' && arr.findIndex(i => isNaN(parseFloat(i)) && i !== 'NE') > -1) {
          callback(new Error(this.$t('trials:readingUnit:qsList:message:msg5')))
        } else {
          callback()
        }
      }
    }
    this.initForm()
    this.getCalculateTableQuestions(['number', 'select', 'radio', 'class', 'basicTable'])
    // this.getCalculateTableQuestions('number')
    // this.getCalculateTableQuestions('table')
  },
  methods: {
    async getCalculateTableQuestions(types) {
      try {
        let params = {
          QuestionId: this.readingQuestionId,
          typeList: types
        }
        let res = await getCalculateTableQuestions(params)
        if (res.Result) {
          this.tableQuestions = res.Result.filter(i => i.Type === 'basicTable')
          this.selectQuestions = res.Result.filter(i => i.Type === 'select' || i.Type === 'radio' || i.Type === 'class')
          this.numberQuestions = res.Result.filter(i => i.Type === 'number')
        }
      } catch (e) {
        console.log(e)
      }
    },
    classifyTypeChange(v) {
      this.form.ClassifyTableQuestionId = ''
      if (this.ClassifyAlgorithmsList.length === 0 && this.form.TypeValue) {
        let list = this.form.TypeValue.split('|')
        this.ClassifyAlgorithmsList = list.map((res, i) => {
          return this.form.ClassifyType === 0 ? {
            label: res.trim(),
            lt: 0,
            gt: 0
          } : {
            label: res.trim(),
            val: []
          }
        })
      }
    },
    deleteCustomCalculateMark(index) {
      this.form.CalculateQuestions.splice(index, 1)
    },
    addCustomCalculateMark(index) {
      this.form.CalculateQuestions.splice(index + 1, 0, {
        IsTable: false,
        QuestionId: this.data.ReadingQuestionId,
        TableQuestionId: null
      })
    },
    typeValueChange(v) {
      this.form.DefaultValue = null
      var list = v.split('|')
      this.form.ClassifyAlgorithms = null
      if (this.form.ClassifyType === 0) {
        this.ClassifyAlgorithmsList = list.map((res, i) => {
          return {
            label: res.trim(),
            lt: 0,
            gt: 0
          }
        })
      } else if (this.form.ClassifyType === 1) {
        this.ClassifyAlgorithmsList = list.map((res, i) => {
          return {
            label: res.trim(),
            val: []
          }
        })
      }
    },
    CustomCalculateMarkChange() {
      if (this.form.CustomCalculateMark <= 4) {
        this.form.CalculateQuestions = [
          {
            IsTable: false,
            QuestionId: this.data.ReadingQuestionId,
            TableQuestionId: null
          }, {
            IsTable: false,
            QuestionId: this.data.ReadingQuestionId,
            TableQuestionId: null
          }
        ]
      } else {
        this.form.CalculateQuestions = [
          {
            IsTable: true,
            QuestionId: this.data.ReadingQuestionId,
            TableQuestionId: null
          }
        ]
      }
    },
    // getCalculateTableQuestions(types) {
    //   getCalculateTableQuestions({
    //     QuestionId: this.readingQuestionId,
    //     typeList: types
    //   }).then(res => {
    //     if (type === 'table') {
    //       this.tableQuestions = res.Result
    //     } else {
    //       this.Questions = res.Result
    //     }
    //   })
    // },
    classifyTableQuestionChange(v) {
      let obj = this.selectQuestions.find(i => i.QuestionId === v)
      let arr = obj && obj.TypeValue ? obj.TypeValue.split('|') : []
      arr = arr.length > 0 ? arr.map(i => i.trim()) : []
      this.classifyQuestionOptions = arr
    },
    async initForm() {
      await this.getParentQuestions()
      if (Object.keys(this.data).length > 0) {
        for (const k in this.form) {
          if (k === 'CalculateQuestions') {
            this.form[k] = JSON.parse(this.data[k])
            console.log('CalculateQuestions', this.form[k])
          } else if (k === 'ClassifyAlgorithms' && this.data[k] !== undefined && this.data[k] !== '') {
            this.ClassifyAlgorithmsList = JSON.parse(this.data[k])
          } else if (k === 'FileType') {
            if (this.data[k]) {
              this.form[k] = this.data[k].split(',')
            }
          } else {
            if (this.data.hasOwnProperty(k)) {
              this.form[k] = this.data[k]
            }
          }
        }
        // for (const k in this.form) {
        //   if (k === 'CalculateQuestions' && this.data[k] !== undefined) {
        //     console.log(this.data[k])
        //     this.form[k] = JSON.parse(this.data[k])
        //     console.log('CalculateQuestions', this.form[k])
        //   } else if (k === 'ClassifyAlgorithms' && this.data[k] !== undefined && this.data[k] !== '') {
        //     this.ClassifyAlgorithmsList = JSON.parse(this.data[k])
        //     console.log(11111, this.form)
        //   } else {
        //     if (this.data.hasOwnProperty(k)) {
        //       this.form[k] = this.data[k]
        //     }
        //   }
        // }
        if (this.form.ParentId) {
          var index = this.parentOptions.findIndex(item => {
            return item.QuestionId === this.form.ParentId
          })
          if (index !== -1) {
            if (this.parentOptions[index].QuestionGenre === 3) {
              // this.parentTriggerValOptions = this.$d[this.parentOptions[index].DictionaryCode]
              let dicCode = this.parentOptions[index].DictionaryCode
              let res = await getCriterionDictionary({ ReadingCriterionId: this.criterionId, DictionaryCode: dicCode })

              this.parentTriggerValOptions = res.Result[dicCode].map(i => {
                return { id: i.Id, label: this.$i18n.locale === 'zh' ? i.ValueCN : i.Value, value: i.Code }
              })
            } else {
              const options = []
              this.parentOptions[index].TypeValue.split('|').forEach((item, index) => {
                options.push({ id: index, label: item, value: item })
              })
              this.parentTriggerValOptions = options
            }

          }
        }
        if (this.form.RelevanceId) {
          var i = this.parentOptions.findIndex(item => {
            return item.QuestionId === this.form.RelevanceId
          })
          if (i !== -1) {
            // this.reParentTriggerValOptions = this.parentOptions[i].TypeValue.split('|')
            if (this.parentOptions[i].QuestionGenre === 3) {
              // this.reParentTriggerValOptions = this.$d[this.parentOptions[i].DictionaryCode] 
              let dicCode = this.parentOptions[i].DictionaryCode
              let res = await getCriterionDictionary({ ReadingCriterionId: this.criterionId, DictionaryCode: dicCode })
              this.reParentTriggerValOptions = res.Result[dicCode].map(i => {
                return { id: i.Id, label: this.$i18n.locale === 'zh' ? i.ValueCN : i.Value, value: i.Code }
              })
            } else {
              const options = []
              this.parentOptions[i].TypeValue.split('|').forEach((item, index) => {
                options.push({ id: i, label: item, value: item })
              })
              this.reParentTriggerValOptions = options
            }
          }
        }
        if (this.form.ImageTool && this.form.ImageMarkTypeEnum === 0) {
          this.imageToolChange(this.form.ImageTool)
        }
        if (this.form.ImageTool && this.form.ImageMarkTypeEnum === 1) {
          this.imageSegmentToolChange(this.form.ImageTool)
        }
      }
      if (this.form.ClassifyTableQuestionId) {
        this.classifyQuestionChange(this.form.ClassifyTableQuestionId)
      }
      if (!this.data.ShowOrder && this.data.ShowOrder !== 0) {
        if (this.list.length > 0) {
          var ShowOrderList = this.list.map(v => v.ShowOrder)
          this.form.ShowOrder = Math.max(...ShowOrderList) + 1
        }
      }
    },
    classifyQuestionChange(v) {
      let obj = this.selectQuestions.find(i => i.Id === v)
      let arr = obj && obj.TypeValue ? obj.TypeValue.split('|') : []
      arr = arr.length > 0 ? arr.map(i => i.trim()) : []
      this.classifyQuestionOptions = arr
    },
    getBasicConfigSelect() {
      getCriterionDictionaryList({
        CriterionId: this.criterionId,
        SystemCriterionId: this.criterionId
      }).then(res => {
        this.dicList = res.Result
      })
    },
    save() {
      this.form.ClassifyAlgorithms = JSON.stringify(this.ClassifyAlgorithmsList)
      this.$refs.tableQsForm.validate(valid => {
        if (!valid) return
        this.loading = true

        if (this.form.QuestionName && this.$i18n.locale === 'zh') {
          this.form.QuestionEnName = this.form.QuestionName;
        } else if (this.form.QuestionEnName && this.$i18n.locale === 'en') {
          this.form.QuestionName = this.form.QuestionEnName;
        }
        var params = Object.assign({}, this.form)
        params.TrialId = this.$route.query.trialId
        params.ReadingQuestionId = this.readingQuestionId
        params.TrialCriterionId = this.criterionId
        params.CalculateQuestions = JSON.stringify(this.form.CalculateQuestions)
        if (this.form.Type !== 'upload') {
          this.form.ImageCount = 0
        }
        params.FileType = this.form.FileType.join(',')
        addOrUpdateReadingTableQuestionTrial(params).then(res => {
          this.$emit('getList')
          this.loading = false
          this.$emit('close')
          this.$emit('reloadArbitrationRules')

          this.$message.success(this.$t('common:message:savedSuccessfully'))
        })
          .catch(() => {
            this.loading = false
          })
      })
    },
    getParentQuestions() {
      return new Promise((resolve, reject) => {
        this.loading = true
        var param = {
          readingQuestionId: this.readingQuestionId,
          id: this.data.Id
        }
        getReadingTableOtherQuestionTrial(param).then(res => {
          this.parentOptions = res.Result
          this.loading = false
          resolve()
        }).catch(() => {
          this.loading = false
          reject()
        })
      })
    },
    isShowQuestionChange(val, form) {
      if (this.form.Type === 'table') return
      if (val === 2) {
        form.IsRequired = 2
        form.ParentId = ''
        form.ParentTriggerValueList = []
        this.isParentExistGroup = false
      } else if (val === 1) {
        form.ParentId = ''
        form.ParentTriggerValueList = []
        form.GroupName = ''
        this.isParentExistGroup = true
      } else if (val === 0) {
        form.ParentId = ''
        form.ParentTriggerValueList = []
        this.isParentExistGroup = false
      }
    },
    isRequiredChange(val, form) {
      if (val !== 1) {
        form.RelevanceId = ''
        form.RelevanceValueList = []
      }
      // if (val === 0 && form.Type === 'number' && !this.isFromSystem) {
      //   form.ImageMarkEnum = 1
      // }
      if (val === 2 && form.Type === 'number' && !this.isFromSystem) {
        form.ImageMarkEnum = 0
      }
    },
    imageMarkEnumChange(val) {
      if (val === 0) {
        this.form.ImageTool = ''
        this.form.ImageToolAttribute = ''
        this.imageToolAttributes = []
        this.form.ImageMarkTypeEnum = 0
      }
    },
    ImageMarkTypeEnumChange(val) {
      this.form.ImageTool = ''
      this.form.ImageToolAttribute = ''
      this.imageToolAttributes = []
    },
    imageToolChange(v) {
      let i = this.readingTools.findIndex(tool => tool.toolName === v)
      if (i > -1) {
        this.imageToolAttributes = this.readingTools[i].props
      }
    },
    imageSegmentToolChange(v) {
      let i = this.readingSegmentTools.findIndex(tool => tool.toolName === v)
      if (i > -1) {
        this.imageToolAttributes = this.readingSegmentTools[i].props
      }
    },
    async parentQuestionChange(val, form) {
      if (val) {
        var index = this.parentOptions.findIndex(item => {
          return item.QuestionId === val
        })
        if (index !== -1) {
          if (this.parentOptions[index].QuestionGenre === 3) {
            // this.reParentTriggerValOptions = this.$d[this.parentOptions[index].DictionaryCode]
            let dicCode = this.parentOptions[index].DictionaryCode
            let res = await getCriterionDictionary({ ReadingCriterionId: this.criterionId, DictionaryCode: dicCode })

            this.parentTriggerValOptions = res.Result[dicCode].map(i => {
              return { id: i.Id, label: this.$i18n.locale === 'zh' ? i.ValueCN : i.Value, value: i.Code }
            })
          } else {
            const options = []
            this.parentOptions[index].TypeValue.split('|').forEach((item, index) => {
              options.push({ id: index, label: item, value: item })
            })
            this.parentTriggerValOptions = options
          }
        }
      }
      form.ParentTriggerValueList = []
    },
    async relevanceQuestionChange(val, form) {
      if (val) {
        var index = this.parentOptions.findIndex(item => {
          return item.QuestionId === val
        })
        if (index !== -1) {
          // this.reParentTriggerValOptions = this.parentOptions[index].TypeValue.split('|')
          if (this.parentOptions[index].QuestionGenre === 3) {
            // this.reParentTriggerValOptions = this.$d[this.parentOptions[index].DictionaryCode]
            let dicCode = this.parentOptions[index].DictionaryCode
            let res = await getCriterionDictionary({ ReadingCriterionId: this.criterionId, DictionaryCode: dicCode })

            this.reParentTriggerValOptions = res.Result[dicCode].map(i => {
              return { id: i.Id, label: this.$i18n.locale === 'zh' ? i.ValueCN : i.Value, value: i.Code }
            })
          } else {
            const options = []
            this.parentOptions[index].TypeValue.split('|').forEach((item, index) => {
              options.push({ id: index, label: item, value: item })
            })
            this.reParentTriggerValOptions = options
          }
        }
      }
      form.RelevanceValueList = []
    },
    tableQuestionTypeChange(val, form) {
      this.form.DictionaryCode = ''
      this.form.DataTableColumn = ''
      this.form.DataTableName = ''
      this.form.DependParentId = ''
      this.form.TypeValue = ''
    },
    dataTableNameChange(val, form) {
      if (val) {
        var index = this.tblOptions.findIndex(item => {
          return item.Id === val
        })
        if (index !== -1) {
          this.colOptions = this.tblOptions[index].Columns
        }
      }
      form.DataTableColumn = ''
    },
    qsTypeChange(val, form) {
      if (val === 'number') {
        form.Unit = 0
      } else {
        form.Unit = null
      }
      if (val === 'input' || val === 'textarea') {
        form.MaxAnswerLength = 500
      } else {
        form.MaxAnswerLength = null
      }
      if (val === 'class') {
        form.ClassifyEditType = 1
      } else {
        form.ClassifyEditType = null
      }
      form.IsRequired = 2
      form.IsPreinstall = false
      form.TypeValue = ''
      form.TableQuestionType = null
      form.DependParentId = ''
      form.DataTableColumn = ''
      form.DataTableName = ''
      form.DictionaryCode = ''
      form.MaxRowCount = null
      form.FileType = []
      form.CalculateQuestions = []
      form.CustomCalculateMark = ''
      form.DataSource = 0
      form.CustomUnit = null
      form.ValueType = null
      form.DefaultValue = null
      form.HighlightAnswerList = []
      form.ClassifyTableQuestionId = null
      form.ClassifyAlgorithms = null
      // form.ExportIdentification = 0
      form.ExportResult = []
      form.ImageCount = 0
      form.ClassifyType = null
      form.ClassifyShowType = null
      form.ImageMarkEnum = 0
      form.ImageMarkTypeEnum = 0
      form.ShowChartTypeEnum = 0
      form.ImageTool = ''
      form.ImageToolAttribute = ''
      form.OptionTypeEnum = 0
      this.imageToolAttributes = []
    },
    close() {
      this.$emit('close')
    }

  }
}
</script>
<style lang="scss" scoped></style>
