xufenglei
2018-04-10 fb73a14c658ce113721542c415402321a985d25b
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
import {environment} from "../../../../environments/environment";
import {Component, OnInit, ViewChild} from '@angular/core';
import {SimpleTableColumn} from "@delon/abc";
import {_HttpClient} from '@delon/theme';
import {Subject} from "rxjs";
import * as moment from 'moment';
import {NzMessageService} from "ng-zorro-antd";
@Component({
  selector: 'app-registration',
  templateUrl: './registration.component.html',
})
export class RegistrationComponent implements OnInit {
  constructor(
    public msgSrv: NzMessageService,
    private http: _HttpClient
  ) {}
 
  @ViewChild('simpleTable') simpleTable: {load: Function};
 
  dataUrl = environment.SERVER_BASH_URL + 'machineactivate/list';
 
  queryTextStream: Subject<string> = new Subject<string>();
 
  extraParams: any = {};
  organization: any = {};
  columns: SimpleTableColumn[] = [
    {title: '注册码', index: 'activationCode'},
    {
      title: '是否使用', index: 'isUsed', format: function(machineActivate) {
        return machineActivate.isUsed == 1 ? '是' : '否';
      }
    },
    {
      title: '生成时间', type: 'date', index: 'createTime', format: function(machineActivate) {
        return moment(machineActivate.createTime).format('YYYY-MM-DD HH:mm:ss');
      }
    },
    {
      title: '失效日期', type: 'date', index: 'expireDate', format: function(machineActivate) {
        return moment(machineActivate.expireDate).format('YYYY-MM-DD');
      }
    },
  ];
  isVisible: boolean = false;
  _date = new Date(Date.now() + 3600 * 24 * 1 * 1000);
 
  ngOnInit() {
    const organization = this.organization = JSON.parse(sessionStorage.getItem("organization"));
    this.extraParams.organizationId = organization.id;
    this.queryTextStream.debounceTime(900).distinctUntilChanged().subscribe(value => {
      this.load();
    });
  }
 
  load() {
    this.simpleTable.load();
  }
 
  _disabledDate(current: Date): boolean {
    return current && current.getTime() < Date.now();
  }
 
  registrationOk() {
    this.http.get(environment.SERVER_BASH_URL + '/machineactivate/machine', {organizationId: this.organization.id, expireDate: moment(this._date).format('YYYY-MM-DD')}).subscribe((res: any) => {
      if (res.code == 1 && res.data == 1) {
        this.isVisible = false;
        this.msgSrv.success('新建注册码成功!');
        this.load();
      }
    });
  }
}