thinkphp5之fastafmin笔记

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_27229113/article/details/82878393

fastafmin笔记

个人推荐的开源框架:官网文档:https://doc.fastadmin.net/docs/controller.html

控制器

  public function _initialize()
    {
        parent::_initialize();
        $this->model = model('AppointmentActivity');
        //查询场馆列表
        $venue_model = model('Venue');
        $venue_list = $venue_model->select();
        $venue_list = Collection($venue_list)->toArray();
        $this->view->assign("venueList", $venue_list);
        $this->view->assign("isListList", $this->model->getIsListList());
    }

html

<div class="form-group">
        <label for="c-pid" class="control-label col-xs-12 col-sm-2">{:__('Venue_name')}:</label>
        <div class="col-xs-12 col-sm-8">
            <select  id="c-pid" data-rule="required" class="form-control selectpicker" name="row[v_id]">
                {foreach name="venueList" item="vo"}
                <option value="{$vo.id}" {in name="key" value="0"}selected{/in}>{$vo.name}</option>
                {/foreach}
            </select>
        </div>
    </div>

编辑

<div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Gid')}:</label>
          <div class="col-xs-12 col-sm-8">
             <select  id="c-gid" data-rule="required" class="form-control selectpicker" name="row[gid]">
                 {foreach name="photo_group" item="vo"}
              <option value="{$vo.id}" {in name="key" value="$row.id"}selected{/in}>{$vo.group_name}</option>
                 {/foreach}
              </select>
          </div>
    </div>


lang
语言{:__('Venue_name')} ,在语言模板中找到添加即可


ajax请求后台数据 并将数据写入前端

api: {
            bindevent: function (data, ret) {
                $(document).on("change", "#c-type", function (e) {
                    var value = e.target.value;
                    $.ajax({
                        url: "appointmentorder/appointmentorder/re_appointment_list",
                        type: 'post',
                        dataType: 'json',
                        data: {value: value},
                        success: function (ret) {
                            console.log(ret);
                            var result = '';
                            for (var i=0; i< ret.length; i++) {
                                var item = ret[i];
                                result += "<option value="+ item.id +">" +  item.name + " " + item.start_time + 

"</option>";
                            };

                            $("#c-pid").empty().append(result);
                            $("#c-pid").selectpicker("refresh");

                        }, error: function (e) {
                            Backend.api.toastr.error(e.message);
                        }
                    });


                });
                Form.api.bindevent($("form[role=form]"));
            }
        }

前端下拉框显示

 <div class="form-group">
        <label for="c-pid" class="control-label col-xs-12 col-sm-2">{:__('appointment_activity_list')}:</label>
        <div class="col-xs-12 col-sm-8">

            <select id="c-pid" data-rule="required" class="form-control selectpicker" name="row[apt_id]">
                {foreach name="appointment_activity_list" item="vo"}
                <option value="{$key}" {in name="key" value="$row.apt_id"}selected{/in}>{$vo.name}.开馆时间.{$vo.start_time}</option>
                {/foreach}
            </select>

        </div>
    </div>

后台富文本字段选text 开启富文本插件,,输入命令生成curl
 

时间弹窗不能完全显示
修改css 

backend.css
.tab-addtabs {
  /*overflow: hidden;*/
}



bootstrap.css和fastadmin.min.css增加
 

.content {
  min-height: 250px;
  padding: 15px;
  margin-right: auto;
  margin-left: auto;
  padding-left: 15px;
  padding-right: 15px;
  padding-bottom:50px;
}

搜索联表处理

表 couponuser,coupon和user表

关联字段分别是c_id和user_id

对应的js

 // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Num_id')},
                        {field: 'coupon.name', title: __('couponuser_list')},
                        {field: 'user.nickname', title: __('user_name')},
                        {field: 'coupon', title: __('Coupon')},
                        {field: 'is_receivelist', title: __('Is_receivelist'),operate:false, visible:false, searchList: {"0":__('Is_receivelist 0'),"1":__('Is_receivelist 1')}},
                        {field: 'is_receivelist_text', title: __('Is_receivelist'), operate:false},
                        {field: 'is_use', title: __('Is_use'), visible:false, searchList: {"0":__('Is_use 0'),"1":__('Is_use 1')}},
                        {field: 'is_use_text', title: __('Is_use'), operate:false},
                        {field: 'imagesurl', title: __('Images'),operate:false, formatter: Table.api.formatter.images},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

model(在当期的model)

public function Coupon()
    {
//        return $this->hasOne('Coupon', 'id', 'c_id');
        return $this->belongsTo('Coupon', 'c_id', 'id', [], 'LEFT')->field('name')->setEagerlyType(0);

    }

    public function User()
    {
//        return $this->hasOne('Coupon', 'id', 'c_id');
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->field('nickname')->setEagerlyType(0);
    }

控制器

/**
     * 查看
     */
    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage,则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $total = $this->model
                ->with(['coupon'])
                ->with(['user'])
                ->where($where)
//                ->order($sort, $order)
                ->count();

            $result = $this->model
                ->with(['coupon','user'])
                ->where($where)
                ->order('coupon_user.'.$sort, $order)
                ->limit($offset, $limit)
                ->select();

            $result = collection($result)->toArray();
            $host_url = "https://" . $_SERVER['HTTP_HOST'] . "/";

            foreach ($result as $k => $v) {
                $imagesurl = $host_url . $v['images'];
                $result[$k]['imagesurl'] = $imagesurl;
                $coupon = model('Coupon')->where('id', $v['c_id'])->select();
                $coupon = collection($coupon)->toArray();
                foreach ($coupon as $kk => $vv) {
                    $result[$k]['name'] = $vv['name'];
                }

                //获取用户名称
                $user_list = model('User')->where('id', $v['user_id'])->select();
                $user_list = collection($user_list)->toArray();
                foreach ($user_list as $key => $value) {
                    $result[$k]['nickname'] = $value['nickname'];
                }

            }

            $result = array("total" => $total, "rows" => $result);
            return $result;
//            return json($result);
        }
        return $this->view->fetch();
    }

猜你喜欢

转载自blog.csdn.net/qq_27229113/article/details/82878393