소스 검색

提交添加规则操作代码

olym 7 년 전
부모
커밋
ce5e4c1f16

+ 26 - 26
web/building_saas/main/html/main.html

@@ -128,57 +128,57 @@
                                               <p style="text-align: center">添加规则</p>
                                               <p>
                                                   <label class="title">添加位置:</label>
-                                                  <select name="" id="add-position">
-                                                      <option value="">添加到项目特征列</option>
-                                                      <option value="">添加到清单名称列</option>
-                                                      <option value="">添加到工作内容列</option>
-                                                      <option value="">分别添加到对应列</option>
+                                                  <select id="add-position">
+                                                      <option value="1" selected="selected">添加到项目特征列</option>
+                                                      <option value="2">添加到清单名称列</option>
+                                                      <option value="3">添加到工作内容列</option>
+                                                      <option value="4">分别添加到对应列</option>
                                                   </select>
                                               </p>
                                               <p>
                                                   <label class="title">添加内容:</label>
-                                                  <select name="" id="add-content">
+                                                  <select id="add-content">
                                                       <option value="">无</option>
-                                                      <option value="">项目特征+工作内容</option>
-                                                      <option value="">工作内容+项目特征</option>
-                                                      <option value="">项目特征</option>
-                                                      <option value="">工作内容</option>
-                                                      <option value="">定额子目</option>
+                                                      <option value="1" selected="selected">项目特征+工作内容</option>
+                                                      <option value="2">工作内容+项目特征</option>
+                                                      <option value="3">项目特征</option>
+                                                      <option value="4">工作内容</option>
+                                                      <option value="5">定额子目</option>
                                                   </select>
                                               </p>
                                               <p>
                                                   <label class="title">显示格式:</label>
-                                                  <select name="" id="format">
-                                                      <option value="">换行分隔</option>
-                                                      <option value="">逗号分隔</option>
-                                                      <option value="">括号分隔</option>
+                                                  <select id="display-format">
+                                                      <option value="1" selected="selected">换行分隔</option>
+                                                      <option value="2">逗号分隔</option>
+                                                      <option value="3">括号分隔</option>
                                                   </select>
                                               </p>
                                               <p>
                                                   <label class="title">特征生成方式:</label>
-                                                  <select name="" id="">
-                                                      <option value="">特征值</option>
-                                                      <option value="">特征:特征值</option>
+                                                  <select id="character-format">
+                                                      <option value="1">特征值</option>
+                                                      <option value="2" selected="selected">特征:特征值</option>
                                                   </select>
                                               </p>
                                               <p>
                                                   <label class="title">子目生成方式:</label>
-                                                  <select name="" id="">
-                                                      <option value="">编号+定额名称</option>
-                                                      <option value="">序号+定额名称</option>
+                                                  <select id="child-display-format">
+                                                      <option value="1" selected="selected">编号+定额名称</option>
+                                                      <option value="2">序号+定额名称</option>
                                                   </select>
                                               </p>
                                               <p>
                                                   <label class="title">序号格式:</label>
-                                                  <select name="" id="">
+                                                  <select id="serial-type" disabled="disabled">
                                                       <option value="">无</option>
-                                                      <option value="">1.</option>
-                                                      <option value="">a.</option>
-                                                      <option value="">A.</option>
+                                                      <option value="1" selected="selected">1.</option>
+                                                      <option value="2">a.</option>
+                                                      <option value="3">A.</option>
                                                   </select>
                                               </p>
                                               <p style="text-align: center">
-                                                  <button class="btn btn-primary btn-sm" type="button">应用到选中清单</button>
+                                                  <button class="btn btn-primary btn-sm" type="button" id="use-to-current">应用到选中清单</button>
                                                   <button class="btn btn-primary btn-sm" type="button">应用到所有清单</button>
                                               </p>
                                           </div>

+ 144 - 1
web/building_saas/main/js/views/character_content_view.js

@@ -751,5 +751,148 @@ let pageCCOprObj = {
                 projectObj.mainSpread.getActiveSheet().autoFitRow(activeCell.row);
             }
         });
