<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('合同付款管理列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>合同名称：</label>
                                <input type="text" id="contractName"  name="params[contractName]"/>
                            </li>
                            
                            <li class="select-time">
                                <label>付款日期：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginPayDate]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endPayDate]"/>
                            </li>
                            <li>
                                <label>付款状态：</label>
                                <select name="payStatus" th:with="type=${@dict.getType('pay_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>是否需要发票：</label>
                                <select name="isInvoice" th:with="type=${@dict.getType('is_invoice')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i> 搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i> 重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="crm:contractPayment:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="crm:contractPayment:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
    	var auditFlag=[[${@permission.hasPermi('crm:contractPayment:audit')}]];
        var editFlag = [[${@permission.hasPermi('crm:contractPayment:edit')}]];
        var removeFlag = [[${@permission.hasPermi('crm:contractPayment:remove')}]];
        var payTypeDatas = [[${@dict.getType('pay_type')}]];
        var payStatusDatas = [[${@dict.getType('pay_status')}]];
        var isInvoiceDatas = [[${@dict.getType('is_invoice')}]];
        var prefix = ctx + "crm/contractPayment";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
		        sortName: "createTime",
		        sortOrder: "desc",
                modalName: "合同付款",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'paymentId', 
                    title : '付款ID',
                    visible: false
                },
                {
                    field : 'contractId', 
                    title : '关联合同id',
                    visible: false
                },
                {
                    field : 'contract.contractName', 
                    title : '合同名称'
                },
                {
                    field : 'contract.totalMoney', 
                    title : '合同总金额'
                },
                {
                    field : 'payMoney', 
                    title : '本次付款金额'
                },
                {
                    field : 'payDate', 
                    title : '付款日期',
                    formatter: function(value, row, index) {
                        return value.substring(0,10);
                     }
                },
                {
                    field : 'payType', 
                    title : '付款方式',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(payTypeDatas, value);
                    }
                },
                {
                    field : 'payStatus', 
                    title : '付款状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(payStatusDatas, value);
                    }
                },
                {
                    field : 'isInvoice', 
                    title : '是否需要发票',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isInvoiceDatas, value);
                    }
                },
                {
                    field : 'createBy', 
                    title : '录入人'
                },
                {
                    field : 'createTime', 
                    title : '录入时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                    	var actions = [];
                        if(row.payStatus=="1"){
                        	actions.push('<a class="btn btn-primary btn-xs ' + auditFlag + '" href="javascript:void(0)" onclick="auditOk(\'' + row.paymentId + '\')"><i class="fa fa-check"></i>审核通过</a> ');
                        	actions.push('<a class="btn btn-danger btn-xs ' + auditFlag + '" href="javascript:void(0)" onclick="auditNo(\'' + row.paymentId + '\')"><i class="fa fa-reply"></i>驳回</a> ');
                        }
                        else if(row.payStatus=="3"){
                        	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.paymentId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        }
                        else if(row.payStatus=="0"){
                        	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.paymentId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.paymentId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        function auditOk(id)
        {        	
        	$.modal.confirm("确认审核通过吗？", function() {
        		$.operate.post(prefix + "/auditOk/"+id);
        	});        	
        }
        
        function auditNo(id)
        {        	
        	$.modal.confirm("确认驳回吗？", function() {
        		$.operate.post(prefix + "/auditNo/"+id);
        	});        	
        }
    </script>
</body>
</html>