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.
133 lines
5.0 KiB
133 lines
5.0 KiB
$(document).ready(function(){
|
|
$('.hminput ,.hmtextarea').on('change focusout keydown', function() {
|
|
this.setAttribute('value', this.value)
|
|
})
|
|
$('textarea').each(function(index,elm){
|
|
$(elm).text(elm.getAttribute('value') || '')
|
|
})
|
|
const initCRF = function() {
|
|
const laydate = window.laydate
|
|
// 删除上传的图片
|
|
$("body").on('click','.closeImg', function(){
|
|
const url = $(this).prev().prop('src')
|
|
deleteFile(url)
|
|
$(this)[0].parentNode.remove()
|
|
});
|
|
// 删除上传的文件
|
|
$("body").on('click','.closeFile', function(){
|
|
const url = $(this).prev().prop('href')
|
|
deleteFile(url)
|
|
$(this)[0].parentNode.remove()
|
|
});
|
|
$('.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)
|
|
}
|
|
})
|
|
}
|
|
})
|
|
$('.hmselect').on('click', function() {
|
|
this.setAttribute('value', this.value)
|
|
$(this).find(`option[value='${this.value}']`).attr("selected",'selected');
|
|
$(this).find(`option[value!='${this.value}']`).each((index, item) => {
|
|
if (item.value !== this.value) { item.removeAttribute('selected') }
|
|
})
|
|
// 把单位赋值给输入框的title
|
|
const id = $(this)[0].getAttribute('data-hm_id')
|
|
$(`input[data-hm_id='${id}']`).each((index, item) => {
|
|
item.setAttribute("title",this.value);
|
|
})
|
|
|
|
})
|
|
|
|
$('.DDDs').on('click', function() {
|
|
this.setAttribute('value', this.value)
|
|
$(this).find(`option[value='${this.value}']`).attr("selected",'selected');
|
|
$(this).find(`option[value!='${this.value}']`).each((index, item) => {
|
|
if (item.value !== this.value) { item.removeAttribute('selected') }
|
|
})
|
|
})
|
|
// 上传
|
|
$('.hmupload').on('change', function() {
|
|
let self = this
|
|
let xhr, formData;
|
|
const file = this.files[0];//转化为易于理解的file对象
|
|
console.log(file);
|
|
xhr = new XMLHttpRequest();
|
|
xhr.withCredentials = false;
|
|
console.log(JSON.parse(window.localStorage.getItem('token')));
|
|
const baseUrl = 'http://192.168.0.32:8023'
|
|
xhr.open('POST', `${baseUrl}/renmin_crf/upload/uploadFiles`);
|
|
xhr.setRequestHeader("token", JSON.parse(window.localStorage.getItem('token')));
|
|
xhr.onload = function () {
|
|
let json = JSON.parse(xhr.responseText);
|
|
if (xhr.status == 200) {
|
|
if (json.code == 0) {
|
|
const data = json.data
|
|
const filePathList = data.filePath || []
|
|
const url = filePathList[0].url
|
|
const id = self.getAttribute('data-hm_id')
|
|
const ul = document.getElementById('div-' + id)
|
|
let li = window.document.createElement("li");
|
|
if (file.type === "application/pdf") {
|
|
li.innerHTML = `<input id="" style="display: none" value="${url}" data-hm_id="${id}" data-hm_type="uploadUrl"><a href="${url}">${file.name}</a><span id="" class="closeFile">×</span>`
|
|
} else {
|
|
li.innerHTML = `<input id="" style="display: none" value="${url}" data-hm_id="${id}" data-hm_type="uploadUrl"><img src="${url}" alt="" style="width: 70px;height: 70px"><span id="" class="closeImg">×</span>`;
|
|
}
|
|
ul.appendChild(li)
|
|
}
|
|
}
|
|
};
|
|
formData = new FormData();
|
|
formData.append('files', file);//此处与源文档不一样
|
|
xhr.send(formData);
|
|
})
|
|
|
|
$('.hmcheckbox').on('change', function() {
|
|
$(this).attr('checked', this.checked)
|
|
})
|
|
|
|
$('.hmradio').on('change', function() {
|
|
const elm = this
|
|
$(elm).attr('checked', this.checked)
|
|
$(`input:radio[name='${this.name}']`).each((index, item) => {
|
|
if (item.value !== elm.value) { item.removeAttribute('checked') }
|
|
})
|
|
// 把单位赋值给输入框的title
|
|
const id = $(this)[0].getAttribute('data-hm_id')
|
|
$(`input:text[data-hm_id='${id}']`).each((index, item) => {
|
|
item.setAttribute("title",this.value);
|
|
// 给单位radio赋个标记unit
|
|
$(`input:radio[data-hm_id='${id}']`).each((index, item) => {
|
|
item.setAttribute("unit",'unit');
|
|
})
|
|
})
|
|
})
|
|
}
|
|
|
|
initCRF()
|
|
})
|
|
function deleteFile(url) {
|
|
const baseUrl = 'http://192.168.0.32:8023'
|
|
$.ajax({
|
|
type:"POST",
|
|
headers: {
|
|
'token': JSON.parse(window.localStorage.getItem('token'))
|
|
},
|
|
contentType:'application/json',
|
|
data: JSON.stringify({url: url}),
|
|
dataType:'json',
|
|
url:`${baseUrl}/renmin_crf/upload/deleteFilesByFilePaths`,
|
|
success:function(msg){
|
|
|
|
}
|
|
});
|
|
}
|