You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
207 lines
6.0 KiB
207 lines
6.0 KiB
import { MessageBox, Message } from 'element-ui'; |
|
import { addOperation, getOperation } from '@/api/http'; |
|
|
|
const phoneListen = function(val, form, prop) { |
|
if(/^[0-9]*$/.test(val)) { |
|
form[prop] = val; |
|
} |
|
} |
|
const mailBoxListen = function(val, form, prop) { |
|
if(/^[\u4E00-\u9FA5A-Za-z0-9_]+$/.test(val) || val==='') { |
|
form[prop] = val; |
|
} |
|
} |
|
|
|
// 校验中文 |
|
const checkHanzi = function(val, form, prop) { |
|
// 检查符号 |
|
const charReg = /[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~!@#¥%……&*()——\-+={}|《》?:“”【】、;‘',。、]/im; |
|
// 检查空格 |
|
const tmpCheck = val.substr(val.length-1, 1); |
|
if(tmpCheck === ' ' || charReg.test(val) || /[\u4E00-\u9FA5]/i.test(val)) { |
|
return; |
|
} |
|
form[prop] = val; |
|
} |
|
|
|
const checkName = function(val, form, prop) { |
|
// 检查符号 |
|
const charReg = /[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~!@#¥%……&*()——\-+={}|《》?:“”【】、;‘',。、]/im; |
|
// // 检查数字 |
|
const charReg2 = /^[0-9]*$/; |
|
const tmpCheck = val.substr(val.length-1, 1); |
|
if(val.length<form[prop].length) { |
|
form[prop] = val; |
|
return; |
|
} |
|
if(charReg.test(val) || charReg2.test(tmpCheck)) { |
|
return; |
|
} |
|
form[prop] = val; |
|
} |
|
|
|
// 监听年利率 |
|
const rateListen = function(val, form, prop) { |
|
|
|
// 检查符号 允许% |
|
const charReg = /[`~!@#$^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~!@#¥……&*()——\-+={}|《》?:“”【】、;‘',。、]/im; |
|
// 检查空格 |
|
if(charReg.test(val) || /[\u4E00-\u9FA5]/i.test(val)) { |
|
return; |
|
} |
|
form[prop] = val; |
|
} |
|
|
|
// 监听数字 |
|
const inputListen = function(val, row, prop) { |
|
// 检查空格 |
|
const tmpCheck = val.substr(val.length-1, 1); |
|
if(tmpCheck === ' ') { |
|
return; |
|
} |
|
if(val === '') { |
|
row[prop] = val; |
|
return; |
|
} |
|
row[prop] = Number(val.replace(/\D+/, '')) |
|
} |
|
|
|
const ismoney = function(val, row, prop) { |
|
// 检查空格 |
|
const tmpCheck = val.substr(val.length-1, 1); |
|
if(tmpCheck === ' ') { |
|
return; |
|
} |
|
// const reg = /([1-9]\d{0,9}|0)(\.\d{1,2})?$/ // 不用保留 |
|
const reg2 = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/; // 保留小数点后两位 |
|
if (reg2.test(Number(val)) || val==='') { |
|
row[prop] = val |
|
} |
|
} |
|
|
|
const checkRequired = function(form, obj) { |
|
for(const prop in obj) { |
|
if(form[prop] === '') { |
|
MessageBox.alert('请填写' + obj[prop], '提示', { |
|
type: 'info', |
|
confirmButtonText: '确定' |
|
}); |
|
return prop |
|
} |
|
} |
|
return ''; |
|
} |
|
|
|
const myValidate = (callback, refs) => { |
|
return (valid, obj) => { |
|
if (valid) { |
|
callback() |
|
} else { |
|
let tmpObj = {}; |
|
for(const key in obj) { |
|
tmpObj = obj[key][0] |
|
break; |
|
} |
|
const { message, field } = tmpObj |
|
refs[field].focus(); |
|
Message.info({ |
|
center: true, |
|
message |
|
}) |
|
// Message.message(message + '', '提示', { |
|
// type: 'info', |
|
// confirmButtonText: message |
|
// }); |
|
} |
|
} |
|
} |
|
|
|
const autoPlay = (parentId, form, myTable2, myTable, cards=[]) => { |
|
let projectId = sessionStorage.getItem('projectId') |
|
let startTime = sessionStorage.getItem('startTime') |
|
let formList = []; |
|
let tmpIndex = 100; |
|
for(const key in myTable2) { |
|
const { prop, type } = myTable2[key] |
|
if(form[prop]){ |
|
formList.push({ "answerId": key + '', "emptyOne": '' + tmpIndex++, "emptyTwo": form[prop], "operationIds": parentId + ',' + key, "type":type }) |
|
} |
|
} |
|
|
|
for(const key in myTable) { |
|
const { prop, type } = myTable[key] |
|
formList.push({ "answerId": key + '', "emptyOne": '' + tmpIndex++, "emptyTwo": form[prop], "operationIds": parentId + ',' + key, "type":type }) |
|
} |
|
|
|
for(let i=0; i<cards.length; i++ ) { |
|
for(const key in cards[i]) { |
|
const tmpJson = JSON.stringify(cards[i][key]) |
|
formList.push({ "answerId": key + '', "emptyOne": '' + tmpIndex++, "emptyTwo": tmpJson, "operationIds": parentId + ',' + key, "type":5 }) |
|
} |
|
} |
|
|
|
|
|
let params= { |
|
parentId, |
|
lcJudgmentRuleReq:formList, |
|
projectId:+projectId, |
|
startTime:startTime, |
|
} |
|
addOperation(params).then((data)=>{ |
|
Message.success({ |
|
center: true, |
|
message: '提交成功' |
|
}) |
|
}).catch((error)=>{ |
|
}) |
|
} |
|
|
|
const autoPlay2 = (parentId, form, myTable2, myTable, cardArr) => { |
|
let param= { |
|
parentId |
|
} |
|
getOperation(param).then((data)=>{ |
|
console.log('---拿到的data') |
|
console.log(data) |
|
if(data.status == 200) { |
|
var list = data.data.judgmentRuleReqs |
|
const tmpObj = Object.assign(myTable, myTable2) |
|
for (var i = 0; i < list.length; i++) { |
|
const { answerId, emptyTwo } = list[i] |
|
if(!cardArr) { |
|
form[tmpObj[answerId].prop] = emptyTwo |
|
} else { |
|
if(cardArr[answerId]) { |
|
try{ |
|
console.log(answerId) |
|
sessionStorage.setItem(cardArr[answerId], JSON.parse(list[i].emptyTwo)) |
|
}catch(e) { |
|
// sessionStorage.setItem(cardArr[answerId], list[i].emptyTwo) |
|
continue; |
|
} |
|
|
|
}else { |
|
form[tmpObj[answerId].prop] = emptyTwo |
|
} |
|
} |
|
|
|
// form[tmpObj[answerId].prop] = emptyTwo |
|
} |
|
} |
|
}).catch((error)=>{ |
|
}) |
|
} |
|
|
|
export { |
|
phoneListen, |
|
mailBoxListen, |
|
checkRequired, |
|
inputListen, |
|
ismoney, |
|
checkHanzi, |
|
myValidate, |
|
checkName, |
|
rateListen, |
|
autoPlay, |
|
autoPlay2 |
|
} |