app-group-picker.vue 7.3 KB
Newer Older
JunZai's avatar
JunZai committed
1 2 3 4
<template>
    <div class="ibiz-group-picker">
        <div class="ibiz-group-container">
            <div v-if="showTree" class="ibiz-group-tree">
5
                <ibiz-select-tree :NodesData="treeItems" v-model="treeSelectVal" :treeOnly="true" :defaultChecked="true" @select="treeSelect"></ibiz-select-tree>
JunZai's avatar
JunZai committed
6
            </div>
7
            <div class="ibiz-group-content">
JunZai's avatar
JunZai committed
8 9 10 11
                <ibiz-group-card :data="cardItems" text="label" value="id" groupName="group" :multiple="multiple" :defaultSelect="cardSelctVal" @select="groupSelect"></ibiz-group-card>
            </div>
        </div>
        <div class="ibiz-group-footer">
12 13
            <el-button size="small" type="primary" @click="onOK">{{$t('app.commonWords.ok')}}</el-button>
            <el-button size="small" @click="onCancel">{{$t('app.commonWords.cancel')}}</el-button>
JunZai's avatar
JunZai committed
14 15 16 17 18 19 20 21 22
        </div>
    </div>
</template>

<script lang="ts">
import { Component, Vue, Prop, Watch } from 'vue-property-decorator';
import { Subject } from 'rxjs';
import { Http } from '../../utils';
@Component({})
tony001's avatar
tony001 committed
23
export default class AppGroupPicker extends Vue {
JunZai's avatar
JunZai committed
24 25 26 27 28

    /**
     * 视图上下文参数
     *
     * @type {*}
tony001's avatar
tony001 committed
29
     * @memberof AppGroupPicker
JunZai's avatar
JunZai committed
30 31 32 33 34 35 36
     */  
    @Prop() viewdata: any;

    /**
     * 视图参数
     *
     * @type {*}
tony001's avatar
tony001 committed
37
     * @memberof AppGroupPicker
JunZai's avatar
JunZai committed
38 39 40 41 42 43 44
     */  
    @Prop() viewparam: any;

    /**
     * 多选
     *
     * @type {*}
tony001's avatar
tony001 committed
45
     * @memberof AppGroupPicker
JunZai's avatar
JunZai committed
46 47 48
     */  
    protected multiple: boolean = false;

49 50 51 52
    /**
     * 加载树url
     *
     * @type {*}
tony001's avatar
tony001 committed
53
     * @memberof AppGroupPicker
54 55 56 57 58 59 60
     */  
    protected treeurl:any;

    /**
     * 加载人员url
     *
     * @type {*}
tony001's avatar
tony001 committed
61
     * @memberof AppGroupPicker
62 63 64
     */  
    protected url:any;

JunZai's avatar
JunZai committed
65 66 67 68
    /**
     * 树数据集
     *
     * @type {*}
tony001's avatar
tony001 committed
69
     * @memberof AppGroupPicker
JunZai's avatar
JunZai committed
70 71 72 73 74 75 76
     */  
    protected treeItems: any[] = [];

    /**
     * 分组表数据集
     *
     * @type {*}
tony001's avatar
tony001 committed
77
     * @memberof AppGroupPicker
JunZai's avatar
JunZai committed
78 79 80 81 82 83 84
     */  
    protected cardItems: any[] = [];

    /**
     * 视图上下文参数对象
     *
     * @type {*}
tony001's avatar
tony001 committed
85
     * @memberof AppGroupPicker
JunZai's avatar
JunZai committed
86 87 88 89 90 91 92
     */  
    protected viewData: any;

    /**
     * 视图参数对象
     *
     * @type {*}
tony001's avatar
tony001 committed
93
     * @memberof AppGroupPicker
JunZai's avatar
JunZai committed
94 95 96 97 98 99 100
     */  
    protected viewParam: any;

    /**
     * 树选中值
     *
     * @type {*}
tony001's avatar
tony001 committed
101
     * @memberof AppGroupPicker
JunZai's avatar
JunZai committed
102 103 104 105 106 107 108
     */  
    protected treeSelectVal: string = '';

