<template>
  <div>
    <el-button size="small" type="text" @click="onShow">编 辑</el-button>
    <el-drawer
        title="新建线索"
        :visible.sync="dialogFormVisible"
        size="30%"
        direction="rtl"
        :show-close="false"
        append-to-body
        @close="onClose">
      <div class="drawer__panel">
        <el-row :gutter="20">
          <el-form :model="form" :rules="rules"  ref="form"  size="mini" label-position="right" label-width="76px">
            <el-col :span="24">
              <el-form-item  label="客户名称:" >
                <el-input  autosize v-model="form.enterprisename_customer" placeholder="请输入客户名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item  label="联系人:" >
                <el-input  autosize v-model="form.name" placeholder="请输入联系人"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item  label="手机号:" prop="phonenumber">
                <el-input  autosize v-model="form.phonenumber" placeholder="请输入手机号"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item  label="省市县:" >
                <el-cascader
                    style="width: 100%"
                    v-model="value"
                    :options="basicData.data().areaData"
                    @change="cascaderChange" clearable>
                </el-cascader>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item  label="地址:" >
                <el-input  autosize v-model="form.address" placeholder="请输入地址"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item  label="来源:" >
                <el-input  autosize v-model="form.cluesource" placeholder="请输入来源"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item  label="备注:" >
                <el-input  autosize v-model="form.notes" 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>
  </div>
</template>

<script>
export default {
  name: "followLeadsedit",
  props:["data"],
  data(){
    var validateMobilePhone = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('手机号不可为空'));
      } else {
        if (value !== '') {
          var reg=/^1[3456789]\d{9}$/;
          if(!reg.test(value)){
            callback(new Error('请输入有效的手机号码'));
          }
        }
        callback();
      }
    };
    return {
      dialogFormVisible:false,
      value:'',
      form:{
        "sat_orderclueid": 0,
        "enterprisename":"",
        "name": "",
        "phonenumber": "",
        "province": "",
        "city": "",
        "county": "",
        "address": "",
        "notes": "",
        "cluesource": "",
        "sat_campaignid":0,//活动id，当活动id大于0是默认业务员创建
        "isprivate":1,//0表示公海，1表示私域，
        "sa_customersid":0,//可不传
      },
      rules:{
        enterprisename: [
          { required: true, message: '客户名称不能为空', trigger: 'blur' },
        ],
        phonenumber: [
          { required: true, validator: validateMobilePhone, trigger: 'blur' },
        ]
      },
    }
  },
  methods:{
    onShow(){
      this.dialogFormVisible = true
      console.log(this.data,"客户信息")
      this.form = Object.assign({},this.form,this.data)
    },
    /*省市县*/
    cascaderChange (val) {
      if (val.length === 1)
        return this.form = Object.assign({},this.form,{province:val[0],city:'',county:''})

      this.form = Object.assign({},this.form,{province:val[0],city:val[1],county:val[2]})

    },
    onClose(){

    },
   onSubmit(){
      this.$refs.form.validate(async (valid) => {
        if (!valid) return false
        const res = await this.$api.requested({
          "id":20221205162402,
          "content": this.form
        })
        this.tool.showMessage(res,()=>{
          this.$emit('onSuccess')
          this.dialogFormVisible = false
        })
      })

    }
  }
}
</script>

<style scoped>

</style>