EasyUI datagrid回車下一個
--------------------------------------------------------------呼叫------------------------------------------------------------------
//開始編輯行時,賦值 聯動資料
function onBeginEdit(rowIndex, rowData) {
//combogrid 設定資訊
var combogrid_Settings = {
'DUTY_MODE': {
required: true,
precision: 0,
url: '/PARA_LEVYMODES/GetPagerDUTY_MODES',
method: 'get',
delay: 500,
multiple: false,
panelHeight: 'auto',
panelWidth: 205,
idField: 'DUTY_MODE',
valueField: 'DUTY_MODE',
textField: 'DUTY_SPEC',
pageSize: 10,//每頁顯示的記錄條數,預設為10
pageList: [5, 10, 20],//可以設定每頁記錄條數的列表
pagination: true,//是否分頁
columns: [[
{ field: 'DUTY_MODE', title: '程式碼', width: 53 },
{ field: 'DUTY_SPEC', title: '名稱', width: 150 }
]],
onLoadSuccess: function () {
ondgLoadSuccess($dg, 'DUTY_MODE', rowIndex);
},
onChange: function (value) {
var Selted = $(this).combogrid('grid').datagrid('getSelected');
if (Selted) {
var datarow = $dg.datagrid('getData').rows[editIndex];
if (!(typeof datarow === 'undefined' || datarow == null)) {
datarow['DUTY_MODE' + 'NAME'] = Selted[$(this).combogrid('options').textField];
}
}
},
keyHandler: {
up: function (e) {
combogrid_upKey(this, e);
},
down: function (e) {
combogrid_downKey(this, e);
},
enter: function (e) {
combogrid_enterKey(this, e, $dg, 'DUTY_MODE', rowIndex);
},
query: function (q) {
combogrid_query(this, q, rowIndex, {});
}
}
}
};
var num = 0;
for (var i in rowData) {
var targetEditor = $dg.datagrid('getEditor', {
field: i,
index: rowIndex
});
//console.log("targetEditor", i, targetEditor);
if (targetEditor) {
num++;
//設定第一個 焦點
if (num == 1 && $(targetEditor.target).val() == '') {
$(targetEditor.target).parent().children("span:eq(0)").children("input:eq(0)").focus();
}
var OldVal = targetEditor.oldHtml;
switch (targetEditor.type.toLowerCase()) {
case "combogrid":
var combogrid_Setting = combogrid_Settings[targetEditor.field];
if (combogrid_Setting) {
$(targetEditor.target).combogrid(combogrid_Setting);
}
if (OldVal != null) {
if (typeof (OldVal) != 'undefined') {
if (OldVal != '') {
if (rowData[targetEditor.field]) {
OldVal = rowData[targetEditor.field];
}
$(targetEditor.target).combogrid('setValue', OldVal);
var opts = $(targetEditor.target).combogrid('options');
var url = opts.url;
//設定查詢引數
var queryParams = {
page: 1,
rows: opts.pageSize,
q: OldVal
};
$(targetEditor.target).combogrid('grid').datagrid('load', queryParams);
}
}
}
break;
case "combobox":
var opts = $(targetEditor.target).combobox({
inputEvents: $.extend({}, $.fn.combobox.defaults.inputEvents, {
keydown: function (event) {
combobox_keydown(this, event, $dg, rowIndex);
}
})
});
break;
case "textbox":
$(targetEditor.target).textbox({
inputEvents: $.extend({}, $.fn.textbox.defaults.inputEvents, {
keydown: function (event) {
Listtextbox_keydown(this, event, $dg, rowIndex);
}
})
});
break;
case "numberbox":
$(targetEditor.target).numberbox({
inputEvents: $.extend({}, $.fn.textbox.defaults.inputEvents, {
keydown: function (event) {
Listtextbox_keydown(this, event, $dg, rowIndex);
}
})
});
break;
case "datebox":
$(targetEditor.target).datebox({
inputEvents: $.extend({}, $.fn.textbox.defaults.inputEvents, {
keydown: function (event) {
Listtextbox_keydown(this, event, $dg, rowIndex);
}
})
});
setTargetVal(targetEditor, OldVal);
break;
case "datetimebox":
$(targetEditor.target).datetimebox({
inputEvents: $.extend({}, $.fn.textbox.defaults.inputEvents, {
keydown: function (event) {
Listtextbox_keydown(this, event, $dg, rowIndex);
}
})
});
setTargetVal(targetEditor, OldVal);
break;
case "checkbox":
$(targetEditor.target).keydown(function (e) {
chk_rdo_keydown(this, e, $dg, rowIndex);
});
setTargetVal(targetEditor, OldVal);
break;
case "radio":
$(targetEditor.target).keydown(function (e) {
chk_rdo_keydown(this, e, $dg, rowIndex);
});
setTargetVal(targetEditor, OldVal);
break;
}
}
}
}
-----------------------------------------------------------------JS--------------------------------------------------------------------
//獲取 targetEditor的options
function getOptions($next) {var nextopts = {};
if ($next) {
if ($next.target.data('textbox')) {
nextopts = $next.target.textbox('options');
}
if ($next.target.data('datebox')) {
nextopts = $next.target.datebox('options');
}
if ($next.target.data('datetimebox')) {
nextopts = $next.target.datetimebox('options');
}
if ($next.target.data('numberbox')) {
nextopts = $next.target.numberbox('options');
}
if ($next.target.data('combobox')) {
nextopts = $next.target.combobox('options');
}
if ($next.target.data('combogrid')) {
nextopts = $next.target.combogrid('options');
}
}
return nextopts;
}
//設定 targetEditor值
function setTargetVal(targetEditor, val) {
switch (targetEditor.type.toLowerCase()) {
case "combogrid":
$(targetEditor.target).combogrid("setValue", val);
var opts = $(targetEditor.target).combogrid('options');
if (opts.queryParams && opts.queryParams.DOCCODE) {
//設定查詢引數
var queryParams = {
page: 1,
rows: opts.pageSize,
q: val,
DOCCODE: opts.queryParams.DOCCODE //列舉程式碼
};
}
else {
//設定查詢引數
var queryParams = {
page: 1,
rows: opts.pageSize,
q: val
};
}
opts.queryParams = queryParams;
$(targetEditor.target).combogrid("grid").datagrid('load', queryParams);
break;
case "combobox":
$(targetEditor.target).combobox("setValue", val);
break;
case "textbox":
$(targetEditor.target).textbox("setValue", val);
break;
case "numberbox":
$(targetEditor.target).numberbox("setValue", val);
break;
case "datebox":
$(targetEditor.target).datebox("setValue", val);
break;
case "datetimebox":
$(targetEditor.target).datetimebox("setValue", val);
break;
case "checkbox":
var OldVal = val;
var slet = false;
if (!(OldVal == null || typeof OldVal === 'undefined' || OldVal == '')) {
if (isNaN(OldVal)) {
if (OldVal == '是' || OldVal == '啟用' || OldVal.toLowerCase() == 'true')
slet = true;
}
else {
if (OldVal)
slet = true;
}
}
$(targetEditor.target).prop("checked", slet);
break;
case "radio":
var OldVal = val;
var slet = false;
if (!(OldVal == null || typeof OldVal === 'undefined' || OldVal == '')) {
if (isNaN(OldVal)) {
if (OldVal == '是' || OldVal == '啟用' || OldVal.toLowerCase() == 'true')
slet = true;
}
else {
if (OldVal)
slet = true;
}
}
$(targetEditor.target).prop("setValue", slet);
break;
}
}
//獲取 targetEditor值
function getTargetVal(targetEditor) {
var val = '';
if (targetEditor != null) {
switch (targetEditor.type.toLowerCase()) {
case "combogrid":
val = $(targetEditor.target).combogrid("getValue");
break;
case "combobox":
val = $(targetEditor.target).combobox("getValue");
break;
case "textbox":
val = $(targetEditor.target).textbox("getValue");
break;
case "numberbox":
val = $(targetEditor.target).numberbox("getValue");
break;
case "datebox":
val = $(targetEditor.target).datebox("getValue");
break;
case "datetimebox":
val = $(targetEditor.target).datetimebox("getValue");
break;
}
}
return val;
}
//combogrid keyhandler 事件【向上鍵】押下處理
function combogrid_upKey(obj, e) {
//console.log('up', obj);
//取得選中行
var selected = $(obj).combogrid('grid').datagrid('getSelected');
if (selected) {
//取得選中行的rowIndex
var index = $(obj).combogrid('grid').datagrid('getRowIndex', selected);
//向上移動到第一行為止
if (index > 0) {
$(obj).combogrid('grid').datagrid('selectRow', index - 1);
}
} else {
var rows = $(obj).combogrid('grid').datagrid('getRows');
$(obj).combogrid('grid').datagrid('selectRow', rows.length - 1);
}
}
//combogrid keyhandler 事件 【向下鍵】押下處理
function combogrid_downKey(obj, e) {
//console.log('down', obj);
//取得選中行
var selected = $(obj).combogrid('grid').datagrid('getSelected');
if (selected) {
//取得選中行的rowIndex
var index = $(obj).combogrid('grid').datagrid('getRowIndex', selected);
//向下移動到當頁最後一行為止
if (index < $(obj).combogrid('grid').datagrid('getData').rows.length - 1) {
$(obj).combogrid('grid').datagrid('selectRow', index + 1);
}
} else {
$(obj).combogrid('grid').datagrid('selectRow', 0);
}
}
//combobox keydown事件
function combobox_keydown(obj, e, $dg_, rowindex) {
//debugger;
//var $thisElem = $(obj).parent().siblings('.easyui-combobox:eq(0)');
var $thisElem = $(obj).parent().parent().children('input:eq(0)');
var $target;
$.each($dg_.datagrid('getEditors', rowindex), function (y, elem) {
if (elem) {
//console.log('keyup', $thisElem[0], $(elem.target)[0]);
if ($(elem.target)[0] == $thisElem[0]) {
$target = elem;
}
}
});
$target.target.combobox('showPanel');
//debugger;
//取得選中行
var opts = $target.target.combobox('options');
if (!opts) {
$target.target.combobox('showPanel');
}
var datarows = $target.target.combobox('getData');
if (!event) {
event = window.event;
}
//console.log('combobox', $(obj), $target, $target.target.combobox('options'),datarows);
//回車事件
if ((event.keyCode || event.which) == 13) {
//debugger;
//console.log('enter', $target.combobox('panel'));
var Selted = $target.target.combobox('getValue');
if (Selted.length <= 0) {
//if (datarows.length > 0) {
// Selted = datarows[0];
// $target.target.combobox('setValue', datarows[0][opts.valueField]);
//}
}
$target.target.combobox('hidePanel');
var rowColumn = $dg_.datagrid('getColumnFields', false);
for (var x = 0; x < rowColumn.length; x++) {
if (rowColumn[x] == $target.field) {
if (x != rowColumn.length - 1) {
var nextNum = x + 1;
var $next = $dg_.datagrid('getEditor', {
field: rowColumn[nextNum],
index: rowindex
});
var nextopts = getOptions($next);
while ($next == null || $next.target.attr('disabled') || $next.readonly) {
nextNum++;
$next = $dg_.datagrid('getEditor', {
field: rowColumn[nextNum],
index: rowindex
});
if (nextNum >= rowColumn.length) {
break;
}
else if ($next) {
nextopts = getOptions($next);
}
}
//console.log('keydown回車事件', $next, nextNum, rowColumn.length);
if ($next) {
if (event && event.preventDefault) {
event.preventDefault();
if ($next.type.toLowerCase() == "checkbox" || $next.type.toLowerCase() == "radio")
$($next.target).focus();
else
$($next.target).parent().children('span:eq(0)').children('input:eq(0)').focus();
}
else {
window.event.returnValue = false;
}
}
else {
if (nextNum >= rowColumn.length)
accept();//儲存
}
}
else
accept();//儲存
break;
}
}
//debugger;
}
//up
if ((event.keyCode || event.which) == 38) {
//console.log('up');
var data = datarows;//$target.target.combobox('options').data;
if (data.length > 0) {
//取得選中值
var selected = $target.target.combobox('getValue');
if (selected.length > 0) {
for (var i = 0; i < data.length; i++) {
if (selected == data[i][opts.valueField]) {
if (i > 0) {
$target.target.combobox('setValue', data[i - 1][opts.valueField]);
}
}
}
}
}
}
//dowm
if ((event.keyCode || event.which) == 40) {
//console.log('down', obj, datarows);
var data = datarows;//opts.data;
if (data.length > 0) {
//取得選中值
var selected = $target.target.combobox('getValue');
if (selected.length > 0) {
for (var i = 0; i < data.length; i++) {
if (selected == data[i][opts.valueField]) {
if (i != data.length - 1) {
$target.target.combobox('setValue', data[i + 1][opts.valueField]);
}
}
}
}
else {
$target.target.combobox('setValue', data[0][opts.valueField]);
}
}
}
}
//combogrid query 事件 按任意鍵 搜尋(本地)
function combogrid_local_query(obj, q, e) {
var opts = $(obj).combogrid('options');
var data = $(obj).combogrid('grid').datagrid('getData');
var $combogridPanel = $(obj).combogrid('panel');
var $trs = $combogridPanel.find('table.datagrid-btable:eq(0)').find('tr.datagrid-row');
$trs.removeClass('hide');
//console.log($trs,data);
if (data) {
$.each(data.rows, function (i, item) {
if (item[opts.valueField].indexOf(q) < 0 && item[opts.textField].indexOf(q) < 0) {
$($trs[i]).addClass('hide');
}
});
}
}
//combogrid query 事件 按任意鍵 搜尋(本地)
function combogrid_query(obj, q, rowIndex, queryparam) {
$(obj).data("LoadSuccess", false);
var opts = $(obj).combogrid('options');
var url = opts.url;
//設定查詢引數
var queryParams = {
page: 1,
rows: opts.pageSize,
q: q
};
queryParams = $.extend(true, queryparam, queryParams);
//設定值,不加搜完後 就清空了
if (q == '')
$(obj).combogrid('setValue', '');
else {
$(obj).combogrid('setValue', q);
}
//動態搜尋
$(obj).combogrid('grid').datagrid('load', queryParams);
setTimeout(function () {
var Selted = $(obj).combogrid('grid').datagrid('getSelected');
if (Selted) {
if (!(typeof opts.onChange === 'undefined' || opts.onChange == null)) {
if (typeof opts.onChange === 'function') {
var valStr = '';
if (!(typeof (opts.valueField) === 'undefined' || opts.valueField == null)) {
valStr = opts.valueField;
} else if (!(typeof (opts.valuefield) === 'undefined' || opts.valuefield == null))
valStr = opts.valuefield;
else if (!(typeof (opts.Valuefield) === 'undefined' || opts.Valuefield == null))
valStr = opts.Valuefield;
opts.onChange(Selted[valStr]);
}
}
}
}, 300);
}
//載入資料成功
function ondgLoadSuccess($dg_, fieldName, rowIndex) {
var targetEditor = $dg_.datagrid('getEditor', {
field: fieldName,
index: rowIndex
});
$(targetEditor.target).data("LoadSuccess", true);
//setTimeout(function () {
// var Selted = $(targetEditor.target).combogrid('grid').datagrid('getSelected');
// if (Selted) {
// console.log('onLoadSuccess', $(targetEditor.target).combogrid('grid'), Selted);
// var opts = $(targetEditor.target).combogrid('options');
// if (!(typeof opts.onChange === 'undegined' || opts.onChange == null)) {
// if (typeof opts.onChange === 'function')
// opts.onChange(Selted[opts.valuefield]);
// }
// //$(targetEditor.target).combogrid('grid').trigger("onChange", Selted);
// //console.log('onLoadSuccess',fieldName, rowIndex);
// }
//}, 300);
}
//combogrid keyhandler 事件 【回車鍵】押下處理
function combogrid_enterKey(obj, e, $dg_, fieldName, editIndex) {
var $target = $dg_.datagrid('getEditor', {
field: fieldName,
index: editIndex
});
var Selted = $(obj).combogrid('grid').datagrid('getSelected');
var val = $(obj).combogrid('getValue');
if (!Selted) {
var LoadSuccess = $($target.target).data('LoadSuccess');
if (!(typeof val === 'undefined' || val == null || val=='') && (typeof LoadSuccess === 'undefined' || LoadSuccess == null || LoadSuccess)) {
var datarows = $(obj).combogrid('grid').datagrid('getData').rows;
if (datarows.length > 0) {
Selted = datarows[0];
var rowindex = $(obj).combogrid('grid').datagrid('getRowIndex', datarows[0]);
$(obj).combogrid('grid').datagrid('selectRow', rowindex);
}
}
}
if (Selted) {
//設定文字框的內容為選中行的的性別欄位內容
//$(obj).val(Selted[$(obj).combogrid('options').valueField]);
}
//選中後讓下拉表格消失
$(obj).combogrid('hidePanel');
if (typeof (fieldName) == undefined || typeof (editIndex) == undefined) {
return false;
}
if (fieldName == '' || isNaN(editIndex)) {
return false;
}
if (Selted) {
var datarow = $dg_.datagrid('getData').rows[editIndex];
if (!(typeof datarow === 'undefined' || datarow == null)) {
datarow[fieldName + 'NAME'] = Selted[$(obj).combogrid('options').textField];
}
}
var dataColumn = $dg_.datagrid('getColumnFields', false);
//console.log(dataColumn,$(this));
for (var x = 0; x < dataColumn.length; x++) {
if (dataColumn[x] == fieldName) {
if (x != dataColumn.length - 1) {
var nextNum = x + 1;
var $next = $dg_.datagrid('getEditor', {
field: dataColumn[nextNum],
index: editIndex
});
//if ($next) {
var nextopts = getOptions($next);
while ($next==null||$next.target.attr('disabled') || nextopts.readonly) {
nextNum++;
$next = $dg_.datagrid('getEditor', {
field: dataColumn[nextNum],
index: editIndex
});
if (nextNum >= dataColumn.length) {
break;
}
nextopts = getOptions($next);
}
//}
//console.log($dg_, editIndex, $next,x, dataColumn[x + 1]);
if ($next) {
//setTimeout(function () {
// $($next.target).parent().children('span:eq(0)').children('input:eq(0)').focus();
//}, 100);
if (e && e.preventDefault) {
e.preventDefault();
if ($next.type.toLowerCase() == "checkbox" || $next.type.toLowerCase() == "radio")
$($next.target).focus();
else
$($next.target).parent().children('span:eq(0)').children('input:eq(0)').focus();
}
else {
window.event.returnValue = false;
}
}
else {
if (nextNum >= rowColumn.length)
dgaccept($dg_);//儲存
}
}
else {
dgaccept($dg_);//儲存
}
break;
}
}
return false;
}
//繼承自textbox的keydown事件 enter 下一個
function Listtextbox_keydown(obj, event, $dg_, rowindex) {
//debugger;
var $thisElem = $(obj).parent().parent().children('input:eq(0)');
var $target;
$.each($dg_.datagrid('getEditors', rowindex), function (y, elem) {
if (elem) {
//console.log('keyup', $thisElem[0], $(elem.target)[0]);
if ($(elem.target)[0] == $thisElem[0]) {
$target = elem;
}
}
});
//console.log('keydown', $target);
if (!event) {
event = window.event;
}
//回車事件
if ((event.keyCode || event.which) == 13) {
if ($target.type == "datebox") {
if ($($thisElem).datebox('getValue') == '') {
//$($thisElem).datebox('setValue', moment().format('YYYY-MM-DD'));
}
}
if ($target.type == "datetimebox") {
if ($($thisElem).datebox('getValue') == '') {
//$($thisElem).datebox('setValue', moment().format('YYYY-MM-DD HH:mm:ss'));
}
}
//console.log('keydown回車事件', $target);
var rowColumn = $dg_.datagrid('getColumnFields', false);
for (var x = 0; x < rowColumn.length; x++) {
if (rowColumn[x] == $target.field) {
if (x != rowColumn.length - 1) {
var nextNum = x + 1;
var $next = $dg_.datagrid('getEditor', {
field: rowColumn[nextNum],
index: rowindex
});
var nextopts = getOptions($next);
while ($next == null || $next.target.attr('disabled') || nextopts.readonly) {
nextNum++;
$next = $dg_.datagrid('getEditor', {
field: rowColumn[nextNum],
index: rowindex
});
if (nextNum >= rowColumn.length) {
break;
}
nextopts = getOptions($next);
}
//console.log('keydown回車事件', $next, nextNum, rowColumn.length);
if ($next) {
if (event && event.preventDefault) {
event.preventDefault();
if ($next.type.toLowerCase() == "checkbox" || $next.type.toLowerCase() == "radio")
$($next.target).focus();
else
$($next.target).parent().children('span:eq(0)').children('input:eq(0)').focus();
}
else {
window.event.returnValue = false;
}
}
else {
if (nextNum >= rowColumn.length)
dgaccept($dg_);
}
}
else
dgaccept($dg_);;//儲存
break;
}
}
}
else {
var KeyCode = (event.keyCode || event.which);
var numberboxOpts = {};//precision
if ($target.type == 'numberbox') {
if (!(KeyCode == 8 || KeyCode == 46 || KeyCode == 110 || KeyCode == 190 || (KeyCode >= 48 && KeyCode <= 57) || (KeyCode >= 96 && KeyCode <= 105))) {
//console.log('KeyCode', KeyCode);
if (!((KeyCode >= 37 && KeyCode <= 40) || (KeyCode >= 112 && KeyCode <= 123))) {
if (event && event.preventDefault)
event.preventDefault();
else
window.event.returnValue = false;
}
}
else {
//console.log('KeyCode-', KeyCode);
var val = $(obj).val();
var _pointNum = val.indexOf('.');
if (KeyCode == 110 || KeyCode == 190) {
if (_pointNum > 0) {
if (event && event.preventDefault)
event.preventDefault();
else
window.event.returnValue = false;
} else {
if (val == "") {
if (event && event.preventDefault)
event.preventDefault();
else
window.event.returnValue = false;
}
}
} else if (!(KeyCode == 8 || KeyCode == 46)) {
numberboxOpts = $target.target.numberbox('options');
if (numberboxOpts.precision) {
if (_pointNum >= 0) {
if (val.length - _pointNum > numberboxOpts.precision) {
if (event && event.preventDefault)
event.preventDefault();
else
window.event.returnValue = false;
}
}
}
}
else
{
}
}
}
}
//debugger;
}
//checkbox或radio keydown事件
function chk_rdo_keydown(obj, event, $dg_, rowindex) {
//debugger;
var $thisElem = $(obj);
var $target;
$.each($dg_.datagrid('getEditors', rowindex), function (y, elem) {
if (elem) {
//console.log('chk_rdo', $thisElem, $(elem.target)[0]);
if ($(elem.target)[0] == $thisElem[0]) {
$target = elem;
}
}
});
//console.log('chk_rdo', $target);
//debugger;
if (!event) {
event = window.event;
}
//回車事件
if ((event.keyCode || event.which) == 13) {
//console.log('chk_rdo回車事件', $target);
//debugger;
$($target.target).prop("checked", true);
var rowColumn = $dg_.datagrid('getColumnFields', false);
for (var x = 0; x < rowColumn.length; x++) {
if (rowColumn[x] == $target.field) {
if (x != rowColumn.length - 1) {
var nextNum = x + 1;
var $next = $dg_.datagrid('getEditor', {
field: rowColumn[nextNum],
index: rowindex
});
var nextopts = getOptions($next);
while ($next == null || $next.target.attr('disabled') || nextopts.readonly) {
nextNum++;
$next = $dg_.datagrid('getEditor', {
field: rowColumn[nextNum],
index: rowindex
});
if (nextNum >= rowColumn.length) {
break;
}
nextopts = getOptions($next);
}
//console.log('keydown回車事件', $next, nextNum, rowColumn.length);
if ($next) {
if (event && event.preventDefault) {
event.preventDefault();
if ($next.type.toLowerCase() == "checkbox" || $next.type.toLowerCase() == "radio")
$($next.target).focus();
else
$($next.target).parent().children('span:eq(0)').children('input:eq(0)').focus();
}
else {
window.event.returnValue = false;
}
}
else {
if (nextNum >= rowColumn.length)
dgaccept($dg_);//儲存
}
}
else
dgaccept($dg_);//儲存
break;
}
}
//debugger;
}
}
//執行Accept方法
function dgaccept($dg_) {
var funcaccept = $dg_.attr('id').replace('_datagrid', '_') + "accept";
//根據函式名得到函式型別
var func;
try{
func = eval(funcaccept);
if (typeof func === 'function') {
//建立函式物件,並呼叫
func.call();
}
}
catch (ex) {
accept();//儲存
}
}
//新增HSCODE關聯規格型號選擇控制元件
function AddHSCODESeltControl($dg_, targetEditor, fieldName, fieldHSCODE, dialogId, rowIndex) {
if (!(typeof targetEditor === 'undefined' || targetEditor == null)) {
if (targetEditor.field == fieldName) {
var $dialog = $('#' + dialogId);
var targetHSCODE = $dg_.datagrid('getEditor', {
field: fieldHSCODE,
index: rowIndex
});
var $span = $(targetEditor.target).siblings("span:eq(0)");
if ($span) {
$span.on("dblclick", function () {
var valStr = $(this).siblings("input[type=text]:eq(0)").textbox("getValue");
var $layout = $dialog.children("div.easyui-layout:eq(0)");
$layout.html('');
$.ajax({
type: 'Get',
url: '/PARA_HSCODES/GetCurrG_ModelType',//獲取資料的函式
async: true,//true 非同步,false 同步
dataType: "json",
contentType: "application/json; charset=utf-8",
data: { G_Model: valStr, HSCODE: getTargetVal(targetHSCODE) },//查詢條件JSON.stringify()
beforeSend: function (XHR) {
$.messager.progress({
title: '設定規格型號',
msg: '正在獲取資料,請等待...'
});
},
success: function (data) {//查詢成功,data為返回的資料
$.messager.progress('close');
if (data.Success) {
if (data.ArrG_ModelType) {
//console.log(data.ArrG_ModelType);
if (data.ArrG_ModelType.length > 0) {
var ArrTemplete = [
'<div style="margin-bottom:1px; max-height:38px; overflow:hidden;"> \r\n',
//' <label class="textbox-label textbox-label-before" for="" style="width:200px; text-align: right; height: 24px; line-height: 24px; overflow:hidden;"></label>',
' <div style="text-align:right; width:200px; height:48px; float:left;">',
' <div style=" height:38px; display:block; vertical-align:middle;">',
' <div name="content" style="border:0px solid red; width:200px; height:48px; margin:0 auto;">',
' ',
' </div>',
' </div>',
' </div>',
//' <input class="easyui-textbox" name="" style="width:200px; height: 24px; line-height: 24px;">',
' <div style="text-align:right; width:200px; height:38px;float:left;">',
' <div style=" height:38px; display:block; vertical-align:middle;">',
' <div name="inputcontent" style="border:0px solid red; width:200px; height:48px; vertical-align:middle; margin:auto;">',
' <input class="easyui-textbox" name="" style="width:200px; height: 24px; line-height: 24px;">',
' </div>',
' </div>',
' </div>',
'</div> \r\n'
];
$.each(data.ArrG_ModelType, function (i, item) {
ArrTemplete[1] = ArrTemplete[1].replace('label:\'\',', 'label:\'' + item.Key + '\',');
var $templete = $(ArrTemplete.join(''));
//var $label = $templete.children('label:eq(0)');
var $label = $templete.children('div:eq(0)').find("div[name=content]");
//var $input = $templete.children('input:eq(0)');
var $input = $templete.children('div:eq(1)').find("div[name=inputcontent]").children('input:eq(0)');
var inputName = "G_ModelType" + i;
$label.attr({ "for": inputName, "title": item.Key });
$label.html(item.Key + ":");
$input.attr("name", inputName);
$input.val(item.Value);
$layout.append($templete);
});
$dialog.dialog('open');
}
else
$.messager.alert("錯誤", "無法解析資料", 'error');
}
else
$.messager.alert("錯誤", "解析資料錯誤", 'error');
}
else {
$.messager.alert("錯誤", data.ErrMsg, 'error');
}
},
error: function (response) {
$.messager.progress('close');
$.messager.alert("錯誤", "處理資料時發生錯誤了!", 'error');
}
});
});
}
}
}
}
//儲存選擇的規格型號類別
function SaveTypeValue($dg_, dialogId, fieldName, editIndex) {
//對話方塊
var $dialog = $("#" + dialogId);
var $layout = $dialog.children("div.easyui-layout:eq(0)");
var G_ModelTypeInputs = $layout.find('input.easyui-textbox');
var G_ModelTypeVals = [];//儲存鍵值對
G_ModelTypeInputs.each(function (i, item) {
//var $label = $(item).siblings("label:eq(0)");
var $label = $(item).parent().parent().parent().parent().find("div[name=content]");
var labelStr = $label.html();
var val = $(item).val();
if (labelStr.length > 1) {
var index = labelStr.length - 1;
var lastval = labelStr.substr(index);
if (lastval == ':' || lastval == ':') {
labelStr = $.trim(labelStr.substr(0, index));
}
}
G_ModelTypeVals.push({ G_ModelType: labelStr, Value: val });
});
if (typeof G_ModelTypeVals === 'undefined' || G_ModelTypeVals == null) {
//$.messager.alert("錯誤", '規格型號型別,必須填寫完整');
//return;
}
else {
for (var x in G_ModelTypeVals) {
var item = G_ModelTypeVals[x];
if (item.G_ModelType != "其他" && (typeof item.Value === 'undefined' || item.Value == null || item.Value == '')) {
//$.messager.alert("錯誤", '規格型號型別,必須填寫完整(除 其他 型別以外)');
//return;
}
}
}
$dialog.dialog('close');
var TargetEditor = $dg_.datagrid('getEditor', {
field: fieldName,
index: editIndex
});
//console.log($dg_, fieldName, editIndex,TargetEditor);
if (!(typeof TargetEditor === 'undefined' || TargetEditor == null)) {
if (TargetEditor.target) {
var TypeValStr = "";
for (var i in G_ModelTypeVals) {
//TypeValStr += (parseInt(i) + 1) + ":" + G_ModelTypeVals[i].G_ModelType + "-" + G_ModelTypeVals[i].Value + ";";
TypeValStr += G_ModelTypeVals[i].Value + "|";
}
if (TypeValStr.substr(TypeValStr.length - 1) == "|")
TypeValStr = TypeValStr.substr(0, TypeValStr.length - 1);
var pmStr = "1:品名";
if (TypeValStr.length < pmStr.length) {
if (TypeValStr.replace(/[|]/g, '') == "") {
TypeValStr = "";
}
$(TargetEditor.target).textbox("setValue", TypeValStr);
} else {
var Str = TypeValStr.substr(0, pmStr.length);
if (Str.indexOf(pmStr) >= 0) {
$.messager.alert("錯誤", '第一個規格型號型別,不能是品名');
return;
}
if (TypeValStr.replace(/[|]/g, '') == "") {
TypeValStr = "";
}
$(TargetEditor.target).textbox("setValue", TypeValStr);
}
}
}
else {
$.messager.alert("錯誤", '規格型號編輯控制元件不存在');
return;
}
}
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
function setdateboxvalue($dg_, index, fields) {
var seletRow = $dg_.datagrid('getSelected');
for (var i = 0; i < fields.length; i++) {
if (seletRow[fields[i]] != null && seletRow[fields[i]] != '') {
var TargetEditor = $dg_.datagrid('getEditor', { index: index, field: fields[i] });
if (TargetEditor!=null && TargetEditor.type.toLowerCase() == 'datebox') {
$(TargetEditor.target).datebox('setValue', moment(seletRow[fields[i]]).format('YYYY-MM-DD'));
}
}
}
}