    /**
     * 分组表选中集合
     *
     * @type {*}
tony001's avatar
tony001 committed
109
     * @memberof AppGroupPicker
JunZai's avatar
JunZai committed
110 111 112 113 114 115 116
     */  
    protected cardSelctVal: any = [];

    /**
     * 数据选中集合
     *
     * @type {*}
tony001's avatar
tony001 committed
117
     * @memberof AppGroupPicker
JunZai's avatar
JunZai committed
118 119 120 121 122 123 124
     */  
    protected selects: any[] = [];

    /**
     * 是否显示树
     *
     * @type {*}
tony001's avatar
tony001 committed
125
     * @memberof AppGroupPicker
JunZai's avatar
JunZai committed
126 127
     */  
    get showTree() {
128 129
        if(this.viewParam) {
            return this.viewParam.showtree;
JunZai's avatar
JunZai committed
130 131 132 133 134 135 136
        }
    }

    /**
     * 生命周期
     *
     * @type {*}
tony001's avatar
tony001 committed
137
     * @memberof AppGroupPicker
JunZai's avatar
JunZai committed
138 139 140 141 142 143 144 145
     */  
    public created() {
        if(!this.viewdata || !this.viewparam) {
            return;
        }
        this.viewData = JSON.parse(this.viewdata);
        this.viewParam = JSON.parse(this.viewparam);
        this.multiple = this.viewParam.multiple;
146 147
        this.treeurl = this.viewParam.treeurl;
        this.url = this.viewParam.url;
JunZai's avatar
JunZai committed
148
        if (this.viewParam.selects) {
JunZai's avatar
JunZai committed
149 150 151 152
            this.viewParam.selects.forEach((select: any) => {
                this.selects.push(select);
                this.cardSelctVal.push(select.id)
            })
JunZai's avatar
JunZai committed
153 154 155 156 157 158 159 160
        }
        this.load();
    }

    /**
     * 加载数据
     *
     * @type {*}
tony001's avatar
tony001 committed
161
     * @memberof AppGroupPicker
JunZai's avatar
JunZai committed
162 163 164 165 166
     */  
    public load() {
        if(this.showTree) {
            this.loadTree();
        } else {
JunZai's avatar
JunZai committed
167
            this.loadGroupData(this.viewParam.filtervalue);
JunZai's avatar
JunZai committed
168 169 170 171 172 173 174
        }
    }

    /**
     * 加载树数据
     *
     * @type {*}
tony001's avatar
tony001 committed
175
     * @memberof AppGroupPicker
JunZai's avatar
JunZai committed
176 177
     */  
    public loadTree() {
178
        let orgid = this.viewParam.filtervalue;
Shine-zwj's avatar
Shine-zwj committed
179
        let tempTreeUrl: string = '';
ShineKOT's avatar
ShineKOT committed
180
        if(this.viewParam.selectType && Object.is(this.viewParam.selectType,"dept")){
Shine-zwj's avatar
Shine-zwj committed
181
            tempTreeUrl = this.treeurl.replace('{deptId}',orgid);
ShineKOT's avatar
ShineKOT committed
182 183
        }else{
            tempTreeUrl = this.treeurl.replace('${orgid}',orgid);
Shine-zwj's avatar
Shine-zwj committed
184
        }
185
        let get = Http.getInstance().get(tempTreeUrl, true);
JunZai's avatar
JunZai committed
186 187 188 189 190 191 192 193 194 195 196 197 198
        get.then((response: any) => {
            if(response.status === 200) {
                this.treeItems = response.data;
            }
        }).catch((error: any) => {
            console.log(error)
        })
    }

