<template>
  <Dialog v-model="diaVisible" diaTitle="预览" width="500" height="80%">
    <div class="right-board">
      <div class="field-box">
        <div class="right-scrollbar">
          <!-- 组件属性 -->
          <el-form v-show="currentTab === 'field' && showField" label-width="90px">
            <!-- <el-form-item v-if="activeData.changeTag" label="组件类型">
              <el-select
                v-model="activeData.tagIcon"
                placeholder="请选择组件类型"
                :style="{ width: '100%' }"
                @change="tagChange"
              >
                <el-option-group v-for="group in tagList" :key="group.label" :label="group.label">
                  <el-option v-for="item in group.options" :key="item.label" :label="item.label" :value="item.tagIcon">
                    <svg-icon class="node-icon" :icon-class="item.tagIcon" />
                    <span> {{ item.label }}</span>
                  </el-option>
                </el-option-group>
              </el-select>
            </el-form-item> -->
            <!-- <el-form-item v-if="activeData.changeTag" label="组件类型">
              <el-input readonly v-model="activeData.tagIcon"></el-input>
            </el-form-item> -->
            <!-- <el-form-item v-if="activeData.vModel !== undefined" label="字段名">
              <el-input v-model="activeData.vModel" placeholder="请输入字段名（v-model）" />
            </el-form-item> -->
            <el-form-item v-if="activeData.componentName !== undefined" label="组件名">
              <el-input v-model="activeData.componentName"></el-input>
            </el-form-item>
            <el-form-item
              :rules="{ required: true }"
              v-if="activeData.label !== undefined && activeData.layout !== 'rowFormItem'"
              label="名称"
            >
              <el-input
                v-model="activeData.label"
                placeholder="请输入名称"
                @change="changeLabel(activeData)"
                :disabled="activeData.isSpecialBox"
              />
            </el-form-item>
            <el-form-item
              :rules="{ required: true }"
              v-if="activeData.englishLabel !== undefined"
              label="英文名称"
            >
              <el-input v-model="activeData.englishLabel" placeholder="请输入英文名称" />
            </el-form-item>
            <!-- 求解器名称 -->
            <template
              v-if="
                activeData.widgetViewType === 'SOLVER' && activeData.englishLabel === 'solverName'
              "
            >
              <el-divider>求解器类型</el-divider>
              <el-radio-group
                :modelValue="activeData.solverNameIndex"
                style="width: 100%"
                @change="solverNameChange($event, activeData)"
              >
                <el-radio
                  v-for="(element, index) in activeData.options"
                  :value="index"
                  class="select-radio-item"
                >
                  <el-input placeholder="求解器类型" size="small" v-model="element.value" />
                  <div
                    v-if="activeData.options.length > 1"
                    class="close-btn select-line-icon"
                    @click.stop.prevent="solverDelete(index, activeData)"
                  >
                    <el-icon size="20" danger><Remove /></el-icon>
                  </div>
                </el-radio>
              </el-radio-group>

              <div style="margin-left: 20px">
                <el-button
                  style="padding-bottom: 0"
                  icon="CirclePlus"
                  type="text"
                  @click="addSelectItem"
                >
                  添加选项
                </el-button>
              </div>
              <el-divider />
              <el-form-item
                :label="
                  activeData.options[activeData.solverNameIndex]?.value
                    ? activeData.options[activeData.solverNameIndex]?.value + '核数'
                    : '' + '核数'
                "
              >
                <div
                  style="
                    display: flex;
                    width: 100%;
                    white-space: nowrap;
                    font-size: 12px;
                    color: #000;
                  "
                >
                  <span>默认核数：</span>
                  <el-input
                    class="mr4"
                    v-model="activeData.coreNodeInfo[activeData.solverNameIndex].defaultCore"
                  ></el-input>
                  <span>最小核数：</span>
                  <el-input
                    class="mr4"
                    v-model="activeData.coreNodeInfo[activeData.solverNameIndex].minCore"
                  ></el-input>
                  <span>最大核数：</span>
                  <el-input
                    v-model="activeData.coreNodeInfo[activeData.solverNameIndex].maxCore"
                  ></el-input>
                </div>
              </el-form-item>
              <el-form-item
                :label="
                  activeData.options[activeData.solverNameIndex]?.value
                    ? activeData.options[activeData.solverNameIndex]?.value + '节点数'
                    : '' + '节点数'
                "
              >
                <div
                  style="
                    display: flex;
                    width: 100%;
                    white-space: nowrap;
                    font-size: 12px;
                    color: #000;
                  "
                >
                  <span>默认节点数：</span>
                  <el-input
                    class="mr4"
                    v-model="activeData.coreNodeInfo[activeData.solverNameIndex].defaultNode"
                  ></el-input>
                  <span>最小节点数：</span>
                  <el-input
                    class="mr4"
                    v-model="activeData.coreNodeInfo[activeData.solverNameIndex].minNode"
                  ></el-input>
                  <span>最大节点数：</span>
                  <el-input
                    v-model="activeData.coreNodeInfo[activeData.solverNameIndex].maxNode"
                  ></el-input>
                </div>
              </el-form-item>
            </template>
            <el-form-item
              v-if="activeData.englishLabel !== undefined && activeData.tag === 'el-upload'"
              label="文件类型"
            >
              <el-radio-group v-model="activeData.fileType" class="ml-4">
                <el-radio value="0" size="large">文件</el-radio>
                <el-radio value="1" size="large">文件夹</el-radio>
                <el-radio value="2" size="large">文件和文件夹</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item v-if="activeData.placeholder !== undefined" label="占位提示">
              <el-input v-model="activeData.placeholder" placeholder="请输入占位提示" />
            </el-form-item>
            <el-form-item v-if="activeData['start-placeholder'] !== undefined" label="开始占位">
              <el-input v-model="activeData['start-placeholder']" placeholder="请输入占位提示" />
            </el-form-item>
            <el-form-item v-if="activeData['end-placeholder'] !== undefined" label="结束占位">
              <el-input v-model="activeData['end-placeholder']" placeholder="请输入占位提示" />
            </el-form-item>
            <!-- <el-form-item v-if="activeData.span !== undefined" label="表单栅格">
              <el-slider v-model="activeData.span" :max="24" :min="1" :marks="{ 12: '' }" @change="spanChange" />
            </el-form-item> -->
            <!-- <el-form-item v-if="activeData.layout === 'rowFormItem'" label="栅格间隔">
              <el-input-number v-model="activeData.gutter" :min="0" placeholder="栅格间隔" />
            </el-form-item> -->
            <el-form-item v-if="activeData.layout === 'rowFormItem'" label="布局模式">
              <el-radio-group v-model="activeData.layoutType">
                <el-radio value="1">子节点嵌套</el-radio>
                <el-radio value="2">行内显示</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item
              v-if="activeData.justify !== undefined && activeData.type === 'flex'"
              label="水平排列"
            >
              <el-select
                v-model="activeData.justify"
                placeholder="请选择水平排列"
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(item, index) in justifyOptions"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item
              v-if="activeData.align !== undefined && activeData.type === 'flex'"
              label="垂直排列"
            >
              <el-radio-group v-model="activeData.align">
                <el-radio-button label="top" />
                <el-radio-button label="middle" />
                <el-radio-button label="bottom" />
              </el-radio-group>
            </el-form-item>
            <!-- <el-form-item v-if="activeData.labelWidth !== undefined" label="标签宽度">
              <el-input v-model.number="activeData.labelWidth" type="number" placeholder="请输入标签宽度" />
            </el-form-item>
            <el-form-item v-if="activeData.style && activeData.style.width !== undefined" label="组件宽度">
              <el-input v-model="activeData.style.width" placeholder="请输入组件宽度" clearable />
            </el-form-item> -->
            <template v-if="!activeData.hiddenDefaultValue">
              <el-form-item v-if="['el-checkbox-group'].includes(activeData.tag)" label="默认值">
                <!-- <el-input v-model="activeData.selectList" placeholder="请输入默认值" /> -->
                <el-select v-model="activeData.selectList" multiple>
                  <el-option
                    v-for="(item, index) in activeData.options"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item
                v-else-if="['el-radio-group', 'el-select'].includes(activeData.tag)"
                label="默认值"
              >
                <!-- <el-input v-model="activeData.selectList" placeholder="请输入默认值" /> -->
                <el-select v-model="activeData.defaultValue">
                  <el-option
                    v-for="(item, index) in activeData.options"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item v-else-if="['el-checkbox'].includes(activeData.tag)" label="默认值">
                <el-checkbox
                  v-model="activeData.defaultValue"
                  true-value="1"
                  false-value="0"
                ></el-checkbox>
              </el-form-item>
              <el-form-item v-else-if="['el-slider'].includes(activeData.tag)" label="默认值">
                <el-input-number
                  v-model="activeData.defaultValue"
                  :min="activeData.min"
                  :max="activeData.max"
                />
              </el-form-item>

              <el-form-item
                v-else-if="
                  activeData.vModel !== undefined &&
                  !['el-upload', 'solverName', 'script'].includes(activeData.tag)
                "
                label="默认值"
              >
                <el-input v-model="activeData.defaultValue" placeholder="请输入默认值" />
              </el-form-item>
            </template>
            <template v-if="activeData.tag === 'script'">
              <el-form-item label="脚本文件">
                <!-- <server-local-file
                  @returnFile="(data) => changeFile(data, activeData)"
                  :record="{
                    Value: activeData.value,
                    Id: activeData.formId,
                    Multiple: CHOOSE_FILE_CONFIG.NO_MULTIPLE,
                    FileType: CHOOSE_FILE_CONFIG.IS_FILE,
                    SelectType: CHOOSE_FILE_CONFIG.SERVER_OR_LOCAL,
                    ParentPath: '',
                  }"
                /> -->
              </el-form-item>
              <el-form-item label="其他参数">
                <el-input v-model="activeData.otherParam" placeholder="请输入其他参数" />
              </el-form-item>
            </template>
            <!-- <el-form-item v-if="activeData.tag === 'el-checkbox-group'" label="至少应选">
              <el-input-number
                :value="activeData.min"
                :min="0"
                placeholder="至少应选"
                @input="$set(activeData, 'min', $event ? $event : undefined)"
              />
            </el-form-item>
            <el-form-item v-if="activeData.tag === 'el-checkbox-group'" label="最多可选">
              <el-input-number
                :value="activeData.max"
                :min="0"
                placeholder="最多可选"
                @input="$set(activeData, 'max', $event ? $event : undefined)"
              />
            </el-form-item> -->
            <!-- <el-form-item v-if="activeData.prepend !== undefined" label="前缀">
              <el-input v-model="activeData.prepend" placeholder="请输入前缀" />
            </el-form-item>
            <el-form-item v-if="activeData.append !== undefined" label="后缀">
              <el-input v-model="activeData.append" placeholder="请输入后缀" />
            </el-form-item> -->
            <!-- <el-form-item v-if="activeData['prefix-icon'] !== undefined" label="前图标">
              <el-input v-model="activeData['prefix-icon']" placeholder="请输入前图标名称">
                <el-button slot="append" icon="el-icon-thumb" @click="openIconsDialog('prefix-icon')"> 选择 </el-button>
              </el-input>
            </el-form-item>
            <el-form-item v-if="activeData['suffix-icon'] !== undefined" label="后图标">
              <el-input v-model="activeData['suffix-icon']" placeholder="请输入后图标名称">
                <el-button slot="append" icon="el-icon-thumb" @click="openIconsDialog('suffix-icon')"> 选择 </el-button>
              </el-input>
            </el-form-item> -->
            <el-form-item v-if="activeData.tag === 'el-cascader'" label="选项分隔符">
              <el-input v-model="activeData.separator" placeholder="请输入选项分隔符" />
            </el-form-item>
            <!-- <el-form-item v-if="activeData.autosize !== undefined" label="最小行数">
              <el-input-number v-model="activeData.autosize.minRows" :min="1" placeholder="最小行数" />
            </el-form-item>
            <el-form-item v-if="activeData.autosize !== undefined" label="最大行数">
              <el-input-number v-model="activeData.autosize.maxRows" :min="1" placeholder="最大行数" />
            </el-form-item> -->
            <el-form-item v-if="activeData.min !== undefined" label="最小值">
              <el-input-number
                v-model="activeData.min"
                placeholder="最小值"
                :min="0"
                :max="activeData.max"
              />
            </el-form-item>
            <el-form-item v-if="activeData.max !== undefined" label="最大值">
              <el-input-number
                v-model="activeData.max"
                placeholder="最大值"
                :min="activeData.min"
              />
            </el-form-item>
            <el-form-item v-if="activeData.step !== undefined" label="步长">
              <el-input-number v-model="activeData.step" placeholder="步数" />
            </el-form-item>
            <el-form-item v-if="activeData.tag === 'el-input-number'" label="精度">
              <el-input-number v-model="activeData.precision" :min="0" placeholder="精度" />
            </el-form-item>
            <el-form-item v-if="activeData.tag === 'el-input-number'" label="单位">
              <el-input v-model="activeData.unit" placeholder="单位" />
            </el-form-item>
            <!-- <el-form-item v-if="activeData.tag === 'el-input-number'" label="按钮位置">
              <el-radio-group v-model="activeData['controls-position']">
                <el-radio-button label=""> 默认 </el-radio-button>
                <el-radio-button label="right"> 右侧 </el-radio-button>
              </el-radio-group>
            </el-form-item> -->
            <!-- <el-form-item v-if="activeData.maxlength !== undefined" label="最多输入">
              <el-input v-model="activeData.maxlength" placeholder="请输入字符长度">
                <template slot="append"> 个字符 </template>
              </el-input>
            </el-form-item> -->
            <el-form-item v-if="activeData['active-text'] !== undefined" label="开启提示">
              <el-input v-model="activeData['active-text']" placeholder="请输入开启提示" />
            </el-form-item>
            <el-form-item v-if="activeData['inactive-text'] !== undefined" label="关闭提示">
              <el-input v-model="activeData['inactive-text']" placeholder="请输入关闭提示" />
            </el-form-item>
            <el-form-item v-if="activeData['active-value'] !== undefined" label="开启值">
              <el-input
                :value="setDefaultValue(activeData['active-value'])"
                placeholder="请输入开启值"
                @input="onSwitchValueInput($event, 'active-value')"
              />
            </el-form-item>
            <el-form-item v-if="activeData['inactive-value'] !== undefined" label="关闭值">
              <el-input
                :value="setDefaultValue(activeData['inactive-value'])"
                placeholder="请输入关闭值"
                @input="onSwitchValueInput($event, 'inactive-value')"
              />
            </el-form-item>
            <el-form-item
              v-if="activeData.type !== undefined && 'el-date-picker' === activeData.tag"
              label="时间类型"
            >
              <el-select
                v-model="activeData.type"
                placeholder="请选择时间类型"
                :style="{ width: '100%' }"
                @change="dateTypeChange"
              >
                <el-option
                  v-for="(item, index) in dateOptions"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <!-- <el-form-item v-if="activeData.name !== undefined" label="文件字段名">
              <el-input v-model="activeData.name" placeholder="请输入上传文件字段名" />
            </el-form-item>
            <el-form-item v-if="activeData.accept !== undefined" label="文件类型">
              <el-select v-model="activeData.accept" placeholder="请选择文件类型" :style="{ width: '100%' }" clearable>
                <el-option label="图片" value="image/*" />
                <el-option label="视频" value="video/*" />
                <el-option label="音频" value="audio/*" />
                <el-option label="excel" value=".xls,.xlsx" />
                <el-option label="word" value=".doc,.docx" />
                <el-option label="pdf" value=".pdf" />
                <el-option label="txt" value=".txt" />
              </el-select>
            </el-form-item>
            <el-form-item v-if="activeData.fileSize !== undefined" label="文件大小">
              <el-input v-model.number="activeData.fileSize" placeholder="请输入文件大小">
                <el-select slot="append" v-model="activeData.sizeUnit" :style="{ width: '66px' }">
                  <el-option label="KB" value="KB" />
                  <el-option label="MB" value="MB" />
                  <el-option label="GB" value="GB" />
                </el-select>
              </el-input>
            </el-form-item>
            <el-form-item v-if="activeData.action !== undefined" label="上传地址">
              <el-input v-model="activeData.action" placeholder="请输入上传地址" clearable />
            </el-form-item>
            <el-form-item v-if="activeData['list-type'] !== undefined" label="列表类型">
              <el-radio-group v-model="activeData['list-type']" size="small">
                <el-radio-button label="text"> text </el-radio-button>
                <el-radio-button label="picture"> picture </el-radio-button>
                <el-radio-button label="picture-card"> picture-card </el-radio-button>
              </el-radio-group>
            </el-form-item>
            <el-form-item
              v-if="activeData.buttonText !== undefined"
              v-show="'picture-card' !== activeData['list-type']"
              label="按钮文字"
            >
              <el-input v-model="activeData.buttonText" placeholder="请输入按钮文字" />
            </el-form-item> -->
            <el-form-item v-if="activeData['range-separator'] !== undefined" label="分隔符">
              <el-input v-model="activeData['range-separator']" placeholder="请输入分隔符" />
            </el-form-item>
            <el-form-item v-if="activeData['picker-options'] !== undefined" label="时间段">
              <el-input
                v-model="activeData['picker-options'].selectableRange"
                placeholder="请输入时间段"
              />
            </el-form-item>
            <!-- <el-form-item v-if="activeData.format !== undefined" label="时间格式">
              <el-input :value="activeData.format" placeholder="请输入时间格式" @input="setTimeValue($event)" />
            </el-form-item> -->
            <template
              v-if="
                ['el-checkbox-group', 'el-radio-group', 'el-select'].indexOf(activeData.tag) > -1
              "
            >
              <el-divider>选项</el-divider>
              <draggable :list="activeData.options" :animation="340" group="selectItem">
                <template #item="{ element }">
                  <div class="select-item">
                    <div class="select-line-icon option-drag">
                      <el-icon size="20"><Operation /></el-icon>
                    </div>
                    <el-input v-model="element.label" placeholder="选项名" size="small" />
                    <el-input placeholder="选项值" size="small" v-model="element.value" />
                    <div
                      class="close-btn select-line-icon"
                      @click="deleteOptionsItem(element, activeData)"
                    >
                      <el-icon size="20" danger><Remove /></el-icon>
                    </div>
                  </div>
                </template>
              </draggable>
              <div style="margin-left: 20px">
                <el-button
                  style="padding-bottom: 0"
                  icon="CirclePlus"
                  type="text"
                  @click="addSelectItem"
                >
                  添加选项
                </el-button>
              </div>
              <el-divider />
            </template>

            <template v-if="['el-cascader'].indexOf(activeData.tag) > -1">
              <el-divider>选项</el-divider>
              <el-form-item label="数据类型">
                <el-radio-group v-model="activeData.dataType" size="small">
                  <el-radio-button label="dynamic"> 动态数据 </el-radio-button>
                  <el-radio-button label="static"> 静态数据 </el-radio-button>
                </el-radio-group>
              </el-form-item>

              <template v-if="activeData.dataType === 'dynamic'">
                <el-form-item label="标签键名">
                  <el-input v-model="activeData.labelKey" placeholder="请输入标签键名" />
                </el-form-item>
                <el-form-item label="值键名">
                  <el-input v-model="activeData.valueKey" placeholder="请输入值键名" />
                </el-form-item>
                <el-form-item label="子级键名">
                  <el-input v-model="activeData.childrenKey" placeholder="请输入子级键名" />
                </el-form-item>
              </template>

              <el-tree
                v-if="activeData.dataType === 'static'"
                draggable
                :data="activeData.options"
                node-key="id"
                :expand-on-click-node="false"
                :render-content="renderContent"
              />
              <div v-if="activeData.dataType === 'static'" style="margin-left: 20px">
                <el-button
                  style="padding-bottom: 0"
                  icon="el-icon-circle-plus-outline"
                  type="text"
                  @click="addTreeItem"
                >
                  添加父级
                </el-button>
              </div>
              <el-divider />
            </template>

            <!-- <el-form-item v-if="activeData.optionType !== undefined" label="选项样式">
              <el-radio-group v-model="activeData.optionType">
                <el-radio-button label="default"> 默认 </el-radio-button>
                <el-radio-button label="button"> 按钮 </el-radio-button>
              </el-radio-group>
            </el-form-item> -->
            <el-form-item v-if="activeData['active-color'] !== undefined" label="开启颜色">
              <el-color-picker v-model="activeData['active-color']" />
            </el-form-item>
            <el-form-item v-if="activeData['inactive-color'] !== undefined" label="关闭颜色">
              <el-color-picker v-model="activeData['inactive-color']" />
            </el-form-item>

            <el-form-item v-if="activeData['allow-half'] !== undefined" label="允许半选">
              <el-switch v-model="activeData['allow-half']" />
            </el-form-item>
            <el-form-item v-if="activeData['show-text'] !== undefined" label="辅助文字">
              <el-switch v-model="activeData['show-text']" @change="rateTextChange" />
            </el-form-item>
            <el-form-item v-if="activeData['show-score'] !== undefined" label="显示分数">
              <el-switch v-model="activeData['show-score']" @change="rateScoreChange" />
            </el-form-item>
            <!-- <el-form-item v-if="activeData['show-stops'] !== undefined" label="显示间断点">
              <el-switch v-model="activeData['show-stops']" />
            </el-form-item>
            <el-form-item v-if="activeData.range !== undefined" label="范围选择">
              <el-switch v-model="activeData.range" @change="rangeChange" />
            </el-form-item> -->
            <!-- <el-form-item
              v-if="activeData.border !== undefined && activeData.optionType === 'default'"
              label="是否带边框"
            >
              <el-switch v-model="activeData.border" />
            </el-form-item> -->
            <el-form-item v-if="activeData.tag === 'el-color-picker'" label="颜色格式">
              <el-select
                v-model="activeData['color-format']"
                placeholder="请选择颜色格式"
                :style="{ width: '100%' }"
                @change="colorFormatChange"
              >
                <el-option
                  v-for="(item, index) in colorFormatOptions"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item
              v-if="
                activeData.size !== undefined &&
                (activeData.optionType === 'button' ||
                  activeData.border ||
                  activeData.tag === 'el-color-picker')
              "
              label="选项尺寸"
            >
              <el-radio-group v-model="activeData.size">
                <el-radio-button label="medium"> 中等 </el-radio-button>
                <el-radio-button label="small"> 较小 </el-radio-button>
                <el-radio-button label="mini"> 迷你 </el-radio-button>
              </el-radio-group>
            </el-form-item>
            <!-- <el-form-item v-if="activeData['show-word-limit'] !== undefined" label="输入统计">
              <el-switch v-model="activeData['show-word-limit']" />
            </el-form-item> -->
            <!-- <el-form-item v-if="activeData.tag === 'el-input-number'" label="严格步数">
              <el-switch v-model="activeData['step-strictly']" />
            </el-form-item> -->
            <el-form-item
              v-if="activeData.tag === 'el-cascader' || activeData.tag === 'el-upload'"
              label="是否多选"
            >
              <el-switch v-model="activeData.multiple" />
            </el-form-item>
            <el-form-item v-if="activeData.tag === 'el-cascader'" label="展示全路径">
              <el-switch v-model="activeData['show-all-levels']" />
            </el-form-item>
            <el-form-item v-if="activeData.tag === 'el-cascader'" label="可否筛选">
              <el-switch v-model="activeData.filterable" />
            </el-form-item>
            <!-- <el-form-item v-if="activeData.clearable !== undefined" label="能否清空">
              <el-switch v-model="activeData.clearable" />
            </el-form-item> -->
            <!-- <el-form-item v-if="activeData.showTip !== undefined" label="显示提示">
              <el-switch v-model="activeData.showTip" />
            </el-form-item> -->
            <!-- <el-form-item v-if="activeData.multiple !== undefined" label="多选文件">
              <el-switch v-model="activeData.multiple" />
            </el-form-item> -->
            <!-- <el-form-item v-if="activeData['auto-upload'] !== undefined" label="自动上传">
              <el-switch v-model="activeData['auto-upload']" />
            </el-form-item> -->
            <!-- <el-form-item v-if="activeData.readonly !== undefined" label="是否只读">
              <el-switch v-model="activeData.readonly" />
            </el-form-item> -->
            <!-- <el-form-item v-if="activeData.disabled !== undefined && activeData.tag !== 'el-upload'" label="是否禁用">
              <el-switch v-model="activeData.disabled" />
            </el-form-item> -->
            <!-- <el-form-item v-if="activeData.tag === 'el-select'" label="是否可搜索">
              <el-switch v-model="activeData.filterable" />
            </el-form-item> -->
            <!-- <el-form-item v-if="activeData.tag === 'el-select'" label="是否多选">
              <el-switch v-model="activeData.multiple" @change="multipleChange" />
            </el-form-item> -->
            <el-form-item
              v-if="activeData.required !== undefined && !['solverName'].includes(activeData.tag)"
              label="是否必填"
            >
              <el-switch v-model="activeData.required" />
            </el-form-item>

            <!-- <template v-if="activeData.layoutTree">
              <el-divider>布局结构树</el-divider>
              <el-tree :data="[activeData]" :props="layoutTreeProps" node-key="renderKey" default-expand-all draggable>
                <span slot-scope="{ node, data }">
                  <span class="node-label">
                    <svg-icon class="node-icon" :icon-class="data.tagIcon" />
                    {{ node.label }}
                  </span>
                </span>
              </el-tree>
            </template> -->
            <!--
            <template v-if="activeData.layout === 'colFormItem' && activeData.tag !== 'el-button'">
              <el-divider>正则校验</el-divider>
              <div v-for="(item, index) in activeData.regList" :key="index" class="reg-item">
                <span class="close-btn" @click="activeData.regList.splice(index, 1)">
                  <i class="el-icon-close" />
                </span>
                <el-form-item label="表达式">
                  <el-input v-model="item.pattern" placeholder="请输入正则" />
                </el-form-item>
                <el-form-item label="错误提示" style="margin-bottom: 0">
                  <el-input v-model="item.message" placeholder="请输入错误提示" />
                </el-form-item>
              </div>
              <div style="margin-left: 20px">
                <el-button icon="el-icon-circle-plus-outline" type="text" @click="addReg"> 添加规则 </el-button>
              </div>
            </template> -->
          </el-form>
          <!-- 表单属性 -->
          <el-form :model="formConf" v-show="currentTab === 'form'" label-width="90px">
            <el-form-item label="表单名">
              <el-input v-model="formConf.formRef" placeholder="请输入表单名（ref）" />
            </el-form-item>
            <el-form-item label="表单模型">
              <el-input v-model="formConf.formModel" placeholder="请输入数据模型" />
            </el-form-item>
            <el-form-item label="校验模型">
              <el-input v-model="formConf.formRules" placeholder="请输入校验模型" />
            </el-form-item>
            <el-form-item label="表单尺寸">
              <el-radio-group v-model="formConf.size">
                <el-radio-button label="medium"> 中等 </el-radio-button>
                <el-radio-button label="small"> 较小 </el-radio-button>
                <el-radio-button label="mini"> 迷你 </el-radio-button>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="标签对齐">
              <el-radio-group v-model="formConf.labelPosition">
                <el-radio-button label="left"> 左对齐 </el-radio-button>
                <el-radio-button label="right"> 右对齐 </el-radio-button>
                <el-radio-button label="top"> 顶部对齐 </el-radio-button>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="标签宽度">
              <el-input-number v-model="formConf.labelWidth" placeholder="标签宽度" />
            </el-form-item>
            <el-form-item label="栅格间隔">
              <el-input-number v-model="formConf.gutter" :min="0" placeholder="栅格间隔" />
            </el-form-item>
            <el-form-item label="禁用表单">
              <el-switch v-model="formConf.disabled" />
            </el-form-item>
            <el-form-item label="表单按钮">
              <el-switch v-model="formConf.formBtns" />
            </el-form-item>
            <!-- <el-form-item label="显示未选中组件边框">
              <el-switch v-model="formConf.unFocusedComponentBorder" />
            </el-form-item> -->
          </el-form>
        </div>
      </div>

      <!-- <treeNode-dialog :visible.sync="dialogVisible" title="添加选项" @commit="addNode" /> -->
      <!-- <icons-dialog :visible.sync="iconsVisible" :current="activeData[currentIconModel]" @select="setIcon" /> -->
    </div>
  </Dialog>
