self::TYPE_DATE, 'editable' => false, 'multiple' => false ]; /** * @var array */ protected static $propsRule = [ 'type' => 'string', 'format' => 'string', 'placement' => 'string', 'placeholder' => 'string', 'size' => 'string', 'confirm' => 'boolean', 'disabled' => 'boolean', 'clearable' => 'boolean', 'readonly' => 'boolean', 'editable' => 'boolean', 'transfer' => 'boolean', 'splitPanels' => 'boolean', 'showWeekNumbers' => 'boolean' ]; /** * */ protected function init() { $this->placeholder($this->getPlaceHolder()); } /** * 开启后, 可以选择多个日期, 仅在 date 下可用, 默认为false * * @param bool $bool * @return $this */ public function multiple($bool = true) { if ($this->props['type'] == 'date') $this->props['multiple'] = (bool)$bool; else $this->props['multiple'] = false; return $this; } /** * @param $value * @return $this */ public function value($value) { if (is_array($value)) { foreach ($value as $k => $v) { $value[$k] = Helper::getDate($v); } } else { $value = Helper::getDate($value); } $this->value = $value; return $this; } public function getValidateHandler() { if (in_array($this->props['type'], ['datetimerange', 'daterange']) || $this->props['multiple']) return Validate::arr(); else return Validate::date(); } public function required($message = null) { $message = $message ?: $this->getPlaceHolder(); if (in_array($this->props['type'], ['datetimerange', 'daterange'])) { $this->validate()->fields([ '0' => ['required' => true, 'type' => 'date', 'message' => $message], '1' => ['required' => true, 'type' => 'date', 'message' => $message] ], true, $message); return $this; } else return parent::required($message); } /** * @return array */ public function build() { return [ 'type' => $this->name, 'field' => $this->field, 'title' => $this->title, 'value' => $this->value, 'props' => (object)$this->props, 'validate' => $this->validate, 'col' => $this->col ]; } }