<template>
  <div>
    <el-dialog
      title="批次属性明细"
      :visible.sync="editFormVisible"
      :before-close="editFormClose">
        <el-form
          inline
          ref="editForm"
          label-position="top"
          :model="formData"
          :rules="rules">
          <el-form-item
          label="批次标签"
          prop="title">
            <el-input v-model="formData.title" :disabled="index < 4"></el-input>
          </el-form-item>
          <el-form-item
          label="批次标签(外语)"
          prop="foreignTitle">
            <el-input v-model="formData.foreignTitle" :disabled="index < 4"></el-input>
          </el-form-item>
          <el-form-item
          label="输入控制"
          prop="inputControl">
            <el-select v-model="formData.inputControl">
              <el-option label="必输" value="R"></el-option>
              <el-option label="可选" value="O"></el-option>
              <el-option label="禁用" value="F"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item
          label="属性类型"
          prop="fieldType">
            <el-select v-model="formData.fieldType" :disabled="index < 4">
              <el-option label="下拉框" value="ComboBox"></el-option>
              <el-option label="日期" value="DateField"></el-option>
              <el-option label="日期时间" value="DateTimeField"></el-option>
              <el-option label="数字" value="NumberField"></el-option>
              <el-option label="弹出框" value="PopField"></el-option>
              <el-option label="文本" value="TextInput"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item
          label="属性选项"
          prop="KeyValue">
            <el-select v-model="formData.KeyValue" :disabled="index < 4">
              <el-option v-for="item in fieldKeys" :key="item.code" :label="item.name" :value="item.code"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item
          label="是否关键字"
          prop="isKeyword">
            <el-select v-model="formData.isKeyword">
              <el-option label="是" value="Y"></el-option>
              <el-option label="否" value="N"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div>
          <el-button type="primary" v-auth="50400050204" @click="handleConfirm">确定</el-button>
        </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  mounted () {
    this.getFieldKeys()
  },
  data () {
    return {
      // formData:{
      //   title:'',
      //   foreignTitle:'',
      //   inputControl: '',
      //   fieldType:'',
      //   KeyValue:'',
      //   isKeyword:''
      // },
      rules: {
        inputControl: [
          { required: true, message: '输入控制必填', trigger: 'blur' }
        ]
      },
      fieldKeys: [], // 属性选项列表
    }
  },
  props: {
    editFormVisible: Boolean,
    formData: {
      type: Object,
      default: () => ({})
    },
    index: ''
  },
  methods: {

    // 关闭弹窗
    editFormClose () {
      this.$emit('editFormClose')
    },

    // 确定
    handleConfirm () {
      this.$emit('handleConfirm', this.formData, this.index)
    },
    // 获取属性选项
    getFieldKeys () {
      const url = this.$API.getCodeMaster + '?cfgKey=SYS_WM_FIELD_KEY'
      this.$https.post(url)
        .then(data => {
          this.fieldKeys = data
        })
    },
  }
}
</script>
