invoicemanage.js 19.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
/**
 * Created by chenbiao on 2017/8/23.
 */

function formatSeconds(value) {
    var theTime = parseInt(value); // 秒
    var theTime1 = 0; // 分
    var theTime2 = 0; // 小时
    // alert(theTime);
    if (theTime < 60) {
        return theTime + '秒';
    }
    if (theTime > 60) {
        theTime1 = parseInt(theTime / 60);
        theTime = parseInt(theTime % 60);
        // alert(theTime1+"-"+theTime);
        if (theTime1 > 60) {
            theTime2 = parseInt(theTime1 / 60);
            theTime1 = parseInt(theTime1 % 60);
        }
    }
    var result = '';
    if (theTime1 > 0) {
        result = "" + parseInt(theTime1) + "分钟" + result;
    }
    if (theTime2 > 0) {
        result = "" + parseInt(theTime2) + "小时" + result;
    }
    return result;
};

window.downloadFile = function (sUrl) {

    //iOS devices do not support downloading. We have to inform user about this.
    if (/(iP)/g.test(navigator.userAgent)) {
        alert('Your device does not support files downloading. Please try again in desktop browser.');
        return false;
    }

    //If in Chrome or Safari - download via virtual link click
    if (window.downloadFile.isChrome || window.downloadFile.isSafari) {
        //Creating new link node.
        var link = document.createElement('a');
        link.href = sUrl;

        if (link.download !== undefined) {
            //Set HTML5 download attribute. This will prevent file from opening if supported.
            var fileName = sUrl.substring(sUrl.lastIndexOf('/') + 1, sUrl.length);
            link.download = fileName;
        }

        //Dispatching click event.
        if (document.createEvent) {
            var e = document.createEvent('MouseEvents');
            e.initEvent('click', true, true);
            link.dispatchEvent(e);
            return true;
        }
    }

    // Force file download (whether supported by server).
    if (sUrl.indexOf('?') === -1) {
        sUrl += '?download';
    }

    window.open(sUrl, '_self');
    return true;
}

window.downloadFile.isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
window.downloadFile.isSafari = navigator.userAgent.toLowerCase().indexOf('safari') > -1;
/*时间筛选框*/
$("#timeoutEndDate").val(moment().subtract('days', 0).format('YYYY-MM-DD'));
$("#timeoutEndDate").datetimepicker({
    endDate: moment().subtract('days', 0).format('YYYY-MM-DD'),
    format: 'yyyy-mm-dd',
    autoclose: true,
    // startView: 3,
    // //maxDate:moment().subtract('months', 3),
    minView: 2,
    forceParse: false,
    locale: "zh-CN",
    language: 'zh-CN',
    pickerPosition: "bottom-left"
});
$("#timeoutoperEndDate").val(moment().subtract('days', 0).format('YYYY-MM-DD'));
$("#timeoutoperEndDate").datetimepicker({
    endDate: moment().subtract('days', 0).format('YYYY-MM-DD'),
    format: 'yyyy-mm-dd',
    autoclose: true,
    // startView: 3,
    // //maxDate:moment().subtract('months', 3),
    minView: 2,
    forceParse: false,
    locale: "zh-CN",
    language: 'zh-CN',
    pickerPosition: "bottom-left"
});
/*搜索条件toggle*/
$('#transQuery_toggle').on('click', function () {
    $('.showtoggle').toggleClass('display-none');
    $(this).find('.transQuery_toggle_arrow').toggleClass('transQuery_toggle_arrow_active');

});

