app-mob-group-picker.vue 10.9 KB
Newer Older
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 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
<template>
<ion-page :className="{ 'app-mob-group-picker': true }">
    <ion-header>
        <ion-toolbar v-show="titleStatus" class="app-mob-group-picker__header">
            <ion-buttons slot="start">
                <ion-button  @click="closeView">
                    <ion-icon name="chevron-back"></ion-icon>
                    {{$t('app.button.back')}}
                </ion-button>
            </ion-buttons>
            <ion-title><label> {{$t('app.title.choose')}}</label></ion-title>
        </ion-toolbar>
    </ion-header>
    <div class="app-mob-group-picker__container">
        <div class="app-mob-group-picker__content">
          <div class="app-mob-group-picker__content__header">
              <div class="header__left" v-if="treeItems.length > 0">
                <van-sidebar v-model="activeKey">
                  <van-sidebar-item :title="item.label" v-for="(item, index) in treeItems" :key="index" @click="treeSelect(item.id)"/>
                </van-sidebar>
              </div>
              <div class="header__right">
                <template v-if="handledCardItems.length > 0">
                    <div v-for="(_item,index) in handledCardItems" :key="index">
                    <div class="header__right__title">{{ _item.title }}</div>
                    <ion-list class="header__right__list">
                        <template v-for="(item, _index) in _item.value">
                        <ion-item :key="_index" @click="click_node(item)" class="list__item">
                            <ion-label>{{ item.label|| item.personname }}</ion-label>
                            <app-mob-icon class="item__icon" position="end" :name="geticon(item.status)" @onClick="icon_click(item)"></app-mob-icon>
                        </ion-item>
                        </template>
                    </ion-list>
                    </div>
                </template>
                <template v-else>
                    <div class="app-mob-group-picker--nodata">{{ $t('app.commonWords.noData') }}</div>
                </template>
              </div>
          </div>
          <div class="app-mob-group-picker__footer">
              <app-mob-button size="large" type="primary" @click="onOK">{{$t('app.button.confirm')}}</app-mob-button>
          </div>
        </div>
    </div>
</ion-page>
</template>

<script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator';
import { Http } from "ibiz-core";
@Component({})
export default class AppMobGroupPicker extends Vue {

    /**
     * 动态参数
     * 
     * @memberof AppGroupPicker
     */
    @Prop() dynamicProps?:any;


    /**
     * 侧边栏激活项
     *
     * @type {*}
     * @memberof AppMobGroupPicker
     */  
    public activeKey:number = 0;

    /**
     * 多选
     *
     * @type {*}
     * @memberof AppMobGroupPicker
     */  
    protected multiple: boolean = false;

    /**
     * 加载树url
     *
     * @type {*}
     * @memberof AppMobGroupPicker
     */  
    protected treeurl:any;

    /**
     * 加载人员url
     *
     * @type {*}
     * @memberof AppMobGroupPicker
     */  
    protected url:any;

    /**
     * 树数据集
     *
     * @type {*}
     * @memberof AppMobGroupPicker
     */  
    public treeItems: any[] = [];

    /**
     * 分组表数据集
     *
     * @type {*}
     * @memberof AppMobGroupPicker
     */  
    protected cardItems: any[] = [];

    /**
     * 视图上下文参数对象
     *
     * @type {*}
     * @memberof AppMobGroupPicker
     */  
    protected viewData: any;

    /**
     * 视图参数对象
     *
     * @type {*}
     * @memberof AppMobGroupPicker
     */  
    protected viewParam: any;

    /**
     * 树选中值
     *
     * @type {*}
     * @memberof AppMobGroupPicker
     */  
    protected treeSelectVal: string = '';

    /**
     * 分组表选中集合
     *
     * @type {*}
     * @memberof AppMobGroupPicker
     */  
    protected cardSelctVal: any = [];

    /**
     * 数据选中集合
     *
     * @type {*}
     * @memberof AppMobGroupPicker
     */  
    protected selects: any[] = [];

    /**
     * 处理后的分组表数据集
     *
     * @type {*}
     * @memberof AppMobGroupPicker
     */  
    public handledCardItems: any[] = [];

     /**
     * 设置工具栏标题状态
     *
     * @memberof IbzDailyDailyCreateMobEditViewBase
     */
    public titleStatus: boolean = true;

     /**
     * 设置工具栏状态
     *
     * @memberof IbzDailyDailyCreateMobEditViewBase
     */
    public setViewTitleStatus(){
        // const thirdPartyName = this.$store.getters.getThirdPartyName();
        // if(thirdPartyName){
        //     this.titleStatus = false;
        // }
    }


    /**
     * 是否显示树
     *
     * @type {*}
     * @memberof AppMobGroupPicker
     */  
    get showTree() {
        if(this.viewParam) {
            return this.viewParam.showtree;
        }
    }

    /**
     * 生命周期
     *
     * @type {*}
     * @memberof AppMobGroupPicker
     */  
    public created() {
        const _context = this.dynamicProps._context;
        const _viewparams = this.dynamicProps._viewparams;
        if(!_context || !_viewparams) {
            return;
        }
        this.viewData = JSON.parse(_context);
        this.viewParam = JSON.parse(_viewparams);
        this.multiple = this.viewParam.multiple;
        this.treeurl = this.viewParam.treeurl;
        this.url = this.viewParam.url;
        if (this.viewParam.selects) {
            this.viewParam.selects.forEach((select: any) => {
                this.selects.push(select);
                this.cardSelctVal.push(select.id)
            })
        }
        this.load();
        this.setViewTitleStatus();
    }

