seniorQueryUtil.js 11.2 KB
Newer Older
wangcong committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 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 104 105 106 107 108 109 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 144 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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 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 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
let util = {};
util.getTimeStamp = function (str) {
    if (str == 'now') {
        let now = new Date().getTime()
        // let now = Date.now();
        return now
    } else if (str == 'last') {
        let now = new Date()
        let year = now.getFullYear(); //当前年份
        let month = now.getMonth() + 1; //当前月份
        let day = now.getDate(); //天
        let hour = now.getHours(); //小时
        let min = now.getMinutes(); //分
        let sec = now.getSeconds(); //秒
        let dateStr = (year - 1) + '-' + month + '-' + day + ' ' + hour + ':' + min + ':' + sec
        let last = new Date(dateStr).getTime()
        return last
    } else if (str == 'next') {
        let now = new Date()
        let year = now.getFullYear(); //当前年份
        let month = now.getMonth() + 1; //当前月份
        let day = now.getDate(); //天
        let hour = now.getHours(); //小时
        let min = now.getMinutes(); //分
        let sec = now.getSeconds(); //秒
        let dateStr = (year + 1) + '-' + month + '-' + day + ' ' + hour + ':' + min + ':' + sec
        let next = new Date(dateStr).getTime()
        return next
    } else if (str == 'nowBegin') {
        let now = new Date()
        let year = now.getFullYear(); //当前年份
        // let month = now.getMonth() + 1; //当前月份
        // let day = now.getDate(); //天
        // let hour = now.getHours(); //小时
        // let min = now.getMinutes(); //分
        // let sec = now.getSeconds(); //秒
        let dateStr = year + '-01-01 00:00:00'
        let nowBegin = new Date(dateStr).getTime()
        return nowBegin
    } else if (str == 'nowEnd') {
        let now = new Date()
        let year = now.getFullYear(); //当前年份
        // let month = now.getMonth() + 1; //当前月份
        // let day = now.getDate(); //天
        // let hour = now.getHours(); //小时
        // let min = now.getMinutes(); //分
        // let sec = now.getSeconds(); //秒
        let dateStr = year + '-12-31 23:59:59'
        let nowEnd = new Date(dateStr).getTime()
        return nowEnd
    } else if (str == 'monthBegin') {
        let now = new Date()
        let year = now.getFullYear(); //当前年份
        let month = now.getMonth() + 1; //当前月份
        let dateStr = year + '-' + month + '-01 00:00:00';
        let monthBegin = new Date(dateStr).getTime();
        return monthBegin;
    }
};
util.getTimeStr = function (str, format) {
    if (!format) {
        format = 'yyyy-M-d';
    }
    if (str == 'now') {
        let now = new Date()
        // let now = Date.now();
        let year = now.getFullYear(); //当前年份
        let month = now.getMonth(); //当前月份-1
        let day = now.getDate(); //天
        let hour = now.getHours(); //小时
        let min = now.getMinutes(); //分
        let sec = now.getSeconds(); //秒
        //  let dateStr = year+'-'+month+'-'+day
        let dateStr = now.format(format);
        return dateStr
    } else if (str == 'last') {
        let now = new Date()
        let year = now.getFullYear(); //当前年份
        let month = now.getMonth(); //当前月份-1
        let day = now.getDate(); //天
        let hour = now.getHours(); //小时
        let min = now.getMinutes(); //分
        let sec = now.getSeconds(); //秒
        //  let dateStr = (year-1)+'-'+month+'-'+day
        let dateStr = new Date(year - 1, month, day).format(format);
        return dateStr
    } else if (str == 'next') {
        let now = new Date()
        let year = now.getFullYear(); //当前年份
        let month = now.getMonth(); //当前月份-1
        let day = now.getDate(); //天
        let hour = now.getHours(); //小时
        let min = now.getMinutes(); //分
        let sec = now.getSeconds(); //秒
        //  let dateStr = (year+1)+'-'+month+'-'+day
        let dateStr = new Date(year + 1, month, day).format(format);
        return dateStr
    } else if (str == 'nowBegin') {
        let now = new Date();
        let year = now.getFullYear(); //当前年份
        // let month = now.getMonth() + 1; //当前月份
        // let day = now.getDate(); //天
        // let hour = now.getHours(); //小时
        // let min = now.getMinutes(); //分
        // let sec = now.getSeconds(); //秒
        // let dateStr = year+'-01-01'
        let dateStr = new Date(year, 0, 1).format(format);
        // console.log(dateStr);
        return dateStr;
    } else if (str == 'nowEnd') {
        let now = new Date()
        let year = now.getFullYear(); //当前年份
        // let month = now.getMonth() + 1; //当前月份
        // let day = now.getDate(); //天
        // let hour = now.getHours(); //小时
        // let min = now.getMinutes(); //分
        // let sec = now.getSeconds(); //秒
        //   let dateStr = year+'-12-31'
        let dateStr = new Date(year, 11, 31).format(format);
        return dateStr
    } else if (str == 'monthBegin') {
        let now = new Date()
        let year = now.getFullYear(); //当前年份
        let month = now.getMonth(); //当前月份-1
        let monthBegin = new Date(year, month, 1).format(format);
        return monthBegin;
    }
};
util.condition_input_initDefaultValue = function (item) {
    let param = {};
    param.id = item.id;
    param.value = item.config.defaultVal;
    param.text = item.config.defaultVal;
    param.type = item.dataType == 'STRING' ? "strInput" : "numInput"
    param.title = item.title;
    param.fuzzySearch = item.config.fuzzySearch;
    param.name = item.config.name;
    param.dataType = item.dataType;
    return param;
};
util.condition_date_initDefaultValue = function (item) {
    let param = {};
    param.id = item.id;
    param.value = util.getTimeStamp(item.config.defaultVal)
    param.text = util.getTimeStr(item.config.defaultVal, item.format && item.format.config ? item.format.config : 'yyyy-M-d');
    param.title = item.title;
    param.name = item.config.name;
    param.type = "date";
    param.dataType = "DATE";
    return param;
};
util.condition_range_initDefaultValue = function (item) {
    if (item.dataType == 'DATE') {
        let param = {
            value: {},
            name: {}
        };
        param.text = util.getTimeStr(item.config.defaultVal.beginDate, item.format && item.format.config ? item.format.config : 'yyyy-M-d') + " - " + this.getTimeStr(item.config.defaultVal.endDate, item.format && item.format.config ? item.format.config : 'yyyy-MM-dd');
        param.id = item.id;
        param.name.min = item.config.names.min;
        param.name.max = item.config.names.max;
        param.title = item.title;
        param.value.min = util.getTimeStamp(item.config.defaultVal.beginDate);
        param.value.max = util.getTimeStamp(item.config.defaultVal.endDate);
        param.type = 'dateRange';
        param.dataType = 'DATE';
        return param;
    } else if (item.dataType == 'NUMBER' || item.dataType == 'STRING') {
        let param = {
            value: {},
            text: {},
            name: {}
        };
        param.name.min = item.config.names.min;
        param.name.max = item.config.names.max;
        param.id = item.id;
        param.title = item.title;
        param.type = item.dataType == 'NUMBER' ? 'numRange' : 'strRange';
        param.dataType = item.dataType;
        param.value.min = item.config.defaultVal.min;
        param.value.max = item.config.defaultVal.max;
        param.text.min = item.config.defaultVal.min;
        param.text.max = item.config.defaultVal.max;
        return param;
    }
};
util.condition_select_initDefaultValue = function (val) {
    let condition = {};
    condition.id = val.id;
    condition.title = val.title;
    condition.text = val.text;
    condition.name = val.name;
    condition.type = val.type;
    condition.dataType = val.dataType;
    condition.isMulti = val.isMulti;
    condition._index = val._index;
    if (val.value != undefined) {
        condition.value = val.value;
    } else {
        return null;
    }
    return condition;
};
util.conditionControls = {
    INPUT: {
        component: 'ConditionInput',
        initDefaultValue: (item) => {
            return this.condition_input_initDefaultValue(item);
        }
    },
    DATE: {
        component: 'ConditionDate',
        initDefaultValue: (item) => {
            return this.condition_date_initDefaultValue(item);
        }
    },
    SELECT: {
        component: 'ConditionSelect',
        initDefaultValue: (item) => {
            return this.condition_select_initDefaultValue(item);
        }
    },
    RANGE: {
        component: 'ConditionRange',
        initDefaultValue: (item) => {
            return this.condition_range_initDefaultValue(item);
        }
    },
    DROPDOWN: {
        component: 'ConditionDropdown',
        initDefaultValue: (item) => {
            return null;
        }
    },
    PERSON: {
        component: 'ConditionPersonDropdown',
        initDefaultValue: (item) => {
            return null;
        }
    },
    ORGPERSON: {
        component: 'ConditionOrgPersonDropdown',
        initDefaultValue: (item) => {
            return null;
        }
    },
    DEPARTMENT: {
        component: 'ConditionDepartmentDropdown',
        initDefaultValue: (item) => {
            return null;
        }
    },
    DANWERTREE: {
        component: 'ConditionOrgDropdown',
        initDefaultValue: (item) => {
            return null;
        }
    },
    DEPOSITARY: {
        component: 'ConditionDepositaryDropdown',
        initDefaultValue: (item) => {
            return null;
        }
    },
    BASEDATA: {
        component: 'ConditionBaseData',
        initDefaultValue: (item) => {
            return null;
        }
    },
    MASTERDATA: {
        component: 'ConditionMasterData',
        initDefaultValue: (item) => {
            return null;
        }
    },
    INPUT_WITH_RANGE: {
        component: 'ConditionInputWithRange',
        initDefaultValue: (item) => {
            return null;
        }
    }
};
util.initCondition = function(val, cType) {
    let condition = {};
    condition.id = val.id;
    condition.name = val.name;
    condition.title = val.title;
    condition.type = val.type;
    condition.dataType = val.dataType;
    condition.text = val.text; //在高级筛选确认时标签展示内容

    if (cType === 'RANGE' && val.isChangeDatasource) {
        condition.isChangeDatasource = val.isChangeDatasource
        condition.suffix = val.suffix
    }
    if (cType === 'BASEDATA' && val.isCountInfo) {
        condition.isCountInfo = val.isCountInfo
    }
    let attrType = {
        INPUT: ['fuzzySearch'],
        DATE: ['isChoseEnum'],
        SELECT: ['isMulti', '_index'],
        RANGE: ['_index', 'isChoseEnum'],
        DROPDOWN: [],
        PERSON: [],
        ORGPERSON: [],
        DEPARTMENT: [],
        DANWERTREE: [],
        DEPOSITARY: [],
        BASEDATA: [],
        MASTERDATA: [],
        INPUT_WITH_RANGE_STR: ['fuzzySearch'],
        INPUT_WITH_RANGE_HAVE: ['_index', 'isChoseEnum']
    }
    attrType[cType] && (attrType[cType].forEach(item => {
        condition[item] = val[item];
    }));
    if (val.value || ['RANGE', 'INPUT_WITH_RANGE_HAVE'].includes(cType)) {
        condition.value = (val.fuzzySearch && cType == 'INPUT') ? ('%' + val.value + '%') : val.value;
    }
    return condition;
}
export default util;