Browse Source

feat:客户-编辑规则页面-精准筛选

fuwencai 1 năm trước cách đây
mục cha
commit
fb045fa817

+ 4 - 4
CMPlatform/service/group.go

@@ -13,7 +13,7 @@ type Groups struct {
 	delGroup    xweb.Mapper `xweb:"/(service|client)/cuser/delGroup"`
 }
 
-func (this *Groups) GroupList() {
+func (this *Groups) GroupList(identityType string) {
 	id := this.GetString("id")
 	datas := []map[string]interface{}{}
 	data, ok := util.Mgo.Find("groups", map[string]interface{}{"ruleId": id}, `{"_id":-1}`, nil, false, -1, -1)
@@ -23,7 +23,7 @@ func (this *Groups) GroupList() {
 	this.ServeJson(map[string]interface{}{"data": datas})
 }
 
-func (this *Groups) AddGroup() {
+func (this *Groups) AddGroup(identityType string) {
 	id := this.GetString("id")
 	name := this.GetString("name")
 	data := map[string]interface{}{
@@ -40,7 +40,7 @@ func (this *Groups) AddGroup() {
 	this.ServeJson(map[string]interface{}{"resp": ok})
 }
 
-func (this *Groups) UpdateGroup() {
+func (this *Groups) UpdateGroup(identityType string) {
 	name := this.GetString("name")
 	mgoId := this.GetString("_id")
 	ruleId := this.GetString("id")
@@ -59,7 +59,7 @@ func (this *Groups) UpdateGroup() {
 	this.ServeJson(map[string]interface{}{"resp": ok})
 }
 
-func (this *Groups) DelGroup() {
+func (this *Groups) DelGroup(identityType string) {
 	ruleId := this.GetString("ruleId")
 	name := this.GetString("name")
 	query := map[string]interface{}{"ruleId": ruleId, "name": name}

+ 170 - 2
CMPlatform/web/templates/client/cuser_rule_edit.html

@@ -458,6 +458,7 @@
                                     <th>匹配方式</th>
                                     <th>采购单位类型</th>
                                     <th>公告行业</th>
+                                    <th>分组</th>
                                 </tr>
                                 </thead>
                             </table>
@@ -867,6 +868,17 @@
                         return str
                     }, width: "5%"
                 },
+                {
+                    "data": "s_group", width: "6%", render: function (val) {
+                        if (dataMap.i_exact !== 1) {
+                            return ""
+                        }
+                        if (val == undefined) {
+                            val = ""
+                        }
+                        return val
+                    }
+                }
             ],
             "columnDefs": [{
                 "targets": [2],
@@ -1721,6 +1733,7 @@
         dataMap["s_globaladdkey"] = $('#g_addkey').val();
         dataMap["s_globalnotkey"] = $('#g_notkey').val();
         dataMap["s_globalclearkey"] = $('#s_globalclearkey').val();
+        dataMap["s_exactRule"] = exactRuleArrToStr()
         if (dataMap["s_customer"] == "" || dataMap["s_name"] == "" || dataMap["s_salesperson"] == "" || dataMap["s_serverperson"] == "") {
             alert("请填写必须字段!")
             return
@@ -2194,8 +2207,26 @@
         $('#addword_txt').val("");
         $('#notword_txt').val("");
         $('#modal-add-keyword > div > div > div > div.modal-header > div > div > span:nth-child(2)').html("新增关键词")
+        $.ajax({
+            url: "/client/cuser/groupList",
+            type: "post",
+            async: false,
+            data: {"id": dataMap.id},
+            success: function (r) {
+                if (r.data) {
+                    var provOpt = ""
+                    provOpt += `<option value='默认分组'>默认分组</option>`
+                    for (var i in r.data) {
+                        provOpt += `<option value='${r.data[i].name}'>${r.data[i].name}</option>`
+                    }
+                    $("#selectGroups").html(provOpt)
+                    $("#selectGroups").selectpicker("refresh");
+                }
+            }
+        })
 
         $('#modal-add-keyword').modal("show");
+
     }
 
     //关键词修改
@@ -2208,7 +2239,27 @@
             $('#addword_txt').val(o_rules[index].s_addkey);
             $('#notword_txt').val(o_rules[index].s_notkey);
             $('#modal-add-keyword > div > div > div > div.modal-header > div > div > span:nth-child(2)').html("修改关键词")
-
+            var provOpt = ``
+            $.ajax({
+                url: "/client/cuser/groupList",
+                type: "post",
+                async: false,
+                data: {"id": dataMap.id},
+                success: function (r) {
+                    if (r.data) {
+                        provOpt += `<option value='默认分组'>默认分组</option>`
+                        for (var i in r.data) {
+                            if (r.data[i].name === o_rules[index].s_group){
+                                provOpt += `<option selected value='${r.data[i].name}'>${r.data[i].name}</option>`
+                            }else {
+                                provOpt += `<option value='${r.data[i].name}'>${r.data[i].name}</option>`
+                            }
+                        }
+                        $("#selectGroups").html(provOpt)
+                        $("#selectGroups").selectpicker("refresh");
+                    }
+                }
+            })
         } else {
             showTip("请选中需要修改的关键词,且只能选中一条", 1000)
         }
@@ -2224,6 +2275,8 @@
             rule["s_matchkey"] = key.replace(",", ",");
             if (addkey != "") rule["s_addkey"] = addkey.replace(",", ",");
             if (notkey != "") rule["s_notkey"] = notkey.replace(",", ",");
+            rule["s_group"] = $('#selectGroups option:selected').val()
+
             $('#modal-add-keyword').modal('hide');
             if (key_flag == 1) {
                 var index = selectIndex[0] - 1;
@@ -2537,7 +2590,6 @@
             type: "post",
             data: {"title": title, "detail": detail},
             success: function (r) {
-                debugger
                 if (r.exactRule != ""){
                     testexactRuleTableArr = exactRuleStrToArr( r.exactRule)
                     $('#checkExactRuleTable').DataTable({
@@ -2610,6 +2662,122 @@
         })
     }
     //分组管理
+    function selectGroups(){
+        $('#modal-select-group').modal("show");
+    }
+
+    function groupList(){
+        $.ajax({
+            url: "/client/cuser/groupList",
+            type: "post",
+            data: {"id": dataMap.id},
+            async: false,
+            success: function (r) {
+                if (r.data) {
+                    var str = ""
+                    for (var i in r.data) {
+                        str += `<div>
+                            <span>${r.data[i].name}</span>
+                            <a onclick="delGroup('${r.data[i].name}')" style="margin-left:15px;float: right">删除</a>
+                            <a onclick="updateGroup(this,'${r.data[i]._id}','${r.data[i].name}')" style="float: right">编辑</a>
+                        </div>`
+                    }
+                    $("#groupList").html(str)
+                }
+            }
+        })
+    }
+    groupList()
+
+    function addGroup(){
+        if ($("#groupList").find("#groupName").length > 0) {
+            str = "请先完成上一个编辑";
+            showTip(str, 2000);
+            return
+        }
+        groupList()
+        $(".addGroup").hide()
+        var str = `<div id="groupDiv">
+            <input type="text" id="groupName" maxlength="10" placeholder="请输入分组名称" style="width: 40%">
+            <a onclick="cancelGroup()" style="margin-left:15px;float: right">取消</a>
+            <a onclick="saveGroup()" style="float: right">确定</a>
+        </div>`
+        $("#groupList").append(str)
+    }
+
+    function saveGroup(id){
+        var name = $("#groupName").val().trim()
+        if (name === "") {
+            str = "请输入分组名称";
+            showTip(str, 1000);
+            return
+        }
+        if (id) {
+            $.ajax({
+                url: "/client/cuser/updateGroup",
+                type: "post",
+                data: {"_id": id,"id":dataMap.id,"name":name},
+                success: function (r) {
+                    if (r.resp) {
+                        groupList()
+                        str = "编辑成功";
+                        showTip(str, 1000);
+                    } else {
+                        str = "分组名不可重复";
+                        showTip(str, 1000);
+                    }
+                }
+            })
+        } else {
+            $.ajax({
+                url: "/client/cuser/addGroup",
+                type: "post",
+                data: {"id": dataMap.id,"name":name},
+                success: function (r) {
+                    if (r.resp) {
+                        groupList()
+                        $(".addGroup").show()
+                        str = "添加成功";
+                        showTip(str, 1000);
+                    } else {
+                        str = "分组名不可重复";
+                        showTip(str, 1000);
+                    }
+                }
+            })
+        }
+    }
+
+    function cancelGroup(){
+        $(".addGroup").show()
+        $("#groupDiv").remove()
+    }
+
+    function updateGroup(obj,id,name){
+        if ($("#groupList").find("#groupName").length > 0) {
+            str = "请先完成上一个编辑";
+            showTip(str, 2000);
+            return
+        }
+        var str = `<input type="text" id="groupName" maxlength="10" placeholder="请输入分组名称" value="${name}" style="width: 40%">
+            <a onclick="groupList()" style="margin-left:15px;float: right">取消</a>
+            <a onclick="saveGroup('${id}')" style="float: right">确定</a>`
+        $(obj).parent().html(str)
+    }
+
+    function delGroup(name){
+        $.ajax({
+            url: "/client/cuser/delGroup",
+            type: "post",
+            data: {"ruleId": dataMap.id,"name": name},
+            success: function () {
+                groupList()
+                str = "删除成功";
+                showTip(str, 1000);
+            }
+        })
+    }
+    //分组管理
     var ruleGroupList = new Array()
     // 精准筛选规则-新增按钮点击方法
     function addExactRuleShow(){