From a8788a3ea2f47089b8d6a52f37556710734f9583 Mon Sep 17 00:00:00 2001 From: wuxuehong Date: Fri, 8 Jul 2022 14:30:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=84=BF=E7=AB=A5=E9=A2=84=E7=BA=A6=E5=BB=BA?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- littleApp_child/app.json | 3 +- .../packageA/pages/preDocumented/preDocumented.js | 480 +++++++++++++++++++++ .../pages/preDocumented/preDocumented.json | 8 + .../pages/preDocumented/preDocumented.wxml | 445 +++++++++++++++++++ .../pages/preDocumented/preDocumented.wxss | 111 +++++ littleApp_child/pages/home/home.js | 5 + littleApp_child/pages/home/home.wxml | 1 + littleApp_child/pages/hospitalList/hospitalList.js | 46 +- littleApp_child/project.config.json | 2 +- littleApp_child/utils/apiFile.js | 2 + littleApp_child/utils/network_util.js | 2 +- littleApp_child/utils/numberUtil.js | 271 ++++++++---- 12 files changed, 1276 insertions(+), 100 deletions(-) create mode 100644 littleApp_child/packageA/pages/preDocumented/preDocumented.js create mode 100644 littleApp_child/packageA/pages/preDocumented/preDocumented.json create mode 100644 littleApp_child/packageA/pages/preDocumented/preDocumented.wxml create mode 100644 littleApp_child/packageA/pages/preDocumented/preDocumented.wxss diff --git a/littleApp_child/app.json b/littleApp_child/app.json index 68beaf4..37addc5 100644 --- a/littleApp_child/app.json +++ b/littleApp_child/app.json @@ -53,7 +53,8 @@ "pages/graph/graph", "pages/editAddress/editAddress", "pages/articleList/articleList", - "pages/article/article" + "pages/article/article", + "pages/preDocumented/preDocumented" ] } ], diff --git a/littleApp_child/packageA/pages/preDocumented/preDocumented.js b/littleApp_child/packageA/pages/preDocumented/preDocumented.js new file mode 100644 index 0000000..edc7fcf --- /dev/null +++ b/littleApp_child/packageA/pages/preDocumented/preDocumented.js @@ -0,0 +1,480 @@ +// packageA/pages/preDocumented/preDocumented.js +const networkUtil = require("../../../utils/network_util.js"); +const api = require("../../../utils/apiFile.js"); +const makePy = require("../../../utils/makepy.js"); +const numberUtil = require("../../../utils/numberUtil.js"); +import { AreaPicker } from "../../../utils/areaSelector/selector.js" +let liveType = ""; +Page(Object.assign({}, AreaPicker,{ + data: { + postObj: {}, + queryData:{}, + currentAddress: {}, + sex:[ + { + name:"男", + value:1, + checked:true + }, + { + name:"女", + value:0, + checked:false + }, + ], + childCardShow: false, + items: [ + {value: 'wr', name: '未入', checked: 'true'}, + {value: 'yr', name: '已入'}, + ], + liveTypes: ['常住','流动','暂住','有居住证'], + liveTypestr: [ + { + "id":"57624c440cf23d4631523ea1", + "code":"bd", + "enable":1, + "parentId":"57624c330cf23d4631523ea0", + "name":"常住", + "parentName":null, + "desc":null, + "level":null, + "weight":null, + "leastUse":null, + "basicConfigs":[ + ], + "childConfigs":null + }, + { + "id":"57624c5e0cf23d4631523ea2", + "code":"wd", + "enable":1, + "parentId":"57624c330cf23d4631523ea0", + "name":"流动", + "parentName":null, + "desc":null, + "level":null, + "weight":null, + "leastUse":null, + "basicConfigs":[ + ], + "childConfigs":null + }, + { + "id":"5a371bce0cf2ab082ac30433", + "code":"bdcz", + "enable":1, + "parentId":"57624c330cf23d4631523ea0", + "name":"暂住", + "parentName":null, + "desc":null, + "level":null, + "weight":null, + "leastUse":null, + "basicConfigs":[ + ], + "childConfigs":null + }, + { + "id":"62270e679932d29c07242e4f", + "code":"jzz", + "enable":1, + "parentId":"57624c330cf23d4631523ea0", + "name":"有居住证", + "parentName":null, + "desc":null, + "level":null, + "weight":null, + "leastUse":null, + "basicConfigs":[ + ], + "childConfigs":null + } + ], + quality:[ + { + name:"农业", + value:1, + checked:false + }, + { + name:"非农业", + value:2, + checked:false + }, + ], + selectedChild:{}, + isChooseBox:true, + //页面显示 1 新增建档 2 查看建档 + showViewType:0, + hospitals:[], + SearchHospitals:[], + pickerBoxModal:true, + endDate:'', + submiting:false + }, + onLoad: function (options) { + var that = this; + networkUtil.showLoading() + networkUtil._get(api.getConfigHospitals,{}, function(res) { + if(0 == res.data.errorcode){ + that.setData({ + hospitals:res.data.data, + selectHospital: {}, //{'hospitalId':216,'hospitalName':'秦皇岛市妇幼保健院'}, + 'queryData.hospital': {} //{'hospitalId':216,'hospitalName':'秦皇岛市妇幼保健院'} + }) + } + }, function(res) { + networkUtil.showErrorToast(res.errormsg) + }) + + var date = new Date(); + var nowMonth = date.getMonth() + 1; + var strDate = date.getDate(); + // 日期分割符号 + var seperator = "-"; + that.setData({ + endDate:date.getFullYear() + seperator + nowMonth + seperator + strDate + }) + + wx.onKeyboardHeightChange(res => { + console.log(res.height) + this.setData({ + bottom:res.height + }) + }) + }, + bindPickerChange: function(e) { + let type = this.data.liveTypes[e.detail.value]; + for (var i in this.data.liveTypestr) { + if (type === this.data.liveTypestr[i].name) { + liveType = this.data.liveTypestr[i].id; + } + } + this.setData({ + index: e.detail.value + }) + }, + bindDateChange(e){ + let value = e.detail.value; + this.setData({ + ['postObj.birth']: value + }) + }, + bindKeyInput(e) { + let key = e.currentTarget.id; + let value = e.detail.value; + this.setData({ + ['postObj.' + key]: value + }) + }, + checkboxChange (e) { + const items = this.data.items + const values = e.detail.value + for (let i = 0, lenI = items.length; i < lenI; ++i) { + items[i].checked = false + for (let j = 0, lenJ = values.length; j < lenJ; ++j) { + if (items[i].value === values[j]) { + items[i].checked = true + break + } + } + } + this.setData({ + items + }) + }, + radioChange(e) { + let value = e.detail.value; + this.setData({ + ['postObj.sex']: value + }) + }, + radioChange1(e) { + let childCardShow = e.detail.value; + if (childCardShow==='yr') { + childCardShow = true; + } else { + childCardShow = false; + } + this.setData({ + childCardShow: childCardShow + }) + }, + radioChange2(e) { + let value = e.detail.value; + this.setData({ + ['postObj.babyAccountNature']: value + }) + }, + bindQueryInput(e) { + // console.log(e) + let key = e.currentTarget.id; + let value = e.detail.value; + this.setData({ + ['queryData.' + key]: value + }) + }, + fouseSearchHospital(e){ + let resultArr = this.data.SearchHospitals + if(this.data.SearchHospitals.length == 0){ + resultArr = this.data.hospitals; + } + this.setData({ + pickerBoxModal:false, + SearchHospitals:resultArr, + 'queryData.hospital':resultArr[0], + }) + }, + bindSearchHospital(e){ + let value = e.detail.value; + let that = this; + let resultArr = [],arr = that.data.hospitals,col='hospitalName'; + for(var i= 0, searchText, tmp; i1){ + that.setData({ + childList : res.data.data, + isChooseBox : false + }) + }else{ + let postObj = res.data.data[0]; + if (postObj) { + postObj.liveType = ""; + } + that.setData({ + postObj : postObj, + showViewType:1 + }) + } + } + }, function(res) { + networkUtil.showErrorToast(res.errormsg) + }) + }, + + onAreaCommit(locationList, e) {//当用户更换地区 + console.log('选择地址后', locationList) + var self = this; + self.addrInfo = { + province: locationList[0] || {}, + city: locationList[1] || {}, + area: locationList[2] || {}, + street: locationList[3] || {}, + } + var address = {} + address.details = '' + for (var i in locationList){ + address.details += locationList[i].name + } + address.addEntry = locationList + if (e.target.dataset.name == 'currentAddress') { + self.setData({ + isShow: 0, + currentAddress: address + }); + } else if (e.target.dataset.name == 'currentAddress1') { + self.setData({ + isShow: 0, + currentAddress1: address + }); + } + }, + checkForm(postData){ + let flag = true; + var data = postData; + var value = ""; + if(!data.mommyCardNo){ + flag = false; + value += "母亲姓名 " + } + if(data.mommyCardNo&&!numberUtil.checkIdCard(data.mommyCardNo,'woman')){ + flag = false; + value += "母亲身份证号码 " + } + if(!(data.phone&&numberUtil.IsTelPhoneNumber(data.phone))){ + flag = false; + value += "母亲手机号 " + } + if(!data.liveType){ + flag = false; + value += "居住属性 " + } + if(!data.babyName){ + flag = false; + value += "儿童姓名 " + } + if (this.data.childCardShow) { + if(data.babyCard&&!numberUtil.validateIdCard(data.babyCard)){ + flag = false; + value += "儿童身份证号码 " + } + } + if(!data.birth){ + flag = false; + value += "出生日期 " + } + if(!data.sex){ + flag = false; + value += "儿童性别 " + } + if(!data.height){ + flag = false; + value += "儿童出生身长 " + } + if(!data.weight){ + flag = false; + value += "儿童出生体重 " + } + if(!this.data.currentAddress.addEntry) { + flag = false; + value += "户籍地址 " + } + if(!data.babyAddress) { + flag = false; + value += "街道门牌 " + } + return { + flag:flag, + value:value + }; + }, + submitData () { + let hospital = this.data.queryData.hospital; + let postData = this.data.postObj; + postData.liveType = liveType; + postData.hospitalId = hospital.hospitalId; + if (this.data.currentAddress.addEntry) { + postData.babyProvinceId = this.data.currentAddress.addEntry[0].id; + postData.babyCityId = this.data.currentAddress.addEntry[1].id; + postData.babyAreaId = this.data.currentAddress.addEntry[2].id; + postData.babyStreetId = this.data.currentAddress.addEntry[3].id; + } + if (this.data.currentAddress1.addEntry) { + postData.provinceId = this.data.currentAddress1.addEntry[0].id; + postData.cityId = this.data.currentAddress1.addEntry[1].id; + postData.areaId = this.data.currentAddress1.addEntry[2].id; + postData.streetId = this.data.currentAddress1.addEntry[3].id; + } + if (postData.vcCardNo===null) { + delete postData.vcCardNo; + } + if (postData.sINCard===null) { + delete postData.sINCard; + } + var key = this.checkForm(postData); + var that = this; + if(key.flag){ + this.setData({ + submiting:true + }) + console.log(postData) + networkUtil._post(api.addBuildArticle, postData , (res)=> { + wx.showModal({ + title: '成功提交', + content: "您已成功预约建档", + showCancel: false, + submiting:false, + success: function (res){ + that.setData({ + babyInfo:postData, + 'babyInfo.hospitalName':that.data.queryData.hospital.hospitalName, + showViewType:2 + }) + } + }) + }, function (res) { + wx.showModal({ + title: '提交失败', + content: '错误信息:'+res.data.errormsg, + showCancel: false, + success: function (res) { + } + }) + },'application/json') + }else{ + wx.showModal({ + title: '表单填写不规范', + content: "这些项目未正确填写:"+key.value, + showCancel: false, + success: function (res) { + } + }) + } + } +})) diff --git a/littleApp_child/packageA/pages/preDocumented/preDocumented.json b/littleApp_child/packageA/pages/preDocumented/preDocumented.json new file mode 100644 index 0000000..9b51d90 --- /dev/null +++ b/littleApp_child/packageA/pages/preDocumented/preDocumented.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "儿童预约建档", + "navigationBarBackgroundColor": "#48C17B", + "navigationBarTextStyle": "white", + "backgroundColor": "#d8dbd4", + "pageOrientation": "auto", + "usingComponents": {} +} diff --git a/littleApp_child/packageA/pages/preDocumented/preDocumented.wxml b/littleApp_child/packageA/pages/preDocumented/preDocumented.wxml new file mode 100644 index 0000000..dd1bab2 --- /dev/null +++ b/littleApp_child/packageA/pages/preDocumented/preDocumented.wxml @@ -0,0 +1,445 @@ + + + + + + + 母亲手机号 + + + + + + + + 建档医院 + + + + + + + + + + + + + * + 母亲姓名 + + + + + + + + + + * + 母亲身份证号 + + + + + + + + + + * + 母亲手机号 + + + + + + + + + + * + 居住属性 + + + + + + + + + + + + 父亲姓名 + + + + + + + + + + 联系方式 + + + + + + + + + + * + 儿童姓名 + + + + + + + + + + 未入户口 + + + + + + + + + + + + * + 儿童身份证号 + + + + + + + + + + * + 儿童出生日期 + + + + + + 请选择出生日期 + {{postObj.birth}} + + + + + + + + * + 儿童性别 + + + + + + + + + + + *儿童出生身长cm + + + + + + + + *儿童出生体重kg + + + + + + + + + 户口性质 + + + + + + + + + + + *户籍地址 + + + 请选择省市区(县) + {{currentAddress.details}} + + + + + *街道门牌 + + + + + + + + + 家庭住址 + + + 请选择省市区(县) + {{currentAddress1.details}} + + + + + 街道门牌 + + + + + + + + + + + + + + + + 母亲姓名 + + + + {{babyInfo.mommyName}} + + + + + + 母亲身份证号码 + + + + {{babyInfo.mommyCardNo}} + + + + + + 母亲手机号 + + + + {{babyInfo.phone}} + + + + + + 居住属性 + + + + 常住 + 流动 + 暂住 + 有居住证 + + + + + + 父亲姓名 + + + + {{babyInfo.fname}} + + + + + + 联系方式 + + + + {{babyInfo.fphone}} + + + + + + 儿童姓名 + + + + {{babyInfo.babyName}} + + + + + + 身份证号 + + + + {{babyInfo.babyCard}} + + + + + + 儿童出生日期 + + + + {{babyInfo.birth}} + + + + + + 儿童性别 + + + + {{babyInfo.sex=='1'?'男':'女'}} + + + + + + 儿童出生身长cm + + + + {{babyInfo.height}} + + + + + + 儿童出生体重kg + + + + {{babyInfo.weight}} + + + + + + 户口性质 + + + 农业 + 非农业 + + + + + 户籍地址 + + + + {{currentAddress.details?currentAddress.details:''}} + + + + + + 街道门牌 + + + {{babyInfo.babyAddress?babyInfo.babyAddress:''}} + + + + + 家庭住址 + + + {{currentAddress1.details?currentAddress1.details:''}} + + + + + 街道门牌 + + + {{babyInfo.address?babyInfo.address:''}} + + + + + 建档医院 + + + {{babyInfo.hospitalName}} + + + + + + + + + + + + + + + diff --git a/littleApp_child/packageA/pages/preDocumented/preDocumented.wxss b/littleApp_child/packageA/pages/preDocumented/preDocumented.wxss new file mode 100644 index 0000000..7c3ebb8 --- /dev/null +++ b/littleApp_child/packageA/pages/preDocumented/preDocumented.wxss @@ -0,0 +1,111 @@ +/* packageA/pages/preDocumented/preDocumented.wxss */ +@import "../../../utils/areaSelector/selector.wxss"; +.Warning{ + font-size: 14px; + padding-left: 10px; + color: #fff; + background-color: #ffc862; +} +.weui-cells{ + padding-right:15px; +} +.weui-cell{ + padding: 10px 0 10px 10px; +} +.page-tt{ + font-size: 18px; +} +.weui-cells{ + margin-top:0; +} +.weui-cell__ft{ + font-size: 14px; + color: #333; +} +.weui-label{ + display: block; + width: 120px!important; +} +.line-tt{ + padding-left: 5px; + color: #505050; + font-size: 14px; +} +.select-placeholder{ + color: #c0c0c0; + font-size: 14px; +} +.query-cell{ + background-color: #fff; + margin: 5px 0px 10px 0px; +} +.query_button { + margin-top:10px; + font: medium; + font-size: 16px; + color: #fff; + width: 30%; + height: 38px; + line-height: 38px; + border-radius: 9rpx; + background-color: #48C17B; + display: inline-block; + text-align: center; + margin-top: 3px; + align-items: center; + margin-left:3%; +} +.we_button { + margin-top:20px; + font: medium; + font-size: 16px; + color: white; + width: 60%; + margin-left:20%; + height: 38px; + line-height: 38px; + border-radius: 19px; + background-color: #48C17B; + display: inline-block; + text-align: center; + /* position: fixed; */ +} +.picker-view{ + font-size: 14px; +} +.radio-group{ + font-size: 14px; +} +.radio{ + width: 90px; + display: inline-block; +} +radio{ + transform:scale(0.8); +} +.pickerBox{ + position: fixed; + bottom: 0; + width: 100%; + z-index: 10; + background: #fff; +} +.pickerButBox{ + height: 38px; + line-height: 38px; + border-bottom: 1px solid #e7e7e7; + width: 100%; + background-color: #fff; +} +.pickerButText{ + font-size: 16px; + margin: 0 10px +} +.pickerButCencle{ + float: left; + color: #333; +} +.pickerButSub{ + float: right; + color: #48C17B; +} diff --git a/littleApp_child/pages/home/home.js b/littleApp_child/pages/home/home.js index 3e40cd5..a56d19e 100644 --- a/littleApp_child/pages/home/home.js +++ b/littleApp_child/pages/home/home.js @@ -184,6 +184,11 @@ Page({ } }, + toPreDoc () { + wx.navigateTo({ + url: '/packageA/pages/preDocumented/preDocumented' + }) + }, getNameFocus: function() { var self = this var inputFocus = { diff --git a/littleApp_child/pages/home/home.wxml b/littleApp_child/pages/home/home.wxml index 3f39eaa..8fc944e 100644 --- a/littleApp_child/pages/home/home.wxml +++ b/littleApp_child/pages/home/home.wxml @@ -211,6 +211,7 @@ + diff --git a/littleApp_child/pages/hospitalList/hospitalList.js b/littleApp_child/pages/hospitalList/hospitalList.js index f138e6a..51cf986 100644 --- a/littleApp_child/pages/hospitalList/hospitalList.js +++ b/littleApp_child/pages/hospitalList/hospitalList.js @@ -40,7 +40,7 @@ Page({ // this.getUserLocation() // this.requestData() }, - + onUnload:function(e){ page = 0 }, @@ -48,25 +48,25 @@ Page({ // 获取地理位置 getUserLocation() { var self = this - wx.getLocation({ - type: 'wgs84', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标 - success: function (res) { - // success - console.log(res) - latitude = res.latitude - longitude = res.longitude - self.requestData() - }, - fail: function (res) { - // fail - console.log(res) - self.requestData() - }, - complete: function (res) { - // complete - console.log(res) - } - }) + // wx.getLocation({ + // type: 'wgs84', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标 + // success: function (res) { + // // success + // console.log(res) + // latitude = res.latitude + // longitude = res.longitude + // self.requestData() + // }, + // fail: function (res) { + // // fail + // console.log(res) + // self.requestData() + // }, + // complete: function (res) { + // // complete + // console.log(res) + // } + // }) // latitude = 115.52 // longitude = 38.23 }, @@ -75,7 +75,7 @@ Page({ var param = { page: page, limit: 15, lat: latitude, lng: longitude} networkUtil._get(api.hospitals, param, function (res) { console.log(res) - + var sumCount = self.paging(res.data.list) if (sumCount < 15) { hasMore = false @@ -91,7 +91,7 @@ Page({ } else { arr = res.data.list } - + self.setData({ hospitalList: arr, hasMore: hasMore @@ -144,4 +144,4 @@ Page({ url: "../hospital_detail/hospital_detail?id="+id }) } -}) \ No newline at end of file +}) diff --git a/littleApp_child/project.config.json b/littleApp_child/project.config.json index 9d44e11..12fdff8 100644 --- a/littleApp_child/project.config.json +++ b/littleApp_child/project.config.json @@ -4,7 +4,7 @@ "ignore": [] }, "setting": { - "urlCheck": true, + "urlCheck": false, "es6": true, "enhance": true, "postcss": true, diff --git a/littleApp_child/utils/apiFile.js b/littleApp_child/utils/apiFile.js index 292869f..4d8a9ba 100644 --- a/littleApp_child/utils/apiFile.js +++ b/littleApp_child/utils/apiFile.js @@ -89,6 +89,8 @@ module.exports = { goodsbuy: 'goods/buy', //儿童建档-提交建档信息 addBabyInfo:'baby/addBabyInfo', + // 儿童建档-预约建档 + addBuildArticle: 'baby/babyBuildArticle', //儿童建档-修改户籍地址 editAddress: '/baby/updateKosekiInfo', //儿童疾病护理获取医生列表 diff --git a/littleApp_child/utils/network_util.js b/littleApp_child/utils/network_util.js index 5ff09df..09047c9 100644 --- a/littleApp_child/utils/network_util.js +++ b/littleApp_child/utils/network_util.js @@ -17,7 +17,7 @@ function kServerBaseUrl() { case 3: return 'https://weixin-bj.healthbaby.com.cn/'; case 4: - return 'http://192.168.2.5:9090/member/' + return 'http://localhost:9090/mombaby/' } } diff --git a/littleApp_child/utils/numberUtil.js b/littleApp_child/utils/numberUtil.js index 742f423..8f760d8 100644 --- a/littleApp_child/utils/numberUtil.js +++ b/littleApp_child/utils/numberUtil.js @@ -2,10 +2,10 @@ var week = ['日', '一', '二', '三', '四', '五', '六'] // 判断手机号 function IsTelPhoneNumber(Tel){ - if(!(/^1\d{10}$/.test(Tel))){ - - return false; - } + if(!(/^1\d{10}$/.test(Tel))){ + + return false; + } return true } @@ -29,7 +29,7 @@ function calculateGestationalWeekDay(time){ // 计算2天的时间间隔 function calculateTimeInterval(before,later){ - + var laterDate = new Date(later) var beforeDate = new Date(before) // 去掉多余的时分秒 @@ -71,7 +71,7 @@ function healthRating_getRiskInfo(highRisk){ color:'page3_-image_qingdu_y_n@3x.png'},{name:'严重风险', color:'page3_-image_yanzhong_p_n@3x.png'},{name:'健康', color:'page3_-image_jiankang_g_n@3x.png'}] - // 健康 轻度 中度 重度 严重 + // 健康 轻度 中度 重度 严重 if(level&8){ return highRiskLevel[3] } @@ -92,7 +92,7 @@ function healthRating_getRiskInfo(highRisk){ function home_getRiskInfo(level){ var color = [{image:'../../source/imageSource/page1_yunqi_green_Image@3x.png',color:'#43bf67'},{image:'../../source/imageSource/page1_yunqi_yellow_Image_n@3x.png',color:'#ffb42e'},{image:'../../source/imageSource/page1_yunqi_orange_Image_n@3x.png',color:'#ff7f29'},{image:'../../source/imageSource/page1_yunqi_red_Image_n@3x.png',color:'#ff6969'},{image:'../../source/imageSource/page1_yunqi_purple_Image_n@3x.png',color:'#c65dbc'}] - // 健康 轻度 中度 重度 严重 + // 健康 轻度 中度 重度 严重 if(level&8){ return color[4] } @@ -111,67 +111,67 @@ function home_getRiskInfo(level){ return color[0] } -function DateAdd(interval,number,date) -{ -/* - * 功能:实现Script的DateAdd功能. - * 参数:interval,字符串表达式,表示要添加的时间间隔. - * 参数:number,数值表达式,表示要添加的时间间隔的个数. - * 参数:date,时间对象. - * 返回:新的时间对象. - * var now = new Date(); - * var newDate = DateAdd( "d ",5,now); - *--------------- DateAdd(interval,number,date) ----------------- - */ - switch(interval) - { - case "y " : { - date.setFullYear(date.getFullYear()+number); - return date; - break; - } - case "q " : { - date.setMonth(date.getMonth()+number*3); - return date; - break; - } - case "m " : { - date.setMonth(date.getMonth()+number); - return date; - break; - } - case "w " : { - date.setDate(date.getDate()+number*7); - return date; - break; - } - case "d " : { - date.setDate(date.getDate()+number); - return date; - break; - } - case "h " : { - date.setHours(date.getHours()+number); - return date; - break; - } - case "m " : { - date.setMinutes(date.getMinutes()+number); - return date; - break; - } - case "s " : { - date.setSeconds(date.getSeconds()+number); - return date; - break; - } - default : { - date.setDate(date.getDate()+number); - return date; - break; - } - } -} +function DateAdd(interval,number,date) +{ +/* + * 功能:实现Script的DateAdd功能. + * 参数:interval,字符串表达式,表示要添加的时间间隔. + * 参数:number,数值表达式,表示要添加的时间间隔的个数. + * 参数:date,时间对象. + * 返回:新的时间对象. + * var now = new Date(); + * var newDate = DateAdd( "d ",5,now); + *--------------- DateAdd(interval,number,date) ----------------- + */ + switch(interval) + { + case "y " : { + date.setFullYear(date.getFullYear()+number); + return date; + break; + } + case "q " : { + date.setMonth(date.getMonth()+number*3); + return date; + break; + } + case "m " : { + date.setMonth(date.getMonth()+number); + return date; + break; + } + case "w " : { + date.setDate(date.getDate()+number*7); + return date; + break; + } + case "d " : { + date.setDate(date.getDate()+number); + return date; + break; + } + case "h " : { + date.setHours(date.getHours()+number); + return date; + break; + } + case "m " : { + date.setMinutes(date.getMinutes()+number); + return date; + break; + } + case "s " : { + date.setSeconds(date.getSeconds()+number); + return date; + break; + } + default : { + date.setDate(date.getDate()+number); + return date; + break; + } + } +} function getMonthAllDayWithDate(date){ //d.getMonth()+1代表下个月,月份索引从0开始,即当前月为6月时,getMonth()返回值为5,创建日期时同理 @@ -192,7 +192,7 @@ function toDecimal(x) { } f = Math.round(x * 100) / 100; return f; -} +} // 获取最近一周 function getLatestWeek() { @@ -215,7 +215,7 @@ function getLatestWeek() { } } return weekList; -} +} function getLatestMonth() { var list = [] @@ -230,7 +230,7 @@ function getLatestMonth() { list.push(dayInfo) } return list; -} +} /** * 检查身份证合法 @@ -421,6 +421,128 @@ function checkIdCard(str_idCard, sex) { return false; } +function validateIdCard(idCard){ + var vcity={ 11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古", + 21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏", + 33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南", + 42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆", + 51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃", + 63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外" + }; + //是否为空 + if(idCard === ''){ + return false; + } + //校验长度,类型 + if(isCardNo(idCard) === false){ + return false; + } + //检查省份 + if(checkProvince(idCard,vcity) === false){ + return false; + } + //校验生日 + if(checkBirthday(idCard) === false){ + return false; + } + //检验位的检测 + if(checkParity(idCard) === false){ + return false; + } + return true; +} +function isCardNo(card){ + //身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X + var reg = /(^\d{15}$)|(^\d{17}(\d|X|x)$)/; + if(reg.test(card) === false){ + return false; + } + return true; +} +function checkProvince(card,vcity){ + var province = card.substr(0,2); + if(vcity[province] == undefined){ + return false; + } + return true; +}; +function checkBirthday(card){ + var len = card.length; + //身份证15位时,次序为省(3位)市(3位)年(2位)月(2位)日(2位)校验位(3位),皆为数字 + if(len == '15'){ + var re_fifteen = /^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/; + var arr_data = card.match(re_fifteen); + var year = arr_data[2]; + var month = arr_data[3]; + var day = arr_data[4]; + var birthday = new Date('19'+year+'/'+month+'/'+day); + return verifyBirthday('19'+year,month,day,birthday); + } + //身份证18位时,次序为省(3位)市(3位)年(4位)月(2位)日(2位)校验位(4位),校验位末尾可能为X + if(len == '18'){ + var re_eighteen = /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X|x)$/; + var arr_data = card.match(re_eighteen); + var year = arr_data[2]; + var month = arr_data[3]; + var day = arr_data[4]; + var birthday = new Date(year+'/'+month+'/'+day); + return verifyBirthday(year,month,day,birthday); + } + return false; +}; +function verifyBirthday(year,month,day,birthday) +{ + var now = new Date(); + var now_year = now.getFullYear(); + //年月日是否合理 + if(birthday.getFullYear() == year && (birthday.getMonth() + 1) == month && birthday.getDate() == day) + { + //判断年份的范围(0岁到100岁之间) + var time = now_year - year; + if(time >= 0 && time <= 100) + { + return true; + } + return false; + } + return false; +} +function checkParity(card){ + //15位转18位 + card = changeFivteenToEighteen(card); + var len = card.length; + if(len == '18'){ + var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); + var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'); + var cardTemp = 0, i, valnum; + for(i = 0; i < 17; i ++) { + cardTemp += card.substr(i, 1) * arrInt[i]; + } + valnum = arrCh[cardTemp % 11]; + if (valnum == card.substr(17, 1).toLocaleUpperCase()) + { + return true; + } + return false; + } + return false; +} +function changeFivteenToEighteen(card){ + if(card.length == '15') + { + var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); + var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'); + var cardTemp = 0, i; + card = card.substr(0, 6) + '19' + card.substr(6, card.length - 6); + for(i = 0; i < 17; i ++) + { + cardTemp += card.substr(i, 1) * arrInt[i]; + } + card += arrCh[cardTemp % 11]; + return card; + } + return card; +} module.exports = { // 判断是不是手机号 @@ -434,7 +556,7 @@ module.exports = { // 计算孕周余天 calculateGestationalWeekDay : calculateGestationalWeekDay, home_getRiskInfo : home_getRiskInfo, - + healthRating_getRiskInfo : healthRating_getRiskInfo, DateAdd : DateAdd, // 保留一位小数 @@ -442,5 +564,6 @@ module.exports = { getMonthAllDayWithDate: getMonthAllDayWithDate, getLatestWeek: getLatestWeek, getLatestMonth: getLatestMonth, - checkIdCard: checkIdCard -} \ No newline at end of file + checkIdCard: checkIdCard, + validateIdCard: validateIdCard +} -- 1.8.3.1