(function () {
    var invoicefun = {
        init: function () {
            //初始化table
            $('#onduty').selectpicker('refresh');
            //初始化停车场下拉框
            commSelect.plName_select("#parkIds",true);
            $('#parkIds').selectpicker('render');
            invoicefun.createTableData();
        },
        //生成表格数据
        createTableData: function () {
            $('#recordtable').bootstrapTable('destroy').bootstrapTable({
                striped: true, //表格显示条纹
                pagination: true, //启动分页
                pageNumber: 1, //当前第几页
                pageSize: 10, //每页显示的记录数
                pageList: [10, 15, 20], //记录数可选列表
                sidePagination: 'server', //表示服务端分页
                queryParamsType: 'limit',
                method: 'POST', //请求方法
                paginationPreText: '<',
                paginationNextText: '>',
                ajax: tableLoadRequest, //自定义ajax加载数据
                // uniqueId:'id',
                columns: [
                    {
                        field: 'invoiceType',
                        title: '<span class="information-icon"></span>开票单位',
                        width: '20%',
                        align: 'left',
                        formatter: function (value, row, index) {
                            return '<div>' +
                                '<div class="ITD-common-fontsize16 ITD-common-color000 margin-bottom-5">' + (null == row.custName ? "-" : row.custName) + '</div>' +
                                '<div class="ITD-common-fontsize12 ITD-common-color60 ">纳税人识别号&nbsp;:&nbsp;' + (null == row.custTaxid ? "-" : row.custTaxid) + '</div>' +
                                '</div>'
                        }
                    },
                    {
                        field: 'invoiceKind',
                        title: '<span class="money-icon"></span>发票信息',
                        width: '15%',
                        align: 'left',
                        formatter: function (value, row, index) {
                            return '<div class="ITD-common-fontsize16 ITD-common-color000 margin-bottom-5">' + commonObj.moneyFormatter(row.invoiceTotalFee) + '元</div>' +
                                '<div class="ITD-common-fontsize12 ITD-common-color60 ">' + (null == row.invoiceKind ? "-" : (0 == row.invoiceKind ? "普通发票" : "增值税发票")) + '</div>'

                        }
                    },
                    {
                        field: 'applyDate',
                        title: '<span class="person-icon"></span>申请人',
                        width: '15%',
                        align: 'left',
                        formatter: function (value, row, index) {
                            return '<div class="ITD-common-fontsize16 ITD-common-color000 margin-bottom-5">' + (null == row.recipients ? "-" : row.recipients) + '</div>' +
                                '<div class="ITD-common-fontsize12 ITD-common-color60 ">电话&nbsp;:&nbsp;' + (null == row.recipientsPhone ? "-" : row.recipientsPhone) + '</div>'

                        }
                    },
                    {
                        field: 'fetchTicketWay',
                        title: '<span class="person-icon"></span>邮寄信息',
                        width: '15%',
                        align: 'left',
                        formatter: function (value, row, index) {
                            return '<div class="ITD-common-fontsize16 ITD-common-color000 margin-bottom-5">' + invoicefun.mailInfoFormater(value, row, index) + '</div>' +
                                '<div class="ITD-common-fontsize12 ITD-common-color60 ">' + (null == row.fetchTicketWay ? "-" : 1 == row.fetchTicketWay ? "上门自取" : "邮寄") + ' &nbsp;&nbsp;'+invoicefun.mailInfoDetail(value,row,index)+'</div>'

                        }
                    },
                    {
                        field: 'invoiceState',
                        title: '<span class="time-icon"></span>开票时间',
                        width: '20%',
                        align: 'left',
                        formatter: function (value, row, index) {
                            return '<div class="ITD-common-fontsize16 ITD-common-color000 margin-bottom-5">' + (1 == row.invoiceState ? "待开票" : (null == row.invoiceDate ? "-" : DateUtils.long2String(row.invoiceDate, 10))) + '</div>' +
                                '<div class="ITD-common-fontsize12 ITD-common-color60 ">申请时间 &nbsp;:&nbsp;' + (null == row.applyDate ? "-" : DateUtils.long2String(row.applyDate, 10)) + '</div>'

                        }
                    },
                    // {
                    //     field: 'invoiceTotalFee',
                    //     title: '发票金额',
                    //     width: '10%',
                    //     align: 'left',
                    //     formatter: invoicefun.moneyFormatter
                    // },
                    // {
                    //     field: 'postDate',
                    //     title: '开票时间',
                    //     width: '15%',
                    //     align: 'left',
                    //     formatter: invoicefun.inDatatimeFormatter
                    // },
                    {
                        field: '',
                        title: '<span class="opration-icon"></span>操作',
                        width: '15%',
                        align: 'left',
                        //visible: false,
                        formatter: invoicefun.freeReasonFormater
                    }
                ]
            });

        },
        /*获取查询参数*/
        getQueryParam: function () {

            var searchLike = $('#searchLike').val();

            var plNos = JSON.parse($("#parkIds").val());


            var onduty;
            var ondutyStr = $('#invoice-toptab div.ITD-graynav-topbaractive').data('type');
            //全部
            if(ondutyStr == 'all'){
                onduty = null;
            }
            //未开票
            if(ondutyStr == 'no'){
                onduty = [1];
            }
            //已开票
            if(ondutyStr == 'yes'){
                onduty = [2,3];
            }


            var _carNumber = $("#_carNumber").val();
            var custPhone = $("#_phone").val();

            var req = {
                custPhone: custPhone,
                carNumber: _carNumber,
                custName : searchLike,
                custTaxid :searchLike,
                // plNos:plNos,
                invoiceStates: onduty
            };
            return req;
        },
        //邮寄信息格式化
        mailInfoFormater: function (value, row, index) {
            /**发票状态,1 待开票,3 已开票,2 已邮寄*/
            //private String invoiceState;

            /**取票方式:1 自取,2 邮寄*/
            //private Integer fetchTicketWay;
            //
            if (null == row.invoiceState ||row.invoiceState==''||row.invoiceState==undefined) {
                return "-";
            }

            if (1 == row.invoiceState) {
                return "待开票"
            }

            if (3 == row.invoiceState) {

                if (1 == row.fetchTicketWay) {
                    return "待自取"
                }

                if (2 == row.fetchTicketWay) {
                    return "待邮寄"
                }

                return "已开票"
            }

            if (2 == row.invoiceState) {
                if (1 == row.fetchTicketWay) {
                    return "已自取"
                }

                if (2 == row.fetchTicketWay) {
                    return "已邮寄"
                }

                return "已开票"
            }


        },
        //邮寄详情 展示邮寄信息,只有邮寄的展示
        mailInfoDetail: function (value, row, index) {
            /**取票方式:1 自取,2 邮寄*/
            //private Integer fetchTicketWay;
            var rowStr = JSON.stringify(row).replace(/\"/g, "'");
            if (2 == row.fetchTicketWay) {
                return '<span class="ITD-common-color ITD-cursor-pointer pop_detail" data-row="'+rowStr+'">详情</span>'
            }
            return '';

        },
        //操作
        freeReasonFormater: function (value, row, index) {
            /**发票状态,1 开票中,3 已开票  2 已邮寄 */
            var invoiceaddState = row.invoiceState;
            var invoiceaddType = row.invoiceType;
            var invoiceid = row.id;
            var row = JSON.stringify(row).replace(/\"/g, "'");
            var operStr = '';
            //
            if (1 == parseInt(invoiceaddState)) {
                operStr = ' <span href="javascript:;" class="lookMsg ITD-status-on" data-index="' + row + '"  style="margin-right: 4px;" data-type=" ' + invoiceaddType + ' ">查看</span><span href="javascript:;" class="reMsg ITD-status-blue"  data-index="' + invoiceid + '" data-status="3" >开票</span>';
                return operStr;
            } else if(3 == parseInt(invoiceaddState)){
                operStr = '<span href="javascript:;" class="lookMsg ITD-status-on" style="margin-right: 4px;" data-type=" ' + invoiceaddType + ' " data-index="' + row + '" >查看</span><span href="javascript:;" class="reMsg ITD-status-blue"  data-index="' + invoiceid + '" data-status="2">邮寄</span>';
                return operStr;
            }else {
                operStr = '<span href="javascript:;" class="lookMsg ITD-status-on" data-type=" ' + invoiceaddType + ' " data-index="' + row + '" >查看</span>';
                return operStr;
            }

        },
    };
    //初始执行
    invoicefun.init();
    //查询
    $(document).on('click', '#invoice-queryBtn', function () {
        invoicefun.createTableData();
    });
    //详情公司 弹窗
    documentBindFunc.on('click', '.lookMsg', function () {
        var type = $(this).attr('data-type')
        var row = eval('(' + $(this).attr("data-index") + ')');
        console.log(type)
        if (type == 0) {
            $('#print_perfoot').css('display', 'block');
            $('#detail_perAddressee').html(row.recipients);//收件人
            $('#detail_peroperAddr').html(row.recipientsAddress);//地址
            $('#detail_peroperAddr').attr('title',row.recipientsAddress);//地址
            $('#detail_perpersonphone').html(row.recipientsPhone);//收件人电话
            // invoicefun.getinvoiceDetailInfo(id);
            $('#invoice_perdetailmodel').modal('show');
        } else if (type == 1) {
            $('#print_foot').css('display', 'block');
            $('#detail_invoicetopCode').html(row.custName);//抬头
            $('#detail_dutynum').html(row.custTaxid);//税号
            $('#detail_bankNum').html(row.custBankName);//银行
            $('#detail_groupphone').html(row.custPhone);//电话
            $('#detail_groupName').html(row.custCardNo);//账户
            $('#detail_Addressee').html(row.recipients);//收件人
            $('#detail_operAddr').html(row.recipientsAddress);//地址
            $('#detail_operAddr').attr('title',row.recipientsAddress);//地址
            $('#detail_personphone').html(row.recipientsPhone);//收件人电话
            // invoicefun.getinvoiceDetailInfo(id);
            $('#invoice_detailmodel').modal('show');
        }

    });
    //公司 打印功能
    documentBindFunc.on('click', '#detail-print', function () {
        var oldstr = document.body.innerHTML;//保存当前页面的HTML
        $('#print_foot').css('display', 'none');
        var newstr = document.getElementById("print_Msg").innerHTML;//得到需要打印的元素HTML
        document.body.innerHTML = newstr;
        window.print();
        $('#print_foot').css('display', 'block');
        document.body.innerHTML = oldstr;

    });
    //公司 close 发票弹窗
    documentBindFunc.on('click', '#print_close', function () {
        $('#invoice_detailmodel').css('display', 'none');
        $('.modal-backdrop').css('display', 'none');
    });
    //个人 打印功能
    documentBindFunc.on('click', '#detail-perprint', function () {
        var oldstr = document.body.innerHTML;//保存当前页面的HTML
        $('#print_perfoot').css('display', 'none');
        var newstr = document.getElementById("print_perMsg").innerHTML;//得到需要打印的元素HTML
        document.body.innerHTML = newstr;
        window.print();
        $('#print_perfoot').css('display', 'block');
        document.body.innerHTML = oldstr;

    });
    //个人 close 发票弹窗
    documentBindFunc.on('click', '#print_perclose', function () {
        $('#invoice_perdetailmodel').css('display', 'none');
        $('.modal-backdrop').css('display', 'none');
    });
    //开票弹窗
    $(document).on('click', '.reMsg', function (element) {
        var id = $(this).attr('data-index');
        var status = $(this).attr('data-status');
        if(2==status){
            $('#resTitle').html('确认邮寄');
            $('#resCont').html('确定已邮寄或已自取吗');
        }

        if(3 ==status){
            $('#resTitle').html('确认开票');
            $('#resCont').html('确定修改开票状态为已开票吗?');
        }

        $("#updateId").val(id);
        $('#updateStatus').val(status);

        $('#resetmodel').modal('show')
    });

    //详情弹窗 邮寄方式
    documentBindFunc.on('click', '.pop_detail', function (element) {
        //收件人
        $('#mail_perAddressee').html('-')
        //地址
        $('#mail_peroperAddr').html('-')
        //电话
        $('#mail_perpersonphone').html('-')

        var rowStr = $(this).data('row').replace(/\'/g, '"');
        var row = JSON.parse(rowStr);

        //收件人
        $('#mail_perAddressee').html(row.recipients)
        //地址
        $('#mail_peroperAddr').html(row.recipientsAddress)
        //电话
        $('#mail_perpersonphone').html(row.recipientsPhone)

        $('#invoice_mailmodel').modal('show')

    });


    //详情弹窗 邮寄方式 确认按钮
    documentBindFunc.on('click', '#mail-sure', function (element) {
        $('#invoice_mailmodel').modal('hide')
    });
    /**
     * 自定义table AJAX请求
     * @param {Object} params
     */
    function tableLoadRequest(params) {
        var req = invoicefun.getQueryParam();
        //设置请求参数
        var pageNum = (params.data.offset / params.data.limit) + 1;

        //条件查询
        req.baseRequest = {
            pageNum: pageNum,
            pageSize: params.data.limit
        };
        req.sysCode = sysComm.sysCode;
        var opt = {
            method: 'post',
            url: dataUrl.util.queryInvoiceListInfo(),
            data: JSON.stringify(req),
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            success: function (res) {
                if (res.code == '8888') {
                    console.log(res.data);
                    params.success(res.data);
                }
            }
        };
        sysAjax(opt);
    }

    //切换 搜索部分 发票
    documentBindFunc.on('click', "#invoice-toptab div.invoice-topbar", function () {
        var index = $(this).index();
        $(this).addClass('ITD-graynav-topbaractive').siblings('div').removeClass('ITD-graynav-topbaractive');

        invoicefun.createTableData();
        //console.log(index);


    })

})();

//发票状态
$("#reset-submit").on('click', function () {
    var id = $("#updateId").val();
    var updateStatus = $('#updateStatus').val();
    console.log(id);
    var req = {
        id: id,
        invoiceState:updateStatus,
        sysCode: sysComm.sysCode
    };

    var opt = {
        method: 'post',
        url: dataUrl.util.updateInvoiceStateById(),
        data: JSON.stringify(req),
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        success: function (res) {
            if (res.code == '8888') {
                swal({
                    title: "提示",
                    text: "保存成功",
                    type: "success",
                    timer: 3000,
                    allowOutsideClick: true
                });
                //关闭添加页面
                $('#resetmodel').modal('hide');
                //初始化table
                $('#recordtable').bootstrapTable('refresh', {
                    silent: true
                });
            } else {
                swal({
                    title: "提示",
                    text: res.msg,
                    type: "warning",
                    timer: 3000,
                    allowOutsideClick: true
                });
            }
        }

    };
    sysAjax(opt);
});