Blame view

src/main/webapp/js/projecttask/selectHandl.js 12 KB
caiyongsong committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
var SEARCHFLOWUSERCOUNTURL = CONF_BACK_SERVERURL + "/mvc/flow/searchFlowUserCount.do";
var SAVEFLOWUSERCOUNTURL = CONF_BACK_SERVERURL + "/mvc/flow/saveFlowUserCount.do";
var LISTSTARTURL = CONF_BACK_SERVERURL + global.modelctls.project.list.start;
var ITEMTYPELISTURL = CONF_BACK_SERVERURL + "/mvc/flow/itemType/list.do";
var ITEMSALLURL = CONF_BACK_SERVERURL + global.modelctls.kvtree.all;
var KVTREEKEY = "高频类事项键值树"; // 默认高频类键值树名称
var SHOWNUMBER = 12;        // 高频类最多显示个数

var defaultUsedClass = [];  // 默认高频类事项
var flowUserCount = [];     // 用户自定义高频类事项
var userId = null;          // 当前登录用户标识
var projectId = null;       // 项目标识。续办时传入
var createMethod = null;    // 流程的创建方式(接件还是续办)
var version = null; // 版本1.0
var orign = null; // 来源页面

weimo934 committed
17
$(function () {
caiyongsong committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
    projectId = getQueryString("projectId");
    createMethod = getQueryString("createmethod");
    version = getQueryString("FLOWVERSION");
    orign = getQueryString("orign");
    createMethod && (createMethod = decodeURI(createMethod));
    let cookieuser = $.cookie("cookieuser");
    let parse = JSON.parse(cookieuser);
    userId = parse.user.id;
});


