/**
* 计量单位
* @author weidy@2019-11-26
*/
layui.define(['layer','element','form','table','util'],function(exports){
var Class = function(){
this.MODELNAME = "platform/basedoc/BdUnit";
this.moduleKey = "BdUnit";
this.id='BdUnit';
this.sourceData={};
this.columns = [];
this.backPath = configData.compatibility?path:configData.frameworkPath;
this.url={
controller:'unitOfMeasurementController/',
dataGrid:'getAllUnitOfMeasure',//列表数据和查询
add:'addUnitOfMeasure',
edit:'editUnitOfMeasure',
deleteUrl:'delUnitOfMeasure',
enableUrl:'enableUnitOfMeasure',
disableUrl:'disableUnitOfMeasure'
};
this.buttonIconMap = {
SEARCH:'layui-icon-refresh-2',
SENIORSEARCH:'layui-icon-query',
ADD:'layui-icon-add-1',
EDIT:'layui-icon-edit',
DELETE:'layui-icon-delete'
};
this.getContent=function(){//返回这个组件的基础html
var that = this;
var html = "";
html = [
'
',
'
',
that.getToolbarHtml(),
'
',//主列表
'
',
'
'
].join("");
return html;
};
this.getToolbarHtml =function(){
var that = this;
var html = [
'',
'',
'',
'',
'',
'',
'',
'
',
].join("");
return html;
};
this.init=function(){//基础的html被添加后,再执行初始化
var that = this;
$webUtil.copyConfig(that,that.moduleKey);
var table = layui.table;
that.checkColumns();//主列表中列。
table.render({
elem: '#table_' + that.id,
id: 'table_' + that.id,
url: that.backPath + that.url.controller + that.url.dataGrid,
page: {
limit: 20,
page: 1
},
selectMode:table.selectMode.muti,
cols: [that.columns]
});
$webUtil.createSearchHtml({
id:'单位',
name:'单位中文说明'
},$("[layui-filter='toolbar_button_" + that.id + "']"),'table_' + that.id);
$webUtil.bindDefultButtonLisenter(that, that.id);
};
this.checkColumns = function(){
var that = this;
var table = layui.table;
if(that.columns==null || that.columns.length==0){//如果其他地方想使用这个组件的时候,可以自定义列
that.columns = [table.getIndexColumn(),table.getCheckColumn(),{
field:'id',
title:'计量单位英文',
width:150
},{
field:'name',
title:'单位中文说明',
width:200
},{
field:'description',
title:'描述',
width:150
},{
field:'lcStatusText',
title:'状态',
width:90
}];
}
};
this.ADD = function(){
var that = this;
that.dealData(true);
};
this.EDIT = function(){
var that = this;
var oid = $webUtil.getOidFromGrid("table_" + that.id,true,true);
if(!oid){
return false;
}
that.dealData(false);
};
this.getFormItems = function(isEdit){
var that = this;
return [{
type: 'text',
name: 'id',
text: '计量单位英文',
required: true
}, {
type: 'text',
name: 'name',
text: '单位中文说明',
required: true
}, {
type: 'text',
name: 'description',
text: '描述'
}];
};
this.dealData = function(add){
var that = this;
var form = layui.form;
var filter ="form_" + that.id;
var addSaveIndex = layer.open({
type:1,
title:add?'添加计量单位':'修改计量单位',
btn:['保存','取消'],
skin:'layui-layer-lan',
content:'',
area:['800px','300px'],
closeBtn:2,
shade:true,
shadeClose:true,
resize:true,
resizing:function(layero){
form.doResize(filter);
},
success:function(layero) {
form.addItems(filter,that.getFormItems(),
function () {
if(!add){
var selectRowData = layui.table.checkStatus("table_" + that.id);
form.setValues(selectRowData.data[0],filter);
}else{
form.setValues({},filter);
}
}, {}, {defaultColumnOneRow: 2});
},
yes:function(layero){
if(form.validata(filter)){
var values = form.getValues(filter,true);
var url = that.url.controller + (add?that.url.add:that.url.edit);
$webUtil.ajax(add?'post':'put',url,values,function(result){
if(result.success){
if($webUtil.isNull(result.msg)) {
result.msg = add ? "添加成功" : "修改成功";
}
$webUtil.showMsg(result.msg);
layer.close(addSaveIndex);
that.refresh();
}else{
$webUtil.showErrorMsg(result.msg);
}
},function(xhr,err){
$webUtil.showErrorMsg("请求服务出现了错误,可能服务器未开启");
},that.backPath);
}
},
btn2:function(layero){
layer.close(addSaveIndex);
that.refresh();
}
});
};
this.DEL = function(){
var that = this;
var oid = $webUtil.getOidFromGrid("table_" +that.id,true,true);
if(!oid){
return false;
}
var ts = $webUtil.getOidFromGrid("table_" +that.id,false,false,"ts");
$webUtil.showConfirmMsg("是否删除这个计量单位",function () {
$webUtil.deleteRequest(that.url.controller + that.url.deleteUrl,{oid:oid,ts:ts},function(result){
if(result.success){
$webUtil.showMsgFromResult(result,"删除成功");
that.refresh();
}else{
$webUtil.showErrorMsg(result.msg);
}
},function(xhr,err){
$webUtil.showErrorMsg("请求服务出现了错误,可能服务器未开启");
},that.backPath);
});
};
this.START = function(){
var that = this;
that.operaData(that.url.controller + that.url.enableUrl,'启用成功');
};
this.STOP = function(){
var that = this;
that.operaData(that.url.controller + that.url.disableUrl,'停用成功');
};
this.operaData = function(url,msg){
var that = this;
var oid = $webUtil.getOidFromGrid("table_" +that.id,true,true);
if(!oid){
return false;
}
$webUtil.post(url,{
oid:oid,
ts:$webUtil.getOidFromGrid("table_" +that.id,false,false,'ts')
},function(result){
if(result.success){
$webUtil.showMsgFromResult(result,msg);
that.refresh();
}else{
$webUtil.showErrorMsg(result.msg);
}
},function(xhr,err){
$webUtil.showErrorMsg("请求服务出现了错误,可能服务器未开启");
},that.backPath);
};
this.refresh = function(){
var that = this;
layui.table.reload("table_" + that.id);
};
};
var cs = new Class();
exports(cs.MODELNAME,cs);
});