123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- 'use strict';
- /**
- *
- *
- * @author lanjianrong
- * @date 2020/8/7
- * @version
- */
- $(document).ready(function () {
- // 控制上报弹窗的文案
- function checkModal(isHide) {
- if (isHide) {
- $('#tm-fail').show()
- $('#tm-success').hide()
- $('#tm-submit').hide()
- } else {
- $('#tm-fail').hide()
- $('#tm-success').show()
- $('#tm-submit').show()
- }
- }
- // 获取审核相关url
- function getUrlPre () {
- const path = window.location.pathname.split('/');
- return _.take(path, 4).join('/') + '/' + advance.id;
- }
- // 审批人分组选择
- $('#account_group').change(function () {
- let account_html = '<option value="0">选择审批人</option>'
- 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 += '<option value="' + account.id + '">' + account.name + role + company + '</option>'
- }
- }
- $('#account_list').html(account_html)
- });
- // 添加到审批流程中
- $('body').on('change', '#account_list', function () {
- let id = $(this).val()
- id = parseInt(id)
- if (id !== 0) {
- postData(getUrlPre() + '/audit/add', { auditorId: id }, (data) => {
- // <p class="m-0 ml-2"><small class="text-muted">中交第一公路工程局有限公司国道311线满别公路施工一分部</small></p>
- const html = []
- html.push('<li class="list-group-item" auditorId="'+ data.audit_id +'"><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>`)
- $('#auditors').append(html.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(getUrlPre() + '/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() || null
- const data = {pay_ratio, cur_amount, prev_amount, prev_total_amount, remark, status: auditConst.status.checking}
- postData(getUrlPre() + '/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
- let prev_total_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,
- prev_amount: p_amount,
- prev_total_amount: ZhCalc.add(cur_amount, p_amount),
- remark: $('#ad-remark').val()
- }
- update(data)
- })
- function update(data) {
- postData(getUrlPre() + '/update', data)
- }
- 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;
- }
- })
|