123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475 |
- 'use strict';
- /**
- *
- *
- * @author lanjianrong
- * @date 2020/8/7
- * @version
- */
- $(document).ready(function () {
- autoFlashHeight();
- $.subMenu({
- menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
- toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
- key: 'menu.1.0.0',
- miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
- callback: function (info) {
- if (info.mini) {
- $('.panel-title').addClass('fluid');
- $('#sub-menu').removeClass('panel-sidebar');
- } else {
- $('.panel-title').removeClass('fluid');
- $('#sub-menu').addClass('panel-sidebar');
- }
- autoFlashHeight();
- }
- });
- const decimal = 2
- let oldVal = null
- let timer = null
- let oldSearchVal = null
- handleFileList(fileList)
- // 控制上报弹窗的文案
- function checkModal(isHide) {
- $('#start-modal').empty()
- if (isHide) {
- // 隐藏上传按钮
- $('#start-modal').append('<p class="text-danger">无法上报,请设置审批流程。</p>')
- $('#tm-submit').hide()
- } else {
- $('#start-modal').append(`<p>确认上报第${advance.order}期${advance.type === 0 ? '开工' : '材料'}预付款?</p>`)
- $('#tm-submit').show()
- }
- }
- $('#gr-search').bind('input propertychange', function(e) {
- oldSearchVal = e.target.value
- timer && clearTimeout(timer)
- timer = setTimeout(() => {
- const newVal = $('#gr-search').val()
- let html = ''
- if (newVal && newVal === oldSearchVal) {
- accountList.filter(item => item && cur_uid !== item.id && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
- html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
- <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
- class="ml-auto">${item.mobile || ''}</span></p>
- <span class="text-muted">${item.role || ''}</span>
- </dd>`
- })
- $('.book-list').empty()
- $('.book-list').append(html)
- } else {
- if (!$('.acc-btn').length) {
- accountGroup.forEach((group, idx) => {
- if (!group) return
- html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
- </a> ${group.groupName}</dt>
- <div class="dd-content" data-toggleid="${idx}">`
- group.groupList.forEach(item => {
- if (item.id !== cur_uid) {
- html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
- <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
- class="ml-auto">${item.mobile || ''}</span></p>
- <span class="text-muted">${item.role || ''}</span>
- </dd>`
- }
- });
- html += '</div>'
- })
- $('.book-list').empty()
- $('.book-list').append(html)
- }
- }
- }, 400);
- })
- // 添加审批流程按钮逻辑
- $('.book-list').on('click', 'dt', function () {
- const idx = $(this).find('.acc-btn').attr('data-groupid')
- const type = $(this).find('.acc-btn').attr('data-type')
- if (type === 'hide') {
- $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
- $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
- $(this).find('.acc-btn').attr('data-type', 'show')
- })
- } else {
- $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
- $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
- $(this).find('.acc-btn').attr('data-type', 'hide')
- })
- }
- return false
- })
- // 添加到审批流程中
- $('dl').on('click', 'dd', function () {
- const id = parseInt($(this).data('id'))
- if (id !== 0) {
- postData(preUrl + '/audit/add', { auditorId: id }, (datas) => {
- // <p class="m-0 ml-2"><small class="text-muted">中交第一公路工程局有限公司国道311线满别公路施工一分部</small></p>
- const html = [];
- // 如果是重新上报,添加到重新上报列表中
- const auditorshtml = [];
- for (const [index,data] of datas.entries()) {
- if (index !== 0) {
- html.push('<li class="list-group-item" auditorId="'+ data.audit_id +'">');
- if (shenpi_status === shenpiConst.sp_status.sqspr || (shenpi_status === shenpiConst.sp_status.gdzs && index+1 !== datas.length)) {
- html.push('<a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
- }
- html.push('<span>');
- html.push(data.order + ' ');
- html.push(data.name + ' ');
- html.push('</span>');
- html.push('<small class="text-muted">');
- html.push(data.role);
- html.push('</small>');
- html.push(`<p class="m-0 ml-2"><small class="text-muted">${data.company}</small></p></li>`);
- }
- // 添加新审批人流程修改
- auditorshtml.push('<li class="list-group-item" data-auditorid="' + data.audit_id + '">');
- auditorshtml.push('<i class="fa ' + (index+1 === datas.length ? 'fa-stop-circle' : 'fa-chevron-circle-down') + '"></i> ');
- auditorshtml.push(data.name + ' <small class="text-muted">' + data.role + '</small>');
- if (index === 0) {
- auditorshtml.push('<span class="pull-right">原报</span>');
- } else if (index+1 === datas.length) {
- auditorshtml.push('<span class="pull-right">终审</span>');
- } else {
- auditorshtml.push('<span class="pull-right">'+ transFormToChinese(index) +'审</span>');
- }
- auditorshtml.push('</li>');
- }
- $('#auditors').html(html.join(''));
- $('#auditors2').html(auditorshtml.join(''));
- // if ($('.fa-stop-circle').length) {
- // $('.fa-stop-circle').removeClass('fa-stop-circle').addClass('fa-chevron-circle-down')
- // }
- // const auditorsHTML = `<li class="list-group-item" data-auditorId='${data.audit_id}'><i class="fa fa fa-stop-circle" ></i> ${data.name} <small class="text-muted">${data.role}</small></li>`
- // $('#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();
- if ($('#auditors2 li').length !== 0 && !$('#auditors2 li i').hasClass('fa-stop-circle')) {
- $('#auditors2 li').eq($('#auditors2 li').length-1).children('i')
- .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
- }
- for (let i = 0; i < $('#auditors2 li').length; i++) {
- $('#auditors2 li').eq(i).find('.pull-right').text(i === 0 ? '原报' : (i+1 === $('#auditors2 li').length ? '终' : transFormToChinese(i)) + '审');
- }
- })
- });
- $('#au-btn').on('click','a', function() {
- const content = $(this).data('target')
- switch (content) {
- case '#sub-sp':
- if ($('#auditors')[0].children.length) {
- checkModal(false)
- } else {
- checkModal(true)
- }
- break;
- default:
- break;
- }
- })
- // 上报审批
- $('#tm-submit').click(function() {
- const pay_ratio = parseFloat($(`.pay-input[data-type=0]`).val())
- const cur_amount = parseFloat(parseFloat($(`.pay-input[data-type=1]`).val()).toFixed(decimal))
- 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 = filterText($('#ad-remark').val())
- 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()
- })
- })
- // 重新上报
- $('#sp-list2-btn').click(() => {
- $('#tm-submit').trigger('click')
- })
- // 转化成两位小数
- function fixedToSub(s, decimal = 2) {
- return parseFloat(parseFloat(s).toFixed(decimal))
- }
- // 自动转换支付比例和本期金额
- $('.pay-input').on('change', function(e) {
- let val = parseFloat(e.target.value)
- const p_amount = prevAdvance && prevAdvance.prev_total_amount || 0 // 截止本期金额
- const re_amount = ZhCalc.sub(advancePayTotal, p_amount) // 剩余未付款的总额
- const min = parseFloat($(this).attr('min'))
- const max = parseFloat($(this).attr('max'))
- const type = parseInt($(this).data('type'))
- let pay_ratio = null
- let cur_amount = null
- let isLimitMax = false // 用来判断是否达到最大
- 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) {
- // 限制不能超过最大值
- val = re_amount
- isLimitMax = true
- }
- $(this).val(isLimitMax ? val : fixedToSub(val, decimal)) // 重新赋值限制只有两位小数
- const pay_a_input = $(`.pay-input[data-type=${reverse(type)}]`)
- pay_ratio = ZhCalc.mul(ZhCalc.div(val, advancePayTotal), 100).toFixed(2)
- cur_amount = isLimitMax ? re_amount : ZhCalc.round(val, decimal)
- pay_a_input.val(pay_ratio)
- const total = ZhCalc.add(cur_amount, p_amount).toString().split('.')[1] || ''
- // 截止本期金额文案更新
- $('#p_total2').text(formatMoney(ZhCalc.add(cur_amount, p_amount), ',', isLimitMax ? total.length : 2) + '元')
- } else {
- // 支付比例转化
- val = fixedToSub(val)
- if (val.toFixed(2) === max.toFixed(2)) {
- // 比例达到最大,特殊处理金额的显示小数点
- val = fixedToSub(max, 2);
- isLimitMax = true
- }
- $(this).val(val) // 重新赋值限制只有两位小数
- const cur_m_input = $(`.pay-input[data-type=${reverse(type)}]`)
- cur_amount = isLimitMax ? re_amount : ZhCalc.round(ZhCalc.mul(advancePayTotal, ZhCalc.div(val, 100), 10), decimal)
- pay_ratio = val
- cur_m_input.val(cur_amount)
- const total = ZhCalc.add(cur_amount, p_amount).toString().split('.')[1] || ''
- // 截止本期金额文案更新
- $('#p_total2').text(formatMoney(ZhCalc.add(cur_amount, p_amount), ',', isLimitMax ? total.length : 2) + '元')
- }
- const data = {
- pay_ratio,
- cur_amount,
- }
- oldVal = {
- cur_amount: parseFloat($(`.pay-input[data-type=${1}]`).val()),
- remark: filterText($('#ad-remark').val())
- }
- clearTimeout(timer)
- timer = setTimeout(() => {
- if (checkInput()) {
- update(data)
- clearTimeout(timer)
- }
- }, 500);
- })
- const payDate = $('.pay-date-input').datepicker().data('datepicker');
- payDate.selectDate(new Date(advance.pay_time));
- $('.pay-date-input').datepicker({
- onShow: function () {
- $('.pay-date-input').attr('readOnly', true);
- },
- onHide: function (dp, animationCompleted) {
- if(animationCompleted) {
- $('.pay-date-input').attr('readOnly', false);
- const val = $('.pay-date-input').val();
- // 日期格式判断
- if (!(isNaN(val)&&!isNaN(Date.parse(val)))) {
- toastr.error('日期格式有误!');
- $('.pay-date-input').val(moment(advance.pay_time).format('YYYY-MM-DD'));
- payDate.selectDate(new Date(advance.pay_time));
- } else if(val !== moment(advance.pay_time).format('YYYY-MM-DD')) {
- const data = {
- pay_time: val
- };
- // console.log(data);
- update(data);
- advance.pay_time = new Date(val);
- }
- }
- }
- });
- function checkInput() {
- const newVal = {
- cur_amount: parseFloat($(`.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('change', function(e) {
- const remark = filterText(e.target.value);
- oldVal = {
- pay_ratio: parseFloat($(`.pay-input[data-type=${0}]`).val()),
- cur_amount: parseFloat($(`.pay-input[data-type=${1}]`).val()),
- remark
- }
- const data = oldVal
- clearTimeout(timer)
- timer = setTimeout(() => {
- if (checkInput()) {
- update(data)
- clearTimeout(timer)
- }
- }, 500);
- })
- function filterText(text) {
- if (!text) return null
- return text.replace(/(\r\n)|(\n)/g, '<br/>').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)
- // }
- if (advance.status === auditConst.status.checked) {
- showDel = Boolean(file.extra_upload )
- } else {
- showDel = true
- }
- }
- return {...file, showDel}
- })
- let html = advance.filePermission ? `<tr><td colspan="3"><a href="#addfujian" data-toggle="modal" class="btn btn-sm btn-light text-primary" data-placement="bottom" title="" data-original-title="添加清单"><i class="fa fa-cloud-upload" aria-hidden="true"></i> 上传附件</a></td></tr>` : '';
- newFiles.forEach((file, idx) => {
- if (file.showDel) {
- html += `<tr><td width="70">${idx + 1}</td><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td width="90"><a href="javascript: void(0);" class="text-danger file-del" data-id="${file.id}">移除</a></td></tr>`
- } else {
- html += `<tr><td width="70">${idx + 1}</td><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td width="90"></td></tr>`
- }
- })
- $('#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 = ',', decimal = 2) {
- if (!s) {
- s = 0;
- return s.toFixed(decimal);
- }
- s = parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(decimal) + '';
- if (!decimal) {
- s += '.';
- }
- const 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 : '');
- }
- const num = t.split('').reverse().join('') + (decimal === 0 ? '' : '.' + r);
- return num.replace('-,', '-');
- }
|