<?php

/* ========================================================================
 * $Id: form.php 1040 2020-06-06 15:51:04Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onez.cn
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
class onezphp_vue_plugin_form extends onezphp{
  var $items=array();
  var $values=array();
  var $_form=false;
  function __construct(){
    
  }
  function init($values){
    $this->values=$values;
    return $this;
  }
  function add(){
    $this->items[]=func_get_args();
    return $this;
  }
  function form(){
    if(!$this->_form){
      $this->_form=onez('factory.form',-1)->widget('form')
        ->set('values',$this->values)
      ;
      $this->_form->orientation='horizontal';
    }
    return $this->_form;
  }
  function build(){
    $this->form()->set('values',$this->values);
    $this->_form->add(array('type'=>'hidden','key'=>'ac','value'=>'save'));
    foreach($this->items as $v){
      $this->_form->add($v[0],$v[1]?$v[1]:false);
    }
    return $this->_form;
  }
  function submit(){
    return $this->build()->submit('ac');
  }
  function output(&$A){
    global $G;
    $code_option=$this->form()->vars;
    $A['form']=$this->build()->code2($code_option);
  }
}