<template>
  <div v-loading="loading">
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="150px" class="cusUser_form">
      <el-form-item label="仓库名称" prop="pro_companyame">
        <el-input v-model="ruleForm.pro_companyame" placeholder="请输入仓库名称 " />
      </el-form-item>
      <el-form-item label="仓库属性" prop="customerdept">
        <el-input v-model="ruleForm.customerdept" placeholder="请输入仓库地址 " />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">保存</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>

import { filterContent } from '@/utils'
// import {
//   getCusUserR,
//   addCusUserR,
//   addCusUserCallInR,
//   editCusUserR
// } from '@/api/customer/customerInfoHY'
import {
  validName,
  validateTel,
  validFax,
  validEmail
} from '@/utils/validate'

export default {
  name: 'AddOrEdit',
  props: {
    rowid: {
      type: String,
      default: ''
    },
    custid: {
      type: String,
      default: ''
    },
    isCallin: {
      type: Boolean,
      default: false
    },
    layerid: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      ruleForm: {
        pro_id: '',
        pro_customerid: '', //	客户id
        pro_name: '', //	否	string	联系人
        pro_companyame: '', // 否	string	单位名称
        customerdept: '', // 客户部门
      },
      rules: {
        pro_companyame: [{
          required: true,
          message: '请输入仓库姓名',
          trigger: 'blur'
        }],
      },
      loading: false
    }
  },
  created() {
    // Promise.all([this.getProCity(), this.getPros(), this.getProType()]).then(() => {
    if (this.rowid) {
      this.ruleForm.pro_id = this.rowid
      this.getDetail(this.rowid)
    }
    // })
  },
  methods: {
    submitForm() {
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          this.ruleForm.pro_customerid = this.custid
          this.loading = true
          // 添加
          if (!this.rowid) {
            if (this.isCallin) {
              // addCusUserCallInR(this.ruleForm)
              //   .then(response => {
              //     this.loading = false
              //     if (response.state.toLowerCase() === 'success') {
              //       this.$parent.$layer.close(this.layerid)
              //       this.$parent.getCusProList() // 弹屏内获取客户资料信息
              //       this.$message.success('恭喜你，客户项目信息添加成功!')
              //     }
              //   })
              //   .catch(() => {
              //     this.loading = false
              //   })
              return
            }
            // addCusUserR(this.ruleForm)
            //   .then(response => {
            //     this.loading = false
            //     if (response.state.toLowerCase() === 'success') {
            //       this.$parent.$layer.close(this.layerid)
            //       this.$parent.getListR() // 重新加载父级数据
            //       this.$message.success('恭喜你，客户项目信息添加成功!')
            //     }
            //   })
            //   .catch(() => {
            //     this.loading = false
            //   })

            return
          }
          // 编辑
          this.ruleForm.followcontent = filterContent.delHtmlTag(this.ruleForm.followcontent) //	跟进内容
          // editCusUserR(this.ruleForm)
          //   .then(response => {
          //     this.loading = false
          //     if (response.state.toLowerCase() === 'success') {
          //       this.$parent.$layer.close(this.layerid)
          //       this.$parent.getListR() // 重新加载父级数据
          //       this.$message.success('恭喜你，客户项目信息编辑成功!')
          //     }
          //   })
          //   .catch(() => {
          //     this.loading = false
          //   })
        } else {
          this.$message.error('请输入有效的必填项信息!')
          return false
        }
      })
    },
    resetForm() {
      this.provinceCity = []
      this.$refs.ruleForm.resetFields()
    },
    // 详情
    getDetail(rid) {
      // getCusUserR(rid).then(response => {
      //   if (response.state.toLowerCase() === 'success') {
      //     const res = response.data
      //     this.ruleForm.pro_companyame = res.companyame // 否	string	单位名称
      //     this.ruleForm.customerdept = res.customerdept // 否	string	客户部门
      //   }
      // })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
	.cusUser_form {
    .form_select,
    .el-date-editor{
      width: 100%;
    }
  }
</style>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
