<template>
  <div>
    <a-form-model ref="form" :model="formData" :rules="rules" class="from-table">
      <a-row>
        <a-col :span="4" class="bg-gray">
          <div class="required">单位名称</div>
        </a-col>
        <a-col :span="20">
          <a-form-model-item prop="unitName">
            <a-input v-model="formData.unitName" placeholder="单位名称" style="width:80%" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <!-- <a-row>
        <a-col :span="4" class="bg-gray">
          <div class="required">单位类型</div>
        </a-col>
        <a-col :span="20">
          <a-form-model-item prop="unitType">
            <base-select v-model="formData.unitType" :type="6" :isAll="true" />
          </a-form-model-item>
        </a-col>
      </a-row> -->
      <a-row>
        <a-col :span="4" class="bg-gray">
          <div class="required">单位地址</div>
        </a-col>
        <a-col :span="20">
          <a-form-model-item prop="unitAddress">
            <a-input v-model="formData.unitAddress" :maxLength="30" style="width:80%" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row type="flex">
        <a-col :span="4" class="bg-gray">
          <div class="special-middle">
            <div class="required">联系人</div>
          </div>
        </a-col>
        <a-col :span="8">
          <div class="special-middle">
            <div>
              <a-form-model-item prop="linkName">
                <a-input placeholder="联系人" v-model="formData.linkName" :maxLength="50" style="width:80%" />
              </a-form-model-item>
            </div>
          </div>
        </a-col>
        <a-col :span="4" class="bg-gray">
          <div class="special-middle">
            <div class="required">电话</div>
          </div>
        </a-col>
        <a-col :span="8">
          <div class="special-middle">
            <div>
              <a-form-model-item prop="telephone">
                <a-input placeholder="电话" v-model="formData.telephone" :maxLength="50" style="width:80%" />
              </a-form-model-item>
            </div>
          </div>
        </a-col>
      </a-row>
      <a-row type="flex">
        <a-col :span="4" class="bg-gray">
          <div class="special-middle">
            <div class="required">电子信箱</div>
          </div>
        </a-col>
        <a-col :span="8">
          <div class="special-middle">
            <div>
              <a-form-model-item prop="email">
                <a-input placeholder="电子信箱" v-model="formData.email" :maxLength="50" style="width:80%" />
              </a-form-model-item>
            </div>
          </div>
        </a-col>
        <a-col :span="4" class="bg-gray">
          <div class="special-middle">
            <div>传真</div>
          </div>
        </a-col>
        <a-col :span="8">
          <div class="special-middle">
            <div>
              <a-form-model-item prop="fax">
                <a-input placeholder="传真" v-model="formData.fax" :maxLength="50" style="width:80%" />
              </a-form-model-item>
            </div>
          </div>
        </a-col>
      </a-row>
      <a-row type="flex">
        <a-col :span="4" class="bg-gray">
          <div class="special-middle">
            <div class="required">组织机构代码</div>
          </div>
        </a-col>
        <a-col :span="20">
          <div class="special-middle">
            <div>
              <a-form-model-item prop="organizationCode">
                <a-input placeholder="组织机构代码/统一社会信用代码" v-model="formData.organizationCode" :maxLength="100" style="width:80%" />
              </a-form-model-item>
            </div>
          </div>
        </a-col>
      </a-row>
      <a-row type="flex">
        <a-col :span="4" class="bg-gray">
          <div class="special-middle">
            <div class="required">注册所在地(县/区)</div>
          </div>
        </a-col>
        <a-col :span="8">
          <div class="special-middle">
            <div>
              <a-form-model-item prop="registeredAddress">
                <a-input placeholder="注册所在地" v-model="formData.registeredAddress" :maxLength="100" style="width:80%" />
              </a-form-model-item>
            </div>
          </div>
        </a-col>
        <a-col :span="4" class="bg-gray">
          <div class="special-middle">
            <div class="required">邮编</div>
          </div>
        </a-col>
        <a-col :span="8">
          <div class="special-middle">
            <div>
              <a-form-model-item prop="postCode">
                <a-input placeholder="邮编" v-model="formData.postCode" :maxLength="10" style="width:80%" />
              </a-form-model-item>
            </div>
          </div>
        </a-col>
      </a-row>
      <a-row type="flex">
        <a-col :span="4" class="bg-gray">
          <div class="special-middle">
            <div class="required">法定代表人</div>
          </div>
        </a-col>
        <a-col :span="8">
          <div class="special-middle">
            <div>
              <a-form-model-item prop="legalPerson">
                <a-input placeholder="法定代表人" v-model="formData.legalPerson" :maxLength="50" style="width:80%" />
              </a-form-model-item>
            </div>
          </div>
        </a-col>
        <a-col :span="4" class="bg-gray">
          <div class="special-middle">
            <div class="required">职工总数</div>
          </div>
        </a-col>
        <a-col :span="8">
          <div class="special-middle">
            <div>
              <a-form-model-item prop="workforce">
                <a-input-number v-model="formData.workforce" :min="0" :step="1" style="width: 100px" />
              </a-form-model-item>
            </div>
          </div>
        </a-col>
      </a-row>
      <a-row type="flex">
        <a-col :span="4" class="bg-gray">
          <div class="special-middle">
            <div class="required">其中专科以上人员</div>
          </div>
        </a-col>
        <a-col :span="8">
          <div class="special-middle">
            <div>
              <a-form-model-item prop="specializedPersonnel">
                <a-input-number v-model="formData.specializedPersonnel" :min="0" :step="1" style="width: 100px" />
              </a-form-model-item>
            </div>
          </div>
        </a-col>
        <a-col :span="4" class="bg-gray">
          <div class="special-middle">
            <div class="required">研究开发人员</div>
          </div>
        </a-col>
        <a-col :span="8">
          <div class="special-middle">
            <div>
              <a-form-model-item prop="researchPersonnel">
                <a-input-number v-model="formData.researchPersonnel" :min="0" :step="1" style="width: 100px" />
              </a-form-model-item>
            </div>
          </div>
        </a-col>
      </a-row>
      <a-row type="flex">
        <a-col :span="4" class="bg-gray">
          <div class="special-middle">
            <div>开户银行</div>
          </div>
        </a-col>
        <a-col :span="8">
          <div class="special-middle">
            <div>
              <a-form-model-item prop="depositBank">
                <a-input placeholder="开户银行" v-model="formData.depositBank" :maxLength="100" style="width:80%" />
              </a-form-model-item>
            </div>
          </div>
        </a-col>
        <a-col :span="4" class="bg-gray">
          <div class="special-middle">
            <div>银行账号</div>
          </div>
        </a-col>
        <a-col :span="8">
          <div class="special-middle">
            <div>
              <a-form-model-item prop="bankAccount">
                <a-input placeholder="银行账号" v-model="formData.bankAccount" :maxLength="100" style="width:80%" />
              </a-form-model-item>
            </div>
          </div>
        </a-col>
      </a-row>
      <a-row type="flex">
        <a-col :span="4" class="bg-gray">
          <div class="special-middle">
            <div>开户银行地址</div>
          </div>
        </a-col>
        <a-col :span="8">
          <div class="special-middle">
            <div>
              <a-form-model-item prop="depositBankAddress">
                <a-input placeholder="开户银行地址" v-model="formData.depositBankAddress" :maxLength="100" style="width:80%" />
              </a-form-model-item>
            </div>
          </div>
        </a-col>
        <a-col :span="4" class="bg-gray">
          <div class="special-middle">
            <div>银行联行号</div>
          </div>
        </a-col>
        <a-col :span="8">
          <div class="special-middle">
            <div>
              <a-form-model-item prop="interbankNumber">
                <a-input placeholder="开户银行地址" v-model="formData.interbankNumber" :maxLength="100" style="width:80%" />
              </a-form-model-item>
            </div>
          </div>
        </a-col>
      </a-row>
    </a-form-model>
  </div>
