Skip to content
car-deal.ts 3.18 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import {Component, ViewChild} from '@angular/core';
import {InfiniteScrollContent, IonicPage, NavController, NavParams} from 'ionic-angular';
import {ServeService} from "../../serve.service";
import {CommonService} from "../../../../provide/common.service";
import {timer} from "rxjs/observable/timer";
import {CarApplyPage} from "../car-apply/car-apply";
wangqinghua's avatar
wangqinghua committed


@Component({
wangqinghua's avatar
wangqinghua committed
    selector: 'page-car-deal',
    templateUrl: 'car-deal.html',
wangqinghua's avatar
wangqinghua committed
})
export class CarDealPage {

wangqinghua's avatar
wangqinghua committed
    @ViewChild(InfiniteScrollContent) infiniteScrollContent: InfiniteScrollContent;
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
    pageNum = 1;
    pageSize = 10;
    changeType = 1;
    footerView = false;
    checkAll = false;
    chooseObj = [];

    totalNum;
    apply = {
        list: [],
        isLoad: false,
        loadMore: false
    };

    constructor(public navCtrl: NavController, public navParams: NavParams,
                private serveSer: ServeService, private commonSer: CommonService) {
    }

    ionViewDidLoad() {
        this.footerView = true;
        this.getList();
    }

    ionViewWillLeave() {
        this.footerView = false;
    }

    getList() {
        const data = {
            P_pageNumber: 1,
            P_pageSize: this.pageSize,
            status: this.changeType
        };
        this.serveSer.searchCarCheckList(data).subscribe(
            (res) => {
                this.apply.list = res.data.list;
            }
        )
    }

    change(type) {
        this.changeType = type;
        this.getList();
    }

    changeCheck(item) {
        const index = this.chooseObj.indexOf(item.id);
        if (index > -1) {
            this.chooseObj.splice(index, 1);
        } else {
            this.chooseObj.push(item.id);
        }
        this.checkAll = this.chooseObj.length === this.apply.list.length;
    }

    //下拉刷新
    doRefresh(e) {
        this.apply.loadMore = true;
        this.infiniteScrollContent.inf.enable(true);
        const data = {
            P_pageNumber: 1,
            P_pageSize: this.pageSize,
            status: this.changeType
        };
        this.serveSer.searchCarCheckList(data).subscribe(
            (res) => {
                this.apply.list = res.data.list;
                this.totalNum = res.data.total;
                timer(800).subscribe(() => {
                    this.commonSer.toast('刷新成功');
                    e.complete()
                });
            }
        )
    }

    //加载更多
    doInfinite(e) {
        if (this.totalNum == this.apply.list.length) {
            console.log("没有更多了");
            this.apply.loadMore = false;
            e.enable(false);
            return false;
        }
        this.pageNum++;
        const data = {
            P_pageNumber: this.pageNum,
            P_pageSize: this.pageSize,
            status: this.changeType
        };
        this.serveSer.searchCarCheckList(data).subscribe(
            (res) => {
                this.totalNum = res.data.total;
                res.list.forEach(e => {
                    this.apply.list.push(e);
                });
                timer(800).subscribe(() => e.complete());
            }
        )
    }

    goDetail(item){
wangqinghua's avatar
wangqinghua committed
        this.navCtrl.push(CarApplyPage,{id:item.id,type:'deal'})
wangqinghua's avatar
wangqinghua committed
    }
wangqinghua's avatar
wangqinghua committed

}