-    }
+    },
+    /**
+     * 根据配置转换清单项目特征
+     *
+     * @param {Object} node - 选中的node节点
+     * @param {Object} setting - 设置
+     * @return {void}
+     */
+    buildCharacterBySetting: function(node, setting) {
+        let contentArray = [];
+        // 特征部分
+        const itemCharacter = node.data.itemCharacter;
+
+        if (itemCharacter === undefined || itemCharacter.length <= 0) {
+            return;
+        }
+        let characterArray = [];
+        for (const tmp of itemCharacter) {
+            if (tmp.eigenvalue === undefined || tmp.eigenvalue.length <= 0) {
+                continue;
+            }
+            // 获取选中的特征值
+            let selectedEigen = '';
+            for (const eigen of tmp.eigenvalue) {
+                if (eigen.isSelected) {
+                    selectedEigen = eigen.value;
+                }
+            }
+            // 匹配设置的序号格式
+            const serialNo = this.formatSerialNumber(setting.serialType, tmp.serialNo);
+            let characterString = '';
+            // 特征生成方式
+            switch (setting.characterFormat) {
+                case '1':
+                    // 特征值
+                    characterString = serialNo + selectedEigen;
+                    break;
+                case '2':
+                    // 特征:特征值
+                    characterString = serialNo + tmp.character + ':' + selectedEigen;
+                    break;
+            }
+            characterArray.push(characterString);
+        }
+
+        // 内容部分
+        const itemJob = node.data.jobContent;
+        if (itemJob === undefined || itemJob.length <= 0) {
+            return;
+        }
+        let jobArray = [];
+        for (const tmp of itemJob) {
+            // 匹配设置的序号格式
+            const serialNo = this.formatSerialNumber(setting.serialType, tmp.serialNo);
+            jobArray.push(serialNo + tmp.content)
+        }
+
+        // 组合数据
+        let content = '';
+        switch (setting.addContent) {
+            case "1":
+                // 项目特征+工作内容
+                contentArray.push('[项目特征]');
+                contentArray.push.apply(contentArray, characterArray);
+                contentArray.push('[工作内容]');
+                contentArray.push.apply(contentArray, jobArray);
+                break;
+            case "2":
+                // 工作内容+项目特征
+                contentArray.push('[工作内容]');
+                contentArray.push.apply(contentArray, jobArray);
+                contentArray.push('[项目特征]');
+                contentArray.push.apply(contentArray, characterArray);
+                break;
+            case "3":
+                // 项目特征
+                contentArray.push(characterArray);
+                break;
+            case "4":
+                // 工作内容
+                contentArray.push(jobArray);
+                break;
+            case "5":
+                // 定额子目
+                break;
+        }
+        // 显示格式
+        switch (setting.displayFormat) {
+            case "1":
+                // 换行分隔
+                content = contentArray.join('\r\n');
+                break;
+            case "2":
+                // 逗号分隔
+                content = contentArray.join(',');
+                break;
+            case "3":
+                // 括号分隔
+                content = '(' + contentArray.join(',') + ')';
+                break;
+        }
+        // 添加到对应位置
+        switch (setting.position) {
+            case "1":
+                // 添加到项目特征列
+                node.data.itemCharacterText = content;
+                break;
+            case "2":
+                // 添加到清单名称列
+                node.data.name = content;
+                break;
+            case "3":
+                // 添加到工作内容列
+                node.data.jobContentText = content;
+                break;
+        }
+
+    },
+    /**
+     * 格式化序号格式
+     *
+     * @param {Number} type - 格式化的类型
+     * @param {String} serialNo - 待格式化的序号
+     * @return {String} - 返回格式化后的字符
+     */
+    formatSerialNumber: function(type, serialNo) {
+        const letter = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
+            's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
+        switch (type) {
+            case '1':
+                // 数字
+                serialNo = serialNo + '.';
+                break;
+            case '2':
+                // 英文字母(小写)
+                serialNo = letter[serialNo - 1] !== undefined ? letter[serialNo - 1] + '.' : '';
+                break;
+            case '3':
+                // 英文字母(大写)
+                serialNo = letter[serialNo - 1] !== undefined ? letter[serialNo - 1].toUpperCase() + '.' : '';
+                break;
+        }
+        return serialNo;
+    },
 }

+ 1 - 2
web/building_saas/main/js/views/project_view.js

@@ -415,10 +415,9 @@ var projectObj = {
                     if (col.data.field === 'name' || col.data.field === 'itemCharacterText' ||
                         col.data.field === 'jobContentText' || col.data.field === 'adjustState') {
                         if (!autoHeight) {
-                            col.data.wordWrap = false;
+                            col.data.autoFitRow();
                             col.showHint = true;
                         } else {
-                            col.data.wordWrap = true;
                             col.showHint = false;
                         }
                     }

+ 61 - 0
web/building_saas/main/js/views/sub_view.js

@@ -114,6 +114,67 @@ $("#linkTZJNR").click(function () {
     gljOprObj.activeTab='#linkTZJNR';
 });
 
+// 应用到选中清单
+$("#use-to-current").click(function() {
+    // 添加位置
+    const position = $("#add-position").val();
+    // 添加内容
+    const addContent = $("#add-content").val();
+    // 显示格式
+    const displayFormat = $("#display-format").val();
+    // 特征生成方式
+    const characterFormat = $("#character-format").val();
+
+    // 序号格式
+    const serialType = $("#serial-type").val();
+    const setting = {
+        serialType,
+        characterFormat,
+        addContent,
+        position,
+        displayFormat,
+    };
+    let selectedNode = projectObj.mainController.tree.selected;
+    pageCCOprObj.buildCharacterBySetting(selectedNode, setting);
+    // console.log(changeNode);
+    projectObj.mainController.refreshTreeNode([selectedNode], false);
+});
+// 添加位置选择
+$("#add-position").change(function() {
+    const selected = $(this).children(":selected").val();
+    const addContentEle = $("#add-content");
+    const displayFormatEle = $("#display-format");
+    switch (selected) {
+        case '4':
+            // 分别添加到对应列
+            // 当“添加位置”是“分别添加到对应列”,则“添加内容”恢复默认“无”,且灰显;“显示格式”恢复默认“换行分隔”,且灰显。
+            addContentEle.val('');
+            addContentEle.attr('disabled', 'disabled');
+            displayFormatEle.val(1);
+            displayFormatEle.attr('disabled', 'disabled');
+            console.log('hello');
+            break;
+        default:
+            addContentEle.removeAttr('disabled');
+            displayFormatEle.removeAttr('disabled');
+            break;
+    }
+});
+
+// 子目生成方式选择事件
+$("#child-display-format").change(function() {
+    const selected = $(this).children(":selected").val();
+    const serialTypeEle = $("#serial-type");
+    // 如果是编号+定额名称则序号格式不能选择
+    if (selected === '1') {
+        // 默认选中数字显示模式
+        serialTypeEle.val(1);
+        serialTypeEle.attr('disabled', 'disabled');
+    } else {
+        serialTypeEle.removeAttr('disabled');
+    }
+});
+
 function activeSubSheetIs(idx){
     let rst = subSpread.getActiveSheetIndex() == idx;
     return rst;