Browse Source

先传人才认证条件修改

sugangqiang 2 năm trước cách đây
mục cha
commit
a0501e118e

+ 40 - 4
app/admin/controller/TalentCondition.php

@@ -36,8 +36,13 @@ class TalentCondition extends AdminController {
      */
     function add() {
         if ($this->request->isPost()) {
-            TalentConditionApi::edit($this->request->param());
-            return json(["code" => 200, "msg" => "添加认定条件成功"]);
+            $params = $this->request->param();
+            $res = $this->myValid($params);
+            if ($res !== true)
+                return $res;
+            if (TalentConditionApi::edit($params))
+                return json(["code" => 200, "msg" => "添加认定条件成功"]);
+            return json(["msg" => "添加认定条件失败"]);
         }
         return view();
     }
@@ -48,14 +53,45 @@ class TalentCondition extends AdminController {
      */
     function edit() {
         if ($this->request->isPost()) {
-            TalentConditionApi::edit($this->request->param());
-            return json(["code" => 200, "msg" => "编辑认定条件成功"]);
+            $params = $this->request->param();
+            $res = $this->myValid($params);
+            if ($res !== true)
+                return $res;
+            if (TalentConditionApi::edit($params))
+                return json(["code" => 200, "msg" => "编辑认定条件成功"]);
+            return json(["msg" => "编辑认定条件失败"]);
         }
         $id = $this->request->param("id");
         $info = TalentConditionApi::getOne($id);
         return view("", ["info" => $info]);
     }
 
+    private function myValid($params) {
+        if (!$params["type"] || !in_array($params["type"], [1, 2]))
+            return json(["msg" => "请选择人才类别"]);
+        if (!$params["talentLevel"] || !in_array($params["talentLevel"], [1, 2, 3, 4, 5, 6, 7]))
+            return json(["msg" => "请选择人才层次"]);
+        if (!$params["name"])
+            return json(["msg" => "请填写名称"]);
+        if ($params["companyIds"] && $params["bindFileTypes"]) {
+            $bindFileTypes = array_filter(explode(",", $params["bindFileTypes"]));
+            $total = count($bindFileTypes);
+            $tmp = [];
+            foreach ($params["relation"] as $_companyId => $_relation) {
+                $_relations = explode(",", $_relation);
+                for ($i = 0; $i < count($_relations); $i++) {
+                    if (in_array($_relations[$i], $bindFileTypes))
+                        $tmp[] = $_relations[$i];
+                }
+            }
+            $_valid_count = count(array_unique($tmp));
+            if ($_valid_count != $total) {
+                return json(["msg" => "选择了审核单位及审核附件后,每个附件必须与其中一个审核单位关联"]);
+            }
+        }
+        return true;
+    }
+
     /**
      * @auth {{/identifyCondition/delete}}
      * @return type

+ 16 - 4
app/admin/view/talent_condition/add.html

@@ -7,6 +7,7 @@
         padding-left: 4px;
     }
     .rowGroup{height:50px;}
+    .table td{border:1px solid #ddd;}
 </style>
 <div class="ibox float-e-margins">
     <div class="ibox-content">
@@ -46,15 +47,26 @@
                         <div class="rowGroup">
                             <label class="col-sm-2 control-label spacing">审核单位</label>
                             <div class="col-sm-4 spacing">
-                                <select class="form-control" id="companyIds" name="companyIds" data-placeholder="请选择审核单位" multiple>
+                                <select class="form-control" id="companyIds" name="companyIds" data-placeholder="请选择审核单位" multiple onchange="IdentifyConditionInfoDlg.onCompanyOrTypeChange();">
                                 </select>
                             </div>
-                            <label class="col-sm-2 control-label spacing">捆绑附件</label>
+                            <label class="col-sm-2 control-label spacing">审核附件</label>
                             <div class="col-sm-4 spacing">
-                                <select class="form-control" id="bindFileTypes" name="bindFileTypes" data-placeholder="请选择捆绑附件" multiple>
+                                <select class="form-control" id="bindFileTypes" name="bindFileTypes" data-placeholder="请选择捆绑附件" multiple onchange="IdentifyConditionInfoDlg.onCompanyOrTypeChange();">
                                 </select>
                             </div>
-                        </div>>
+                        </div>
+                        <div class="rowGroup">
+                            <label class="col-sm-2 control-label spacing">单位与附件关联<br></label>
+                            <div class="col-sm-10 spacing">
+                                <table id="relationTable" class="table">
+                                    <tbody>
+                                        
+                                    </tbody>
+                                </table>
+                                <span style='color:#ff0000'>*1.同时设置了审核单位与附件后,所选附件必须关联其中一个审核单位。<br>*2.审核单位可关联复数附件,但是附件只能关联一个审核单位。</span>
+                            </div>
+                        </div>
                     </div>
                 </form>
             </div>

+ 15 - 3
app/admin/view/talent_condition/edit.html

@@ -14,6 +14,7 @@
                 <form id="identifyConditionInfoForm">
                     <div class="col-sm-12 ">
                         <input id="id" name="id" value="{$info.id}" type="hidden"/>
+                        <input id="companyWithFileType" value="{$info.companyWithFileType}" type="hidden"/>
                         <div class="rowGroup">
                             <label class="col-sm-2 control-label spacing" onchange="IdentifyConditionInfoDlg.onTypeChange();">人才类别</label>
                             <div class="col-sm-4 spacing">
@@ -45,15 +46,26 @@
                         <div class="rowGroup">
                             <label class="col-sm-2 control-label spacing">审核单位</label>
                             <div class="col-sm-4 spacing">
-                                <select class="form-control" id="companyIds" name="companyIds" selectVal="{$info.companyIds}" data-placeholder="请选择审核单位" multiple>
+                                <select class="form-control" id="companyIds" name="companyIds" selectVal="{$info.companyIds}" data-placeholder="请选择审核单位" multiple onchange="IdentifyConditionInfoDlg.onCompanyOrTypeChange();">
                                 </select>
                             </div>
-                            <label class="col-sm-2 control-label spacing">捆绑附件</label>
+                            <label class="col-sm-2 control-label spacing">审核附件</label>
                             <div class="col-sm-4 spacing">
-                                <select class="form-control" id="bindFileTypes" name="bindFileTypes" selectVal="{$info.bindFileTypes}" data-placeholder="请选择捆绑附件" multiple>
+                                <select class="form-control" id="bindFileTypes" name="bindFileTypes" selectVal="{$info.bindFileTypes}" data-placeholder="请选择捆绑附件" multiple onchange="IdentifyConditionInfoDlg.onCompanyOrTypeChange();">
                                 </select>
                             </div>
                         </div>
+                        <div class="rowGroup">
+                            <label class="col-sm-2 control-label spacing">单位与附件关联<br></label>
+                            <div class="col-sm-10 spacing">
+                                <table id="relationTable" class="table">
+                                    <tbody>
+
+                                    </tbody>
+                                </table>
+                                <span style='color:#ff0000'>*1.同时设置了审核单位与附件后,所选附件必须关联其中一个审核单位。<br>*2.审核单位可关联复数附件,但是附件只能关联一个审核单位。</span>
+                            </div>
+                        </div>
                     </div>
                 </form>
             </div>

+ 5 - 0
app/common/api/TalentConditionApi.php

@@ -30,6 +30,11 @@ class TalentConditionApi {
         $data["bindFileTypes"] = $params["bindFileTypes"];
         $data["name"] = $params["name"];
         $data["active"] = $params["active"];
+        $relation = [];
+        foreach ($params["relation"] as $_companyId => $_relation) {
+            $relation[] = $_companyId . ":" . $_relation;
+        }
+        $data["companyWithFileType"] = implode(";", $relation);
         if ($params["id"]) {
             $data["id"] = $params["id"];
             $data["updateUser"] = session("user")["uid"];

+ 109 - 10
public/static/modular/talentIdentify/identifyCondition/identifyCondition_info.js

@@ -103,6 +103,34 @@ IdentifyConditionInfoDlg.collectData = function () {
     this.identifyConditionInfoData['companyIds'] = company_ids;
     this.identifyConditionInfoData['bindFileTypes'] = bind_fts_ids;
 
+    var chks = $("#relationTable input[type=checkbox]:checked");
+    var relation = {};
+    for (var i = 0; i < chks.length; i++) {
+        var companyId = $(chks[i]).data("company-id");
+        if (typeof relation[companyId] == "undefined") {
+            relation[companyId] = $(chks[i]).val();
+        } else {
+            relation[companyId] += "," + $(chks[i]).val();
+        }
+    }
+    this.identifyConditionInfoData['relation'] = relation;
+}
+
+IdentifyConditionInfoDlg.otherValid = function () {
+    if (this.identifyConditionInfoData.companyIds != '' && this.identifyConditionInfoData.bindFileTypes != '') {
+        var fileTypes = this.identifyConditionInfoData.bindFileTypes.split(",");
+        var total = fileTypes.length;
+        var _goal = 0;
+        for (var i = 0; i < total; i++) {
+            var typeId = fileTypes[i];
+            _goal += $("input[type=checkbox][value='" + typeId + "']:checked").length > 0 ? 1 : 0;
+        }
+        if (_goal != total) {
+            Feng.error("选择了审核单位及审核附件后,每个附件必须与其中一个审核单位关联");
+            return false;
+        }
+    }
+    return true;
 }
 
 /**
@@ -111,13 +139,10 @@ IdentifyConditionInfoDlg.collectData = function () {
 IdentifyConditionInfoDlg.addSubmit = function () {
     this.clearData();
     this.collectData();
-    if (!this.validate()) {
+    if (!this.validate() || !IdentifyConditionInfoDlg.otherValid()) {
         return;
     }
-    // if(this.identifyConditionInfoData.companyIds==null||this.identifyConditionInfoData.companyIds==''){
-    //     Feng.error("审核单位不能为空");return ;
-    // }
-    //提交信息
+
     var ajax = new $ax("/admin/talent_condition/add", function (data) {
         if (data.code == "200") {
             Feng.success(data.msg);
@@ -139,13 +164,9 @@ IdentifyConditionInfoDlg.addSubmit = function () {
 IdentifyConditionInfoDlg.editSubmit = function () {
     this.clearData();
     this.collectData();
-    if (!this.validate()) {
+    if (!this.validate() || !IdentifyConditionInfoDlg.otherValid()) {
         return;
     }
-    // if(this.identifyConditionInfoData.companyIds==null||this.identifyConditionInfoData.companyIds==''){
-    //     Feng.error("审核单位不能为空");return ;
-    // }
-    //提交信息
     var ajax = new $ax(Feng.ctxPath + "/admin/talent_condition/edit", function (data) {
         if (data.code == "200") {
             Feng.success(data.msg);
@@ -172,6 +193,83 @@ IdentifyConditionInfoDlg.onTypeChange = function () {
     $("#bindFileTypes").trigger("chosen:updated");
 }
 
+IdentifyConditionInfoDlg.onCompanyOrTypeChange = function () {
+    var companyIds = $("#companyIds").val();
+    var bindFileTypes = $("#bindFileTypes").val();
+    IdentifyConditionInfoDlg.buildRelationTable(companyIds, bindFileTypes);
+}
+
+IdentifyConditionInfoDlg.fstLoad = true;
+IdentifyConditionInfoDlg.buildRelationTable = function (companyIds, bindFileTypes) {
+    var companyWithFileType = $("#companyWithFileType").val();
+    var setting = [];
+    if (companyWithFileType) {
+        var companyTmps = companyWithFileType.split(";")
+        for (var i in companyTmps) {
+            var _companyTmp = companyTmps[i].split(":");
+            var _companyId = _companyTmp[0];
+            var _fileTypes = _companyTmp[1].split(",");
+            setting[_companyId] = _fileTypes;
+        }
+    }
+    var trs = $("#relationTable tbody").find("tr");
+    trs.each(function (index, tr) {
+        if (!companyIds || companyIds.indexOf($(tr).data("id").toString()) == -1)
+            $(tr).remove();
+    })
+    for (let i in companyIds) {
+        let companyId = companyIds[i];
+        if (companyId == "")
+            continue;
+        var cfg = setting[companyId];
+        if ($("#relationTable tbody").find("tr[data-id='" + companyId + "']").length > 0) {
+            var chks = $("#relationTable tbody").find("tr[data-id='" + companyId + "']").find("input[type=checkbox]");
+            chks.each(function (index, chk) {
+                if (!bindFileTypes || bindFileTypes.indexOf($(chk).val().toString()) == -1)
+                    $(chk).parents("li").remove();
+            })
+            for (let n in bindFileTypes) {
+                let fileType = bindFileTypes[n];
+                if ($("#relationTable tbody").find("tr[data-id='" + companyId + "']").find("input[value='" + fileType + "']").length == 0) {
+                    let typename = $("#bindFileTypes option[value='" + fileType + "']").text();
+                    let disabled = $("input[type=checkbox][value='" + fileType + "']:checked").length > 0 ? "disabled" : "";
+                    let li = '<li><label for="relation[' + companyId + ']">' + typename + '</label><input type="checkbox" data-company-id="' + companyId + '" value="' + fileType + '" ' + disabled + ' onchange="IdentifyConditionInfoDlg.onCheckChange(this);"></li>';
+                    $("#relationTable tbody").find("tr[data-id='" + companyId + "'] ul").append(li);
+                }
+            }
+        } else {
+            let newTr = "";
+            let companyName = $("#companyIds option[value='" + companyId + "']").text();
+            newTr = '<tr data-id="' + companyId + '"><td style="width:10%;">' + companyName + '</td><td style="width:90%"><ul>';
+            for (let n in bindFileTypes) {
+                let fileType = bindFileTypes[n];
+                let typename = $("#bindFileTypes option[value='" + fileType + "']").text();
+
+                var checked = "";
+                if (typeof cfg != "undefined" && cfg.indexOf(fileType) > -1 && $("input[type=checkbox][value='" + fileType + "']:checked").length == 0)
+                    checked = "checked";
+                if (IdentifyConditionInfoDlg.fstLoad && checked == "checked") {
+                    $("input[type=checkbox][value='" + fileType + "']").prop("disabled", true);
+                }
+                let disabled = $("input[type=checkbox][value='" + fileType + "']:checked").length > 0 ? "disabled" : "";
+                newTr += '<li><label for="relation[' + companyId + ']">' + typename + '</label><input type="checkbox" data-company-id="' + companyId + '" value="' + fileType + '" ' + checked + " " + disabled + ' onchange="IdentifyConditionInfoDlg.onCheckChange(this);"></li>';
+            }
+            newTr += '</ul></td></tr>'
+            $("#relationTable tbody").append(newTr);
+        }
+    }
+    IdentifyConditionInfoDlg.fstLoad = false;
+}
+IdentifyConditionInfoDlg.onCheckChange = function (chk) {
+    var typeId = $(chk).val();
+    if ($(chk).is(":checked")) {
+        $("input[type=checkbox][value='" + typeId + "']").prop("disabled", true);
+        $(chk).removeAttr("disabled");
+    } else {
+        $("input[type=checkbox][value='" + typeId + "']").removeAttr("disabled");
+    }
+}
+
 /**
  * 验证数据是否为空
  */
@@ -223,4 +321,5 @@ $(function () {
     if (Feng.isNotEmptyStr(bindFileTypes)) {
         $("#bindFileTypes").val(bindFileTypes.split(",")).trigger("chosen:updated");
     }
+    IdentifyConditionInfoDlg.onCompanyOrTypeChange();
 });