hardware.js 5.3 KB
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'province_id', title: __('Province_id')},
                        // {field: 'state_id', title: __('State_id')},
                        // {field: 'county_id', title: __('County_id')},
                        // {field: 'reservoir_id', title: __('Reservoir_id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1')}, formatter: Table.api.formatter.normal},
                        {field: 'type_child_name', title: __('Type_child_name'), searchList: {"1":__('Type_child_name 1'),"2":__('Type_child_name 2')}, formatter: Table.api.formatter.normal},
                        // {field: 'rcode', title: __('Rcode'), operate: 'LIKE'},
                        // {field: 'vcode', title: __('Vcode'), operate: 'LIKE'},
                        {field: 'channel_no', title: __('Channel_no'), operate: 'LIKE'},
                        {field: 'scode', title: __('Scode'), operate: 'LIKE'},
                        {field: 'indexCode', title: __('indexCode'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'reservoirprovince.name', title: __('Reservoirprovince.name'), operate: 'LIKE'},
                        {field: 'reservoirstate.name', title: __('Reservoirstate.name'), operate: 'LIKE'},
                        {field: 'reservoircounty.name', title: __('Reservoircounty.name'), operate: 'LIKE'},
                        {field: 'longitude', title: __('设备经度'), operate: 'LIKE'},
                        {field: 'latitude', title: __('设备纬度'), operate: 'LIKE'},
                        {field: 'reservoirlist.name', title: __('Reservoirlist.name'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
             $("#c-province_id").on("change",function(){
                $("#c-state_id").selectPageClear();
            });
            $("#c-state_id").on("change",function(){
                $("#c-county_id").selectPageClear();
            });
            $("#c-county_id").on("change",function(){
                $("#c-reservoir_id").selectPageClear();
            });
            $("#c-state_id").data("params", function (obj) {
                return {custom: {province_id: $("#c-province_id").val()}};
            });
            $("#c-county_id").data("params", function (obj) {
                return {custom: {state_id: $("#c-state_id").val()}};
            });
            $("#c-reservoir_id").data("params", function (obj) {
                return {custom: {county_id: $("#c-county_id").val()}};
            });
            Controller.api.bindevent();
        },
        edit: function () {
            $("#c-province_id").on("change",function(){
                $("#c-state_id").selectPageClear();
            });
            $("#c-state_id").on("change",function(){
                $("#c-county_id").selectPageClear();
            });
            $("#c-county_id").on("change",function(){
                $("#c-reservoir_id").selectPageClear();
            });
            $("#c-state_id").data("params", function (obj) {
                return {custom: {province_id: $("#c-province_id").val()}};
            });
            $("#c-county_id").data("params", function (obj) {
                return {custom: {state_id: $("#c-state_id").val()}};
            });
            $("#c-reservoir_id").data("params", function (obj) {
                return {custom: {county_id: $("#c-county_id").val()}};
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});