<?php

namespace app\admin\controller;

use app\admin\common\AdminController;
use app\common\api\DictApi;

/**
 * Description of Dict
 *
 * @author sgq
 */
class Dict extends AdminController {

    /**
     * @auth {{/dict}}
     * @return type
     */
    public function index() {
        return view();
    }

    /**
     * @auth {{/dict/list}}
     * @return type
     */
    public function list() {
        $res = DictApi::getList($this->request);
        return json($res);
    }

    /**
     * @auth {{/dict/add}}
     * @return type
     */
    public function add() {
        if ($this->request->isPost()) {
            return json(DictApi::create($this->request->param()));
        }
        return view();
    }

    /**
     * @auth {{/dict/update}}
     * @return type
     */
    public function edit() {
        if ($this->request->isPost()) {
            return json(DictApi::update($this->request->param()));
        }

        $dict = DictApi::getOne($this->request->param("id"));
        return view("", ["dict" => $dict]);
    }

    /**
     * @auth {{/dict/delete}}
     * @return type
     */
    public function delete() {
        if ($this->request->isPost()) {
            return json(DictApi::delete($this->request->param("dictId")));
        }
    }
    
    public function findChildDictByCode(){
        return json(DictApi::findChildDictByCode($this->request->param("code")));
    }

}
