<?php
namespace app\common\model;

use think\Model;

class FormItem extends Model
{
	// 设置字段信息
    protected $schema = [
        'id'			=> 'int',
		'formid'		=> 'int',
		'title'			=> 'string',
		'imust'			=> 'tinyint',
		'itype'			=> 'tinyint',
		'options'		=> 'string',
		'picnumber'		=> 'int',
		'placeholder'	=> 'string',
		'priority'		=> 'int'
    ];
	
	// 设置字段自动转换类型
	protected $type = [
		'options'		=> 'json'
	];
	// 设置JSON数据返回数组
	protected $jsonAssoc = true;
	
	public function getImustTextAttr($value,$data)
	{
		$imust = [1=>'是',2=>'否'];
		return $imust[$data['imust']];
	}
	
	public function getItypeTextAttr($value,$data)
	{
		$itype = [1=>'单行输入框', 2=>'多行输入框', 3=>'普通选择', 4=>'单选选择', 5=>'多选选择', 6=>'日期选择', 7=>'时间选择', 8=>'图片上传'];
		return $itype[$data['itype']];
	}
	
	// 关联Form
	public function form()
	{
	    return $this->hasOne(Form::class, "id", "formid");
	}
	
	
}