fastadmin public js 内 selectpage 联动下拉

js 页面

define(['jquery', 'bootstrap', 'backend', 'table', 'form','selectpage'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'shop/goods/index' + location.search,
                    add_url: 'shop/goods/add',
                    edit_url: 'shop/goods/edit',
                    del_url: 'shop/goods/del',
                    multi_url: 'shop/goods/multi',
                    import_url: 'shop/goods/import',
                    table: 'goods',
                }
            });

            var table = $("#table");
            // var $link = $('a');
            // $("input[name='product.title']").selectPage({
            //     eAjaxSuccess: function (data) {
            //         data.list = typeof data.rows !== 'undefined' ? data.rows : (typeof data.list !== 'undefined' ? data.list : []);
            //         data.totalRow = typeof data.total !== 'undefined' ? data.total : (typeof data.totalRow !== 'undefined' ? data.totalRow : data.list.length);
            //         return data;
            //     },
            //     eSelect:function(data){
            //         $link.data("product_id", data.id);
            //         //product_id = data.id;
            //     }
            // });
            // table.on('post-common-search.bs.table', function (event, table) {
            //     var form = $("form", table.$commonsearch);
            //     $("input[name='product.title']", form).addClass("selectpage").data("source", "secondhand/product/product/index").data("primaryKey", "id").data("field", "title").data("orderBy", "id desc");
            //
            //
            //     $("input[name='brand.title']", form).addClass("selectpage").data("source", "secondhand/brand/brand/index").data("primaryKey", "id").data("params",{"custom[product_id]":$("body").data("product_id")}).data("field", "title").data("orderBy", "id desc");
            //
            //
            //
            //
            //
            //     // $("input[name='brand.title']", form).addClass("selectpage").data("source", "secondhand/brand/brand/index").data("primaryKey", "id").data("field", "title").data("orderBy", "id desc");
            //     $("input[name='model.title']", form).addClass("selectpage").data("source", "secondhand/model/index").data("primaryKey", "id").data("field", "title").data("orderBy", "id desc");
            //     Form.events.cxselect(form);
            //     Form.events.selectpage(form);
            // });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        {field: 'type', title: __('Type'), searchList: {"sell":__('Type sell'),"purchase":__('Type purchase'),"new":__('Type new')}, formatter: Table.api.formatter.normal},
                        {field: 'describe', title: __('Describe'), operate: 'LIKE'},
                        {field: 'price', title: __('Price')},
                        {field: 'parameter', title: __('Parameter'), operate: 'LIKE'},
                        {field: 'address', title: __('Address'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"up":__('Status up'),"down":__('Status down')}, formatter: Table.api.formatter.status},
                        {field: 'product_id', title: __('Product.title'),visible: false,placeholder: '产品选择', addClass: "selectpage product_id", extend: "data-source='secondhand/product/product/index/selectpage' data-field='title'"},
                        {field: 'product.title', title: __('Product.title'),operate: false},
                        {field: 'brand_id', title: __('Brand.title'),visible: false,placeholder: '品牌选择', addClass: "selectpage brand_id", extend: "data-source='secondhand/brand/brand/index/selectpage' data-field='title'"},
                        {field: 'brand.title', title: __('Brand.title'), operate: false},
                        {field: 'model_id', title: __('Model.title'),visible: false,placeholder: '型号选择', addClass: "selectpage model_id", extend: "data-source='secondhand/model/index/selectpage' data-field='title'"},
                        {field: 'model.title', title: __('Model.title'), operate: false},
                        {field: 'title', title: __('内存'),operate: 'LIKE',visible: false,placeholder: '内存选择', addClass: "selectpage memory_id",extend: "data-source='shop/goods/spec_memory' data-field='title' data-primary-key='title' "}, //获取数据源
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'subtitle', title: __('Subtitle'), operate: 'LIKE'},
                        {field: 'highlight', title: __('Highlight'), operate: 'LIKE'},
                        {field: 'refresh_time', title: __('Refresh_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            $('.brand_id').data('eSelect',function () {
                $('#area_id_text').removeClass('sp_input_off');
                $("#area_id_text").removeAttr("disabled");
            }).data("eClear", function(){
                $("#area_id_text").attr("disabled",'disabled');
                $('.brand_id').selectPageClear();
            }).data('params',function () {
                var  product_id =  $("input[name='product_id']").val(); //获取上级  已选择的id
                return {custom:{product_id:product_id}};   //提交  自定义过滤数据
            });
            $('.model_id').data('eSelect',function () {
                $('#model_id_text').removeClass('sp_input_off');
                $("#model_id_text").removeAttr("disabled");
            }).data("eClear", function(){
                $("#area_id_text").attr("disabled",'disabled');
                $('.model_id').selectPageClear();
            }).data('params',function () {
                var  brand_id =  $("input[name='brand_id']").val();
                return {custom:{brand_id:brand_id}};
            });
            $('.memory_id').data('eSelect',function () {
                $('#memory_id_text').removeClass('sp_input_off');
                $("#memory_id_text").removeAttr("disabled");
            }).data("eClear", function(){
                $("#area_id_text").attr("disabled",'disabled');
                $('.memory_id').selectPageClear();
            }).data('params',function () {
                var  model_id =  $("input[name='model_id']").val();
                return {custom:{model_id:model_id}};
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'shop/goods/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'title', title: __('Title'), align: 'left'},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '130px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'shop/goods/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'shop/goods/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});

后台自写 数据源部分

/**
*内存数据源
*/
public function spec_memory(){
		$custom = (array)$this->request->request("custom/a");
		$model_id = $custom['model_id'];
		$list = \addons\secondhand\model\Spec::with(['children'])->where('spec_name','内存')->where(function ($query) use ($model_id) {
			$query->where(['model_id'=>$model_id])->whereor('pid', 0);
		})->order('weigh')->field('id,spec_name,position,model_id,weigh')->select();
		$data = [];
		foreach ($list as $key => $value) {
			$data = $value['children'];
		}
		return json(['list' => $data, 'total' => count($data)]);
	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

炒鸡时光机

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值