Sanakey
2021-01-31 53cc6f817625897935fb10c3845ad7be400f3036
src/vant-weapp/datetime-picker/index.js
@@ -1,5 +1,5 @@
import { VantComponent } from '../common/component';
import { isDef } from '../common/utils';
import { isDef } from '../common/validator';
import { pickerProps } from '../picker/shared';
const currentYear = new Date().getFullYear();
function isValidDate(date) {
@@ -20,7 +20,9 @@
  return result;
}
function getTrueValue(formattedValue) {
  if (!formattedValue) return;
  if (formattedValue === undefined) {
    formattedValue = '1';
  }
  while (isNaN(parseInt(formattedValue, 10))) {
    formattedValue = formattedValue.slice(1);
  }
@@ -29,7 +31,7 @@
function getMonthEndDay(year, month) {
  return 32 - new Date(year, month - 1, 32).getDate();
}
const defaultFormatter = (_, value) => value;
const defaultFormatter = (type, value) => value;
VantComponent({
  classes: ['active-class', 'toolbar-class', 'column-class'],
  props: Object.assign(Object.assign({}, pickerProps), {
@@ -89,7 +91,7 @@
  methods: {
    updateValue() {
      const { data } = this;
      const val = this.correctValue(this.data.value);
      const val = this.correctValue(data.value);
      const isEqual = val === data.innerValue;
      if (!isEqual) {
        this.updateColumnValue(val).then(() => {
@@ -251,12 +253,16 @@
      const { data } = this;
      let value;
      const picker = this.getPicker();
      const originColumns = this.getOriginColumns();
      if (data.type === 'time') {
        const indexes = picker.getIndexes();
        value = `${+data.columns[0].values[indexes[0]]}:${+data.columns[1]
        value = `${+originColumns[0].values[indexes[0]]}:${+originColumns[1]
          .values[indexes[1]]}`;
      } else {
        const values = picker.getValues();
        const indexes = picker.getIndexes();
        const values = indexes.map(
          (value, index) => originColumns[index].values[value]
        );
        const year = getTrueValue(values[0]);
        const month = getTrueValue(values[1]);
        const maxDate = getMonthEndDay(year, month);
@@ -281,7 +287,8 @@
    },
    updateColumnValue(value) {
      let values = [];
      const { type, formatter = defaultFormatter } = this.data;
      const { type } = this.data;
      const formatter = this.data.formatter || defaultFormatter;
      const picker = this.getPicker();
      if (type === 'time') {
        const pair = value.split(':');