    /**
     * 加载分组表数据
     *
     * @type {*}
tony001's avatar
tony001 committed
199
     * @memberof AppGroupPicker
JunZai's avatar
JunZai committed
200 201
     */  
    public loadGroupData(key: string) {
Shine-zwj's avatar
Shine-zwj committed
202
        let tempUrl: string = '';
ShineKOT's avatar
ShineKOT committed
203
        if(this.viewParam.selectType && Object.is(this.viewParam.selectType,"dept")){
Shine-zwj's avatar
Shine-zwj committed
204
            tempUrl = this.url.replace('{deptId}',key);
ShineKOT's avatar
ShineKOT committed
205 206
        }else{
            tempUrl = this.url.replace('${selected-orgid}',key);
Shine-zwj's avatar
Shine-zwj committed
207
        }
208
        let get = Http.getInstance().get(tempUrl, true);
JunZai's avatar
JunZai committed
209 210 211 212 213 214 215 216 217 218 219 220 221
        get.then((response: any) => {
            if(response.status === 200) {
                this.cardItems = response.data;
            }
        }).catch((error: any) => {
            console.log(error)
        })
    }

    /**
     * 树选中
     *
     * @type {*}
tony001's avatar
tony001 committed
222
     * @memberof AppGroupPicker
JunZai's avatar
JunZai committed
223 224 225 226 227 228 229 230 231 232 233 234 235
     */  
    public treeSelect(event: any) {
        if(!event || JSON.parse(event).length == 0) {
            return;
        }
        const items: any = JSON.parse(event);
        this.loadGroupData(items[0].id);
    }

    /**
     * 分组表选中
     *
     * @type {*}
tony001's avatar
tony001 committed
236
     * @memberof AppGroupPicker
JunZai's avatar
JunZai committed
237 238
     */  
    public groupSelect(event: any) {
JunZai's avatar
JunZai committed
239
        if (!event || !event.select) {
JunZai's avatar
JunZai committed
240 241
            return;
        }
JunZai's avatar
JunZai committed
242 243 244
        if(!this.multiple) {
            this.selects = [];
        }
JunZai's avatar
JunZai committed
245 246
        if(event.rselect) {
            let index: number = this.selects.findIndex((item: any) => Object.is(event.rselect, item.id));
JunZai's avatar
JunZai committed
247
            if(index >= 0) {
JunZai's avatar
JunZai committed
248
                this.selects.splice(index, 1);
JunZai's avatar
JunZai committed
249
            }
JunZai's avatar
JunZai committed
250
        } else {
JunZai's avatar
JunZai committed
251
            event.select.forEach((key: string) => {
JunZai's avatar
JunZai committed
252 253 254 255 256 257 258 259 260 261
                let index: number = this.selects.findIndex((item: any) => Object.is(key, item.id));
                if(index >= 0) {
                    return;
                }
                let item: any = this.cardItems.find((item: any) => Object.is(key, item.id));
                if (item) {
                    this.selects.push(item);
                }
            });
        }
JunZai's avatar
JunZai committed
262 263 264 265 266 267
    }

    /**
     * 确认
     *
     * @type {*}
tony001's avatar
tony001 committed
268
     * @memberof AppGroupPicker
JunZai's avatar
JunZai committed
269 270 271 272 273 274 275 276 277
     */  
    public onOK() {
        this.$emit('close', this.selects);
    }
    
    /**
     * 取消
     *
     * @type {*}
tony001's avatar
tony001 committed
278
     * @memberof AppGroupPicker
JunZai's avatar
JunZai committed
279 280 281 282 283 284 285 286
     */  
    public onCancel() {
        this.$emit('close');
    }
}
</script>

<style lang="less">
tony001's avatar
tony001 committed
287
.ibiz-group-picker{
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
  width: 100%;
  height: 100%;
  .ibiz-group-container {
      display: flex;
      height: calc(100% - 65px);
      .ibiz-group-tree {
          min-width: 200px;
          border-right: 1px solid #ddd;
          padding: 0 34px 0 10px;
          overflow: auto;
          height: 100%;
      }
      .ibiz-group-content {
          flex-grow: 1;
          padding: 0 10px;
          overflow: auto;
          height: 100%;
      }
  }
  .ibiz-group-footer {
      padding: 16px;
      text-align: right;
      border-top: 1px solid #ddd;
  }
JunZai's avatar
JunZai committed
312 313
}
</style>