</template>

<script>
import { isEmptyParams, checkEmail, checkPhone, checkIdentitytionId, personBirthday, personGender } from "@/views/utils/common"


export default {
  name: "infoEdit",
  components: {

  },
  data () {
    return {
      rules: {
        unitName: [{ required: true, message: '*' }],
        // unitType: [{ required: true, message: '*' }],
        unitAddress: [{ required: true, message: '*' }],
        linkName: [{ required: true, message: '*' }],
        telephone: [{ required: true, message: '*' }],
        email: [
          { required: true, message: '*', trigger: 'blur' },
          { required: true, validator: checkEmail, trigger: 'blur' }
        ],
        fax: [{ required: false, message: '*' }],
        organizationCode: [{ required: true, message: '*', trigger: 'blur' },],
        registeredAddress: [{ required: true, message: '*', trigger: 'blur' },],
        postCode: [{ required: true, message: '*', trigger: 'blur' },],
        legalPerson: [{ required: true, message: '*', trigger: 'blur' },],
        workforce: [{ required: true, message: '*', trigger: 'blur' },],
        specializedPersonnel: [{ required: true, message: '*', trigger: 'blur' },],
        researchPersonnel: [{ required: true, message: '*', trigger: 'blur' },],
        depositBank: [{ required: false, message: '*', trigger: 'blur' },],
        bankAccount: [{ required: false, message: '*', trigger: 'blur' },],
        depositBankAddress: [{ required: false, message: '*', trigger: 'blur' },],
        interbankNumber: [{ required: false, message: '*', trigger: 'blur' },],

        // unitName: [{ required: true, message: '请输入单位名称' }],
        // unitType: [{ required: true, message: '请选择单位类型' }],
        // unitAddress: [{ required: true, message: '请输入单位地址' }],
        // linkName: [{ required: true, message: '请输入联系人' }],
        // telephone: [{ required: true, message: '请输入电话' }],
        // email: [{ required: true, message: '请输入电子信箱' }],
        // fax: [{ required: true, message: '请输入传真' }],
        // organizationCode: [{ required: true, message: '请填写组织机构代码/统一社会信用代码', trigger: 'blur' },],
        // registeredAddress: [{ required: true, message: '请填写注册所在地', trigger: 'blur' },],
        // postCode: [{ required: true, message: '请填写邮编', trigger: 'blur' },],
        // legalPerson: [{ required: true, message: '请填写法定代表人', trigger: 'blur' },],
        // workforce: [{ required: true, message: '请填写职工总数', trigger: 'blur' },],
        // specializedPersonnel: [{ required: true, message: '请填写其中专科以上人员', trigger: 'blur' },],
        // researchPersonnel: [{ required: true, message: '请填写研究开发人员', trigger: 'blur' },],
        // depositBank: [{ required: true, message: '请填写开户银行', trigger: 'blur' },],
        // bankAccount: [{ required: true, message: '请填写银行账号', trigger: 'blur' },],
        // depositBankAddress: [{ required: true, message: '请填写开户银行地址', trigger: 'blur' },],
        // interbankNumber: [{ required: true, message: '请填写开户银行地址', trigger: 'blur' },],
      },
      managersState: true,
      loading: false
    }
  },
  props: {
    formData: {
      type: Object,
      default: () => {
        return null
      }
    },
  },
  created () {
  },
  methods: {
    submit () {
      //提交单位数据
      this.$refs.form.validate(valid => {
        if (valid) {
          this.$emit('load', true)
          let pars = isEmptyParams(this.formData)
          let par = { ...pars }
          this.$api.unit.updateUnit(par).then(({ data = {} }) => {
            if (data) {
              this.$message.success('修改成功！')
              this.$emit('sub', true)
            }
            this.$emit('load', false)
          }).catch(() => {
            this.$emit('load', false)
          })
        } else {
          this.$message.error('信息未填写完全！')
          return false
        }
      })
    }
  }
}
</script>