<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"
        :show-close="false"
        direction="rtl"
        append-to-body
        @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="企业名称:" prop="enterprisename">
                <el-input v-model="form.enterprisename" placeholder="请选择企业" @focus="enterpriseList"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注:" >
                <el-input v-model="form.remarks" type="textarea" rows="5" placeholder="请输入备注信息"></el-input>
              </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="onSubmit" class="normal-btn-width">确 定</el-button>
      </div>
    </el-drawer>
    <enterprise
        :visible="visibleEnterprise"
        :index="index"
        :sa_projectid="form.sa_projectid"
        v-if="visibleEnterprise"
        @onEnterprise="onEnterprise">
    </enterprise>
  </div>
</template>

<script>
import enterprise from './enterprise'
export default {
  name: "edit",
  props:["data","disabled"],
  components:{enterprise},
  data(){
    return {
      visible:false,
      visibleEnterprise:false,
      index:'',
      form:{
        sa_project_partiesid: 0,
        sa_projectid: '',
        sys_enterpriseid:'',
        enterprisename:'',
        remarks:""
      },
      rules:{
        enterprisename:[
          { required: true, message: '请选择企业', trigger: 'change'},
        ],
      }
    }
  },
  methods:{
    onshow(){
      console.log("新增企业缔约信息")
      console.log(this.data)
      this.form = this.data
      this.visible = true
    },
    onSubmit(){
      this.form.sa_projectid = this.data.sa_projectid
      this.$refs['form'].validate(async (valid) => {
        if (!valid) return false
        const res = await this.$api.requested({
          "id": 20221027143602,
          "content": this.form
        })
        this.tool.showMessage(res,()=>{
          this.$emit('updateSuccess')
          this.onClose()
        })
      })
    },
    onClose(){
      this.visible = false
      this.$refs.form.resetFields()
      this.form={
        sa_project_partiesid: 0,
        sa_projectid: '',
        sys_enterpriseid:'',
        enterprisename:'',
        remarks:""
      }
    },
    enterpriseList(){
      this.visibleEnterprise = true
    },
    /*客户列表*/
    onEnterprise(data){
      this.visibleEnterprise = false
      console.log("企业信息",data)
      this.form.sys_enterpriseid = data.sys_enterpriseid
      this.form.enterprisename = data.enterprisename

    },
  },
  mounted() {

  }
}
</script>

<style scoped>

</style>