layTable(function () { $this->title = '员工部门'; }, static function (QueryHelper $query) { $query->with('parent.parent')->append(['headman_name']); $query->equal('status')->like('name'); }); } /** * 添加部门 * @auth true * @menu true * @return void */ public function add() { StaffDept::mForm('form'); } /** * 编辑部门 * @auth true * @return void */ public function edit() { StaffDept::mForm('form'); } protected function _form_filter(array &$data) { if ($this->request->isPost()) { $this->_vali([ 'name.require' => '部门名称不能为空!', ]); } else { $this->depts = StaffDept::topItems(); } } /** * 部门排序 * @auth true * @return void */ public function sort() { StaffDept::mSave($this->_vali([ 'sort.require' => '排序参数不能为空!', 'sort.number' => '排序参数格式错误!', ])); } /** * 设置部门领导人 * @auth true * @return void */ public function headman() { $data = $this->_vali([ 'id.require' => '部门不能为空!', ]); if ($this->request->isGet()) { $this->title = '设置部门负责人'; $this->dept = StaffDept::mk()->where(['id' => $data['id']])->findOrEmpty(); if ($this->dept->isEmpty()) $this->error('部门不存在!'); $this->users = StaffUser::mk()->where(['status' => 1, 'dept_id' => $this->dept['id']])->select(); $this->fetch(); } else { StaffDept::mSave($this->_vali([ 'headman_id.require' => '部门领导人不能为空!', 'headman_id.number' => '部门领导人格式错误!', ])); } } /** * 启用禁用部门 * @auth true * @return void */ public function state() { StaffDept::mSave($this->_vali([ 'status.in:0,1' => '状态值范围异常!', 'status.require' => '状态值不能为空!', ])); } /** * 删除部门 * @auth true * @return void */ public function del() { StaffDept::mDelete(); } }