<style>
.addCustomer .add-tit{
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 20px;
}
.addCustomer .add-tit p{
    display: flex;
    align-items: center;
    font-weight: bold;
    color:rgba(17,17,17,1);
    font-size:14px;
}
.addCustomer .add-tit p span{
    display: inline-block;
    width:6px;
    height:6px;
    background:rgba(13,36,129,1);
    border-radius:50%;
    margin-right: 10px;
}
.addCustomer .el-dialog__header{
    padding: 15px 20px;
    background:rgba(255,255,255,1);
}
.addCustomer .dialog-footer{
    text-align: center;
    background-color: rgba(248,250,251,1);
    padding-bottom: 20px;
}
.addCustomer .el-dialog__footer{
    padding: 0;
}
.addCustomer .el-tag.el-tag--info{
    background-color: rgba(0,0,0,0);
    border-color: rgba(0,0,0,0);
    display: inline-block;
    white-space: nowrap; 
    overflow: hidden;
    text-overflow:ellipsis;
}
</style>
<template>
    <el-dialog @closed="closedDialog" :modal="false" :visible.sync="dialogTableVisible" width="450px"  :close-on-click-modal="false" class="addCustomer">
        <div class="add-tit" slot="title">
            <p><span></span>{{obj.title}}</p>
            <span icon="el-icon-close"></span>
        </div>
        <div class="form-box" >
            <el-form :model="form" ref="form" class="MyEditForm">
                <div class="MyEditForm-item">
                    <el-form-item label="账号" class="label-pad-left" prop="Name">
                        <el-input placeholder="请输入账号" v-model="form.Name" clearable></el-input>
                    </el-form-item>
                </div>
            </el-form>
        </div>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" class="add-box-btn" @click="submitForm('form')">确 定</el-button>
            <el-button class="add-box-btn add-box-cancel" @click="dialogTableVisible = false, resetForm('form')">取 消</el-button>
        </div>
    </el-dialog>
</template>
<script>
export default {
  props: {
    obj:Object
  },
  data() {
    return {
        title:"",
        dialogTableVisible: true,
        TransferOther: [],
        form: {
            Name: '',
            SNO: '',
            ID: 0,
        }
    };
  },
  watch:{
    
 },
  mounted() {
      if(this.obj.title=='新建账号'){
          this.form.SNO = this.obj.ID
      }else{
          this.form = {
              ID: this.obj.ID,
              SNO: this.obj.SNO,
              Name: this.obj.Name,
          }

      }
    let $this = this
    setTimeout(()=>{
        $this.dialogTableVisible = true
    },50)
  },
  methods: {
    closedDialog(){
        this.MsgBus.$emit('closeaaddCustomer')
    },
    addData(){
        if (!this.form.Name) {
            return this.$message.error('请输入账号')
        }
        this.apipost('/api/Customer/SetGuestSourceAccount', this.form, res=>{
            if (res.data.resultCode == 1) {
                this.resetForm("form");
                this.dialogTableVisible = false;
                this.$emit('addCustomerOk')
                this.$message.success(res.data.message)
            } else {
                this.$message.error(res.data.message)
            }
        })
    },
    submitForm(addMsg) {
      //提交创建、修改表单
      this.$refs[addMsg].validate(valid => {
        if (valid) {
          this.addData();
        } else {
          return false;
        }
      });
    },
    resetForm(formName) { // 重置表单
        this.form =  {
            Name: '',
            SNO: '',
            ID: '',
        }
        this.$refs[formName].resetFields();
    },
  }
}
</script>