var vm = new Vue({
    el: "#app",
    data: function () {
        return {
            radio: '',
            filterType: "所有",
            searchText: "",
            itemObject: "",
            activeNames: [],
            itemTypeArray: [],
            oldItemObject: {}
        }
    },
    methods: {
        openCreate: function (flowObj) {
            ajaxPromise({
                url: ITEMTYPELISTURL,
                data: {flowId: flowObj.id}
weimo934 committed
47
            }).then((result) => {
caiyongsong committed
48
                if (Array.isArray(result) && result.length > 0) {
weimo934 committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
                    layer.open({
                        type: 1,
                        btn: ['确定', '取消'],
                        title: '请选择事项类型',
                        content: $("#itemTypeDiv"),
                        success: function () {
                            vm.itemTypeArray = result;
                            vm.radio = result[0].id;
                        },
                        yes: function () {
                            vm.openHandleJumpUrl(flowObj.id, vm.radio);
                        },
                        btn2: function (index) {
                            layer.close(index);
                        }
                    });
caiyongsong committed
65

weimo934 committed
66 67 68 69 70 71
                } else {
                    vm.openHandleJumpUrl(flowObj.id);
                }
            }).catch((error) => {
                layer.msg("获取事项类型出错!", {icon: 2});
            });
caiyongsong committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
        },
        /**
         * //TODO:wei
         * 打开详情页
         * @param flowId        流程标识
         * @param itemTypeId    事项标识
         */
        openHandleJumpUrl: function (flowId, itemTypeId) {
            localStorage.flowId = flowId;
            var unique = uuid();
            let url = CONF_FRONT_SERVERURL + 'view/projecttask/detailproject.jsp?';
            url += 'stats=create';
            url += '&flowid=' + flowId;
            url += '&create=' + (projectId ? 1 : 0);
            url += '&projectid=' + (projectId || "");
            url += '&flowItemTypeId=' + (itemTypeId || "");
            url += '&uniquePath=' + unique;
            url += '&FLOWVERSION=' + version;
            window.open(handleJumpUrl(url));
            vm.addFlowUserCount(flowId);
            parent.layer.close(parent.typeIndex)
        },

        /**
         * 事项操作+1
         */
        addFlowUserCount: function (flowId) {
            if (flowId === null || flowId === undefined) {
                return false;
            }

            ajaxPromise({
weimo934 committed
104
                data: JSON.stringify({"flowId": flowId, "userId": userId}),
caiyongsong committed
105 106
                contentType: "application/json",
                url: SAVEFLOWUSERCOUNTURL
weimo934 committed
107
            }).catch((error) => {
caiyongsong committed
108
                console.error(error);
weimo934 committed
109
            });
caiyongsong committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
        },
        /**
         * 流程名称搜索
         */
        search: function () {
            let newItemObject = {};
            let oldItemObject = JSON.parse(JSON.stringify(vm.oldItemObject));
            for (let key in oldItemObject) {
                // 流程分类过滤
                if (vm.filterType !== "所有" && key !== vm.filterType) {
                    continue;
                }
                let array = [];
                if (vm.searchText) {
                    // 流程名称过滤
                    array = oldItemObject[key].filter(function (item) {
                        let text = highilghtField(vm.searchText, item.name);
                        return text !== item.name && (item.name = text);
                    });
                } else {
                    array = oldItemObject[key];
                }
                if (array.length > 0) {
                    newItemObject[key] = array;
                }
            }
            vm.itemObject = newItemObject;
        },
        setData: function (data) {
            var dataflows = data[0],
                datatypes = data[1],
                itemObject = {};

            // 获取所有符合显示的事项
weimo934 committed
144
            dataflows.forEach(function (item) {
caiyongsong committed
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
                var createmethod = item.createmethod;
                var flowtypeName = datatypes[item.flowtype];
                if (flowtypeName && flowtypeName !== "会议类") {   // 过滤会议类和其他类
                    if (createmethod === null || createmethod == createMethod || createmethod == "全部") {    // 入口匹配。接件、续办
                        if (itemObject[flowtypeName]) {
                            itemObject[flowtypeName].push(item);
                        } else {
                            itemObject[flowtypeName] = new Array(item);
                        }
                    }
                }
            });

            // 显示事项分类
            var newItemObject = {};
            // let usedClass = vm.getUsedClass(data);
            // if (Array.isArray(usedClass) && usedClass.length > 0) {
            //     newItemObject["高频类"] = usedClass;
            // }
            for (let typeid in datatypes) {
                var typename = datatypes[typeid];
                if (typename && itemObject[typename]) {
                    newItemObject[typename] = itemObject[typename];
                }
            }

            return newItemObject;
            //vm.itemObject = newItemObject;
            //vm.activeNames = Object.keys(newItemObject);
        },
        /**
         * 获取高频类事项
         */
        // getUsedClass: function (data) {
        //     let itemidObj = {},
        //         dataflows = data[0],
        //         datatypes = data[1],
        //         usedClass = new Array();

        //     let nameObject = {};
        //     defaultUsedClass.forEach(function (item) {
        //         nameObject[item.name] = item.sortid;
        //     });

        //     let itemArray = [];
        //     dataflows.forEach( function (item) {
        //         var flowtypeName = datatypes[item.flowtype];
        //         if (flowtypeName && flowtypeName !== "会议类") {
        //             itemidObj[item.id] = item;
        //             if (nameObject[item.name]) {
        //                 itemArray.push({ flowId: item.id, count: nameObject[item.name] })
        //             }
        //         }
        //     });

        //     // 根据用户点击数显示高频类
        //     let addNameArr= [];
        //     let concat = flowUserCount.concat(itemArray);
        //     concat.sort(function (var1, var2) {
        //         return var2.count - var1.count;
        //     })

        //     concat.forEach( function (item) {
        //         if (addNameArr.length >= SHOWNUMBER) {
        //             return true;
        //         }
        //         if (itemidObj[item.flowId] && addNameArr.indexOf(item.flowId) === -1) {
        //             addNameArr.push(item.flowId);
        //             usedClass.push(itemidObj[item.flowId]);
        //         }
        //     });

        //     return usedClass;
        // }
    },
    created: function () {
        ajaxPromise({
            data: JSON.stringify({"userId": userId}),
            contentType: "application/json",
            url: SEARCHFLOWUSERCOUNTURL
weimo934 committed
225
        }).then(function (result) {
caiyongsong committed
226 227
            if (result.status === "ok") {
                flowUserCount = result.data.rows;
weimo934 committed
228
                return ajaxPromise({url: LISTSTARTURL});
caiyongsong committed
229 230 231
            } else {
                console.error(result.message);
            }
weimo934 committed
232
        }).catch(function (error) {
caiyongsong committed
233 234 235
            console.error(error);
        }).then(function (result) {
            localStorage.orign = orign;
weimo934 committed
236
            var result = result;
caiyongsong committed
237 238
            // 规划审查流程筛选
            if (orign === 'ghsc') {
weimo934 committed
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
                let keys = [];
                keys = Object.keys(result[1]);
              for (let item=0;item<keys.length;item++){
                  if (result[1][keys[item]] === "规划审查") {
                      result[0] = result[0].filter(it => {
                          return it.flowtype === keys[item];
                      });
                  }
              }
            } else if (orign === 'ajcc') {
                let keys = [];
                keys = Object.keys(result[1]);
                for (let item=0;item<keys.length;item++){
                    if (result[1][keys[item]] === "案件查处") {
                        result[0] = result[0].filter(it => {
                            console.log(keys[item])
                            return it.flowtype === keys[item];
                        });
                    }
                }
            }else if (orign==='phgl'){
                let keys = [];
                keys = Object.keys(result[1]);
                for (let item=0;item<keys.length;item++){
                    if (result[1][keys[item]] === "批后监管") {
                        result[0] = result[0].filter(it => {
                            console.log(keys[item])
                            return it.flowtype === keys[item];
                        });
                    }
                }
caiyongsong committed
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
            }
            var itemObject = vm.setData(result);
            vm.itemObject = itemObject;
            vm.oldItemObject = itemObject;
            vm.activeNames = Object.keys(itemObject);
        }).catch(function (error) {
            console.error(error);
        })
    }
});

