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.
 
 
 
 

367 lines
13 KiB

$(document).ready(function () {
$('.hminput,.hmtextarea').on('change focusout keydown', function () {
console.log(123);
this.setAttribute('value', this.value)
$(this).next().html(this.value)
})
// $('select').on('change', function() {
// console.log('获取选中的value',$(this).val())
// $(this).val('2')
// console.log('获取选中的value',$("select option:selected").text())
// })
$('#chuli-input').on('input', function (e) {
console.log(e.target.value);
inputChange($(this).val().trim())
})
$('#chuli-input').on('change', function () {
console.log('获取选中的value', $(this).val())
this.setAttribute('value', $(this).val())
inputChange($(this).val().trim())
})
function inputChange(inputValue) {
if (inputValue == '1') {
$('.1').css('display', 'block')
$('.2').css('display', 'none')
$('.3').css('display', 'none')
$('.4').css('display', 'none')
$('.5').css('display', 'none')
}
if (inputValue == '2') {
$('.1').css('display', 'none')
$('.2').css('display', 'block')
$('.3').css('display', 'none')
$('.4').css('display', 'none')
$('.5').css('display', 'none')
}
if (inputValue == '3') {
$('.1').css('display', 'none')
$('.2').css('display', 'none')
$('.3').css('display', 'block')
$('.4').css('display', 'none')
$('.5').css('display', 'none')
}
if (inputValue == '4') {
$('.1').css('display', 'none')
$('.2').css('display', 'none')
$('.3').css('display', 'none')
$('.4').css('display', 'block')
$('.5').css('display', 'none')
}
if (inputValue == '5') {
$('.1').css('display', 'none')
$('.2').css('display', 'none')
$('.3').css('display', 'none')
$('.4').css('display', 'none')
$('.5').css('display', 'block')
}
if (inputValue !== '1' && inputValue !== '2' && inputValue !== '3' && inputValue !== '4' && inputValue !== '5') {
$('.1').css('display', 'none')
$('.2').css('display', 'none')
$('.3').css('display', 'none')
$('.4').css('display', 'none')
$('.5').css('display', 'none')
}
}
// $('#ff').on('focus', function() {
// console.log('focus');
// $(this).next().css("top",'30px')
// })
// $('#ff').on('blur', function() {
// console.log('blur');
// $(this).next().css("top",'-99999px')
// })
$('textarea').each(function (index, elm) {
$(elm).text(elm.getAttribute('value') || '')
})
const initCRF = function () {
// const doc = window.document
// const win = window
const laydate = window.laydate
$('.hminput').each(function () {
const elm = this
const hmDataType = elm.getAttribute('data-hm_type')
// 时间控件
if (hmDataType === 'date' || hmDataType === 'datetime' || hmDataType === 'time') {
laydate.render({
elem: '#' + elm.id,
type: hmDataType,
done: function (value, date, endDate) {
elm.setAttribute('value', value)
}
})
}
})
$('.hmcheckbox').on('change', function () {
$(this).attr('checked', this.checked)
})
$('.hmradio').on('change', function () {
// console.log(12333);
const elm = this
// console.log($('.hmradio'));
$(elm).attr('checked', this.checked)
$(`input:radio[name='${this.name}']`).each((index, item) => {
if (item.id !== elm.id) { item.removeAttribute('checked') }
})
// 问卷调查计算总分
var score = 0
$('.hmradio').each((index, ele) => {
// console.log(parseInt(ele.value));
if (ele.checked) {
score = score + parseInt(ele.value)
}
})
// console.log( score);
$('#score').attr('value', score + '分')
})
$('img').on('click', function () {
// console.log(window.parent['goBack']);
// iframe调取vue中的方法
window.parent['goBack'] ? window.parent['goBack'](this.getAttribute('src'), this.getAttribute('alt')) : ''
})
}
initCRF()
// 处理选择-默认展示
function chuliDefault() {
$('#chuli-input').val() ? inputChange($('#chuli-input').val().trim()) : ''
// console.log( $('#chuli-input').val());
}
chuliDefault()
})
/** 对象数组,对象格式
const demo = {
both: null,
id: '4',
name: '眼压',
od: '20.3',
os: '16',
recId: '9379374',
time: '2013-04-15 13:27:14'
}
*/
// 下拉选择回显
function multipleSelectFull(val) {
console.log('val', val);
let values = val ? val : []; //存储选择的内容
let opts = [] //存储option标签
let select = document.querySelector(".hmselectmultiple")
console.log(select);
if (select) {
val && val.length > 0 ? $('.hmselectmultiple').attr('disabled', true) : $('.hmselectmultiple').attr('disabled', false)
for (let i = 0; i < select.length; i++) {
opts.push(select.item(i));
}
//创建一个隐藏起来的option
let optionHide = document.createElement('option');
optionHide.hidden = true;
optionHide.className = "multipleSelect_optionHide"
select.appendChild(optionHide);
// 动态赋值回显
let innerText = val ? val.toString() : ''
values.forEach(item => {
let selectindex = Array.from(select.options).findIndex(iten => iten.innerText === item)
console.log('selectindex', selectindex);
selectindex !== -1 ? select.options[selectindex].style = "background: #c2e0f4" : ''; //选中的option背景为粉色
})
select.options[select.length - 1].text = values.toString(); //将values数组中的数据转化成字符串的格式赋给隐藏的option
if (values.length > 0) { //将隐藏的option的selected属性设置为true,这样select.value获取的值就是多选选中的值
select.options[select.length - 1].selected = true;
} else {
select.options[0].selected = true;
}
}
}
// 下拉多选
function multipleSelect(operaList) {
let values = []; //存储选择的内容
let opts = [] //存储option标签
let select = document.querySelector(".hmselectmultiple")
operaList ? setTimeout(() => {
operaList.forEach((item, index) => {
var option = document.createElement('option')
option.innerHTML = item.operaName
option.value = item.operaId
// 插入的数据一定要展示在默认数据的上方 'displayOption'是插件hm_select_multiple---plugin.js中定的固定class
select.insertBefore(option,document.querySelector('.displayOption'))
})
}, 100) : ''
// 点击进行多选
select.addEventListener('input', function () {
let innerText = this.options[this.selectedIndex].innerText; //获取当前选择的值
console.log(innerText);
this.options[this.selectedIndex].style = "background: #c2e0f4"; //选中的option背景为粉色
let index = values.indexOf(innerText); //判断是否被选择,返回-1说明没选择,否则已被选择
if (index > -1) { //若已选择,就删除该选择,并且将option的背景恢复为未被选择的状态
values.splice(index, 1);
opts.filter(function (opt) {
if (opt.innerText === innerText) {
opt.style = "";
}
});
} else {
//没选择就将该值push到values中
values.push(innerText);
console.log(values);
};
console.log(this.options[this.length - 1]);
this.options[this.length - 1].text = values.toString(); //将values数组中的数据转化成字符串的格式赋给隐藏的option
if (values.length > 0) { //将隐藏的option的selected属性设置为true,这样select.value获取的值就是多选选中的值
this.options[this.length - 1].selected = true;
} else {
this.options[0].selected = true;
}
// console.log(select.innerText);// 打印多选的内容
})
}
function imgEditFull(base64, imgAlt) {
// console.log(base64);
// console.log(imgAlt);
document.querySelectorAll('img').forEach(item => {
if (item.alt === imgAlt) {
item.setAttribute('src', base64)
}
})
// console.log(document.querySelectorAll('img'));
}
// 填充回显
function dataFill(itemList, fullDate) {
// console.log(itemList);
// 如果是data-hm_id='qm-date 签字日期自动填充
if (fullDate) {
$(`[data-hm_id='qm-date']`).each((index, elm) => {
$(elm).attr('value', fullDate)
})
}
// console.log(itemList)
if (itemList) {
itemList ? itemList.forEach(item => {
// console.log(item)
const eyeType = item.both ? '' : ''
// data-hm_bd_id--字典表/sys/table/dict/getList--id
// 根据字典表id填充数据
// console.log(item.id);
// console.log( $(`[data-hm_bd_id='${item.id}']`));
$(`[data-hm_bd_id='${item.id}']`).each(function (index, elm) {
// 如果不是单选多选执行
if (!$(elm).attr('class').includes('hmradio') && !$(elm).attr('class').includes('hmcheckbox')) {
if (elm.getAttribute("data-hm_bd_eye_type") === 'od') {
$(elm).attr('value', item.od || '')
$(elm).next().html(item.od)
} else if (elm.getAttribute("data-hm_bd_eye_type") === 'os') {
$(elm).attr('value', item.os || '')
$(elm).next().html(item.os)
} else {
$('textarea').each(function (index, elm) {
$(elm).text(elm.getAttribute('value') || '')
$(elm).width(elm.getAttribute('value') ? (elm.getAttribute('value').length * 16) + 'px' : '450px')
})
$(elm).attr('value', item.value || '')
$(elm).next().html(item.value)
}
}
// 如果单选框
else if ($(elm).attr('class').includes('hmradio')) {
if ($(elm).val() === item.value) {
$(elm).prop('checked', true)
}
}
// 如果多选框
else if ($(elm).attr('class').includes('hmcheckbox')) {
// console.log(item);
// console.log($(elm).attr('data-hm_bd_id'))
if ($(elm).attr('data-hm_bd_id') === item.id) {
item.value.forEach(iten => {
if (iten === $(elm).val()) {
$(elm).prop('checked', true)
}
})
}
}
})
}) : $('textarea').each(function (index, elm) {
$(elm).width(elm.getAttribute('value') ? (elm.getAttribute('value').length * 16) + 'px' : '450px')
})
}
}
// 获取表单value
function getFormValue() {
console.log('获取表单value')
// 复选框的值获取
let checkboxArr = []
let checkboxValue = {}
hmcheckboxDom = Array.from($('.hmcheckbox'))
hmcheckboxDom.forEach((item, index) => {
checkboxArr.push($(item).attr('name'))
if (hmcheckboxDom.length - 1 === index) {
let setCheckboxArr = [...new Set(checkboxArr)]
let checkboxObj = {}
setCheckboxArr.forEach((iten, i) => {
checkboxObj[iten] = []
hmcheckboxDom.forEach((itex, m) => {
if (iten == $(itex).attr('name')) {
checkboxObj[iten].push(itex)
}
if (i === setCheckboxArr.length - 1 && m == hmcheckboxDom.length - 1) {
// console.log(checkboxObj);
setCheckboxArr.forEach(itee => {
checkboxValue[itee] = []
checkboxObj[itee].forEach(itep => {
if ($(itep).prop('checked') === true) {
console.log(itep);
checkboxValue[itee].push($(itep).val())
}
})
})
// console.log(checkboxValue);
}
})
})
}
})
// 单选框的值获取
let hmradioDOM = Array.from($('.hmradio'))
let hmradioValue = {}
hmradioDOM.forEach(item => {
if ($(item).prop('checked') === true) {
console.log($(item).attr('name'));
hmradioValue[$(item).attr('name')] = $(item).val()
}
})
// console.log(hmradioValue);
// 下拉多选的值获取
let hmselectmultiple = Array.from($('.hmselectmultiple '))
let hmselectmultipleValue = {}
console.log(hmselectmultiple);
hmselectmultiple.forEach(item => {
console.log(item.value);
hmselectmultipleValue[item.dataset.hm_id] = item.value.split(',')
})
console.log(hmselectmultipleValue);
// console.log(hmselectmultipleValue);
return { checkboxValue, hmradioValue, hmselectmultipleValue }
}
// 判断是否签字
function isSignSuccess() {
// console.log($('.shouqian').next().length);
// console.log($('.shouqian').next().prevObject.length);
// console.log($('.auto-import').next().length);
// console.log($('.auto-import').next().prevObject.length);
if (($('.shouqian').next().length === $('.shouqian').next().prevObject.length) && ($('.auto-import').next().length === $('.auto-import').next().prevObject.length)) {
return true
} else {
return false
}
}