<template>
  <div>
    <el-button size="mini" type="primary" @click="dialogFormVisible = true">新 建</el-button>
    <el-dialog title="新 建" :visible.sync="dialogFormVisible" width="60%">
      <div slot="title" style="font-size: 15px">
        新增私域客户
      </div>
      <el-row :gutter="20">
        <el-form :model="form" :rules="rules" ref="form" label-width="90px" label-position="right" size="mini">
          <el-col :span="12">
            <el-form-item label="客户名称" prop="enterprisename">
              <el-input v-model="form.enterprisename" placeholder="客户名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户类型" prop="type">
              <el-select v-model="form.type" placeholder="请选择客户类型" size="small">
                <el-option
                  v-for="item in customerType()"
                  :key="item.value"
                  :label="item.value"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户来源" prop="source">
              <el-input v-model="form.source" placeholder="客户来源"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户等级" prop="grade">
              <el-select v-model="form.grade" placeholder="请选择客户等级" size="small">
                <el-option
                  v-for="item in customerLead()"
                  :key="item.rowindex"
                  :label="item.value"
                  :value="item.rowindex">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="详细地址" prop="address">
              <el-input v-model="form.address" placeholder="详细地址"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="企业简称" prop="abbreviation">
              <el-input v-model="form.abbreviation" placeholder="企业简称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="税号" prop="taxno">
              <el-input v-model="form.taxno" placeholder="税号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属行业" prop="industry">
              <el-input v-model="form.industry" placeholder="所属行业"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系人" prop="contact">
              <el-input v-model="form.contact" placeholder="联系人"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="phonenumber">
              <el-input v-model="form.phonenumber" placeholder="联系电话"></el-input>
            </el-form-item>
          </el-col>
           <el-col :span="12">
            <el-form-item label="省市县" prop="province">
              <el-cascader
                size="small"
                v-model="form.province"
                :options="arealist()"
                @change="cascaderChange"
                ref="cascader">
              </el-cascader>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="dialog-footer">
        <el-button size="small" @click="dialogFormVisible = 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: "add",
  inject:['customerLead','customerType','arealist'],
  data(){
    return {
      dialogFormVisible:false,
      isordercheck:true,
      isusedcheck:false,
      form:{
        "sa_customersid": 0,//新增是传0
        "parentid": 0, //上级客户ID,默认或没有上级的时候传0
        "sys_enterpriseid": 0, //合作企业档案ID，新增是传0，更新
        "enterprisename":"",//客户名称（企业名称）
        "type": "", //客户类型
        "sa_customerpoolid": 0, //客户池（公海池）ID,默认或没有的时候传0
        "source": "", //客户来源
        "province":"",//非必填，可选
        "city":"",//非必填，可选
        "county":"",//非必填，可选
        "address":"",//非必填，可选
        "abbreviation":"",//非必填，可选
        "taxno":"",//税号,非必填，可选
        "grade":'',// 客户等级（商户等级）
        "industry":"",//非必填，可选，所属行业
        "contact":"",//非必填，可选
        "phonenumber":""//非必填，可选
      },
      rules:{
        enterprisename:[
          { required: true, message: '输入客户名称', trigger: 'blur'},
        ],
        type:[
          { required: true, message: '请选择客户类型', trigger: 'blur'}
        ],
        source:[
          { required: true, message: '请填写客户来源', trigger: 'blur'}
        ],
        grade:[
          { required: true, message: '请选择客户等级', trigger: 'blur'}
        ]
      }
    }
  },
  methods:{
    onSubmit(){
      this.$refs['form'].validate(async (valid) => {
        if (!valid) return false
        if (this.form.province) {
          this.form.city = this.form.province[1]
          this.form.county = this.form.province[2]
          this.form.province = this.form.province[0]
        }
        const res = await this.$api.requested({
          "id": "20221010164302",
          "version":1,
          "content": this.form
        })
        this.tool.showMessage(res,()=>{
          this.$emit('onSuccess')
          this.$refs['form'].resetFields();
          this.dialogFormVisible = false
        })
      })
    },
    cascaderChange() {

    }
  }
}
</script>

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