/**
 * 高亮字段
 * @param highilght     亮显值
 * @param text
 */
weimo934 committed
286
function highilghtField(highilght, text) {
caiyongsong committed
287 288 289
    if (highilght && text) {
        var reg = new RegExp(highilght.replace(/[.\\[\]{}()|^$?*+]/g, "\\$&"), "g");
        text = text.toString().replace(reg, '<span style="color: red">' + highilght + '</span>');
weimo934 committed
290 291
    }
    ;
caiyongsong committed
292 293 294 295 296
    return text;
};

function ajaxPromise(options) {
    return new Promise(function (resolve, reject) {
weimo934 committed
297
        if (typeof options !== "object") {
caiyongsong committed
298 299 300 301 302 303 304 305 306 307
            return reject("参数错误!");
        }
        let _type = options.type || "POST";
        //'application/json'
        $.ajax({
            type: _type,
            url: options.url,
            data: options.data,
            dataType: options.dataType,
            contentType: options.contentType,
weimo934 committed
308 309
            headers: {"token": $.cookie('ftoken')},
            success: function (result) {
caiyongsong committed
310 311 312 313 314 315 316 317 318 319 320 321 322 323
                resolve(result);
            },
            error: function (error) {
                reject(error);
            }
        });
    })
}

/**
 * 生成UUID
 *
 * @returns uuid
 */
weimo934 committed
324
function uuid() {
caiyongsong committed
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
    var s = [];
    var hexDigits = "0123456789abcdef";
    for (var i = 0; i < 36; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
    }
    s[14] = "4";
    s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
    s[8] = s[13] = s[18] = s[23] = "-";

    var uuid = s.join("");
    return uuid;
}

ajaxPromise({
    url: ITEMSALLURL,
    data: {name: KVTREEKEY}
weimo934 committed
341 342
}).then((result) => {
    debugger
caiyongsong committed
343 344
    defaultUsedClass = result;
});