vue表单内嵌表格验证

走远了吗. 提交于 2020-03-04 14:20:04
     <el-form
        label-suffix=":"
        label-width="110px"
        v-if="!isShowPersonal"
        label-position="left"
        :model="enterpriseAuthenticationInfo"
        ref="modifyEnterpriseForm"
      >
          <el-table
              border
              :data="enterpriseAuthenticationInfo.businessContactPersonsVos"
              style="width: 100%"
            >
              <el-table-column label="姓名">
                <template slot-scope="scope">
                  <el-input
                    size="medium"
                    v-model="scope.row.business_name"
                    :disabled="isDisableInAuthentication"
                  ></el-input>
                </template>
              </el-table-column>
              <el-table-column label="手机号">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="'businessContactPersonsVos.' + scope.$index + '.business_phone'"
                    :rules='modifyPhoneNumberRules.newPhone'
                  >
                    <el-input
                      size="medium"
                      v-model="scope.row.business_phone"
                      :disabled="isDisableInAuthentication"
                    ></el-input>
                  </el-form-item>
                </template>
              </el-table-column>
                </el-table>

       <el-table
              border
              :data="enterpriseAuthenticationInfo.financialContactPersonsVos"
              style="width: 100%"
            >
              <el-table-column label="手机号">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="'financialContactPersonsVos.' + scope.$index + '.financial_phone'"
                    :rules='modifyPhoneNumberRules.newPhone'
                  >
                    <el-input
                      size="medium"
                      v-model="scope.row.financial_phone"
                      :disabled="isDisableInAuthentication"
                    ></el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column
                label="操作"
                width="80"
              >
                <template slot-scope="scope">
                  <el-button
                    :disabled="isDisableInAuthentication"
                    type="danger"
                    size="small"
                    @click="handleDelFinancial(scope.$index)"
                  >删除</el-button>
                </template>
              </el-table-column>
            </el-table>
   
 export default {
  data() {
    var validatePhoneNumber = (rule, value, callback) => {
      if (value != "") {
        var partten = /^[1][3,4,5,7,8][0-9]{9}$/;
        if (!partten.test(value)) {
          callback(new Error("手机号码格式不正确,请重新输入"));
        } else {
          callback();
        }
      }
    };
      return {
    // 校验规则
      modifyPhoneNumberRules: {
        newPhone: [
          { required: true, message: "手机号码不能为空", trigger: "change" },
          { validator: validatePhoneNumber, trigger: "blur" }
        ],
        sms_code: [
          { required: true, message: "请输入验证码", trigger: "change" }
        ]
      },
}
}

   enterpriseClick() {
         this.$refs["modifyEnterpriseForm"].validate(valid => {
        if (valid) {

           }
      });
    },
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!