</template>

<script setup lang="tsx">
import { ref, computed, nextTick } from 'vue';
import draggable from 'vuedraggable';
import Dialog from '@/components/common/dialog/index.vue';
// import { WIDGET_IDS, WIDGET_TYPE } from '@/views/pages/flowCreate/components/enum';

import { inputComponents, selectComponents, layoutComponents, isNumberStr } from './formConfig';
// import { nextTick } from 'process';
// import { CHOOSE_FILE_CONFIG } from '@/config/enum';
// import serverLocalFile from '@/components/serverLocalFile/serverLocalFile.vue';

const props = withDefaults(
  defineProps<{
    showField: any;
    activeData: any;
    formConf: any;
    showDialog: boolean;
  }>(),
  {
    showField: false,
    showDialog: false,
    activeData: {},
    formConf: {},
  }
);
const diaVisible = computed({
  get() {
    return props.showDialog;
  },
  set(val) {
    emits('update:showDialog', val);
  },
});
const emits = defineEmits([
  'update:activeData',
  'update:showDialog',
  'tagChange',
  'updateActiveData',
]);
const dateTimeFormat = {
  date: 'yyyy-MM-dd',
  week: 'yyyy 第 WW 周',
  month: 'yyyy-MM',
  year: 'yyyy',
  datetime: 'yyyy-MM-dd HH:mm:ss',
  daterange: 'yyyy-MM-dd',
  monthrange: 'yyyy-MM',
  datetimerange: 'yyyy-MM-dd HH:mm:ss',
};
const currentTab = ref<any>('field');
const currentNode = ref<any>(null);
const dialogVisible = ref<boolean>(false);
const iconsVisible = ref<boolean>(false);
const currentIconModel = ref<any>(null);
const dateTypeOptions = ref<any>([
  {
    label: '日(date)',
    value: 'date',
  },
  {
    label: '周(week)',
    value: 'week',
  },
  {
    label: '月(month)',
    value: 'month',
  },
  {
    label: '年(year)',
    value: 'year',
  },
  {
    label: '日期时间(datetime)',
    value: 'datetime',
  },
]);
const dateRangeTypeOptions = ref<any>([
  {
    label: '日期范围(daterange)',
    value: 'daterange',
  },
  {
    label: '月范围(monthrange)',
    value: 'monthrange',
  },
  {
    label: '日期时间范围(datetimerange)',
    value: 'datetimerange',
  },
]);
const colorFormatOptions = ref<any>([
  {
    label: 'hex',
    value: 'hex',
  },
  {
    label: 'rgb',
    value: 'rgb',
  },
  {
    label: 'rgba',
    value: 'rgba',
  },
  {
    label: 'hsv',
    value: 'hsv',
  },
  {
    label: 'hsl',
    value: 'hsl',
  },
]);
const justifyOptions = ref<any>([
  {
    label: 'start',
    value: 'start',
  },
  {
    label: 'end',
    value: 'end',
  },
  {
    label: 'center',
    value: 'center',
  },
  {
    label: 'space-around',
    value: 'space-around',
  },
  {
    label: 'space-between',
    value: 'space-between',
  },
]);
const layoutTreeProps = ref<any>({
  label(data: any, node: any) {
    return data.componentName || `${data.label}: ${data.vModel}`;
  },
});
const documentLink = computed(() => {
  return props.activeData.document || 'https://element.eleme.cn/#/zh-CN/component/installation';
});
const dateOptions = computed(() => {
  if (props.activeData.type !== undefined && props.activeData.tag === 'el-date-picker') {
    if (props.activeData['start-placeholder'] === undefined) {
      return dateTypeOptions.value;
    }
    return dateRangeTypeOptions.value;
  }
  return [];
});
const tagList = computed(() => {
  return [
    {
      label: '输入型组件',
      options: inputComponents,
    },
    {
      label: '选择型组件',
      options: selectComponents,
    },
  ];
});
const addReg = () => {
  props.activeData.regList.push({
    pattern: '',
    message: '',
  });
};
const addSelectItem = () => {
  props.activeData.options.push({
    label: '',
    value: '',
  });
};
const addTreeItem = () => {
  // ++this.idGlobal
  dialogVisible.value = true;
  currentNode.value = props.activeData.options;
};
const renderContent = (h: any, { node, data, store }: any) => {
  return (
    <div class="custom-tree-node">
      <span>{node.label}</span>
      <span class="node-operation">
        <i on-click={() => append(data)} class="el-icon-plus" title="添加"></i>
        <i on-click={() => remove(node, data)} class="el-icon-delete" title="删除"></i>
      </span>
    </div>
  );
};
const append = (data: any) => {
  if (!data.children) {
    // this.$set(data, 'children', [])
  }
  dialogVisible.value = true;
  currentNode.value = data.children;
};
const remove = (node: any, data: any) => {
  const { parent } = node;
  const children = parent.data.children || parent.data;
  const index = children.findIndex((d: any) => d.id === data.id);
  children.splice(index, 1);
};
const addNode = (data: any) => {
  currentNode.value.push(data);
};
const setOptionValue = (item: any, val: any) => {
  item.value = isNumberStr(val) ? +val : val;
};
const setDefaultValue = (val: any) => {
  if (Array.isArray(val)) {
    return val.join(',');
  }
  if (['string', 'number'].indexOf(val) > -1) {
    return val;
  }
  if (typeof val === 'boolean') {
    return `${val}`;
  }
  return val;
};
const onDefaultValueInput = (str: any) => {
  if (Array.isArray(props.activeData.defaultValue)) {
    emits('update:activeData', {
      ...props.activeData,
      defaultValue: str.split(',').map((val: any) => (isNumberStr(val) ? +val : val)),
    });
    // 数组
    // this.$set(
    //   this.activeData,
    //   'defaultValue',
    //   str.split(',').map(val => (isNumberStr(val) ? +val : val))
    // )
  } else if (['true', 'false'].indexOf(str) > -1) {
    emits('update:activeData', {
      ...props.activeData,
      defaultValue: JSON.parse(str),
    });
    // 布尔
    // this.$set(this.activeData, 'defaultValue', JSON.parse(str))
  } else {
    emits('update:activeData', {
      ...props.activeData,
      defaultValue: isNumberStr(str) ? +str : str,
    });
    // 字符串和数字
    // this.$set(
    //   this.activeData,
    //   'defaultValue',
    //   isNumberStr(str) ? +str : str
    // )
  }
};
const onSwitchValueInput = (val: any, name: any) => {
  if (['true', 'false'].indexOf(val) > -1) {
    // this.$set(this.activeData, name, JSON.parse(val))
  } else {
    // this.$set(this.activeData, name, isNumberStr(val) ? +val : val)
  }
};
const setTimeValue = (val: any, type: any) => {
  const valueFormat = type === 'week' ? dateTimeFormat.date : val;
  // this.$set(this.activeData, 'defaultValue', null)
  // this.$set(this.activeData, 'value-format', valueFormat)
  // this.$set(this.activeData, 'format', val)
};
const spanChange = (val: any) => {
  // this.formConf.span = val
};
const multipleChange = (val: any) => {
  emits('updateActiveData', { key: 'defaultValue', data: [] });
};
const dateTypeChange = (val: any) => {};
const rangeChange = (val: any) => {};
const rateTextChange = (val: any) => {
  // if (val) this.activeData['show-score'] = false
};
const rateScoreChange = (val: any) => {
  // if (val) this.activeData['show-text'] = false
};
const colorFormatChange = (val: any) => {
  // this.activeData.defaultValue = null
  // this.activeData['show-alpha'] = val.indexOf('a') > -1
  // this.activeData.renderKey = +new Date() // 更新renderKey,重新渲染该组件
};
const openIconsDialog = (model: any) => {
  // this.iconsVisible = true
  // this.currentIconModel = model
};
const setIcon = (val: any) => {
  // this.activeData[this.currentIconModel] = val
};
const tagChange = (tagIcon: any) => {
  let target: any = inputComponents.find((item: any) => item.tagIcon === tagIcon);
  if (!target) target = selectComponents.find((item) => item.tagIcon === tagIcon);
  emits('tagChange', target);
};
const solverDelete = (element: any, activeData: any) => {
  activeData.options.splice(element, 1);
  activeData.coreNodeInfo.splice(element, 1);
  nextTick(() => {
    activeData.solverNameIndex = activeData.solverNameIndex - 1;
  });
};
const solverNameChange = (val: any, activeData: any) => {
  activeData.solverNameIndex = val;
  if (!activeData.coreNodeInfo[val]) {
    activeData.coreNodeInfo[val] = {
      minCore: 12,
      maxCore: 24,
      defaultCore: 12,
      minNode: 1,
      maxNode: 1,
      defaultNode: 1,
    };
  }
};
const deleteOptionsItem = (element: any, activeData: any) => {
  let deleteOptionIndex = activeData.options.findIndex((item: any) => {
    return item.value === element.value;
  });

  activeData.options.splice(deleteOptionIndex, 1);
  if (activeData.selectList) {
    let deleteIndex = activeData.selectList.findIndex((item: any) => {
      return item === element.value;
    });
    deleteIndex !== -1 && activeData.selectList.splice(deleteIndex, 1);
  }
};
const changeFile = (data: any, widget: any) => {
  // attributeList[0].value = data;
  // widget.value.length = 0
  widget.value = [];
  if (data[0]?.name) {
    data[0].fileName = data[0].name;
  }

  widget.value.push(...data);
  if (data.length) {
    if (data[0].fileName) {
      widget.choosePath = data[0].allPath;
    } else {
      // data[0].fileName = data[0].name;
      widget.file = data[0];
    }
  } else {
    widget.choosePath = '';
    widget.file = null;
  }
};

