<!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>
                                <p>客户名称：</p>
                                <input type="text" id="customerName"  name="params[customerName]"/>
                            </li>
                            <li>
                                <label>订单主题：</label>
                                <input type="text" id="orderName"  name="params[orderName]"/>
                            </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="payType" th:with="type=${@dict.getType('pay_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>期次：</label>
                                <select name="payTimes" th:with="type=${@dict.getType('pay_times')}">
                                    <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>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="crm:pay:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="crm:pay:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="crm:pay:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-info multiple disabled" onclick="javascript:transferPerson();" shiro:hasPermission="crm:pay:transfer">
                    <i class="fa fa-exchange"></i> 转交
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="crm:pay: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 editFlag = [[${@permission.hasPermi('crm:pay:edit')}]];
        var removeFlag = [[${@permission.hasPermi('crm:pay:remove')}]];
        var payTypeDatas = [[${@dict.getType('pay_type')}]];
        var payTimesDatas = [[${@dict.getType('pay_times')}]];
        var payStatusDatas = [[${@dict.getType('pay_status')}]];
        var isInvoiceDatas = [[${@dict.getType('is_invoice')}]];
        var prefix = ctx + "crm/pay";

        $(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 : 'payId', 
                    title : '合同付款ID',
                    visible: false
                },
                {
                    field : 'payDate', 
                    title : '回款时间',
                    formatter: function(value, row, index) {
                        return value.substring(0,16);
                     },
		            sortable: true
                },
                {
                    field : 'payMoney', 
                    title : '回款金额',
		            sortable: true
                },
                {
                    field : 'orderId', 
                    title : '关联订单ID',
                    visible: false
                },
                {
                    field : 'customer.customerName', 
                    title : '客户名称',
		            sortable: true
                },
                {
                    field : 'order.orderName', 
                    title : '成交订单',
		            sortable: true
                },
                {
                    field : 'payTimes', 
                    title : '期次',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(payTimesDatas, value);
                    },
		            sortable: true
                },
                {
                    field : 'payType', 
                    title : '付款方式',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(payTypeDatas, value);
                    },
		            sortable: true
                },
                {
                    field : 'payStatus', 
                    title : '付款状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(payStatusDatas, value);
                    },
		            sortable: true
                },
                {
                    field : 'isInvoice', 
                    title : '是否需要发票',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isInvoiceDatas, value);
                    },
		            sortable: true
                },
                {
                    field : 'sourceBelongTo', 
                    title : '原负责人',
                    visible: false,
		            sortable: true
                },
                {
                    field : 'belongTo', 
                    title : '负责人',
		            sortable: true
                },
                {
                    field : 'trasferDate', 
                    title : '转交时间',
                    visible: false,
		            sortable: true
                },
                {
                    field : 'trasferTo', 
                    title : '转交人',
                    visible: false,
		            sortable: true
                },
                {
                    field : 'createBy', 
                    title : '录入人',
		            sortable: true
                },
                {
                    field : 'createTime', 
                    title : '录入时间',
		            sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.payId + '\')"><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.payId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        /* 转交给其他人 */
		function transferPerson() {
			var payId = $.table.selectColumns("payId");
			if (payId.length == 0) {
				$.modal.alertWarning("请至少选择一条记录");
				return;
			}	
			var url = ctx + 'crm/transfer/transferPerson?ids=' + payId.join()+"&businessType=Pay";
			$.modal.open("转给其它团队成员（变更负责人）", url);
		}
    </script>
</body>
</html>