<!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>
                                <label>姓名：</label>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <label>公司：</label>
                                <input type="text" name="company"/>
                            </li>
                            <li>
                                <label>职务：</label>
                                <input type="text" name="duty"/>
                            </li>
                            <li>
                                <label>手机：</label>
                                <input type="text" name="mobile"/>
                            </li>
                            <li>
                                <label>用户邮箱：</label>
                                <input type="text" name="email"/>
                            </li>
                            <li>
                                <label>线索状态：</label>
                                <select name="clueStatus" th:with="type=${@dict.getType('clue_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="clueSource" th:with="type=${@dict.getType('crm_customer_source')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>决策等级：</label>
                                <select name="decisionLevel" th:with="type=${@dict.getType('person_decision_level')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>市场活动：</label>
                                <input type="text" name="marketActivity"/>
                            </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-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="crm:clue:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="crm:clue:remove">
                    <i class="fa fa-remove"></i> 删除
                </a> -->                
                 <div class="btn-group" shiro:hasPermission="crm:clue:transfer">
                 	<button data-toggle="dropdown" class="btn  btn-sm btn-info dropdown-toggle  multiple disabled "><i class="fa fa-exchange"></i>&nbsp;转交<span class="caret"></span></button>
                    	<ul class="dropdown-menu">
                        	<li><a href="javascript:transferPerson();">转交给指定人员</a></li>
                       	</ul>
                 </div>
                 <a class="btn btn-primary single disabled" onclick="get()" shiro:hasPermission="crm:customer:get">
                    <i class="fa fa-hand-o-up"></i> 领取
                 </a>			
				<a class="btn btn-success single disabled" onclick="addFollow();" shiro:hasPermission="crm:clueFollow:add"> 
					<i class="fa fa-plus"></i> 写跟进
				</a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="crm:clue: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 cancelFlag = [[${@permission.hasPermi('crm:clue:cancel')}]];
        var editFlag = [[${@permission.hasPermi('crm:clue:edit')}]];
        var removeFlag = [[${@permission.hasPermi('crm:clue:remove')}]];
        var sexDatas = [[${@dict.getType('sys_user_sex')}]];
        var clueSourceDatas = [[${@dict.getType('crm_customer_source')}]];
        var decisionLevelDatas = [[${@dict.getType('person_decision_level')}]];
        var clueStatusDatas = [[${@dict.getType('clue_status')}]];
        var prefix = ctx + "crm/clue";
		var prefixFollow= ctx + "crm/clueFollow";

        $(function() {
            var options = {
                url: prefix + "/listPublic",
                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 : 'clueId', 
                    title : '线索ID',
                    visible: false
                },
                {
                    field : 'name', 
                    title : '姓名',
		            sortable: true,
		            formatter: function(value, row, index) {
		            	if(row.belongTo==""||row.belongTo==null){ 
		            		return '<span style="color:red;" title="这是一个公共线索">[公共线索]</span><a style="color:blue;" href="javascript:void(0)" title="查看详情" onclick="detail(\'' +row.clueId + '\')">'+value+'</a> ';
		            	}
		            	else{
		            		return '<a style="color:blue;" href="javascript:void(0)" title="查看详情" onclick="detail(\'' +row.clueId + '\')">'+value+'</a> ';
		            	} 
	                }
                
                },
                {
                    field : 'company', 
                    title : '公司',
		            sortable: true
                },
                {
                    field : 'address', 
                    title : '地址',
		            sortable: true
                },
                {
                    field : 'duty', 
                    title : '职务',
		            sortable: true
                },
                {
                    field : 'mobile', 
                    title : '手机',
		            sortable: true
                },
                {
                    field : 'email', 
                    title : '用户邮箱',
		            sortable: true
                },
                {
                    field : 'qq', 
                    title : 'qq',
		            sortable: true,
                    visible: false
                },
                {
                    field : 'wechat', 
                    title : '微信',
		            sortable: true,
                    visible: false
                },
                {
                    field : 'wangwang', 
                    title : '旺旺',
		            sortable: true,
                    visible: false
                },
                {
                    field : 'msn', 
                    title : 'MSN',
		            sortable: true,
                    visible: false
                },
                {
                    field : 'sex', 
                    title : '性别',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(sexDatas, value);
                    },
		            sortable: true
                },
                {
                    field : 'clueStatus', 
                    title : '线索状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(clueStatusDatas, value);
                    },
		            sortable: true
                },
                {
                    field : 'clueSource', 
                    title : '线索来源',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(clueSourceDatas, value);
                    },
		            sortable: true
                },
                {
                    field : 'decisionLevel', 
                    title : '决策等级',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(decisionLevelDatas, value);
                    },
		            sortable: true
                },
                {
                    field : 'marketActivity', 
                    title : '市场活动',
		            sortable: true
                },
                {
                    field : 'remark', 
                    title : '备注',
		            sortable: true,
                    visible: false
                },
                {
                    field : 'belongTo', 
                    title : '负责人',
		            sortable: true,
		            formatter: function(value, row, index) {
		            	if(row.belongTo==""||row.belongTo==null){
		            		return '<span style="color:red;">[公共线索]</span>'; 
		            	}else{
		            		return value;
		            	}
	                },
                    visible: false
                },
                {
                    field : 'createBy', 
                    title : '录入人',
		            sortable: true,
                    visible: false
                },
                {
                    field : 'createTime', 
                    title : '录入时间',
		            sortable: true,
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                    	var actions = [];
                        if(row.clueStatus=="0"){
			                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.clueId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
			                actions.push("<a class='btn btn-warning btn-xs " + cancelFlag + "' href='javascript:void(0)' onclick='cancelOk(" + row.clueId + ")'><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.clueId + '\')"><i class="fa fa-remove"></i>删除</a> ');
	                    }
                        else if(row.clueStatus=="1"){
	                       	actions.push('<a class="btn btn-primary btn-xs ' + cancelFlag + '" href="javascript:void(0)" onclick="cancelNo(\'' + row.clueId + '\')"><i class="fa fa-check"></i>取消作废</a> ');
	                       	actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.clueId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }
		                return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        function cancelOk(clueId)
        {        	
        	$.modal.confirm("确认作废吗？", function() {
        		var data = { "clueId": clueId,"isCancel":1};
    			$.operate.post(prefix + "/cancel", data);
        	});
        }        
        function cancelNo(clueId)
        {        	
        	$.modal.confirm("确认取消作废吗？", function() {
        		var data = { "clueId": clueId,"isCancel":0};
    			$.operate.post(prefix + "/cancel", data);
        	});
        }
        
        /*转客户*/
		function convert(clueId) {
		    $.modal.confirm("确认要转成客户吗?", function() {
    			$.operate.post(prefix + "/convert/"+clueId);
    		});
		}
		/*转交给个人 */
        function transferPerson(){
        	var ids = $.table.selectColumns("clueId");
        	if (ids.length == 0) {
        		$.modal.alertWarning("请至少选择一条记录");
        		return;
        	}
        	var url = ctx + 'crm/transfer/transferPerson?ids=' + ids.join()+"&businessType=Clue";
        	$.modal.open("转给其它团队成员（变更负责人）", url);
        }
        /* 领取 */
        function get() {
        	var ids = $.table.selectColumns("clueId");
        	if (ids.length == 0) {
        		$.modal.alertWarning("请至少选择一条记录");
        		return;
        	}
        	var url = ctx + 'crm/transfer/getPublic?ids=' + ids.join()+"&businessType=Clue";
        	$.modal.open("领取线索", url);
        }
        
        /*详细*/
        function detail(id) {
        	var url = prefix + '/detail/' + id;
        	$.modal.openTab("查看线索详情", url);
        }
        
        /*跟进*/
		 function addFollow()
		 {
			 var clueId = $.table.selectColumns("clueId");
			 $.modal.open('添加跟进', prefixFollow + '/addFollow/'+clueId);
		 }
    </script>
</body>
</html>