import { Component, OnInit } from '@angular/core';
import {environment} from '../../../../environments/environment';
import {DistributionService} from '../../../services/distribution.service';
import {IconService} from '../../../services/icon.service';
import {FormBuilder, FormGroup} from '@angular/forms';
import {NzMessageService} from 'ng-zorro-antd';

@Component({
  selector: 'app-promotion-order-list',
  templateUrl: './promotion-order-list.component.html',
  styleUrls: ['./promotion-order-list.component.scss']
})
export class PromotionOrderListComponent implements OnInit {

    WEB_SERVE_URL = environment.imageUrl;
    searchForm: FormGroup; // 搜索框
    requestData = []; // 列表数据
    agentData = []; // 代理商列表


    total: number; // 页码
    pageNum = 1; // 页码
    pageSize = 10; // 条码
    loading = true;



    constructor(
        private form: FormBuilder,
        private distribution: DistributionService,
        private iconService: IconService,
        private message: NzMessageService,
    ) {
    }

    ngOnInit(): void {
        this.init();
        this.getInitData();
    }

    // 获取初始化数据
    private getInitData(): void {
        // 获取价格数据
        this.distribution.agentUserList( data => {
            this.agentData = data['return_data'];
        });

    }

    public init(): void {
        this.searchForm = this.form.group({
            agentId : [null],
            popularizeUserId: [null],
            orderNo: [null],
            title: [null],
            userName: [null],
            code: [null],
        });

        this.getRequest(true, this.searchForm.value);
    }

    // 查询列表
    public getRequest(reset: boolean = false, whereObject: object) {

        this.loading = false;
        if (reset) {
            this.pageNum = 1;
        }
        whereObject['pageNum'] = this.pageNum;
        whereObject['pageSize'] = this.pageSize;
        this.distribution.orderListByAgentId(whereObject, data => {
            if (data['return_code'] === '000000') {
                this.requestData = data['return_data'].list;
                this.total = data['return_data'].total;
            } else {
                this.message.error(data['return_msg']);
            }
        });
    }

    // 重置
    public resetForm(): void {
        this.searchForm.reset();
    }


}
