From 5f6185c29f9d3353de79537a8a1a52060e46c100 Mon Sep 17 00:00:00 2001
From: KK <57750083+zhangkang1314@users.noreply.github.com>
Date: Fri, 15 May 2020 16:53:46 +0800
Subject: [PATCH] update

---
 .../app-form-item/app-form-item.vue           | 49 +++++++++++++++++--
 1 file changed, 46 insertions(+), 3 deletions(-)

diff --git a/src/components/app-form-item/app-form-item.vue b/src/components/app-form-item/app-form-item.vue
index 76e8132..ba55ab2 100644
--- a/src/components/app-form-item/app-form-item.vue
+++ b/src/components/app-form-item/app-form-item.vue
@@ -10,7 +10,7 @@
                 <div :style="contentStyle">
                     <slot></slot>
                 </div>
-                <div class="prompt_text">{{error}}</div>
+                <div class="prompt_text">{{errorText}}</div>
             </template>
             <template v-if="labelPos == 'TOP'">
                 <ion-label
@@ -19,12 +19,12 @@
                     v-if="isShowCaption && labelWidth > 0"
                 ><span v-if="required" class="required">* </span>{{isEmptyCaption ? '' : caption}}</ion-label>
                 <slot></slot>
-                <div class="prompt_text">{{error}}</div>
+                <div class="prompt_text">{{errorText}}</div>
             </template>
             <template v-if="labelPos == 'RIGHT' ">
                 <slot></slot>
                 <ion-label :style="{minWidth:labelWidth+'px'}" v-if="isShowCaption && labelWidth > 0"><span v-if="required" class="required">* </span> {{isEmptyCaption ? '' : caption}}</ion-label>
-                <div class="prompt_text">{{error}}</div>
+                <div class="prompt_text">{{errorText}}</div>
             </template>
             <template v-if="labelPos == 'NONE'" >
                 <slot></slot>
@@ -67,6 +67,48 @@ export default class AppFormItem extends Vue {
      */
     @Prop() public error?: string;
 
+    /**
+     * 琛ㄥ崟椤瑰€�
+     *
+     * @type {string}
+     * @memberof AppFormItem
+     */
+    @Prop() public checkValue?: any;
+
+    /**
+     * 鏍¢獙鍊艰鍒�
+     *
+     * @type {string}
+     * @memberof AppFormItem
+     */
+    @Watch('checkValue')
+    checkRule() {
+        let erro_text :any = "";
+        this.rules.forEach((item:any)=>{
+            if(item.hasOwnProperty('pattern') && item.trigger == 'change' && this.checkValue){
+                let pattern: any =  item.pattern;
+                if(!pattern.test(this.checkValue)){
+                    erro_text = item.message;
+                }
+            }
+            if(item.hasOwnProperty('required') && item.trigger == 'change'){
+                if(item.required && !this.checkValue){
+                    erro_text = item.message;
+                }
+            }
+        });
+        this.errorText = erro_text;
+    }
+
+    /**
+     * 閿欒淇℃伅
+     *
+     * @type {string}
+     * @memberof AppFormItem
+     */
+    public errorText = "";
+
+
     /**
      * label鏍峰紡
      *
@@ -173,6 +215,7 @@ export default class AppFormItem extends Vue {
         }
     }
 
+
     /**
      * 璁$畻鏍峰紡
      *
-- 
2.21.0