invoicemanage.js 16.3 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
/**
 * 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() {
    /**
     * 自定义table AJAX请求
     * @param {Object} params
     */
    /*function tableLoadRequest(params) {
        var req = fun.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.queryParkOrderForFinance(),
            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);
    }*/

    var invoicefun = {
        init: function() {
            //初始化table
            $('#onduty').selectpicker('refresh');
            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: '发票类型',
                        width: '10%',
                        align: 'left',
                        formatter: function(value, row, index) {
                            if(undefined != value && null != value) {
                                if(value == '1') {
                                    return '公司'
                                } else if(value == '0') {
                                    return '个人';
                                } else {
                                    return '未知'
                                }
                            }
                            else {
                                return '-'
                            }
                        }
                    },
                    {
                        field: 'invoiceKind',
                        title: '发票种类',
                        width: '10%',
                        align: 'left',
                        formatter: function(value, row, index) {
                            if(undefined != value && null != value) {
                                if(value == '1') {
                                    return '增值发票'
                                } else if(value == '0') {
                                    return '普通发票';
                                } else {
                                    return '-'
                                }
                            }else {
                                return '-'
                            }
                        }
                    },
                    {
                        field: 'applyDate',
                        title: '申领时间',
                        width: '15%',
                        align: 'left',
                        formatter: invoicefun.inDatatimeFormatter
                    },
                    {
                        field: 'fetchTicketWay',
                        title: '取票方式',
                        width: '15%',
                        align: 'left',
                        formatter:  function(value, row, index) {
                            if(undefined != value && null != value) {
                                if(value == '1') {
                                    return '自取'
                                } else if(value == '2') {
                                    return '邮寄'
                                }
                            }else{
                                return '-';
                            }
                        }
                    },
                    {
                        field: 'invoiceState',
                        title: '开票状态',
                        width: '5%',
                        align: 'left',
                        formatter: function(value, row, index) {
                            if(undefined != value && null != value) {
                                if(value == '1') {
                                    return '未开票'
                                }  else if(value == '2') {
                                    return '已开票'
                                }else {
                                    return '未知';
                                }
                            }
                        }
                    }, {
                        field: 'invoiceTotalFee',
                        title: '发票金额',
                        width: '10%',
                        align: 'left',
                        formatter: invoicefun.moneyFormatter
                    },
                    {
                        field: 'postDate',
                        title: '开票时间',
                        width: '15%',
                        align: 'left',
                        formatter: invoicefun.inDatatimeFormatter
                    },
                    {
                        field: '',
                        title: '操作',
                        width: '20%',
                        align: 'left',
                        //visible: false,
                        formatter: invoicefun.freeReasonFormater
                    }
                ]
            });

        },
        /*获取查询参数*/
        getQueryParam: function() {
            var _carNumber = $("#_carNumber").val();
            var custPhone = $("#_phone").val();
            var onduty = $('#onduty').val();
            var req = {
                custPhone: custPhone,
                carNumber: _carNumber,
                invoiceState: onduty != '' ? onduty : null
            };
            return req;
        },

        //操作
        freeReasonFormater: function(value, row, index) {
            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 = ' <a href="javascript:;" class="lookMsg" data-index="' +  row + '"  style="margin-right: 10px;" data-type=" ' + invoiceaddType  + ' ">详情</a><a href="javascript:;" class="reMsg"  data-index="' +invoiceid+ '" >开票</a>';
                return operStr;
            }else{
                operStr ='<a href="javascript:;" class="lookMsg" data-type=" ' + invoiceaddType  + ' " data-index="' + row   + '" >详情</a>';
                return operStr;
            }

        },
        inDatatimeFormatter: function(value, row, index) {
            if(value == null) {
                return "";
            } else {
                return "<div class='imgClick'>" + DateUtils.long2String(value, 7) + "</div>";
            }
        },
        //金额处理
        moneyFormatter: function(value) {
            // console.log(typeof value)
            if(value == 0 || value == undefined || value == null) {
                return 0;
            } else {
                return(value / 100).toFixed(2);
            }
        },
        imageformatter: function(value, row, index) {
            return "<span onClick='' id='inParkimage'></span>";

        }
    };
    //初始执行
    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_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_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');
        $("#updateId").val(id);
        $('#resetmodel').modal('show')
    });
    /**
     * 自定义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);
    }

})();

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

    var opt = {
        method: 'post',
        url: dataUrl.util.updateInvioceById(),
        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);
});