var acceptClick;
var keyValue = request('keyValue');
var bootstrap = function ($, learun) {
"use strict";
var page = {
init: function () {
//$('.lr-form-wrap').lrscroll();
page.bind();
page.initData();
},
bind: function () {
$('#WCS_DEVICEPROTOCOL').jfGrid({
headData: [
{
label: 'PLCDB编号', name: 'DBCODE', width: 200, align: 'left'
, edit: {
type: 'select',
op: { data: getGroupContractNum(), allowSearch: true}
// editoptions: { value: getGroupContractNum() }
, formatter: function (value, options, row) {
}
}
//, edit: {
// type: 'select',
// datatype: 'dataSource',
// code: 'crmCustomer',
// op: {
// value: 'f_customerid',
// text: 'f_fullname',
// title: 'f_fullname'
// }
//}
},
{
label: '起始位置', name: 'Position', width: 200, align: 'left', edit: {
type: 'input'
}
},
{
label: '是否启用', name: 'Enabled', width: 60, align: 'left'
, formatter: function (cellvalue) {
//if (cellvalue == "1")
// return '是';
//else {
// return '否';
//}
if (cellvalue == '1' || cellvalue == "") {
return '是';
} else {
return '否';
}
}
,edit: {
type: 'radio',
init: function (data, $edit) {// 在点击单元格的时候触发,可以用来初始化输入控件,行数据和控件对象
var sss = data;
var sd = $edit;
},
change: function (data, num) {// 行数据和行号
},
data: [
{ 'id': '1', 'text': '是' },
{ 'id': '0', 'text': '否' },
],
dfvalue: '1'// 默认选中项
}
}
],
isEdit: true,
height: 400
});
},
initData: function () {
if (!!keyValue) {
$.lrSetForm(top.$.rootUrl + '/WCSManager/WcsDeviceInfo/GetFormData?keyValue=' + keyValue, function (data) {
for (var id in data) {
if (!!data[id].length && data[id].length > 0) {
for (var i = 0; i < data[id].length; i++) {
data[id][i].Enabled = data[id][i].Enabled ? '1' : '0';
}
$('#' + id).jfGridSet('refreshdata', data[id]);
}
else {
data[id].Enabled = data[id].Enabled ? '1' : '0';
$('[data-table="' + id + '"]').lrSetFormData(data[id]);
}
}
});
}
}
};
// 保存数据
acceptClick = function (callBack) {
if (!$('body').lrValidform()) {
return false;
}
var postData = {};
var Entity = $('[data-table="WCS_DEVICE"]').lrGetFormData();
Entity.Enabled = Entity.Enabled == '1' ? true : false;
// postData.strEntity = JSON.stringify(Entity);
postData.strEntity = Entity;
var list = $('#WCS_DEVICEPROTOCOL').jfGridGet('rowdatas');
for (var i = 0; i < list.length; i++) {
if (!Object.hasOwn(list[i], 'Enabled')) {
list[i].Enabled = true;
}
else {
list[i].Enabled = list[i].Enabled == '1' ? true : false;
}
//if (list[i].hasOwnProperty("Enabled")) {
// list[i].Enabled = true;
//}
//if ("Enabled" in list[i]) {
// list[i].Enabled = true;
//}
}
/* postData.strwCS_DEVICEPROTOCOLList = JSON.stringify(list);*/
postData.strwCS_DEVICEPROTOCOLList = list;
$.lrSaveForm(top.$.rootUrl + '/WCSManager/WcsDeviceInfo/SaveForm?keyValue=' + keyValue, postData, function (res) {
// 保存成功后才回调
if (!!callBack) {
callBack();
}
});
};
function getGroupContractNum() {
var GroupContractNum = [];
var i;
$.ajax({
type: "get",
async: false,
url: "/WCSManager/WcsDatablock/GetSelectDBNameList",
success: function (result) {
var result = eval('(' + result + ')');
//for (i = 0; i < result.data.length; i++) {
// if (i != result.data.length - 1) {
// GroupContractNum += result.data[i].id + ":" + result.data[i].text + ";";
// } else {
// GroupContractNum += result.data[i].id + ":" + result.data[i].text;
// }
//}
GroupContractNum = result.data;
}
});
return GroupContractNum; //必须有此返回值
}
page.init();
}