@@ -58,6 +58,7 @@
import { RadioGroup, Radio, Icon, Dialog } from 'vant'
import { changeEdor, policyInfo } from '@/api/ebiz/preserve/preserve'
import filters from '@/views/ebiz/preserve/filters'
+import businessCommon from '../js/business-common'
export default {
name: 'BeneficiaryInfo',
@@ -75,10 +76,9 @@ export default {
isDisType: false,
policy: null,
customerInfo: {}, //客户详情
- insuredInfo: {}, //被保险人信息
- appntInfo: {}, //投保人信息
insuredName: '', //被保险人
- beneficiaries: [] // 指定受益人列表
+ beneficiariesOld: [], // 变更前指定受益人列表
+ beneficiariesNew: [] // 变更后指定受益人列表
}
},
async created() {
@@ -86,8 +86,9 @@ export default {
this.customerInfo = JSON.parse(localStorage['preserve-customerInfo']) //客户详情
this.policy = JSON.parse(localStorage['preserve-policy'])
if (localStorage.fromAddBC) {
- this.beneficiaries = this.policy.bnfDTOs
- this.type = this.beneficiaries.some(i => {
+ this.beneficiariesNew = this.policy.bnfDTOs.beneficiariesNew
+ this.beneficiariesOld = this.policy.bnfDTOs.beneficiariesOld
+ this.type = this.beneficiariesNew.some(i => {
//isLegal:法定标记 1-是法定受益人 0-是指定受益人
return i.isNewInfo == '0' && i.isLegal == '0' //新增受益人存在指定受益人
})
@@ -95,11 +96,14 @@ export default {
: '1'
} else {
await this.getPolicyInfo()
- this.type = this.beneficiaries.some(i => {
+ this.type = this.beneficiariesOld.some(i => {
return i.isNewInfo == '1' && i.isLegal == '0' //初始化受益人存在指定受益人
})
? '2'
: '1'
+ if (this.type == '1') {
+ this.beneficiariesNew = []
+ }
}
this.insuredName = this.policy.insuredName
if (this.type == 2) {
@@ -121,17 +125,16 @@ export default {
policyInfo(data).then(
res => {
if (res.result == '0') {
- this.beneficiaries = res.content.cont.bcBnfList
- this.riskList = res.content.cont.riskList
- this.insuredInfo = res.content.cont.insuredList[0]
- this.appntInfo = res.content.cont.appnt
- this.policy.appntInfo = this.appntInfo
- this.policy.insuredInfo = this.insuredInfo
- localStorage['preserve-policy'] = JSON.stringify(this.policy)
- //isNewInfo 是否新信息 0-是 1-否
- this.beneficiaries.forEach(item => {
+ res.content.cont.bcBnfList.forEach(item => {
+ //isNewInfo 是否新信息 0-是 1-否
item.isNewInfo = '1'
})
+ this.beneficiariesOld = [...res.content.cont.bcBnfList]
+ this.beneficiariesNew = [...res.content.cont.bcBnfList]
+ this.riskList = res.content.cont.riskList
+ this.policy.appntInfo = res.content.cont.appnt //投保人信息
+ this.policy.insuredInfo = res.content.cont.insuredList[0] //被保险人信息
+ localStorage['preserve-policy'] = JSON.stringify(this.policy)
resolve()
} else {
reject(this.$toast(res.content))
@@ -145,29 +148,33 @@ export default {
},
//下一步
nextStep() {
- if (this.type == 2 && this.beneficiaries.length < 1) {
+ if (this.type == 2 && this.beneficiariesNew.length < 1) {
this.$toast('受益人列表不能为空')
return
}
let beneRatio = 0
- this.beneficiaries.forEach(item => {
+ this.beneficiariesNew.forEach(item => {
beneRatio += Number(item.bnfLot)
})
if (beneRatio != 100 && this.type == 2) {
return (this.dialogShow = true)
}
+ let beneficiaries = [...this.beneficiariesOld, ...this.beneficiariesNew]
+ beneficiaries = businessCommon.unrepeatObj(beneficiaries, 'idNo')
let feachData = {
platformType: 'app',
edorType: 'BC',
operateType: '01',
- bcBnfDTOList: this.beneficiaries
+ bcBnfDTOList: beneficiaries
}
changeEdor(feachData).then(
res => {
if (res.result == 0) {
- this.policy.bnfDTOs = this.beneficiaries
+ this.policy.bnfDTOs = {
+ beneficiariesOld: this.beneficiariesOld,
+ beneficiariesNew: this.beneficiariesNew
+ }
localStorage['preserve-policy'] = JSON.stringify(this.policy)
- localStorage.removeItem('fromAddBC')
this.customerInfo.surrenderId = res.content.surrenderId
this.customerInfo.edorApplyNo = res.content.edorApplyNo
localStorage.setItem('preserve-customerInfo', JSON.stringify(this.customerInfo))
@@ -197,13 +204,16 @@ export default {
//添加受益人
add() {
let beneRatio = 0
- this.beneficiaries.forEach(item => {
+ this.beneficiariesNew.forEach(item => {
beneRatio += parseFloat(item.bnfLot | 0)
})
if (beneRatio >= 100) {
return this.$toast('受益份额已满~')
}
- this.policy.bnfDTOs = this.beneficiaries
+ this.policy.bnfDTOs = {
+ beneficiariesOld: this.beneficiariesOld,
+ beneficiariesNew: this.beneficiariesNew
+ }
this.checkIsDetail(this.riskList)
localStorage['preserve-policy'] = JSON.stringify(this.policy)
this.$jump({
@@ -227,8 +237,11 @@ export default {
})
.then(() => {
// 删除页面中的对应数据
- this.beneficiaries.splice(index, 1)
- this.policy.bnfDTOs = this.beneficiaries
+ this.beneficiariesNew.splice(index, 1)
+ this.policy.bnfDTOs = {
+ beneficiariesOld: this.beneficiariesOld,
+ beneficiariesNew: this.beneficiariesNew
+ }
localStorage['preserve-policy'] = JSON.stringify(this.policy)
})
.catch(() => {
@@ -237,7 +250,10 @@ export default {
},
// 编辑受益人
editBeneficiary(index) {
- this.policy.bnfDTOs = this.beneficiaries
+ this.policy.bnfDTOs = {
+ beneficiariesOld: this.beneficiariesOld,
+ beneficiariesNew: this.beneficiariesNew
+ }
this.checkIsDetail(this.riskList)
localStorage['preserve-policy'] = JSON.stringify(this.policy)
let path = '/preserve/bc/BeneficiaryInfoAdd?edit=' + index
diff --git a/src/views/ebiz/preserve/bc/BeneficiaryInfoAdd.vue b/src/views/ebiz/preserve/bc/BeneficiaryInfoAdd.vue
index 518ad6b06..b83aff768 100644
--- a/src/views/ebiz/preserve/bc/BeneficiaryInfoAdd.vue
+++ b/src/views/ebiz/preserve/bc/BeneficiaryInfoAdd.vue
@@ -101,16 +101,7 @@
长期
-
+
{
- if (i.idExpDate == '9999-01-01') {
- i.effectiveDateType = true
- }
- })
+ if (this.bnfDTOs.length > 0) {
+ this.bnfDTOs.map(i => {
+ if (i.idExpDate == '9999-01-01') {
+ i.effectiveDateType = true
+ }
+ })
+ }
if (this.$route.query.edit) {
this.editIndex = this.$route.query.edit
this.userInfo = this.bnfDTOs[this.$route.query.edit]
+ this.userInfo.isNewInfo = '0'
}
},
mounted() {},
@@ -546,8 +540,8 @@ export default {
} else {
this.bnfDTOs[this.editIndex] = this.userInfo
}
- this.policy.bnfDTOs = this.bnfDTOs
- this.policy.bnfDTOs.map(i => {
+ this.policy.bnfDTOs.beneficiariesNew = this.bnfDTOs
+ this.policy.bnfDTOs.beneficiariesNew.map(i => {
if (i.effectiveDateType) {
i.idExpDate = '9999-01-01'
}
diff --git a/src/views/ebiz/preserve/bc/BeneficiaryInfoDetail.vue b/src/views/ebiz/preserve/bc/BeneficiaryInfoDetail.vue
index 41525788c..b79c4a35d 100644
--- a/src/views/ebiz/preserve/bc/BeneficiaryInfoDetail.vue
+++ b/src/views/ebiz/preserve/bc/BeneficiaryInfoDetail.vue
@@ -3,85 +3,40 @@
-
-
-
-
-
-
- 长期
-
+
+
+
+
+
+
+
+
+ 长期
+
-
+
-
-
-
+
+
+
+
@@ -154,16 +102,11 @@ import { Field, CellGroup, Checkbox, Popup, Picker, Area } from 'vant'
import SelectRadio from '@/components/ebiz/SelectRadio'
import FieldDatePicter from '@/components/ebiz/FieldDatePicter'
import OccupationPicker from '@/components/ebiz/occipation/OccupationPicker'
-import DataDictionary from '@/assets/js/utils/data-dictionary'
import areaList from '@/assets/js/utils/area'
-import getAreaName from '@/assets/js/utils/get-area-name'
-import utilsAge from '@/assets/js/utils/age'
import IdentityCardScan from '@/components/ebiz/sale/IdentityCardScan'
import CustomerPicker from '@/components/ebiz/customer/CustomerPicker'
-import idNoCheck from '@/assets/js/utils/idNoCheck'
-import { idToData } from '../js/verification'
-import { selectComp } from '../js/methods'
-let relationToInsured = DataDictionary.relationToAppnt
+import filters from '@/views/ebiz/preserve/filters'
+import getAreaName from '@/views/ebiz/preserve/js/utils/get-area-name'
export default {
name: 'beneficiaryInfoAdd',
@@ -182,8 +125,6 @@ export default {
},
data() {
return {
- effectiveDateTypeAble: true, //长期按钮是否禁用
- isScan: false, //是否显示证件扫描组件
sexRadio: [
{
label: '男',
@@ -194,79 +135,57 @@ export default {
value: '1'
}
],
- currentPopupIndex: '',
- relationToAppnt: '',
- popupShow: false,
- areaShow: false,
- pickerType: undefined,
- columns: [],
- valueKey: 'text',
- nationality: '',
- idType: '居民身份证',
- degree: '',
- socialSecurity: '',
- taxIdentity: '',
+ isDetailFlag: '',
areaName: '',
- areaValue: '110101',
effectiveDateRequired: true, //证件截止日期是否需要校验
effectiveDateShow: true, //证件截止日期是否可以选择
- marriage: '',
isRequired: '', //长期前是否有*
userInfo: {
- bnfId: '',
- bnfType: '2',
+ bnfType: '1', //受益人类别 0-生存受益人 1-身故受益人
+ isLegal: '0', //1-法定受益人 0-指定受益人
+ // bnfNo: '1',
+ relationToInsured: '', //受益人和被保人关系
+ bnfOrder: '1',
bnfGrade: '',
name: '',
sex: '0',
- nationality: '1',
- birthday: '',
+ isNewInfo: '0', //是否是新信息 0-是 1-否
idType: '1',
idNo: '',
- certificateValidate: '',
- effectiveDate: '',
- effectiveDateType: false, //是否长期
- bnfNo: '1',
- bnfOrder: 1,
- bnfLot: '',
+ idExpDate: '', //证件截止日期
phone: '',
+ birthday: '',
+ nativeplace: '1',
+ email: '',
province: '',
city: '',
- area: '',
- postalAddress: '',
- email: '',
+ postalAddress: '', //详细地址
occupationCode: '',
- occupationName: '' // 职业中文
+ occupationType: '',
+ occupationName: '',
+ area: '',
+ bnfLot: '', //受益比例
+ effectiveDateType: false //是否长期
},
areaList: areaList,
occupationShowPicker: false,
customerShowPicker: false, //客户列表展示
idLimit: false, //证件起止日期是否只读
- policy: null,
- bnfDTOs: []
+ policy: JSON.parse(localStorage['preserve-policy']),
+ fileList: []
}
},
created() {
- this.policy = JSON.parse(localStorage['preserve-policy'])
- this.bnfDTOs = this.policy.bnfDTOs.filter(i => {
- return i.isNewInfo == '0'
- })
+ this.isDetailFlag = this.policy.isDetailFlag
if (this.$route.query.edit) {
this.editIndex = this.$route.query.edit
- this.userInfo = this.bnfDTOs[this.$route.query.edit]
+ this.userInfo = this.policy.bnfDTOs.beneficiariesNew[this.$route.query.edit]
+ this.userInfo.effectiveDateType = this.userInfo.idExpDate == '9999-01-01' ? true : false
}
+ this.areaName = getAreaName([{ code: this.userInfo.province }, { code: this.userInfo.city }, { code: this.userInfo.area }])
},
mounted() {},
methods: {
- chooseOccupation() {
- this.$jump({
- flag: 'navigation',
- extra: {
- title: '指定受益人信息',
- hiddenRight: '1'
- }
- })
- this.occupationShowPicker = false
- },
//时间戳格式处理
timeStampFormat(timeStamp) {
let date = new Date(timeStamp)
@@ -277,6 +196,9 @@ export default {
day = day.toString().padStart(2, '0')
return `${year}-${month}-${day}`
}
+ },
+ filters: {
+ idToText: filters.idToText
}
}
diff --git a/src/views/ebiz/preserve/ct/SurrenderInfo.vue b/src/views/ebiz/preserve/ct/SurrenderInfo.vue
index af240dfb2..f094f3814 100644
--- a/src/views/ebiz/preserve/ct/SurrenderInfo.vue
+++ b/src/views/ebiz/preserve/ct/SurrenderInfo.vue
@@ -102,8 +102,8 @@
maxlength="200"
name="其他退保原因"
placeholder="请输入其他退保原因"
- v-validate="surrenderReasonType == '6' ? 'required' : ''"
- v-if="surrenderReasonType == '6'"
+ v-validate="surrenderReasonType == '06' ? 'required' : ''"
+ v-if="surrenderReasonType == '06'"
/>
diff --git a/src/views/ebiz/preserve/js/business-common.js b/src/views/ebiz/preserve/js/business-common.js
new file mode 100644
index 000000000..9d40c2493
--- /dev/null
+++ b/src/views/ebiz/preserve/js/business-common.js
@@ -0,0 +1,534 @@
+// import utilsAge from '@/assets/js/utils/age'
+/**
+ * @desc 扩展对象继承
+ * @param {Object} out 一个或多个对象
+ * @return {Object} 对象
+ */
+Object.extend = function(out) {
+ out = out || {}
+ for (var i = 1; i < arguments.length; i++) {
+ if (!arguments[i]) continue
+
+ for (var key in arguments[i]) {
+ if (arguments[i].hasOwnProperty(key)) out[key] = arguments[i][key]
+ }
+ }
+ return out
+}
+
+/**
+ * @desc 时间格式转化
+ * @param {String} format 转化格式
+ * @return {String} 已转化的时间
+ */
+Date.prototype.format = function(format) {
+ let args = {
+ 'M+': this.getMonth() + 1,
+ 'd+': this.getDate(),
+ 'h+': this.getHours(),
+ 'm+': this.getMinutes(),
+ 's+': this.getSeconds(),
+ 'q+': Math.floor((this.getMonth() + 3) / 3), // quarter
+ S: this.getMilliseconds()
+ }
+ if (/(y+)/.test(format)) format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length))
+ for (var i in args) {
+ var n = args[i]
+ if (new RegExp('(' + i + ')').test(format)) format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? n : ('00' + n).substr(('' + n).length))
+ }
+ return format
+}
+
+export default {
+ /**
+ * @desc 判断对象是否为空
+ * @param {Object} o 对象
+ * @return {Boolean}
+ */
+ isEmptyObject(o = {}) {
+ let flag = true
+ for (let k in o) {
+ if (k) {
+ flag = false
+ break
+ }
+ }
+ return flag
+ },
+
+ /**
+ * @description 去除前后空格
+ * @param {String} 值
+ * @return {String}
+ */
+ trim(val) {
+ return val.replace(/(^\s*)|(\s*$)/g, '')
+ },
+
+ // 获取query特定参数
+ getQueryParameter() {
+ let activityFromApp = this.getQuery().activityFromApp
+ let appUserToken = this.getQuery().appUserToken
+ let env = this.getQuery().env
+ let query = {}
+ if (activityFromApp) {
+ query.activityFromApp = activityFromApp
+ }
+ if (appUserToken) {
+ query.appUserToken = decodeURIComponent(appUserToken.replace(/%20/g, '+'))
+ }
+ if (env) {
+ query.env = env
+ }
+ return query
+ },
+
+ /**
+ * 替换字符串具体位置字符
+ * @param {String} str 目标字符串
+ * @param {String} char 字符
+ * @param {Number} start 数组开始索引
+ * @param {Number} end 数组结束索引
+ * @return {[type]} [description]
+ */
+ replaceChar(str = '', char = '*', start = 0, end) {
+ let list = []
+ if (str) {
+ list = str.split('')
+ let len = list.length
+ start = start > 0 ? (start <= len ? start : len) : 0
+ end = end ? (end > start ? end : start) : len
+ for (let i = 0; i < len; i++) {
+ if (i >= start && i < end) {
+ list[i] = char
+ }
+ }
+ }
+ return list.join('')
+ },
+
+ addSpace(value) {
+ if (value) {
+ return value.replace(/\s/g, '').replace(/(.{4})/g, '$1 ')
+ }
+ return value
+ },
+
+ // 字符省略
+ ellipsis(value = '', num = -1) {
+ if (value) {
+ let str = ''
+ if (num > 0 && value.length > num) {
+ str = '...'
+ }
+ return value.slice(0, num) + str
+ }
+ return value
+ },
+
+ /**
+ * @desc 获取 cookie
+ * @param {String}
+ * @return {*}
+ */
+ getCookie(name1) {
+ let rs = ''
+ var name = name1 + '='
+ var ca = document.cookie.split(';')
+ for (var i = 0; i < ca.length; i++) {
+ var c = ca[i]
+ while (c.charAt(0) == ' ') {
+ c = c.substring(1)
+ }
+ if (c.indexOf(name) != -1) {
+ rs = this._string2json(c.substring(name.length, c.length))
+ }
+ }
+ return rs
+ },
+
+ /**
+ * @desc 设置 cookie
+ * @param {String} name 名称
+ * @param {*} value 值
+ * @param {Number} hours 时长
+ */
+ setCookie(name, value, hours) {
+ let str = name + '=' + this._json2string(value)
+ if (hours && hours > 0) {
+ var date = new Date()
+ date.setTime(date.getTime() + hours * 3600 * 1000)
+ str += '; expires=' + date.toUTCString()
+ }
+ document.cookie = str
+ },
+
+ /**
+ * @desc 清除 cookie
+ * @param {String} 名称
+ */
+ delCookie(name) {
+ var date = new Date()
+ date.setTime(date.getTime() - 10000)
+ document.cookie = name + '=a; expires=' + date.toGMTString()
+ },
+
+ /**
+ * @desc 获取 localStorage 中指定的变量
+ * @param {String} name 名称
+ * @return {*} rs
+ */
+ getStorage(name) {
+ return this._string2json(window.localStorage[name])
+ },
+
+ /**
+ * @desc 设置或添加 localStorage 中指定的变量
+ * @param {String} name 名称
+ */
+ setStorage(name, value) {
+ window.localStorage[name] = this._json2string(value)
+ },
+
+ /**
+ * @desc 删除 localStorage 中指定的变量
+ * @param {String} name 名称
+ */
+ delStorage(name) {
+ window.localStorage.removeItem(name)
+ },
+
+ /**
+ * @desc json转string
+ * @param {*} value 值
+ * @return {*} value 值
+ */
+ _json2string(value) {
+ return JSON.stringify(value)
+ },
+ /**
+ * 获取设备类型
+ */
+ device() {
+ let ua = navigator.userAgent
+ return {
+ isChrome: ua.match(/Chrome\/([\d.]+)/) || ua.match(/CriOS\/([\d.]+)/),
+ // eslint-disable-next-line no-useless-escape
+ isAndroid: ua.match(/(Android);?[\s\/]+([\d.]+)?/),
+ isIphone: ua.indexOf('iPhone') != -1,
+ isWeixin: ua.match(/MicroMessenger/i)
+ }
+ },
+ /**
+ * 设置title
+ */
+ setTitle(title) {
+ let device = this.device()
+ if (device.isIphone && device.isWeixin) {
+ document.title = title
+ var i = document.createElement('iframe')
+ i.src = '/favicon.ico'
+ i.style.display = 'none'
+ i.onload = function() {
+ setTimeout(function() {
+ i.remove()
+ }, 9)
+ }
+ document.body.appendChild(i)
+ } else {
+ document.title = title
+ }
+ },
+ /**
+ * @desc string转json
+ * @param {*} value 值
+ * @return {*} value 值
+ */
+ _string2json(value) {
+ try {
+ value = JSON.parse(value)
+ } catch (e) {
+ //console.log(e)
+ }
+ return value
+ },
+ /**
+ *@desc 只能输入单词字符
+ *@param { String } value
+ */
+ character(value) {
+ if (value) {
+ value = value.replace(/[^A-Za-z0-9]/g, '')
+ }
+ return value
+ },
+
+ m2km(value) {
+ if (value < 1000) return value + 'm'
+ else if (value >= 1000 && value <= 20000) return (value / 1000).toFixed(1) + 'km'
+ else if (value >= 2000) return '>20km'
+ return value
+ },
+
+ /**
+ * 除法
+ * @param {Number} dividend 被除数
+ * @param {Number} divisor 除数
+ * @return {Number} 值
+ */
+ divide(dividend, divisor = 100) {
+ if (dividend && divisor) {
+ dividend = Number(dividend)
+ return this.toFloatFixed(dividend / divisor)
+ }
+ return dividend
+ },
+
+ // 保留小数位,替代Number.toFixed()方法,针对于某些数据(16.455)不能做到四舍五入
+ toFixed(value, num = 0) {
+ let pos = value.toString().indexOf('.')
+ let decimalPlaces = value.toString().length - pos - 1
+ let intValue = value * Math.pow(10, decimalPlaces)
+ let divisor1 = Math.pow(10, decimalPlaces - num)
+ let divisor2 = Math.pow(10, num)
+ return Math.round(intValue / divisor1) / divisor2
+ },
+
+ /**
+ * 获取App信息
+ */
+ detectApp() {
+ var ua = navigator.userAgent
+ //RegExp.$1; RegExp.$2; RegExp.$3;
+ //var info = ua.match(/(CarmeApp)\s*[v]*(\d+\.\d+\.\d+)\s*\/\s*(IOS|Android)/i)
+ ua.match(/(CarmeApp)\s*[v]*(\d+\.\d+\.\d+)\s*\/\s*(IOS|Android)/i)
+ return {
+ appName: RegExp.$1,
+ appVersion: RegExp.$2,
+ appOS: RegExp.$3
+ }
+ },
+
+ /**
+ * 如果是小数则保留小数位,默认两位
+ * @param {[type]} value [description]
+ * @param {Number} num [description]
+ * @return {[type]} [description]
+ */
+ toFloatFixed(value, num = 2) {
+ let values = Number(value)
+ if (values) {
+ if (/^\d+\.\d+/.test(values)) {
+ return this.toFixed(values, num)
+ } else {
+ return this.toFixed(values)
+ }
+ }
+ return value
+ },
+
+ // 获取周
+ getWeek(str) {
+ let rs = ''
+ switch (str + '') {
+ case '1':
+ rs = '一'
+ break
+ case '2':
+ rs = '二'
+ break
+ case '3':
+ rs = '三'
+ break
+ case '4':
+ rs = '四'
+ break
+ case '5':
+ rs = '五'
+ break
+ case '6':
+ rs = '六'
+ break
+ case '7':
+ case '0':
+ rs = '日'
+ break
+ default:
+ break
+ }
+ return rs
+ },
+
+ // 获取补全的时间
+ getTime(str) {
+ if (str < 10) {
+ return '0' + str
+ }
+ return str
+ },
+
+ // 数组去重
+ unrepeat(arr) {
+ if (arr instanceof Array) {
+ let hash = {}
+ let rsArr = []
+ let len = arr.length
+ // eslint-disable-next-line no-unused-vars
+ let type = ''
+ for (let i = 0; i < len; i++) {
+ if (typeof arr[i] == 'string') {
+ type = 'string'
+ }
+ if (!hash[arr[i]]) {
+ hash[arr[i]] = arr[i]
+ rsArr.push(arr[i])
+ }
+ }
+ return rsArr
+ }
+ },
+ // 一层对象数组去重
+ unrepeatObj(arr, key) {
+ if (arr instanceof Array) {
+ let hash = {}
+ let rsArr = []
+ let len = arr.length
+ let type = ''
+ for (let i = 0; i < len; i++) {
+ if (typeof arr[i] == 'string') {
+ type = 'string'
+ }
+ if (!hash[arr[i][key]]) {
+ hash[arr[i][key]] = arr[i]
+ rsArr.push(arr[i])
+ }
+ }
+ return rsArr
+ }
+ },
+ /**
+ @desc:只能输入整数
+ @param
+ value 操作数值
+ max 最大值
+ **/
+ intOnly(value, max = Infinity, min = 0) {
+ if (value) {
+ let regular0 = /^0{1,}$/
+ if (regular0.test(value)) {
+ // 如果输入1个0以上,去除掉
+ value = value.replace(/^0{1,}$/, '')
+ }
+ if (/[^0-9]*$/.test(value)) {
+ value = value.replace(/\D/g, '')
+ } else {
+ if (value > max) value = value.substr(0, value.length - 1)
+ if (value < min) value = min
+ }
+ }
+ return value
+ },
+
+ //解析url参数
+ getQuery() {
+ var query = []
+ // 当url是通过传参过来的话,我们把第一个参数作为url并进行解析
+ if (arguments[0]) {
+ let lnk = document.createElement('a')
+ lnk.href = arguments[0]
+ query = this.extractQuery(lnk)
+ } else {
+ /*
+ var query = window.location.search.split('?');
+ if(query.length <= 1) query = window.location.hash.split('#');
+ query = query.length > 1 ? query[1].split('&') : []
+ */
+ query = this.extractQuery(window.location)
+ }
+
+ var json = {}
+ for (var i = 0, len = query.length; i < len; i++) {
+ var key = query[i].split('=')[0],
+ index = query[i].indexOf('='),
+ value = query[i].substr(index + 1)
+ json[key] = value
+ }
+
+ return json
+ },
+ extractQuery(lnk) {
+ var query = lnk.search.split('?')
+ //url/#/repairBooking?activityFromApp=1
+ if (query.length <= 1) query = lnk.hash.split('?')
+ query = query.length > 1 ? query[1].split('&') : []
+
+ return query
+ },
+ formatDate(date, fmt) {
+ date = date == undefined ? new Date() : date
+ date = typeof date == 'number' ? new Date(date) : date
+ fmt = fmt || 'yyyy-MM-dd HH:mm:ss'
+ var obj = {
+ y: date.getFullYear(), // 年份,注意必须用getFullYear
+ M: date.getMonth() + 1, // 月份,注意是从0-11
+ d: date.getDate(), // 日期
+ q: Math.floor((date.getMonth() + 3) / 3), // 季度
+ w: date.getDay(), // 星期,注意是0-6
+ H: date.getHours(), // 24小时制
+ h: date.getHours() % 12 == 0 ? 12 : date.getHours() % 12, // 12小时制
+ m: date.getMinutes(), // 分钟
+ s: date.getSeconds(), // 秒
+ S: date.getMilliseconds() // 毫秒
+ }
+ var week = ['天', '一', '二', '三', '四', '五', '六']
+ for (var i in obj) {
+ fmt = fmt.replace(new RegExp(i + '+', 'g'), function(m) {
+ var val = obj[i] + ''
+ if (i == 'w') return (m.length > 2 ? '星期' : '周') + week[val]
+ for (var j = 0, len = val.length; j < m.length - len; j++) val = '0' + val
+ return m.length == 1 ? val : val.substring(val.length - m.length)
+ })
+ }
+ return fmt
+ },
+ /*根据出生日期算出年龄*/
+ jsGetAge(strBirthday) {
+ var returnAge
+ var strBirthdayArr = strBirthday.split('-')
+ var birthYear = strBirthdayArr[0]
+ var birthMonth = strBirthdayArr[1]
+ var birthDay = strBirthdayArr[2]
+
+ let 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 //返回周岁年龄
+ }
+}