## js計算年齡及判斷是否享受養老保險



~~~
var actionURL = '/No1_yanglaobx/ashx/No1_yanglaobxHandler.ashx';
var formurl = '/No1_yanglaobx/html/No1_yanglaobx.html';
$(function () {
//為避免數據字典加載不完整。這段在后面加載
//autoResize({ dataGrid: '#list', gridType: 'datagrid', callback: grid.bind, height: 0 });
$('#a_add').click(CRUD.add);
$('#a_edit').click(CRUD.edit);
$('#a_delete').click(CRUD.del);
//高級查詢
$('#a_search').click(function () {
search.go('list');
});
$('#a_refresh').click(grid.reload);//刷新
$('#a_getSearch').click(function () {//自定義搜索框
mySearch();
});
/*導出EXCEL*/
$('#a_export').click(function () {
var ee = new ExportExcel('list', actionURL);
ee.go();
});
/*導入EXCEL*/
$('#a_inport').click(function () {
var ii = new ImportExcel('list', actionURL);
ii.go();
});
//批量刪除
$("#a_alldel").click(function () {
var ids = [];
var rows = $('#list').datagrid('getSelections');
for (var i = 0; i < rows.length; i++) {
ids.push(rows[i].KeyId);
}
var allid = ids.join(',');//所有的id
var o = {};
o.action = "alldel";
o.KeyIds = allid;
var param = "json=" + JSON.stringify(o);
if (confirm('確認要執行批量刪除操作嗎?')) {
jQuery.ajaxjson(actionURL, param, function (d) {
if (parseInt(d) > 0) {
msg.ok('批量刪除成功!');
grid.reload();
} else {
MessageOrRedirect(d);
}
});
}
});
});
//這段后加載,避免數據字典加載不完整的問題
window.onload = function () {
autoResize({ dataGrid: '#list', gridType: 'datagrid', callback: grid.bind, height: 0 });
};
//editor:'datetimebox' 日期及時間選擇框 editor:'datebox' 日期選擇框 editor:'numberspinner' 數字調節器 editor:{type: 'numberspinner',options:{value:0,required:true}}
//定義一個$JQ為$. 以后在js 中就可以用${JQ}AJAX了在前臺這樣寫(定義)://通用數據字典start
var getDic = {
jsonData: function (dicID) {
$.getJSON('/sys/ashx/dichandler.ashx?categoryId=' + dicID + '', function (data) {
var newData = JSON.stringify(data).replace(/KeyId/g, "id").replace(/Title/g, "text");
//alert(newData);
$('body').data('data' + dicID + '', newData); //意思是得到數據并賦值給body
});
},
jsonParentData: function (dicID) {
$.getJSON('/sys/ashx/dichandler.ashx?action=parent&parentid=' + dicID + '', function (data) {
var newData = JSON.stringify(data).replace(/KeyId/g, "id").replace(/Title/g, "text");
$('body').data('data' + dicID + '', newData); //意思是得到數據并賦值給body
});
},
}
//通用數據字典end
//調用數據字典和使用數據字典 如果不需要請不要打開否則會導致系統速度慢
//getDic.jsonData(9);//取得性別數據字典
//在onLoad:的地方如下使用
//top.$('#txt_user_sex').combobox({ data: eval($('body').data('data9')), valueField: 'text', textField: 'text', editable: false, required: true, missingMessage: '請選擇性別', disabled: false });
var grid = {
bind: function (winSize) {
$('#list').datagrid({
url: actionURL,
toolbar: '#toolbar',
title: "數據列表",
iconCls: 'icon icon-list',
width: winSize.width,
height: winSize.height,
nowrap: false, //折行
rownumbers: true, //行號
striped: true, //隔行變色
idField: 'KeyId',//主鍵
singleSelect: true, //單選
frozenColumns: [[]],
columns: [[//應為寬度不是很需要所以注釋了寬度
{ title: '選擇', field: 'ck', checkbox: true },//后加進去全選字段數據庫里是沒有的
{ title: '自增ID', field: 'KeyId', sortable: true, width: '', hidden: true },
{ title: '姓名', field: 'truename', sortable: true, width: '', hidden: false },
{ title: '身份證', field: 'idcard', sortable: true, width: '', hidden: false },
{ title: '性別', field: 'sex', sortable: true, width: '', hidden: false },
{
title: '出生日期', field: 'birthday', sortable: true, width: '', hidden: false
, formatter: function (v, r, i) {
var adtime = r.birthday;//字段名
if (adtime == null) {
return null;
} else {
var addtime = r.birthday;
var myDate = new Date(addtime);
var shijian = myDate.toLocaleDateString();
console.log("時間:" + shijian);
return shijian;
}
},
},
{
title: '年齡', field: 'age', sortable: true, width: '',
formatter: function (value, row, index) {//單元格formatter(格式化器)函數,帶3個參數:value:字段值。row:行記錄數據。index: 行索引。
return jsGetAge(row.birthday);
//想法擴展 判斷幾歲到幾歲是否有勞動能力
//var nl=jsGetAge(row.birthday);
//if (nl => 16 & nl <= 60) {//年齡16-60的有勞動能力
// return "有";
//} else {
// return "無";
//}
},
hidden: false
},
{ title: '戶籍性質', field: 'household', sortable: true, width: '', hidden: false },
{
title: '到齡享受待遇標志', field: 'treatment', sortable: true, width: '',
formatter: function (value, row, index) {//單元格formatter(格式化器)函數,帶3個參數:value:字段值。row:行記錄數據。index: 行索引。
var nl=jsGetAge(row.birthday);
if (nl >= 60) {//年齡達到60歲享受養老保險
return "是";
} else {
return "否";
}
},
hidden: false
},
{ title: '參保狀態', field: 'canbaostate', sortable: true, width: '', hidden: false },
{ title: '繳費狀態', field: 'jiaofeistate', sortable: true, width: '', hidden: false },
{ title: '特殊身份', field: 'special', sortable: true, width: '', hidden: false },
{ title: '被征地身份', field: 'propriation', sortable: true, width: '', hidden: false },
{
title: '首次參保經辦時間', field: 'shccbjbtime', sortable: true, width: '', hidden: false
, formatter: function (v, r, i) {
var adtime = r.shccbjbtime;//字段名
if (adtime == null) {
return null;
} else {
var addtime = r.shccbjbtime;
var myDate = new Date(addtime);
var shijian = myDate.toLocaleDateString();
console.log("時間:" + shijian);
return shijian;
}
},
},
{ title: '領取待遇', field: 'receivetreatment', sortable: true, width: '', hidden: false },
]],
onEndEdit: onEndEdit,//結束編輯時函數 這里為了簡潔 該函數寫在下面
onUnselect: onUnselect,
onLoadSuccess: function (data) {
//alert($('body').data('data70'));
//alert($('body').data('data69'));
},
onCancelEdit: onCancelEdit,//在用戶取消編輯一行的時候觸發
onSelect: onSelect,//在用戶選擇一行的時候觸發
onClickRow: onClickRow,//在用戶點擊一行的時候觸發
//onAfterEdit: onAfterEdit,//在用戶完成編輯一行的時候觸發
onDblClickCell: onDblClickCell,//為了程序邏輯清楚函數寫在外面
onHeaderContextMenu: function (e, field) {//列菜單實現動態隱藏列
e.preventDefault();
if (!cmenu) {
createColumnMenu();
}
cmenu.menu('show', {
left: e.pageX,
top: e.pageY
});
},
pagination: true,
pageSize: PAGESIZE,
pageList: [20, 40, 50, 100, 200]
});
},
getSelectedRow: function () {
return $('#list').datagrid('getSelected');
},
reload: function () {
$('#list').datagrid('clearSelections').datagrid('reload', { filter: '' });
}
};
function createParam(action, keyid) {
var o = {};
var query = top.$('#uiform').serializeArray();
query = convertArray(query);
o.jsonEntity = JSON.stringify(query);
o.action = action;
o.keyid = keyid;
return "json=" + JSON.stringify(o);
}
var CRUD = {
add: function () {
var hDialog = top.jQuery.hDialog({
title: '添加', width: 800, height: 600, href: formurl, iconCls: 'icon-add',
onLoad: function () {
top.$('#txt_sex').combobox({ url: '/sys/ashx/dichandler.ashx?showType=noselected&categoryId=69', valueField: 'Title', textField: 'Code', editable: false, required: true });
top.$('#txt_treatment').combobox({ url: '/sys/ashx/dichandler.ashx?showType=noselected&categoryId=88', valueField: 'Title', textField: 'Code', editable: false, required: true });
top.$('#txt_propriation').combobox({ url: '/sys/ashx/dichandler.ashx?showType=noselected&categoryId=88', valueField: 'Title', textField: 'Code', editable: false, required: true });
top.$('.kindeditor').kindeditor();//初始化kingdeditor編輯器
},
submit: function () {
//alert(top.$("#uiform").form('enableValidation').form('validate'));
//alert(top.$("#uiform").form('validate'));
//原來用的是這種方法 alert(top.$('#uiform').validate().form());
if (top.$("#uiform").form('validate')) {
var query = createParam('add', '0');
jQuery.ajaxjson(actionURL, query, function (d) {
if (parseInt(d) > 0) {
msg.ok('添加成功!');
hDialog.dialog('close');
grid.reload();
} else {
MessageOrRedirect(d);
}
});
}
msg.warning('請填寫必填項!');
return false;
}
});
top.$('#uiform').validate();
},
edit: function () {
var row = grid.getSelectedRow();
if (row) {
var hDialog = top.jQuery.hDialog({
title: '編輯', width: 800, height: 600, href: formurl, iconCls: 'icon-save',
onLoad: function () {
top.$('#txt_sex').combobox({ url: '/sys/ashx/dichandler.ashx?showType=noselected&categoryId=69', valueField: 'Title', textField: 'Code', editable: false, required: true });
top.$('#txt_KeyId').numberspinner('setValue', row.KeyId);
top.$('#txt_truename').textbox('setValue', row.truename);
top.$('#txt_idcard').textbox('setValue', row.idcard);
top.$('#txt_sex').textbox('setValue', row.sex);
top.$('#txt_birthday').datetimebox('setValue', row.birthday);
top.$('#txt_age').textbox('setValue', row.age);
top.$('#txt_household').textbox('setValue', row.household);
top.$('#txt_treatment').textbox('setValue', row.treatment);
top.$('#txt_canbaostate').textbox('setValue', row.canbaostate);
top.$('#txt_jiaofeistate').textbox('setValue', row.jiaofeistate);
top.$('#txt_special').textbox('setValue', row.special);
top.$('#txt_propriation').textbox('setValue', row.propriation);
top.$('#txt_shccbjbtime').datetimebox('setValue', row.shccbjbtime);
top.$('#txt_receivetreatment').textbox('setValue', row.receivetreatment);
//top.$('#txt_$item.colAttribute').val(row.$item.colAttribute);//$item.coltitle
//top.$('.kindeditor').kindeditor();//初始化kingdeditor編輯器
//注意 如果控件被EasyUI初始化過,賦值的方法有所改變 下面提供幾個例子。程序員根據情況改動一下
//$('#nn').numberbox('setValue', 206.12);
//$('#nn').textbox('setValue',1);
//$('#cc').combobox('setValues', ['001','002']);
//$('#dt').datetimebox('setValue', '6/1/2012 12:30:56');
},
submit: function () {
//alert(top.$("#uiform").form('enableValidation').form('validate'));
//alert(top.$("#uiform").form('validate'));
//原來用的是這種方法 alert(top.$('#uiform').validate().form());
if (top.$("#uiform").form('validate')) {
var query = createParam('edit', row.KeyId);;
jQuery.ajaxjson(actionURL, query, function (d) {
if (parseInt(d) > 0) {
msg.ok('修改成功!');
hDialog.dialog('close');
grid.reload();
} else {
MessageOrRedirect(d);
}
});
}
msg.warning('請填寫必填項!');
return false;
}
});
} else {
msg.warning('請選擇要修改的行。');
}
},
del: function () {
var row = grid.getSelectedRow();
if (row) {
if (confirm('確認要執行刪除操作嗎?')) {
var rid = row.KeyId;
jQuery.ajaxjson(actionURL, createParam('delete', rid), function (d) {
if (parseInt(d) > 0) {
msg.ok('刪除成功!');
grid.reload();
} else {
MessageOrRedirect(d);
}
});
}
} else {
msg.warning('請選擇要刪除的行。');
}
}
};
//實現動態隱藏列
var cmenu = null;
function createColumnMenu() {
cmenu = $('<div/>').appendTo('body');
cmenu.menu({
onClick: function (item) {
if (item.iconCls == 'icon-ok') {
$('#list').datagrid('hideColumn', item.name);
cmenu.menu('setIcon', {
target: item.target,
iconCls: 'icon-empty'
});
} else {
$('#list').datagrid('showColumn', item.name);
cmenu.menu('setIcon', {
target: item.target,
iconCls: 'icon-ok'
});
}
}
});
var fields = $('#list').datagrid('getColumnFields');
for (var i = 0; i < fields.length; i++) {
var field = fields[i];
var col = $('#list').datagrid('getColumnOption', field);
cmenu.menu('appendItem', {
text: col.title,
name: field,
iconCls: 'icon-ok'
});
}
}
//實現動態隱藏列結束
//雙擊編輯表單焦點消失后保存
var editIndex = undefined;
function endEditing() {
if (editIndex == undefined) { return true }
if ($('#list').datagrid('validateRow', editIndex)) {
$('#list').datagrid('endEdit', editIndex);
editIndex = undefined;
return true;
} else {
return false;
}
}
function onDblClickCell(index, field) {
if (editIndex != index) {
if (endEditing()) {
$('#list').datagrid('selectRow', index)
$('#list').datagrid('beginEdit', index);
var ed = $('#list').datagrid('getEditor', { index: index, field: field });
if (ed) {
($(ed.target).data('textbox') ? $(ed.target).textbox('textbox') : $(ed.target)).focus();
//這個寫法很有意思
//為了方便 ,類似字段要同事寫兩個值 1把部門id寫入隱藏字段2把標題換成值寫入 顯示字段
}
editIndex = index;
} else {
setTimeout(function () {
$('#list').datagrid('selectRow', editIndex);
}, 0);
}
}
}
function onUnselect(index, row) {
//alert(index);
}
function onCancelEdit(index, row) {
//alert(index);
}
function onClickRow(index, row) {
if (editIndex != undefined) {
//alert("正在編輯的行是:" + editIndex);
//alert("驗證正在編輯的行:" + $('#list').datagrid('validateRow', editIndex));
if ($('#list').datagrid('validateRow', editIndex)) {//如果驗證正在編輯的行數據有效則
$("#list").datagrid('endEdit', editIndex);//如果點其他行,結束編輯正在編輯的行
editIndex = undefined;
} else {
msg.warning("還有一行沒編輯完啦!!");
}
}
$("#list").datagrid('selectRow', index);
}
function onSelect(index, row) {
}
function onEndEdit(index, row, changes) {
//alert('結束編輯'+index+JSON.stringify(row));
var o = {};
var query = JSON.stringify(row);
o.jsonEntity = query;
o.action = 'edit';
o.keyid = row.KeyId;
query = "json=" + JSON.stringify(o);
//alert(query);
//表格內編輯模式編輯成功不提示信息
jQuery.ajaxjson(actionURL, query, function (d) {
//if (parseInt(d) > 0) {
// msg.ok('編輯成功!');
// hDialog.dialog('close');
grid.reload();
// } else {
// MessageOrRedirect(d);
// }
});
}
function append() {
if (endEditing()) {
$('#list').datagrid('appendRow', { status: 'P' });
editIndex = $('#list').datagrid('getRows').length - 1;
$('#list').datagrid('selectRow', editIndex)
.datagrid('beginEdit', editIndex);
}
}
function removeit() {
if (editIndex == undefined) { return }
$('#list').datagrid('cancelEdit', editIndex)
.datagrid('deleteRow', editIndex);
editIndex = undefined;
}
function accept() {
if (endEditing()) {
$('#list').datagrid('acceptChanges');
}
}
function reject() {
$('#list').datagrid('rejectChanges');
editIndex = undefined;
}
function getChanges() {
var rows = $('#list').datagrid('getChanges');
alert(rows.length + ' rows are changed!');
}
//雙擊編輯表單焦點消失后保存結束
//自定義搜索開始
function mySearch() {
//page=1&rows=20&filter={"groupOp":"AND","rules":[{"field":"unit","op":"cn","data":"昆明"},{"field":"connman","op":"cn","data":"朱光明"}],"groups":[]}
var myunit = $("#myUnit").textbox('getValue');
var connman = $("#myConnMan").textbox('getValue');
var query = '{"groupOp":"AND","rules":[],"groups":[]}';
var o = JSON.parse(query);
var i = 0;
if (myunit != '' && myunit != undefined) {//假如單位搜索不為空
o.rules[i] = JSON.parse('{"field":"unit","op":"cn","data":"' + myunit + '"}');
i = i + 1;
}
if (connman != '' & connman != undefined) {//聯系人不為空
o.rules[i] = JSON.parse('{"field":"connman","op":"cn","data":"' + connman + '"}');
}
$('#list').datagrid('reload', { filter: JSON.stringify(o) });
}
//自定義搜索結束
//單選多選開關
$('#selectSwitch').switchbutton({
checked: false,
onChange: function (checked) {
if (checked) {
$('#list').datagrid({ singleSelect: false });//多選
} else {
$('#list').datagrid({ singleSelect: true });//單選
}
}
})
/*根據出生日期算出年齡*/
function jsGetAge(strBirthday) {
var returnAge;
var strBirthdayArr = strBirthday.split("-");
var birthYear = strBirthdayArr[0];
var birthMonth = strBirthdayArr[1];
var birthDay = strBirthdayArr[2];
d = new Date();
var nowYear = d.getFullYear();
var nowMonth = d.getMonth() + 1;
var nowDay = d.getDate();
if (nowYear == birthYear) {
returnAge = 0;//同年 則為0歲
}
else {
var ageDiff = nowYear - birthYear; //年之差
if (ageDiff > 0) {
if (nowMonth == birthMonth) {
var dayDiff = nowDay - birthDay;//日之差
if (dayDiff < 0) {
returnAge = ageDiff - 1;
}
else {
returnAge = ageDiff;
}
}
else {
var monthDiff = nowMonth - birthMonth;//月之差
if (monthDiff < 0) {
returnAge = ageDiff - 1;
}
else {
returnAge = ageDiff;
}
}
}
else {
returnAge = -1;//返回-1 表示出生日期輸入錯誤 晚于今天
}
}
return returnAge;//返回周歲年齡
}
~~~
- 翼通長租公寓管理系統
- 版本升級
- 操作手冊
- 添加新店
- 給新店分配管理員(店長)
- 新店必須完成的基礎信息
- 常見問題
- 翼通經銷商管理系統
- 版本升級
- 聚源達印刷管理系統
- 0、升級說明及重要問題注意
- 1、訂單狀態說明(兼容老系統)
- 四月顯示之僵尸產品
- 打印
- Html5中localStorage存儲JSON數據并讀取JSON數據的實現方法
- 功能說明
- 2.各種操作說明
- 升級說明
- 物聯網
- CentosARM
- 樹莓派(RPi) CentOS7擴展內存卡剩余空間
- 翼通管理系統快速開發框架LayUI版
- layui模塊使用方法
- 默認顯示自定義排序方法
- linq查詢輸出json小例子
- layui json格式
- treetable借鑒
- layui表單驗證
- layui圖標
- 第一書記信息管理系統
- 多條件查詢搜索
- 年齡計算
- 家庭數據打印
- 數據打印框架
- 后臺處理獲取需打印數據
- js打印方法
- 圖片上傳
- 單圖上傳
- 多圖上傳
- 多圖上傳CSS樣式
- 圖片保存
- 高級大招
- SqlServer
- sqlserver 去重復并查詢的一列數據拼接用逗號隔開顯示
- 修復SqlServer孤立用戶
- VS2017提高開發效率的幾大技巧看過終生受用,錯過繼續盲目忙碌。
- 微信開發
- 微信開發基礎
- 1、微信公眾平臺測試帳號的注冊與使用
- 2、NuGet引用Senparc微信開發類
- 3、微信接入應答問文件
- 微信開發進階
- 1、綁定用戶把openid、用戶頭像、昵稱綁定到數據庫
- 2、阿里大魚發送驗證短信
- 3、測試用戶是否關注公眾號
- 人人商城
- 1、公眾號接入配置
- 2、公眾號支付配置
- 3、手機短信配置
- 4、小程序配置
- 5、店鋪可視化裝修
- 6、三級分銷配置
- MarkDown
- 1、markdown寫流程圖幫助文檔
- 阿里短信
- 常用短信模板
- 中國翼通基類庫
- 一、說明
- 二、基類庫代碼(用法索引)
- 1、阿里大魚短信
- 2、阿里云短信類
- 3、web.config操作類
- 4、字符操作類
- 5、隨機數
- 6、拼音類
- 7、身份證類
- 8、SqlServer數據庫操作sqleasy
- 9、JSON類
- 999、日志調試類
- 10、QRCode生成二維碼
- 11、保存遠程圖片到本地
- 12、Session類
- 13、ip類
- 14、驗證碼
- 15、base64類
- 翼通CMS版本升級
- 昆明市公安局政治部
- 3D打印
- 老撾消費機
- 幫助文檔
- 工作流開發
- 工作流數據庫結構
- 工作流借鑒
- 思想
- 設計工作流要注意的問題
- 編譯錯誤
- 缺少編譯器要求的成員“Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create"
- EasyUI操作例子
- combogrid綁定
- linq
- 建立linqToSqlServer連接
- 公租房管理系統
- 改進升級更新
- 云南民間工藝傳承協會
- 思路
- 問題
- 云南麥根科技有限公司
- 月嫂多APP
- 嫂多點APP
- 管理后臺
- Laravel
- 一、開發環境搭建
- 二、如何正確使用 Composer 安裝 Laravel 擴展包
- 三、修改數據庫連接
- 四、創建一個簡單的Laravel例子
- 五. laravel維護日記
- 六、nginx下偽靜態配置
- 七、增刪查改知識點
- 騰訊借貸反欺詐開發
- ThinkPHP
- 0、ThinkPHP安裝
- 2、Zend Studio 13.6.1 的安裝和破解
- 1、thinkphp自由查詢語句分頁
- 3、thinkphp M R 方法詳解
- 4、前臺循環
- 5、laiui提交表單
- 翼通云官方網站(里面有內容)
- 開發過程中各種問題
- 小鳥云系統的坑
- 更新日志
- 單頁面模板
- 翼通智慧網站策劃
- 4.05到4.10升級
- phpstom
- 一、設置字體、外觀
- 二、phpstom運行php教程
- 三、phpstom debug調試
- 四、PHPStorm 提示502 Bad Gateway
- vscode
- vscode常用插件
- vscode使用git翼通教程
- Git忽略提交規則 - .gitignore配置運維總結
- Git忽略文件不起作用解決方案
- vscode添加新建文件頭部注釋和函數注釋
- git命令
- git命令大全
- vscode每次打開都會覆蓋窗口
- git忽略文件格式
- ios au 更新APP store教程
- iOS APP版本更新升級教程
- 上傳ipa常見錯誤解決方案
- 上傳ipa報錯版本號重復問題解決教程
- hbuider
- Hbuider制作app升級包的簡單辦法 (升級官方提供的案例)
- linux
- wdcp后臺訪問安全設置即限制域名/IP訪問設置及清除方法
- MSSQL數據庫
- 恢復
- SqlServer將沒有log文件的數據庫文件附加到服務器中
- 1、mssql2019報18456不能登錄
- [簡易版]幼兒園新生入學報名管理系統
- 物流園電子出門條系統
- 電腦自選超市開發
- 服務商操作手冊
- 管理員操作手冊
- EcShop
- 一、EcShop5.3升級5.6遇到問題
- 2、ECShop 時間相差8小時、時間不對的問題
- 3、數據庫操作
- 3、嵌入類的方法
- 4、入駐商列表sql