const changeLabel = (activeData: any) => {
  activeData.oldLabel = activeData.label;
};
</script>

<style lang="scss" scoped>
.right-board {
  width: 100%;
  height: 100%;
  .field-box {
    position: relative;
    height: calc(100% - 40px);
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    .right-scrollbar {
      height: 100%;
      width: 100%;
      overflow-y: auto;
      overflow-x: hidden;
      padding: 12px 0;
    }
  }
  .el-scrollbar {
    height: 100%;
  }
}
.select-item {
  display: flex;
  border: 1px dashed #fff;
  box-sizing: border-box;
  & .close-btn {
    cursor: pointer;
    color: #f56c6c;
  }
  & .el-input + .el-input {
    margin-left: 4px;
  }
}
.select-item + .select-item {
  margin-top: 4px;
}
.select-item.sortable-chosen {
  border: 1px dashed #409eff;
}
.select-line-icon {
  line-height: 32px;
  font-size: 22px;
  padding: 0 4px;
  color: #777;
  display: flex;
  align-items: center;
}
.option-drag {
  cursor: move;
}
.time-range {
  .el-date-editor {
    width: 227px;
  }
  .el-icon-time {
    display: none;
  }
}

.node-label {
  font-size: 14px;
}
.node-icon {
  color: #bebfc3;
}
:deep(.el-tabs__item) {
  width: 100% !important;
}

:deep(.select-radio-item) {
  width: 100%;
  margin-left: 12px !important;
  .el-radio__label {
    width: 100%;
    display: flex;
  }
}
</style>
