<template>
  <div>
    <el-button size="mini" :type="disabled || data.status === '已无效'?'':'primary'" @click="dialog=true" :disabled="disabled || data.status === '已无效'">转化项目</el-button>
    <el-dialog append-to-body width="30%" title="转化为项目商机" :visible.sync="dialog">
      <el-form :model="form" :rules="rules" ref="form" label-width="90px" label-position="right" size="mini">
          <el-col :span="24">
            <el-form-item label="项目名称" prop="projectname">
                <el-input type="text" placeholder="请输入项目名称" size="small" v-model="form.projectname"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="项目类型" prop="projecttype">
              <el-select v-model="form.projecttype" placeholder="请选择项目类型" size="mini">
                <el-option
                    v-for="(item,index) in projectType"
                    :key="index"
                    :label="item.value"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
      </el-form>
      <div class="dialog-footer">
        <el-button size="small" @click="dialog = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="warning" @click="onSubmit" class="normal-btn-width btn-warning">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: '',
  components: {},
  data() {
    return {
      dialog:false,
      form: {
        projectname:'',
        projecttype:'',
      },
      rules:{
        projectname: [
          { required: true, message: '请选择项目名称', trigger: 'change' },
        ],
        projecttype: [
          { required: true, message: '请选择项目类型', trigger: 'change' },
        ],
      },
      projectVisible:false,
      projectType:[],
    };
  },
  props:['idName','idKey','id','disabled','data'],
  computed:{
  },
  async created () {
    /* 获取项目类型 */
    let res = await this.$store.dispatch('optiontypeselect','projecttype')
    this.projectType = res.data
  },
  methods: {
    async onSubmit () {
      let res = await this.$api.requested({
        "id": 20221124154902,
        "content": {
            "sat_orderclueid": this.$route.query.id,
            "projectname": this.form.projectname,
            "projecttype": this.form.projecttype
        },
      })
      this.tool.showMessage(res,() => {
        this.dialog = false
        this.$emit('onSuccess')
        console.log(res);
        
        let active_module = JSON.parse(sessionStorage.getItem('module_info')).find(item => item.systemname == 'CRM').modules.find(item => item.systemmodulename == '项目管理')

        window.sessionStorage.setItem('active_modules',JSON.stringify(active_module))

        this.$router.push({path:'/projectChangeDetail',query:{id:res.data.sa_projectid,rowindex:res.data.rowindex}})
      })
    },
  },
};
</script>

<style scoped>
.el-select {
  width: 100%;
}
</style>
