<template>
  <div class="inline-16">
    <el-button size="small" type="text" @click="onshow">编 辑</el-button>
    <el-dialog
        :visible.sync="dialogFormVisible"
        width="900px"
        @close="dialogFormVisible = false"
    >
      <div slot="title" style="font-size: 15px">
        新增联系人信息
      </div>
      <div>
        <el-row :gutter="20">
          <el-form :model="form" :rules="rules"  ref="form"  size="mini" label-position="right" label-width="90px">
            <el-col :span="20">
              <el-form-item label="省市县" >
                <el-cascader
                    style="width:100%"
                    v-model="form.value"
                    :options="basicData.data().areaData"
                    @change="cascaderChange" clearable>
                </el-cascader>
              </el-form-item>
            </el-col>
            <el-col :span="20">
              <el-form-item  label="详细地址:" prop="address">
                <el-input type="textarea" autosize v-model="form.address" placeholder="请输入家庭住址"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="20">
              <el-form-item  label="备注:" >
                <el-input type="textarea"  autosize v-model="form.remarks" placeholder="请输入备注"></el-input>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>
      </div>
      <div class="dialog-footer">
        <el-button size="small" @click="dialogFormVisible = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="primary" @click="onSubmit"   class="normal-btn-width btn-primary">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "edit",
  props:["data"],
  data(){
    return {
      dialogFormVisible:false,
      form:{
        value:[],
        contactsid: "",
        sys_enterpriseid: "",
        name: "",
        sex: "",
        depname: "",
        position: "",
        birthday: "",
        phonenumber: "",
        email: "",
        province: "",
        city: "",
        county: "",
        address: "",
        remarks: "",
        workaddress: 1,
        isdefault: 1,
        isprimary: 1
      },
      rules:{
        address: [
          { required: true, message: '地址不能为空', trigger: 'blur' },
        ],
      },
      value:''
    }
  },
  methods:{
    onshow(){
      this.dialogFormVisible = true
      this.form.sys_enterpriseid = this.data.sys_enterpriseid
      this.form.contactsid = this.data.contactsid
      this.form.remarks = this.data.remarks
      this.form.address = this.data.address
      this.form.province = this.data.province
      this.form.city = this.data.city
      this.county = this.data.county
      this.form.value[0] = this.data.province
      this.form.value[1] = this.data.city
      this.form.value[2] = this.data.county
    },
    onSubmit(){
      this.$refs['form'].validate(async (valid) => {
        if (!valid) return false
        const res = await this.$api.requested({
          "id": "20221018141802",
          "content": this.form
        })
        this.tool.showMessage(res,() => {
          this.$emit("updateSuccess")
          this.$refs['form'].resetFields()
          this.dialogFormVisible = false
        })
      })
    },
    /*省市县*/
    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]})

    },
  }
}
</script>

<style scoped>

</style>