Browse Source

时间控件:首位为0去掉;选则两个0则提示请选择正确的时间

liucf 5 years ago
parent
commit
39d9e0652f
2 changed files with 24 additions and 3 deletions
  1. 1 1
      src/common/PickTime.vue
  2. 23 2
      src/common/Picker.vue

+ 1 - 1
src/common/PickTime.vue

@@ -25,12 +25,12 @@
         $(".foot").css({'position':'fixed'})
       },
       getTimeVal(value){//确定
+        // 首位为0则去掉
         if(value.charAt(0) == 0){
           this.val = value.substr(1);
         }else{
           this.val = value;
         }
-        
         this.showTime = false;
         const newData = Object.assign({},this.item,{value:this.val,valueP:this.val});
         this.$emit("updata",newData);

+ 23 - 2
src/common/Picker.vue

@@ -6,8 +6,10 @@
           <van-picker
             :columns="columns"
             :visible-item-count='3'
+            @change="handlechange"
           />
           <div class="confBtn">
+            <p class="tip" v-show="showTip">请选择正确的时间</p>
             <div @click="getVal">确认</div>
           </div>
         </div>
@@ -17,8 +19,8 @@
 </template>
 <script type="text/javascript">
   import $ from 'jquery';
-  const num = [0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9];
-  const unit = ['分钟', '小时', '天', '周', '月','年','分钟', '小时', '天', '周', '月','年','分钟', '小时', '天', '周', '月','年'];
+  const num = [0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9];
+  const unit = ['分钟', '小时', '天', '周', '月','年','分钟', '小时', '天', '周', '月','年'];
   export default {
     name:'Picker',
     data() {
@@ -40,6 +42,7 @@
             defaultIndex: 6
           },
         ],
+        showTip:false
       }
     },
     props:['show'],
@@ -48,11 +51,19 @@
         const val1 = $(".column1 ul .van-picker-column__item--selected")[0].innerText;
         const val2 = $(".column2 ul .van-picker-column__item--selected")[0].innerText;
         const val3 = $(".column3 ul .van-picker-column__item--selected")[0].innerText;
+        // 如果选两个0,则提示
+        if(val1 == 0 && val2 == 0){
+          this.showTip = true;
+          return
+        }
         const value = val1 + val2 + val3;
         this.$emit("comfirn",value)
       },
       onCancel() {
         this.$emit("cancel")
+      },
+      handlechange(){//关掉提示
+        this.showTip = false;
       }
     }
   };
@@ -82,6 +93,16 @@
         text-align: center;
         border-top: 1px solid #ebedf0;
         margin-top: 25px;
+        position: relative;
+        .tip{
+          position: absolute;
+          top:-22px;
+          font-size: .12rem;
+          color: red;
+          line-height: 20px;
+          width:100%;
+          text-align: center;
+        }
         div{
           color: #colors[theme];
         }