<!-- 获取验证字段 -->
<template>
  <GlobalWindow
    :title="title"
    v-model:visible="visible"
    :confirm-working="isWorking"
    width="36%"
    @confirm="confirm"
  >
    <el-form :model="form" ref="form" :rules="rules">
      <el-form-item label="图标名称" prop="name" required>
        <el-input
          v-model="form.name"
          placeholder="请输入图标名称"
          v-trim
        />
      </el-form-item>
      <el-form-item
        label="图标值"
        prop="value"
        required
      >
        <div class="value-input">
          <el-input
            v-model="form.value"
            placeholder="请输入图标值"
            v-trim
          >
            <template #prefix>
              <Icon :value="form.value" size="18px"/>
            </template>
          </el-input>
        </div>
        <FormItemTip>图标值可以为class、Element-Plus图标或路径图标</FormItemTip>
      </el-form-item>
    </el-form>
  </GlobalWindow>
</template>

<script>
import BaseOpera from '@/components/base/BaseOpera.vue'

export default {
  name: 'OperaIconWindow',
  extends: BaseOpera,
  data () {
    return {
      // 表单数据
      form: {
        id: null,
        name: '',
        value: ''
      },
      // 验证规则
      rules: {
        name: [
          { required: true, message: '请输入图标名称' }
        ],
        value: [
          { required: true, message: '请输入图标值' }
        ]
      }
    }
  },
  async created () {
    this.config({
      api: await import('@/api/system/icon'),
      'field.id': 'id'
    })
  }
}
</script>

<style scoped lang="scss">
.el-form {
  :deep(.value-input) {
    .icon {
      width: 18px !important;
      height: 18px !important;
    }
  }
}
</style>
