<template>
  <div>
    <el-button size="mini" type="text" @click="onshow" :disabled="!tool.checkAuth($route.name,'andEnterpriseManage') || !disabled">设置项目角色</el-button>
    <el-drawer
        title="设置客户类型"
        :visible.sync="visible"
        size="600px"
        direction="rtl"
        append-to-body
        :show-close="false"
        @close="onClose">
      <div class="drawer__panel">
        <el-row :gutter="20">
          <el-form :model="form" :rules="rules" ref="form" label-width="90px" label-position="right" size="mini">
            <el-col :span="24">
              <el-form-item label="客户名称:" >
                <el-input v-model="form.enterprisename" placeholder="请选择企业" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="项目角色:" prop="type">
                <el-select v-model="form.type" placeholder="请选择项目角色" size="small"  style="width: 100%">
                  <el-option
                      v-for="item in enterpriseType()"
                      :key="item.value"
                      :label="item.value"
                      :value="item.value">
                    <span style="float: left">{{ item.value }}</span>
                    <span style="float: right; color: #999999; font-size: 10px">{{ item.remarks }}</span>
                  </el-option>

                </el-select>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>
      </div>
      <div class="fixed__btn__panel">
        <el-button size="small" @click="onClose" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="primary" @click="onSave" class="normal-btn-width">确 定</el-button>
      </div>
    </el-drawer>
  </div>
</template>

<script>
export default {
  name: "setCustomerType",
  props:["data","disabled"],
  inject:["enterpriseType"],
  data(){
    return {
      visible:false,
      form:{
        sa_project_partiesid: '',
        type: ""
      },
      rules:{
        type:[
          { required: true, message: '请选择客户类型', trigger: 'change'},
        ],
      },
    }
  },
  methods:{
    onSave(){
      this.onSubmit()
    },
    onSubmit(){
      this.$refs.form.validate(async(valid) =>{
        if (!valid) return false
        const res = await this.$api.requested({
          "id": 20221116142502,
          "content":this.form
        })
        this.tool.showMessage(res,()=>{
          this.visible = false
          this.$emit('setSuccess')
        })
      })
    },
    onClose(){
      this.visible = false
    },
    onshow(){
      this.visible = true
      this.form = this.data
      this.form = Object.assign({},this.data,this.form)
      console.log(this.form)
      console.log(this.data)
    }
  },
  mounted() {

  }
}
</script>

<style scoped>

</style>