liucf преди 5 години
родител
ревизия
01950e7251
променени са 2 файла, в които са добавени 31 реда и са изтрити 7 реда
  1. 12 3
      src/common/PickTime.vue
  2. 19 4
      src/common/Picker.vue

+ 12 - 3
src/common/PickTime.vue

@@ -3,7 +3,7 @@
   <div class="toast-wrap">
     <p v-show="val" :class="['ptab',{'check':val != '请选择'}]" @click="showPicker">{{val}}</p>
     <p v-show="val != '请选择'" class="tip">点击可修改</p>
-    <Picker :show="showTime" @comfirn="getTimeVal" @cancel="close"/>
+    <Picker :show="showTime" @comfirn="getTimeVal" @cancel="close" :picIndex="item.pickIndex||[]"/>
   </div> 
 </template>
 <script type="text/javascript">
@@ -24,7 +24,7 @@
         $(".btscroll").css({'position':'fixed'})
         $(".foot").css({'position':'fixed'})
       },
-      getTimeVal(value){//确定
+      getTimeVal(value,index){//确定
         // 首位为0则去掉
         if(value.charAt(0) == 0){
           this.val = value.substr(1);
@@ -32,7 +32,7 @@
           this.val = value;
         }
         this.showTime = false;
-        const newData = Object.assign({},this.item,{value:this.val,valueP:this.val});
+        const newData = Object.assign({},this.item,{value:this.val,valueP:this.val,pickIndex:index});
         this.$emit("updata",newData);
         $(".btscroll").css({'position':'absolute'})
       },
@@ -43,6 +43,14 @@
     },
     components:{
       Picker
+    },
+    watch:{
+      item:{
+        handler(newVal,oldVal){
+          this.val = newVal.value|| '请选择';
+        },
+        deep:true
+      }
     }
   };
 </script>
@@ -66,6 +74,7 @@
     }
     .tip{
       color: #7C828E;
+      font-size: .24rem;
     }
   }
 </style>

+ 19 - 4
src/common/Picker.vue

@@ -42,10 +42,16 @@
             defaultIndex: 6
           },
         ],
-        showTip:false
+        showTip:false,
+        columIndx:[]
       }
     },
-    props:['show'],
+    props:['show','picIndex'],
+    created(){//记录位置
+      this.columns[0].defaultIndex = this.columIndx[0] = this.picIndex[0] || 10;
+      this.columns[1].defaultIndex = this.columIndx[1] = this.picIndex[1] || 11;
+      this.columns[2].defaultIndex = this.columIndx[2] = this.picIndex[2] || 6;
+    },
     methods: {
       getVal() {
         const val1 = $(".column1 ul .van-picker-column__item--selected")[0].innerText;
@@ -57,13 +63,22 @@
           return
         }
         const value = val1 + val2 + val3;
-        this.$emit("comfirn",value)
+        this.$emit("comfirn",value,this.columIndx)
+        this.columns[0].defaultIndex = this.columIndx[0] || 10;
+        this.columns[1].defaultIndex = this.columIndx[1] || 11;
+        this.columns[2].defaultIndex = this.columIndx[2] || 6;
       },
       onCancel() {
         this.$emit("cancel")
+        this.showTip = false;
       },
-      handlechange(){//关掉提示
+      handlechange(picker, value, colum){//关掉提示
         this.showTip = false;
+        if(colum == 2){
+          this.columIndx[colum] = unit.lastIndexOf(value[colum]);
+        }else{
+          this.columIndx[colum] = num.lastIndexOf(value[colum]);
+        }
       }
     }
   };