fengxiang
2017-12-29 f01d6b7e6bf8132524c1c2821fdcbbc5ca548369
src/app/routes/devices/version/version.component.ts
@@ -1,8 +1,10 @@
import { DataType } from './../../../core/entity/grid';
import { AddOrEditComponent } from './add-or-edit/add-or-edit.component';
import { Version } from '@angular/compiler/src/util';
import { Subject } from 'rxjs/Subject';
import '../../../rxjs-operators';
import { ToolsService } from '@core/services/tools.service';
import { Component, OnInit } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { ModalHelper } from '@delon/theme';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../../../environments/environment';
@@ -10,13 +12,14 @@
import { VersionService } from 'app/routes/devices/version/version.service';
import { Types } from '@core/enum/types.enum';
import { Column, Grid, PageBean } from '@core/entity/grid';
import { filter } from 'rxjs/operators/filter';
interface DeviceVersion {
  createTime: Column;
  description: Column;
  id?: Column;
  name: Column;
  version: Column;
export interface DeviceVersion {
  createTime?: Column|any;
  description?: Column|any;
  id?: Column|any;
  name?: Column|any;
  version?: Column|any;
}
@Component({
  selector: 'app-version',
@@ -24,44 +27,46 @@
  styles: []
})
export class VersionComponent implements OnInit {
  grid: Grid = new Grid(null);
  private version: DeviceVersion;
  grid: Grid<DeviceVersion> = new Grid(null);
  queryMap = { text: '请输入名称或型号', value: ''};
  queryTextStream: Subject<string> = new Subject<string>();
    private initPage() {
    const columns: DeviceVersion = {
    this.version = {
       name: {
        text: '名称',
        width: '22%'
        width: '18%'
       },
       version: {
        text: '型号',
        width: '22%'
        width: '18%',
        isSort: true
      },
      createTime: {
          text: '创建时间',
          width: '22%',
          width: '18%',
          type: {
            name: Types.Date,
            format: 'YYYY-MM-DD HH:mm:ss'
          }
          },
          isSort: true
      },
      description: {
          text: '备注',
          width: '22%'
          width: '18%'
      }
    };
    this.grid.title = '设备型号';
    this.grid.setColumns(columns);
    this.grid.setColumns(this.version);
    this.grid.pageSize = 10;
  }
  constructor(
    public http: HttpClient,
    private versionService: VersionService,
    public dateSrv: DateService,
    private confirmServ: NzModalService,
    public msgSrv: NzMessageService,
    private modalHelper: ModalHelper,
    private toolsService: ToolsService) {}
  ) {}
  ngOnInit() {
    this.initPage();
@@ -75,56 +80,89 @@
  queryTextChanged($event) {
      this.queryTextStream.next(this.queryMap.value);
  }
  load(reload: boolean = false) {
  load(reload: boolean = false) {
    if (reload) {
      this.grid.pageIndex = 1 ;
    }
    // 延时加载避免ExpressionChangedAfterItHasBeenCheckedError
    setTimeout(() => {
      this.grid.loading = true;
     }, 1);
    this.versionService.getPagingList(this.grid, this.queryMap.value).subscribe(
       (res: PageBean) => {
            this.grid.loading = true;
            if (res != null && res.data != null) {
              this.grid.initData(res);
              this.grid.refreshStatus();
              setTimeout(() => {
                this.grid.loading = false;
               }, 1);
            }
       }
    );
  }
  edit() {
    // this.modalHelper.static(VersionEditComponent, { user }).subscribe(() => {
    //   this.load(true);
    //   this.msgSrv.success('安装用户修改成功!');
    // });
  }
  add() {
    // const user = {};
    // this.modalHelper.static(VersionEditComponent, { user }).subscribe(() => {
    //   this.load(true);
    //   this.msgSrv.success('安装用户保存成功!');
    // });
  }
  delete(user) {
    this.http.delete(environment.SERVER_BASH_URL + '/user/operate_user/' + user.id).subscribe((res: any) => {
      this.msgSrv.success('安装用户删除成功!');
      this.load(true);
// rowData为null时,为新增
  addOrModify(data) {
    if ( data == null) {
       data = {};
    }
    const cols = this.version;
    this.modalHelper.static(AddOrEditComponent, { cols , data }).subscribe(
      ( ret: { data: any, close: Function} ) => {
      this.versionService.save(ret.data).subscribe(
         ( res: any) => {
            if (res.code === 1) {
              this.load();
              ret.close();
              this.msgSrv.success('设备型号保存成功!');
            }
         }
      );
    });
  }
  remove() {
  delete(...id: number[]) {
    this.versionService.delete( ...id ).subscribe(
      ( res: any) => {
         if (res.code === 1) {
           this.load();
           this.msgSrv.success('设备型号删除成功!');
         }
      }
   );
  }
  dataChange(res: any) {
   deleteSelected() {
    this.confirmServ.confirm({
      title: '批量删除',
      content: '注意:数据一旦删除,将不可恢复!',
      okText: '确定',
      cancelText: '取消'
    }).on('onOk', () => {
       if (this.grid.selectedIndexs != null && this.grid.selectedIndexs.length > 0) {
          const ids = this.grid.selectedIndexs.map(
              (index: number) => {
                  const id = this.grid.data[index].id;
                  return Number.parseInt(id);
              }
          );
          this.delete( ...ids );
       }
    });
  }
  sort(field: string, value: any) {
    // this.sortMap = {};
    // this.sortMap[field] = value;
    // this.q.sorter = value ? `${field}_${value}` : '';
    // this.load(true);
  sort(field: string, value: string) {
    // 删除当前field
    this.grid.sorts = this.grid.sorts.filter(
       (fn: string) => {
          return fn !== field;
       }
     );
     // 如果value不为null,在排序数组最后加上filed
     if ( value != null ) {
        this.grid.sorts.push(field);
     }
     this.load();
  }
  reset(ls: any[]) {