<!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>客户名称：</p>
                                <input type="text" id="customerName"  name="params[customerName]"/>
                                <input type="text" id="customerId"  name="customerId" th:value="${customerId}" />
                            </li>
                            <li>
                                <p>报价单名称：</p>
                                <input type="text" name="orderName"/>
                            </li>
                            <li>
                                <p>总价：</p>
                                <input type="text" name="totalPrice"/>
                            </li>
                            <li class="select-time">
                                <p>报价时间：</p>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginPrcieDate]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endPrcieDate]"/>
                            </li>
                            <li>
                                <p>报价单状态：</p>
                                <select name="orderStatus" th:with="type=${@dict.getType('price_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:orderPrice:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <!-- <a class="btn btn-primary single disabled" onclick="$.operate.editTab()" shiro:hasPermission="crm:orderPrice:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="crm:orderPrice:remove">
                    <i class="fa fa-remove"></i> 删除
                </a> -->
                <a class="btn btn-info multiple disabled" onclick="javascript:transferPerson();" shiro:hasPermission="crm:orderPrice:transfer">
                    <i class="fa fa-exchange"></i> 转交
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="crm:orderPrice: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 priceFlag=[[${@permission.hasPermi('crm:orderPrice:price')}]];
    	var cancelFlag=[[${@permission.hasPermi('crm:orderPrice:cancel')}]];
    	var auditFlag=[[${@permission.hasPermi('crm:orderPrice:audit')}]];
    	var convertFlag = [[${@permission.hasPermi('crm:orderPrice:convert')}]];
        var editFlag = [[${@permission.hasPermi('crm:orderPrice:edit')}]];
        var removeFlag = [[${@permission.hasPermi('crm:orderPrice:remove')}]];
        var orderStatusDatas = [[${@dict.getType('price_order_status')}]];
        var prefix = ctx + "crm/orderPrice";
        var customerId= [[${customerId}]];
        $(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,
		            sortable: true
                },
                {
                    field : 'orderCode', 
                    title : '订单编码',
                    visible:false,
		            sortable: true
                },
                {
                    field : 'totalPrice', 
                    title : '报价总额',
		            sortable: true
                },
                {
                	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 : 'contractId', 
                    title : '合同ID',
                    visible:false,
		            sortable: true
                },
                {
                    field : 'customerId', 
                    title : '客户id',
                    visible:false,
		            sortable: true
                },
                {
                    field : 'orderName', 
                    title : '主题',
		            sortable: true,
                    visible:false
                },
                {
                    field : 'prcieDate', 
                    title : '报价时间',
                    formatter: function(value, row, index) {
                        return value.substring(0,10);
                     },
 		            sortable: true
                },
                {
                    field : 'prcieEndDate', 
                    title : '报价截止时间',
                    formatter: function(value, row, index) {
                        return value.substring(0,10);
                     },
 		            sortable: true
                },
                {
                    field : 'orderStatus', 
                    title : '报价单状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(orderStatusDatas, value);
                    },
		            sortable: true
                },
                {
                    field : 'prcieBy', 
                    title : '报价人',
		            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 = [];
                        if(row.orderStatus=="0"){//已保存
                        	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-warning btn-xs ' + cancelFlag + '" href="javascript:void(0)" onclick="cancelOk(\'' + row.orderId + '\')"><i class="fa fa-reply"></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>');
                        }
                        else if(row.orderStatus=="1"){//已提交
                        	actions.push('<a class="btn btn-primary btn-xs ' + auditFlag + '" href="javascript:void(0)" onclick="auditOk(\'' + row.orderId + '\')"><i class="fa fa-check"></i>审核通过</a> ');
                        	actions.push('<a class="btn btn-danger btn-xs ' + auditFlag + '" href="javascript:void(0)" onclick="auditNo(\'' + row.orderId + '\')"><i class="fa fa-reply"></i>驳回</a> ');
                        }
                        else if(row.orderStatus=="2"){//已审核
                        	actions.push('<a class="btn btn-primary btn-xs ' + priceFlag + '" href="javascript:void(0)" onclick="price(\'' + row.orderId + '\')"><i class="fa fa-check"></i>报价</a> ');
                        	actions.push('<a class="btn btn-warning btn-xs ' + cancelFlag + '" href="javascript:void(0)" onclick="cancelOk(\'' + row.orderId + '\')"><i class="fa fa-reply"></i>作废</a> ');
                        }      
                        else if(row.orderStatus=="3"){//已驳回
                        	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-warning btn-xs ' + cancelFlag + '" href="javascript:void(0)" onclick="cancelOk(\'' + row.orderId + '\')"><i class="fa fa-reply"></i>作废</a> ');
                        }  
                        else if(row.orderStatus=="4"){//已作废
                        	actions.push('<a class="btn btn-primary btn-xs ' + cancelFlag + '" href="javascript:void(0)" onclick="cancelNo(\'' + row.orderId + '\')"><i class="fa fa-check"></i>取消作废</a> ');
                        }
                        else if(row.orderStatus=="5"){//已报价
                        	actions.push('<a class="btn btn-primary btn-xs ' + convertFlag + '" href="javascript:void(0)" onclick="convert(\'' + row.orderId + '\')"><i class="fa fa fa-arrow-right"></i>转成订单</a> ');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        function auditOk(orderId)
        {        	
        	$.modal.confirm("确认审核通过吗？", function() {
        		$.operate.post(prefix + "/auditOk/"+orderId);
        	});
        }        
        function auditNo(orderId)
        {        	
        	$.modal.confirm("确认驳回吗？", function() {
        		$.operate.post(prefix + "/auditNo/"+orderId);
        	});
        }
        function cancelOk(orderId)
        {        	
        	$.modal.confirm("确认作废吗？", function() {
        		$.operate.post(prefix + "/cancelOk/"+orderId);
        	});
        }        
        function cancelNo(orderId)
        {        	
        	$.modal.confirm("确认取消作废吗？", function() {
        		$.operate.post(prefix + "/cancelNo/"+orderId);
        	});
        }
        function price(orderId)
        {        	
        	$.modal.confirm("确认报价吗？", function() {
        		$.operate.post(prefix + "/price/"+orderId);
        	});
        }        
                
		/*转成订单*/
		function convert(orderId) {
		    $.modal.confirm("确认要转成订单吗?", function() {
    			$.operate.post(prefix + "/convert/"+orderId);
    		});
		}
		
		/* 转交给其他人 */
		function transferPerson() {
			var orderId = $.table.selectColumns("orderId");
			if (orderId.length == 0) {
				$.modal.alertWarning("请至少选择一条记录");
				return;
			}	
			var url = ctx + 'crm/transfer/transferPerson?ids=' + orderId.join()+"&businessType=OrderPrice";
			$.modal.open("转给其它团队成员（变更负责人）", url);
		}
    </script>
</body>
</html>