ibiz-mpickup-result.ts 5.6 KB
Newer Older
ibiz's avatar
ibiz 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
/**
 * 多项选择结果集合控件服务对象
 *
 * @class IBizMPickupResult
 * @extends {IBizControl}
 */
class IBizMPickupResult extends IBizControl {

    /**
     * 按钮文本--数据选中
     *
     * @type {string}
     * @memberof IBizMPickupResult
     */
    public onRightText: string = '选中';

    /**
     * 按钮文本--取消选中
     *
     * @type {string}
     * @memberof IBizMPickupResult
     */
    public onLeftText: string = '取消';

    /**
     * 按钮文本--全部选中
     *
     * @type {string}
     * @memberof IBizMPickupResult
     */
    public onAllRightText: string = '全部选中';

    /**
     * 按钮文本--取消全部选中
     *
     * @type {string}
     * @memberof IBizMPickupResult
     */
    public onAllLeftText: string = '全部取消';

    /**
     * 当前结果数据中选中数据
     * 
     * @type {Array<any>}
     * @memberof IBizMPickupResult
     */
    public resSelecttions: Array<any> = []

    /**
     * 多项数据结果集中所有数据
     * 
     * @type {Array<any>}
     * @memberof IBizMPickupResult
     */
    public selections: Array<any> = [];

    /**
     * 当前表格选中数据
     *
     * @type {Array<any>}
     * @memberof IBizMPickupResult
     */
    public curSelecttions: Array<any> = [];

    /**
     * 当前表格所有数据
     *
     * @type {Array<any>}
     * @memberof IBizMPickupResult
     */
    public allData: Array<any> = [];

    /**
     * Creates an instance of IBizMPickupResult.
     * 创建 IBizMPickupResult 实例
     * 
     * @param {*} [opts={}] 
     * @memberof IBizMPickupResult
     */
    constructor(opts: any = {}) {
        super(opts);
    }

    /**
     * 结果集数据选中
     * 
     * @param {*} [item={}] 
     * @memberof IBizMPickupResult
     */
    public resultSelect(item: any = {}): void {
        if (Object.keys(item).length === 0) {
            return;
        }

        const index: number = this.resSelecttions.findIndex(select => Object.is(item.srfkey, select.srfkey));
        if (index === -1) {
            this.resSelecttions.push(item);
            item.select = true;
        } else {
            this.resSelecttions.splice(index, 1);
            item.select = false;
        }

    }

    /**
     * 结果数据选中激活
     *
     * @param {*} [item={}]
     * @returns {void}
     * @memberof IBizMPickupResult
     */
    public dataActivated(item: any = {}): void {
        if (Object.keys(item).length === 0) {
            return;
        }

        const index: number = this.selections.findIndex(select => Object.is(item.srfkey, select.srfkey));
        this.selections.splice(index, 1);
        const _index: number = this.resSelecttions.findIndex(select => Object.is(item.srfkey, select.srfkey));
        if (_index !== -1) {
            this.resSelecttions.splice(_index, 1);
        }
        item.select = false;
    }

    /**
     * 移除结果数据中已选中数据
     * 
     * @memberof IBizMPickupResult
     */
    public onLeftClick(): void {
        this.resSelecttions.forEach((item) => {
            const index: number = this.selections.findIndex(select => Object.is(item.srfkey, select.srfkey));
            if (index !== -1) {
                this.selections.splice(index, 1);
            }
        });
        this.resSelecttions = [];
    }

    /**
     * 添加表格选中数据至结果数据中
     * 
     * @memberof IBizMPickupResult
     */
    public onRightClick(): void {
        this.curSelecttions.forEach((item) => {
            const index: number = this.selections.findIndex(select => Object.is(item.srfkey, select.srfkey));
            if (index === -1) {
                item.select = false;
                this.selections.push(item);
            }
        });
    }

    /**
     * 将所有表格数据添加到结果数据中
     * 
     * @memberof IBizMPickupResult
     */
    public onRightAllClick(): void {
        this.allData.forEach((item) => {
            const index: number = this.selections.findIndex(select => Object.is(item.srfkey, select.srfkey));
            if (index === -1) {
                item.select = false;
                this.selections.push(item);
            }
        });
    }

    /**
     * 移除所有结果数据
     * 
     * @memberof IBizMPickupResult
     */
    public onLeftAllClick(): void {
        this.selections = [];
        this.resSelecttions = [];
    }

    /**
     * 获取选中值
     * 
     * @returns {Array<any>} 
     * @memberof IBizMPickupResult
     */
    public getSelections(): Array<any> {
        let sele: Array<any> = [];
        sele = [...this.selections];
        return sele;
    }

    /**
     * 添加结果数据中的选中数据
     * 
     * @param {Array<any>} items 
     * @memberof IBizMPickupResult
     */
    public appendDatas(items: Array<any>): void {
        items.forEach(item => {
            const index: number = this.selections.findIndex(data => Object.is(data.srfkey, item.srfkey));
            if (index === -1) {
                item.select = false;
                this.selections.push(item);
            }
        });
    }

    /**
     * 设置设置当前选中数据
     * 
     * @param {Array<any>} data 
     * @memberof IBizMPickupResult
     */
    public setCurSelections(data: Array<any>): void {
        this.curSelecttions = [];
        this.curSelecttions = [...data];
    }

    /**
     * 设置当前表格所有数据
     * 
     * @param {Array<any>} data 
     * @memberof IBizMPickupResult
     */
    public setAllData(data: Array<any>): void {
        this.curSelecttions = [];
        this.allData = [];
        this.allData = [...data];
    }
}