<!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" style="display: none;">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>合同ID：</p>
                                <input type="text" name="contractId"/>
                            </li>
                            <li>
                                <p>客户名称：</p>
                                <input type="text" id="customerName"  name="params[customerName]"/>
                            </li>
                            <li>
                                <p>主题：</p>
                                <input type="text" name="orderName"/>
                            </li>
                            <li>
                                <p>总价：</p>
                                <input type="text" name="totalPrice"/>
                            </li>
                            <li>
                                <p>订单状态：</p>
                                <select name="orderStatus" th:with="type=${@dict.getType('order_status')}">
                                    <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:order:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <!-- <a class="btn btn-primary single disabled" onclick="$.operate.editTab()" shiro:hasPermission="crm:order:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="crm:order:remove">
                    <i class="fa fa-remove"></i> 删除
                </a> -->
                <a class="btn btn-info multiple disabled" onclick="javascript:transferPerson();" shiro:hasPermission="crm:order:transfer">
                    <i class="fa fa-exchange"></i> 转交
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="crm:order: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:order:edit')}]];
        var removeFlag = [[${@permission.hasPermi('crm:order:remove')}]];
        var orderStatusDatas = [[${@dict.getType('order_status')}]];
        var prefix = ctx + "crm/order";

        $(function() {
            var options = {
                url: prefix + "/list",
                detailUrl: prefix + "/detail/{id}",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
		        sortName: "createTime",
		        sortOrder: "desc",
                modalName: "成交订单",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'orderId', 
                    title : '订单ID',
                    visible: false
                },
                {
                    field : 'orderCode', 
                    title : '订单编码',
                    visible:false
                },
                {
                    field : 'contractId', 
                    title : '合同ID',
		            sortable: true,
                    visible:false
                },
                {
                    field : 'customerId', 
                    title : '客户id',
                    visible:false,
		            sortable: true
                },
                {
                    field : 'orderName', 
                    title : '主题',
		            sortable: true,
                    visible:false
                },
                {
                    field : 'orderDate', 
                    title : '成交/签约时间',
		            sortable: true,
                    formatter: function(value, row, index) {
                    	if($.common.isNotEmpty(value)){
                    		return value.substring(0,10);
                    	}
                     }
                },
                {
                	field : 'customer.customerName', 
                    title : '成交客户',
		            sortable: true,
		            formatter: function(value, row, index) {
		            	return '<a style="color:blue;" href="javascript:void(0)" title="查看详情" onclick="$.operate.detail(\'' +row.orderId + '\')">'+value+'</a> ';
	                }
                },
                {
                    field : 'totalPrice', 
                    title : '成交总额',
		            sortable: true
                },
                {
                    field : 'costPrice', 
                    title : '总成本',
		            sortable: true
                },
                {
                    field : 'aaa', 
                    title : '利润',
		            sortable: true,
                    formatter: function(value, row, index) {
                    	if($.common.isNotEmpty(row.totalPrice)&&$.common.isNotEmpty(row.costPrice)){
                    		return row.totalPrice-row.costPrice;
                    	}
                     }
                },
                {
                    field : 'orderStatus', 
                    title : '订单状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(orderStatusDatas, value);
                    },
		            sortable: true
                },
                {
                    field : 'validStart', 
                    title : '有效期开始时间',
		            sortable: true,
                    formatter: function(value, row, index) {
                    	if($.common.isNotEmpty(value)){
                    		return value.substring(0,10);
                    	}
                     }
                },
                {
                    field : 'validEnd', 
                    title : '有效期结束时间',
		            sortable: true,
                    formatter: function(value, row, index) {
                    	if($.common.isNotEmpty(value)){
                    		return value.substring(0,10);
                    	}
                     }
                },
                {
                    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.editTab(\'' + row.orderId + '\')"><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.orderId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });        

		/* 转交给其他人 */
		function transferPerson() {
			var orderId = $.table.selectColumns("orderId");
			if (orderId.length == 0) {
				$.modal.alertWarning("请至少选择一条记录");
				return;
			}	
			var url = ctx + 'crm/transfer/transferPerson?ids=' + orderId.join()+"&businessType=Order";
			$.modal.open("转给其它团队成员（变更负责人）", url);
		}
    </script>
</body>
</html>