'use strict'; /** * * * @author lanjianrong * @date 2020/8/7 * @version */ $(document).ready(function () { let oldVal = null let timer = null handleFileList(fileList) // 控制上报弹窗的文案 function checkModal(isHide) { if (isHide) { $('#tm-fail').show() $('#tm-success').hide() $('#tm-submit').hide() } else { $('#tm-fail').hide() $('#tm-success').show() $('#tm-submit').show() } } // 审批人分组选择 $('#account_group').change(function () { let account_html = '' for (const account of accountList) { if ((parseInt($(this).val()) === 0 || parseInt($(this).val()) === account.account_group) && account.id !== parseInt(userID)) { const role = account.role !== '' ? '(' + account.role + ')' : '' const company = account.company !== '' ? ' -' + account.company : '' account_html += '' } } $('#account_list').html(account_html) }); // 添加到审批流程中 $('body').on('change', '#account_list', function () { let id = $(this).val() id = parseInt(id) if (id !== 0) { postData(preUrl + '/audit/add', { auditorId: id }, (data) => { //

中交第一公路工程局有限公司国道311线满别公路施工一分部

const html = [] html.push('
  • 移除') html.push('') html.push(data.order + ' ') html.push(data.name + ' ') html.push('') html.push('') html.push(data.role) html.push('') html.push(`

    ${data.company}

  • `) $('#auditors').append(html.join('')) if ($('.fa-stop-circle').length) { $('.fa-stop-circle').removeClass('fa-stop-circle').addClass('fa-chevron-circle-down') } const auditorsHTML = `
  • ${data.name} ${data.role}
  • ` $('#auditors2').append(auditorsHTML) if ($('#auditors')[0].children.length > 0) { checkModal(false) } }); } }); // 删除审批人 $('body').on('click', '#auditors li>a', function () { const li = $(this).parent() const data = { auditorId: parseInt(li.attr('auditorId')), }; postData(preUrl + '/audit/delete', data, (result) => { li.remove(); for (const rst of result) { const aLi = $('li[auditorId=' + rst.audit_id + ']'); $('span', aLi).text(rst.order + ' ' + rst.name + ' ') } // 删除左边审核人 $(`#auditors2 li[data-auditorId='${data.auditorId}']`).remove() }) }) $('#au-btn').on('click','a', function() { const content = $(this).data('target') switch (content) { case '#sub-sp': if ($('#auditors')[0].children.length) { checkModal(false) } break; default: break; } }) // 上报审批 $('#tm-submit').click(function() { const pay_ratio = parseInt($(`.pay-input[data-type=0]`).val()) const cur_amount = parseInt($(`.pay-input[data-type=1]`).val()) if (!pay_ratio || !cur_amount) { return toastr.error('请填写本期金额!') } const prev_amount = prevAdvance && prevAdvance.prev_total_amount || 0 const prev_total_amount = ZhCalc.add(cur_amount, prev_amount) const remark = $('#ad-remark').val().replace(/\r\n/g, '
    ').replace(/\n/g, '
    ').replace(/\s/g, ' ') || null const data = {pay_ratio, cur_amount, prev_amount, prev_total_amount, remark, status: auditConst.status.checking} postData(preUrl + '/audit/start', data, (data) => { window.location.reload() }, () => { window.location.reload() }) }) // 自动转换支付比例和本期金额 $('.pay-input').on('input propertychange', function(e) { let val = parseInt(e.target.value) const p_amount = prevAdvance && prevAdvance.prev_total_amount || 0 // 截止本期金额 const re_amount = ZhCalc.sub(advancePayTotal, p_amount) // 剩余未付款的总额 const min = parseInt($(this).attr('min')) const max = parseInt($(this).attr('max')) const type = parseInt($(this).data('type')) let pay_ratio = null let cur_amount = null if (val < min) { // 限制最小值为min $(this).val(min) val = min } if (max && val > max) { // 限制最大值为max $(this).val(max) val = max } // 本期金额转化 if (type === 1) { if (val > re_amount) { // 限制超过最大值 $(this).val(re_amount) val = re_amount } const pay_a_input = $(`.pay-input[data-type=${reverse(type)}]`) pay_ratio = ZhCalc.round(ZhCalc.mul(ZhCalc.div(val, re_amount), 100), 2) cur_amount = val pay_a_input.val(pay_ratio) // 截止本期金额文案更新 $('#p_total2').text(formatMoney(ZhCalc.add(val, p_amount))) } else { // 支付比例转化 const cur_m_input = $(`.pay-input[data-type=${reverse(type)}]`) cur_amount = ZhCalc.mul(re_amount, ZhCalc.div(val, 100)) pay_ratio = val cur_m_input.val(cur_amount) // 截止本期金额文案更新 $('#p_total2').text(formatMoney(ZhCalc.add(cur_amount, p_amount))) } const data = { pay_ratio, cur_amount, } oldVal = { cur_amount: parseInt($(`.pay-input[data-type=${1}]`).val()), remark: filterText($('#ad-remark').val()) } clearTimeout(timer) timer = setTimeout(() => { if (checkInput()) { update(data) clearTimeout(timer) } }, 2000); }) function checkInput() { const newVal = { cur_amount: parseInt($(`.pay-input[data-type=${1}]`).val()), remark: filterText($('#ad-remark').val()) } return newVal.cur_amount === oldVal.cur_amount && newVal.remark === oldVal.remark } $('#ad-remark').on('input propertychange', function(e) { const remark = filterText(e.target.value); oldVal = { pay_ratio: parseInt($(`.pay-input[data-type=${0}]`).val()), cur_amount: parseInt($(`.pay-input[data-type=${1}]`).val()), remark } const data = oldVal clearTimeout(timer) timer = setTimeout(() => { if (checkInput()) { update(data) clearTimeout(timer) } }, 2000); }) function filterText(text) { if (!text) return null return text.replace(/(\r\n)|(\n)/g, '
    ').replace(/\s/g, ' ') } function update(data) { postData(preUrl + '/update', data) } $('#file-modal-target').click(function () { $('#file-modal').trigger('click') }) $('#file-ok').click(function () { const files = Array.from($('#file-modal')[0].files) const valiData = files.map(v => { const ext = v.name.substring(v.name.lastIndexOf('.') + 1) return { size: v.size, ext } }) if (validateFiles(valiData)) { if (files.length) { const formData = new FormData() files.forEach(file => { formData.append('name', file.name) formData.append('size', file.size) formData.append('file', file) }) postDataWithFile(preUrl + '/file/upload', formData, function (result) { handleFileList(result) $('#file-cancel').click() }); } } }) function handleFileList(files) { $('#file-content').empty() const { uncheck, checkNo } = auditConst.status const newFiles = files.map(file => { let showDel = false; if (file.uid === cur_uid) { if (!curAuditor) { advance.status === uncheck && cur_uid === advance.uid && (showDel = true) advance.status === checkNo && cur_uid === advance.uid && (showDel = true) } else { curAuditor.audit_id === cur_uid && (showDel = true) } } return {...file, showDel} }) let html = ` 上传附件` newFiles.forEach((file, idx) => { if (file.showDel) { html += `${idx + 1}${file.filename}移除` } else { html += `${idx + 1}${file.filename}` } }) $('#file-content').append(html) } $('#file-content').on('click', 'a', function () { if ($(this).hasClass('file-del')) { const id = $(this).data('id') postData(preUrl + '/file/del', {id}, (result) => { handleFileList(result) }) } }) }) /** * 校验文件大小、格式 * @param {Array} files 文件数组 */ function validateFiles(files) { if (files.length > 10) { toastr.error('至多同时上传10个文件'); return false } return files.every(file => { if (file.size > 1024 * 1024 * 30) { toastr.error('文件大小限制为30MB'); return false } if (whiteList.indexOf('.' + file.ext) === -1) { toastr.error('请上传正确的格式文件'); return false } return true }) } function reverse(num){ return 1^num } function formatMoney(s, dot = ',') { if (!s) return '0.00'; s = parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(2) + ''; let l = s.split('.')[0].split('').reverse(), r = s.split('.')[1]; let t = ''; for (let i = 0; i < l.length; i++) { t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? dot : ''); } return t.split('').reverse().join('') + '.' + r; }