123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- define(['jquery', 'base', 'config'], function($, base, config) {
- var con = {
- init: function() {
- base.listType('#bd-type', config.baseUrl + config.baseData.listAllType, 0);
- this.getAllType();
- this.addType();
- this.searchType('.bd-search', '#bd-dg');
- this.updateType();
- },
- //获取页面数据
- getAllType: function() {
- var self = this;
- $('#bd-dg').datagrid({
- url: config.baseUrl + config.baseData.listPage,
- method: 'post',
- toolbar: '#bd-toolbar',
- rownumbers: false,
- pagination: true,
- fitColumns:true,
- singleSelect: true,
- title: '基础参数管理',
- fit: true,
- columns: [[
- {field:'typeId', title:'编码', width:'20%'},
- {field:'name', title:'名称', width:'20%'},
- {field:'typeName', title:'类型', width:'20%'},
- {field:'remarks', title:'备注', width:'20%'},
- {
- field:'id',
- title:'操作',
- width:'20%',
- align: 'center',
- formatter: function(value, row, index) {
- return '<a class="t-update bd-update" data-id=' + value + '>修改</a> | <a class="t-del bd-del" data-id=' + value + '>删除</a>';
- }
- }
- ]],
- loadFilter: function(e) {
- return {
- page: e.data.pageNo,
- total: e.data.count,
- rows: e.data.list
- };
- },
- onLoadSuccess: function() {
- self.updateType();
- // self.delType();
- base.delInfo('.bd-del', config.baseData.delete, '#bd-dg');
- }
- });
- },
- //添加字典
- addType: function() {
- var self = this;
- //渲染window窗口
- base.renderwindow('.bd-add-win', {
- width: 400,
- height: 260,
- title: '添加类型'
- });
- //绑定点击新增事件
- $('.bd-add-bt').on('click', function() {
- //打开window窗口
- $('.bd-add-win').window('open');
- //设置名称默认值
- $('.bd-w-name').textbox('setValue', '');
- $('.bd-w-type').combobox('select', '');
- //设置备注默认值
- $('.bd-w-backup').textbox('setValue', '');
-
- //调用获取所有类型函数
- base.listType('.bd-w-type', config.baseUrl + config.baseData.listAllType, 0);
- self.doAddType('.bd-win-y', '.bd-add-win', config.baseData.insert, 0);
- });
- },
- /**
- * 执行添加类型的函数
- * @param {string} selector 确认按钮的类
- * @param {string} wSelector window窗口的类
- * @param {string} url 请求地址
- * @param {模式} mode 0为插入,1为更新
- * @return {null}
- */
- doAddType: function(selector, wSelector, url, mode) {
- //解绑之前的点击事件
- $(selector).off('click');
- //绑定点击确定按钮事件
- $(selector).on('click', function(e) {
- //阻止默认事件
- e.preventDefault();
- var data = {
- name: $('input[name=name]').val(),
- typeId: $('input[name=bd-type]').val(),
- remarks: $('input[name=bd-backup]').val()
- };
- //如果是更新操作的话,获取绑定在确认按钮上的id值
- if(mode === 1) {
- data.id = $(this).data('id');
- }
- //发送添加ajax请求
- base.ajaxFunc('post', url, data, function(e) {
- //请求成功后的提示
- base.requestTip(e, wSelector, '#bd-dg', 0);
- });
- });
- },
- /**
- * 查询
- * @param {string} selector 绑定搜索
- * @param {string} dSelector 需要重新载入数据的表格
- * @return {null} 无
- */
- searchType: function(selector, dSelector) {
- $(selector).on('click', function(e) {
- e.preventDefault();
- $(dSelector).datagrid('load', {
- name: $('input[name=bd-s-name]').val(),
- typeId: $('input[name=bd-s-type]').val()
- });
- });
- },
- updateType: function() {
- var self = this,
- id = -1;
- $('.bd-update').on('click', function(e) {
- e.preventDefault();
- //渲染window窗口
- base.renderwindow('.bd-add-win', {
- width: 400,
- height: 260,
- title: '更新类型'
- });
- $('.bd-add-win').window('open');
- var id = $(this).data('id');
- //将id的值绑定到确认按钮上
- $('.bd-win-y').data('id', id);
- base.ajaxFunc('post', config.baseData.listPage, {id:id}, function(e) {
- //设置名称默认值
- $('.bd-w-name').textbox('setValue', e.data.list[0].name);
- //设置备注默认值
- $('.bd-w-backup').textbox('setValue', e.data.list[0].remarks);
- //获取所有type类型
- base.listType('.bd-w-type', config.baseUrl + config.baseData.listAllType, 0);
- //选中返回的类型
- $('.bd-w-type').combobox('select', e.data.list[0].typeId);
- });
- self.doAddType('.bd-win-y', '.bd-add-win', config.baseData.update, 1);
- });
- }
- };
- con.init();
- });
|