import { Component, OnInit } from '@angular/core';
import {environment} from '../../../../environments/environment';
import {RechargeService} from '../../../services/recharge.service';
import {DiscountService} from '../../../services/discount.service';
import {ApiMerchantsService} from '../../../services/api-merchants.service';
import {CouponService} from '../../../services/coupon.service';
import {IconService} from '../../../services/icon.service';
import {FormBuilder, FormGroup} from '@angular/forms';
import {NzMessageService, NzModalService} from 'ng-zorro-antd';

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

    FILE_URL = environment.imageUrl;
    WEB_SERVE_URL = environment.baseUrl;
    searchForm: FormGroup; // 搜索框
    validateForm: FormGroup; // 添加框
    requestData = []; // 列表数据
    total: number; // 页码
    pageNum = 1; // 页码
    pageSize = 10; // 条码
    loading = true;
    isVisible = false;
    constructor(
        private form: FormBuilder,
        private recharge: RechargeService,
        private discount: DiscountService,
        private apiMerchant: ApiMerchantsService,
        private modal: NzModalService,
        private coupon: CouponService,
        private iconService: IconService,
        private message: NzMessageService,

    ) {
    }

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

    public init(): void {
        this.searchForm = this.form.group({
            orderStatus: [null], // 订单状态
            orderNo: [null], // 订单号
            productType: [2], // 产品类型
            sourceOrderNo: [null], // 第三方订单号
            callbackStatus: [null],  // 回调状态
            payTime: [null], // 支付时间
            createTime: [null],   // 创建时间
        });

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

    // 查询列表
    public getRequest(reset: boolean = false, whereObject: object) {
        if (whereObject['payTime'] != null && whereObject['payTime'].length !== 0) {
            whereObject['payTimeS'] = whereObject['payTime'][0].getTime();
            whereObject['payTimeE'] = whereObject['payTime'][1].getTime();
        }

        if (whereObject['createTime'] != null && whereObject['createTime'].length !== 0) {
            whereObject['createTimeS'] = whereObject['createTime'][0].getTime();
            whereObject['createTimeE'] = whereObject['createTime'][1].getTime();
        }
        this.loading = false;
        if (reset) {
            this.pageNum = 1;
        }
        whereObject['pageNum'] = this.pageNum;
        whereObject['pageSize'] = this.pageSize;
        this.apiMerchant.getApiThirdOrderByList(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();
    }

}