    /**
     * 加载数据
     *
     * @type {*}
     * @memberof AppMobGroupPicker
     */  
    public load() {
        if(this.showTree) {
            this.loadTree();
        } else {
            this.loadGroupData(this.viewParam.filtervalue);
        }
    }

    /**
     * 加载树数据
     *
     * @type {*}
     * @memberof AppMobGroupPicker
     */  
    public loadTree() {
        let orgid = this.viewParam.filtervalue;
        let tempTreeUrl: string = '';
        if(this.viewParam.selectType && Object.is(this.viewParam.selectType,"dept")){
            tempTreeUrl = this.treeurl.replace('${deptId}',orgid);
        }else{
            tempTreeUrl = this.treeurl.replace('${orgid}',orgid);
        }
        let get = Http.getInstance().get(tempTreeUrl, true);
        get.then((response: any) => {
            if(response.status === 200) {
                this.treeItems = response.data;
                this.treeSelect(this.treeItems[0].id)
            }
        }).catch((error: any) => {
            console.log(error)
        })        
    }

    /**
     * 加载分组表数据
     *
     * @type {*}
     * @memberof AppMobGroupPicker
     */  
    public loadGroupData(key: string) {
        let tempUrl: string = '';
        if(this.viewParam.selectType && Object.is(this.viewParam.selectType,"dept")){
            tempUrl = this.url.replace('{deptId}',key);
        }else{
            tempUrl = this.url.replace('${selected-orgid}',key);
        }
        let get = Http.getInstance().get(tempUrl, true);
        get.then((response: any) => {
            if(response.status === 200) {
                this.cardItems = response.data;
                this.handledCardItems = []
                this.handleGroupData()
            }
        }).catch((error: any) => {
            console.log(error)
            // 插件代码 (模拟数据) 需删除
            // this.cardItems = error.data;
            //     this.handleGroupData()
        })
    }

    /**
     * 处理分组表数据
     *
     * @type {*}
     * @memberof AppMobGroupPicker
     */  
    public handleGroupData(){
      const  groupBy = (array:any, f:any) => {
          let groups:any = {};
          array?.forEach(function (o:any) {
              var group:any = JSON.stringify(f(o));
              groups[group] = groups[group] || [];
              groups[group].push(o);
          });
          return Object.keys(groups).map(function (group:any) {
              return groups[group];
          });
      };
      const arrayGroupBy = (list:any, groupId:any) => {
          let handled:any = groupBy(list, function (item:any) {
              return [item[groupId]];
          });

          for (let i = 0; i < handled.length; i++) {
            let array:any = handled[i];
            // 初始化图标状态
            for (let i = 0; i < array.length; i++) {
              let element = array[i];
              element.status = this.selects.findIndex((item)=>{return item.id === element.id}) > -1 ? 1 : 0;

            }
            this.handledCardItems[i] = {}
            this.handledCardItems[i].title = array[0].group
            this.handledCardItems[i].value = array;
          }          
      }
      arrayGroupBy(this.cardItems,'group');
      this.$forceUpdate();
    }


    /**
     * 树选中
     *
     * @type {*}
     * @memberof AppMobGroupPicker
     */  
    public treeSelect(event: any) {
        this.loadGroupData(event);
    }


    /**
     * 节点点击
     */
    public click_node(item: any) {
        this.icon_click(item);
    }

    /**
     * 图标点击
     */
    public icon_click(item: any) {
      if (item.status === 0) {
        let index = this.selects.indexOf(item)
        if (index == -1) {
          if (this.multiple) {
            item.status = 1;
            this.selects.push(item);
          } else {
            this.selects[0] = item;
            // 维护图标状态
            this.handledCardItems.forEach((arr:any)=>{
                arr.value.forEach((item:any)=>{
                  item.status = 0;
                })
            })
            item.status = 1;
          }
        }
      } else {
        item.status = 0;
        let index = this.selects.indexOf(item)
        this.selects.splice(index,1)
      }
      this.geticon(item);
      this.$forceUpdate();
    }

    /**
     * 获取图标
     */
    public geticon(value: any) {
        switch (value) {
            case 0:
                return 'ellipse-outline'
            case 1:
                return 'checkmark-circle-outline'
            default: 'ellipse-outline'
                break;
        }
    }

    /**
     * 确认
     *
     * @type {*}
     * @memberof AppMobGroupPicker
     */  
    public onOK() {
        this.$emit('close', this.selects);
    }
    
    /**
     * 取消
     *
     * @type {*}
     * @memberof AppMobGroupPicker
     */  
    public onCancel() {
        this.$emit('close');
    }

    public mounted(){
      
    }

     /**
     * 第三方容器初始化
     * 
     * @memberof IbzDailyDailyCreateMobEditViewBase
     */
    protected  thirdPartyInit(){
    //   this.$viewTool.setViewTitleOfThirdParty(this.$t('app.title.choose'));
    //   this.$viewTool.setThirdPartyEvent(this.closeView);
    }

    /**
     * on_ok_click
     */
    public closeView() {
      this.$emit('close');
    }

}
</script>