    <!-- 发布 -->
<template>

    <el-form label-position="left" ref="form" label-width="100px" :model="form" :size="defaultFormItemSize">
      <el-row class="title">基本信息</el-row>
      <el-form-item label="任务名称及版本:">
        <!-- <el-cascader v-model="form.runPublishDto.modelVersionId" :options="modelList" disabled
        :props='{ label: "name", value: "id", emitPath: false }'></el-cascader> -->
        {{ item.runName }}
      </el-form-item>

      <el-form-item label="发布方式:">
        <el-radio v-for="item in PublishWay.getList()"  :key="item.id" v-model="form.runPublishDto.publishWay" :label="item.id">{{  item.name}}</el-radio>
      </el-form-item>
      <el-form-item label="模型名称:" v-if="form.runPublishDto.publishWay===0" >
        <el-input v-model="form.runPublishDto.modelName" placeholder="请输入模型名称" class="inputWidth" :size="defaultFormItemSize"></el-input>
    </el-form-item>

    <el-form-item label="模型选择:" v-else>
        <el-select v-model="form.runPublishDto.modelId" placeholder="请选择">
        <el-option v-for="item in modelList" :key="item.id" :label="item.name" :value="item.id"></el-option>
      </el-select>
    </el-form-item>
    <!-- <el-form-item label="模型类型:">
      {{  form.runPublishDto.modelType}}
    </el-form-item> -->
    
    <el-form-item label="模型版本:">
      V{{ form.runPublishDto.modelVersion }}
    </el-form-item>
    <el-form-item label="版本描述:">
        <el-input placeholder="请输入版本描述" v-model="form.runPublishDto.modelDescribe" type="textarea" :rows="4" class="inputWidth" :size="defaultFormItemSize"></el-input>

    </el-form-item>

      <el-row type="flex" justify="end" class="dialog-btn-layer mt20">
        <el-button :size="defaultFormItemSize" :plain="true" @click="onCancel(false)">取消</el-button>
        <el-button type="primary" :size="defaultFormItemSize" @click="onSubmit">确定</el-button>
      </el-row>
    </el-form>
  </template>
  
<script>
  
import { TuningRun, MyModel} from '@/api/gptController.js';

export default {
  data () {
    return {
      modelList: [],
      form: {
        'runPublishDto': {
          'modelDescribe': undefined,
          'modelId': undefined,
          'modelName': undefined,
          'modelType': undefined,
          'modelVersion': undefined,
          'publishWay': 0,
          'runId': undefined
        }
      }
  
    };
  },
  props: ['item'],
  components: {},
  
  computed: {
  
  },
  
  mounted () {
    console.log(this.item);
    this.getModelList()
    this.intFrom()
  },
  
  methods: {
    intFrom () {
      this.form.runPublishDto.modelVersionId = this.item.modelVersionId
      this.form.runPublishDto.modelId = this.item.modelId
      this.form.runPublishDto.modelType = this.item.modelType
      this.form.runPublishDto.modelVersion = this.item.runVersion
      this.form.runPublishDto.runId = this.item.runId
    },
    onCancel (isSuccess) {
      if (this.observer != null) {
        this.observer.cancel(isSuccess);
      }
    },
    onSubmit () {
      return new Promise((resolve, reject) => {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            let params = {};
            params = { ...this.form };
  
            TuningRun.publish(this, params).then(res => {
              resolve(res);
              this.$message.success('发布成功');
              this.onCancel(true);
            }).catch(e => {
              reject(e);
            });
          } else {
            reject();
          }
        });
      });
    },
    getModelList () {
      MyModel.listForTree(this, {}).then(res => {
        this.modelList = res.data.map((item) => {
          return { id: item.modelId, name: item.modelName, children: item.modelVersionList === [] ? [] : item.modelVersionList.map((item2) => { return { id: item2.versionId, name: 'V' + item2.modelVersion } }) }
        })
        console.log(this.modelList);
      }).catch(e => {
        console.log(e);
      });
    }
  }
};
</script>
  <style scoped>
  .inputWidth {
    width: 300px;
  }
  .title {
    font-size: 20px;
    margin-bottom: 16px;
  }
  .introduce {
    font-size: 12px;
    color: #909399;
    margin-bottom: 10px;
      display: block;
  }
  </style>
