import { upcloud_base_strategy,  } from "@/config/serviceSettings";

const remote = function(value) {
  return {
    autoLoad: true,
    remoteUrl: {
      url: upcloud_base_strategy + '/enum/v1',
      params: { typeNname: value },
      headers: {
        'Content-Type': 'application/JSON'
      },
      method: 'get'
    },
    doneBefore(data) {
      if (data && data.success) {
        var da = data.data
        var arr = da.map(x => {
          return {
            label: x.key,
            value: x.value
          }
        })
        data.data = arr
      }
      return data
    }
  }
}
const model = {
  //策略
  strategy: {
    items: [
      {
        type: 'input',
        name: 'name',
        label: '算法名称',
        required: true,
        value: '',
        labelCol: { span: 6 },
        span: 24
      },
      {
        // language    ： Java ("Java"),Javascript("Javascript"),Beanshell("Beanshell");/
        type: 'select',
        name: 'language',
        label: ' 语言',
        required: true,
        value: '',
        labelCol: { span: 6 },
        span: 24,
        on: {
          change(value, label, options, form) {
            if (value == 'Java') {
              form.visibleItem('clz')
              form.invisibleItem('scriptData')
            } else {
              form.visibleItem('scriptData')
              form.invisibleItem('clz')
            }
          }
        },
        options: [
          { label: 'Java', value: 'Java' },
          { label: 'Javascript', value: 'Javascript' },
          { label: 'Beanshell', value: 'Beanshell' }
        ]
      },
      {
        type: 'textarea',
        name: 'scriptData',
        label: '脚本',
        style: {
          height: '100px'
        },
        required: true,
        value: '',
        labelCol: { span: 6 },
        span: 24
      },
      {
        type: 'input',
        name: 'clz',
        label: '类',
        required: true,
        value: '',
        labelCol: { span: 6 },
        span: 24
      },
      {
        type: 'select',
        name: 'category',
        label: '算法分类',
        required: true,
        value: '',
        labelCol: { span: 6 },
        span: 24,
        ...remote('strategy')
      },
      {
        type: 'input',
        name: 'id',
        label: 'ID',
        value: '',
        labelCol: { span: 6 },
        span: 24,
        hidden: true
      },
      {
        type: 'textarea',
        name: 'remark',
        label: '备注',
        value: '',
        style: {
          height: '100px'
        },
        labelCol: { span: 6 },
        span: 24
      }
    ]
  }
}
export default model
