#include "mainForm.h"
#include "QsLog.h"
#include "ui_mainForm.h"
#include "preDefine.h"
//#include "Control/flowControl.h"
#include "QsLog.h"
//#include "DTools/util.h"
#include <QList>
#include <QMap>
#include <QProcess>
#include <QThread>
#include <QDateTime>

#include <QDesktopWidget>

#include "base/Config/configManger.h"
#include "event/posevent.h"
#include "event/fmapplication.h"
#include "model/posorderpool.h"

//#include "Control/entryControl.h"

extern QThread  workThread;

MainForm::MainForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MainForm)
{
    ui->setupUi(this);

    // 初始化成员变量
    m_prevBtn = NULL;
    m_prevTable = NULL;
    m_tableList.append(ui->mainTableNew);
    m_tableList.append(ui->mainTableMake);
    m_tableList.append(ui->mainTableSend);
    m_tableList.append(ui->mainTableRefund);
    m_tableList.append(ui->mainTableFinsh);
    m_tableList.append(ui->mainTableOther);

    // 注册信号槽参数
//    qRegisterMetaType<CashierObject>("CashierObject");
//    qRegisterMetaType< QList<CashierObject> >("QList<CashierObject>");
//    qRegisterMetaType<DeliverObject>("DeliverObject");
//    qRegisterMetaType< QList<DeliverObject> >("QList<DeliverObject>");
//    qRegisterMetaType<AlertForm::Type>("AlertForm::Type");
//    qRegisterMetaType< QMap<QString,QString> >("QMap<QString,int>");

    // 连接信号槽
    //connect(this, &MainForm::processRejectOrder, &FlowControl::GetInstance(), &FlowControl::onProcessRejectOrder);
    connect(&m_timeTimer, &QTimer::timeout, this, &MainForm::onSetCurrentTime);
    //connect(this, &MainForm::processOrder, &FlowControl::GetInstance(), &FlowControl::onProcessOrder);
    //connect(this, &MainForm::flowStart, &FlowControl::GetInstance(), &FlowControl::onflowStart);
    //connect(this, &MainForm::getOrderDetails, &FlowControl::GetInstance(), &FlowControl::onGetOrderDetails);
    //connect(this, &MainForm::getDayReport, &FlowControl::GetInstance(), &FlowControl::onDailyReport);
    //connect(&FlowControl::GetInstance(), &FlowControl::showDailyReportData, this, &MainForm::onSetDailyReportData);
    //connect(&FlowControl::GetInstance(), &FlowControl::hideAlert, this, &MainForm::onHideAlert);
    //connect(&FlowControl::GetInstance(), &FlowControl::showAlert, this, &MainForm::onShowAlert);
    //connect(&FlowControl::GetInstance(), &FlowControl::setOpeStatus, this, &MainForm::onSetOpeStatus);
    //connect(&FlowControl::GetInstance(), &FlowControl::setNetStatus, this, &MainForm::onSetNetStatus);
    //connect(&FlowControl::GetInstance(), &FlowControl::setStoreInfo, this, &MainForm::onSetStoreInfo);
    //connect(&FlowControl::GetInstance(), &FlowControl::setCashierInfo, this, &MainForm::onSetCashierInfo);
    //connect(&FlowControl::GetInstance(), &FlowControl::changeOrderStatus, this, &MainForm::onChangeOrderStatus);
    //connect(&FlowControl::GetInstance(), &FlowControl::showDeliverPickForm, this, &MainForm::onShowDeliverPickForm);
    //connect(&FlowControl::GetInstance(), &FlowControl::showOrderDetails, this, &MainForm::onShowOrderDetails);
    //connect(&FlowControl::GetInstance(), &FlowControl::clearorder, this, &MainForm::onOrderClear);
    // 搜索订单的信号槽
    //connect(ui->mainEdtSearch, &ClickedLineEdit::textChanged, &FlowControl::GetInstance(), &FlowControl::onSerachOrder);
    //connect(&FlowControl::GetInstance(), &FlowControl::showSearchOrderResult, this, &MainForm::onShowSearchOrderResult);

    //订阅事件
    FMApplication::subscibeEvent(this, PosEvent::s_login_status);
    FMApplication::subscibeEvent(this, PosEvent::s_opt_status);
    FMApplication::subscibeEvent(this, PosEvent::s_change_order);
    FMApplication::subscibeEvent(this, PosEvent::s_get_order_status);
    FMApplication::subscibeEvent(this, PosEvent::s_delete_order);
    FMApplication::subscibeEvent(this, PosEvent::s_login_storeinfo);

    // 初始化界面
    _Init();

    // 开启时间定时器
    m_raiseIndex = 0;
    m_timeTimer.start(1000);
    emit flowStart();
}

MainForm::~MainForm()
{
    delete ui;
}

void MainForm::MyShow()
{
//    if(ConfigManger::GetInstance().GetUiVisible())
//    {
//        this->showFullScreen();
//    }
//    else{
//        this->hide();
//    }
    //this->show();

    //ui->mainBtnDayReport->hide();
    // 考虑到坐标问题放到这里构建

    this->showFullScreen();
    this->hide();

    m_alertForm = new AlertForm(this);

    m_pickForm = new PickForm(this);

    m_prtForm = new PrtSettingForm(this);

    m_settingForm = new SettingForm(this);

    m_rejectForm = new RejectForm(this);

    m_detailForm = new DetailForm(this);
    connect(m_detailForm, &DetailForm::showAlert, this, &MainForm::onShowAlert);
    m_padForm = new PadForm(this);
    m_padForm->move(pos().x()+width()-300, pos().y()+height()-438);
    m_padForm->hide();
    connect(m_padForm, &PadForm::numClicked, this, &MainForm::onNumClicked);
    connect(m_padForm, &PadForm::numDelete, this, &MainForm::onNumDelete);
    connect(m_padForm, &PadForm::numClear, ui->mainEdtSearch, &ClickedLineEdit::clear);
    //m_dailyReportForm =new DailyReportForm(this);
    m_resultForm = new QListWidget(this);
    m_resultForm->setObjectName("mainListWdg0");
    m_resultForm->setFixedSize(340, 200);
    m_resultForm->move(70, ui->mainFrmSearch->pos().y()-190);
    m_resultForm->hide();
    connect(m_resultForm, &QListWidget::itemClicked, this, &MainForm::onSearchResultItemClicked);
    //on_mainBtnHide_clicked();

    return;
}

bool MainForm::event(QEvent *e)
{
    if(e->type() == PosEvent::s_change_order)
    {
        QString orderid;

        GETEVENTINFO(orderid,e,QString);

        OrderObject order;

        if(!PosOrderPool::GetOrderObject(orderid, order))
            return true;

        onChangeOrderStatus(&order);

        return true;
    }

    if(e->type() == PosEvent::s_login_storeinfo)
    {
        QVariantMap map;

        GETEVENTINFO(map, e, QVariantMap);

        m_storeinfo = map;

        return true;
    }

    if(e->type() == PosEvent::s_delete_order)
    {
        QVariantMap value;

        GETEVENTINFO(value,e,QVariantMap);

        if(value.contains(EVENT_KEY_ORDERID) && value.contains(EVENT_KEY_ORDERSTATUS))
                    deleteOrderItem(value[EVENT_KEY_ORDERID].toString());
        return true;
    }

    if(e->type() == PosEvent::s_opt_status)
    {
        QVariantMap value;

        GETEVENTINFO(value,e,QVariantMap);

        if(value.contains(EVENT_KEY_ORDERSTATUS) && value[EVENT_KEY_ORDERSTATUS].toInt() == 0)
        {
            if(!this->isHidden())
                onShowAlert(AlertForm::LOADING, value[EVENT_KEY_MSG].toString());
            return true;
        }

        if(value.contains(EVENT_KEY_STATUS) && value[EVENT_KEY_STATUS].toBool() == false)
        {
            QLOG_INFO() << value[EVENT_KEY_MSG].toString();
            if(!this->isHidden())
                onShowAlert(AlertForm::ERROR, value[EVENT_KEY_MSG].toString());
        }
        else if(value.contains(EVENT_KEY_STATUS) && value[EVENT_KEY_STATUS].toBool() == true)
        {
            if(!this->isHidden())
                onShowAlert(AlertForm::SUCCESS, value[EVENT_KEY_MSG].toString());
        }
        return true;
    }

    if(e->type() == PosEvent::s_login_status)
    {
        QVariantMap value;

        GETEVENTINFO(value,e,QVariantMap);

        if(value.contains(EVENT_KEY_STATUS) && value[EVENT_KEY_STATUS].toBool() == false)
        {
            QLOG_INFO() << value[EVENT_KEY_MSG].toString();
//            if(!this->isHidden())
//                onShowAlert(AlertForm::ERROR, value[EVENT_KEY_MSG].toString());
            onSetOpeStatus(QString::fromLocal8Bit("未登录"));
        }
        else if(value.contains(EVENT_KEY_STATUS) && value[EVENT_KEY_STATUS].toBool() == true)
        {
            onSetStoreInfo(m_storeinfo[JSON_STOREID].toString());
            onSetCashierInfo(m_storeinfo[JSON_STATIONID].toString());
            onSetOpeStatus(QString::fromLocal8Bit("登陆成功"));
            onSetNetStatus(QString::fromLocal8Bit("正常"));
//            onHideAlert();
        }
        return true;
    }
    return QWidget::event(e);
}

#ifdef FM_TEST
void MainForm::setStoreinfo(const QVariantMap &storeinfo)
{
    m_storeinfo.insert(JSON_STOREID, "ldd666");
    m_storeinfo.insert(JSON_STATIONID, "001");
    m_storeinfo.insert(JSON_KEY_USERID, "ldd123");
    m_storeinfo.insert(JSON_KEY_PWD, "123456");
    m_storeinfo.insert(JSON_KEY_PARTNERID, "8888");

}
#else
void MainForm::setStoreinfo(const QVariantMap &storeinfo)
{
    m_storeinfo = storeinfo;
}
#endif

void MainForm::_Init()
{

    this->setWindowFlags(this->windowFlags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
    //this->showFullScreen();
    // 显示托盘
    m_tray.show();

    //ui->mainBtnDayReport->hide();

    // 设置任务栏图标和标题
    setWindowIcon(QIcon(":fm.ico"));

    // 初始化文字
    ui->mainLabStoreid->setText(QString::fromLocal8Bit(UI_STOREID));
    ui->mainLabVersion->setText(APP_VERSION);

    // 初始化表
    int scales6[] = {3, 4, 2, 3, 3, 3};
    int scales5[] = {3, 6, 2, 3, 3};
    int tableWidth = this->width() - 75;
    foreach(QTableWidget *table, m_tableList)
    {
        table->hide();
        if(table == ui->mainTableFinsh ||
           table == ui->mainTableOther)
        {
            for(int i=0; i<5; i++)
            {
                table->setColumnWidth(i, tableWidth*scales5[i]/21);
            }
        }else
        {
            for(int i=0; i<6; i++)
            {
                table->setColumnWidth(i, tableWidth*scales6[i]/21);
            }
        }
        table->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
        table->horizontalHeader()->setFixedHeight(30);
    }

    // 默认选中【新订单】
    ui->mainTableNew->show();
    ui->mainBtnNew->setChecked(true);
    ui->mainBtnNew->setEnabled(false);
    m_prevBtn = ui->mainBtnNew;
    m_prevTable = ui->mainTableNew;
    m_currentTable = ui->mainTableNew;
}

void MainForm::onSetCurrentTime()
{
    if(m_raiseIndex++>10)
    {
       m_raiseIndex=0;
       raise();
    }
    ui->mainSlabTime->setText(QDateTime::currentDateTime().toString(QString::fromLocal8Bit("yyyy年MM月dd日 hh:mm:ss")));
}

void MainForm::onMainTabBtnClicked()
{
    _RevertBtnTable();
    QPushButton *btn = (QPushButton*)sender();
    m_currentTable = findChild<QTableWidget*>(btn->property("tableName").toString());

    m_currentTable->show();
    btn->setChecked(true);
    btn->setEnabled(false);

    m_prevBtn = btn;
    m_prevTable = m_currentTable;
}

void MainForm::onMainProcBtnClicked()
{
    QPushButton *pBtn = (QPushButton*)sender();
//    if(pBtn->text()=="同意")
//    {
//        m_rejectForm->InitUi(REJECTUITYPE_AGREEREFUND);
//        m_rejectForm->show();
//        if(m_rejectForm->exec()==QDialog::Accepted)
//        {
//            emit processRejectOrder( pBtn->property("orderId").toString(),m_rejectForm->GetReasonCode(),m_rejectForm->GetReason(),REJECTUITYPE_AGREEREFUND);
//        }
//    }
//    else
//        emit processOrder(pBtn->property("operation").toString(), pBtn->property("orderId").toString(), DeliverObject());

//    if((pBtn->property("ordertype").toInt() == 1 || pBtn->property("ordertype").toInt() == 2) &&
//            pBtn->property("operation").toString().compare(OPERATION_MAKEOVER, Qt::CaseInsensitive) == 0)
//    {
//        QLOG_DEBUG() << "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&" << "operation : " << pBtn->property("operation").toString() << "; ordertype : " << pBtn->property("ordertype").toInt();
//        return ;
//    }

    //QLOG_INFO() << "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&" << "operation : " << pBtn->property("operation").toString() << "; ordertype : " << pBtn->property("ordertype").toInt();

    QVariantMap value;

    value.insert(EVENT_KEY_ORDERID, pBtn->property("orderId").toString());
    value.insert(EVENT_KEY_STATUS, pBtn->property("operation").toString());

    POSTEVENTTYPE(PosEvent::s_opt_order,value,QVariantMap);
}

void MainForm::on_mainBtnSet_clicked()
{
    m_settingForm->show();
}

void MainForm::on_mainBtnHide_clicked()
{
    hide();
    ui->mainEdtSearch->clear();
    m_padForm->hide();
    showFloatForm();
}

void MainForm::onShowOrderDetails(OrderObject *orderObject)
{
    //m_detailForm->InitData(orderObject);
    //m_detailForm->show();
    //detailForm->show();
}

void MainForm::onShowSearchOrderResult(const QMap<QString,QString>& orderIdList)
{

    if(orderIdList.isEmpty())
    {
        m_resultForm->hide();
        return;
    }
    m_resultForm->clear();
    QMap<QString,QString>::const_iterator order;
    for(order=orderIdList.begin(); order!=orderIdList.end(); order++)
    {
        QListWidgetItem* item=new QListWidgetItem();
        item->setText(order.key()+"  "+order.value());
        m_resultForm->addItem(item);
    }
    m_resultForm->show();
}

void MainForm::onOrderClear(const QString &orderId, const int &oldstatus)
{

    _SetTablesSortEnable(false);
    QTableWidget *table;
    QPushButton *tabBtn;
    // 非首次收到的订单需要现在原先表中删除
    tabBtn = _GetTabBtnByOrderStatus(oldstatus);
    table = findChild<QTableWidget*>(tabBtn->property("tableName").toString());
    for(int i=0; i<table->rowCount(); i++)
    {
        if(!table->item(i, 1)->text().compare(orderId))
        {
            table->removeRow(i);
            QString btnText(tabBtn->property("name").toString());
            btnText = QString("%1\n%2").arg(table->rowCount()).arg(btnText);
            tabBtn->setText(btnText);
        }
    }
    _SetTablesSortEnable(true);
}

void MainForm::_RevertBtnTable()
{
    m_prevBtn->setChecked(false);
    m_prevBtn->setEnabled(true);
    m_prevTable->hide();
}

void MainForm::_SetTablesSortEnable(bool bEnable)
{
    foreach (QTableWidget *table, m_tableList)
    {
        table->setSortingEnabled(bEnable);
    }
}

QPushButton *MainForm::_GetTabBtnByOrderStatus(int orderStatus)
{
    switch(orderStatus)
    {
    case 1:
        return ui->mainBtnNew;
        break;
    case 2:
        return ui->mainBtnMake;
        break;
    case 5:
        return ui->mainBtnSend;
        break;
    case 4:
        return ui->mainBtnSend;
        break;
    case 6:
    case 200:
        return ui->mainBtnFinsh;
        break;
    case 20:
    case 22:
        return ui->mainBtnRefund;
        break;
    default:
        return ui->mainBtnOther;
        break;
    }
}

QPushButton *MainForm::_GetTabBtn(QTableWidget *view)
{
    if(view == ui->mainTableNew)
        return ui->mainBtnNew;

    if(view == ui->mainTableMake)
        return ui->mainBtnMake;

    if(view == ui->mainTableSend)
        return ui->mainBtnSend;

    if(view == ui->mainTableFinsh)
        return ui->mainBtnFinsh;

    if(view == ui->mainTableRefund)
        return ui->mainBtnRefund;

    return ui->mainBtnOther;
}

void MainForm::onHideAlert()
{
    m_alertForm->hide();
}

void MainForm::onShowAlert(AlertForm::Type type, const QString &msg)
{

    if(this->isVisible())
    {
        m_alertForm->SetContent(type, msg);
        m_alertForm->show();
    }
}

void MainForm::onSetStoreInfo(const QString &storeId)
{
    QString store_id=storeId;

    QLOG_INFO() << store_id << storeId;

    ui->mainLabStoreid->setText(store_id);
}

void MainForm::onSetCashierInfo(const QString &cashierInfo)
{
    ui->mainLabCashier->setText(cashierInfo);
}

void MainForm::onSetOpeStatus(const QString &status)
{
    ui->mainLabOpeStatus->setText(status);
}

void MainForm::onSetNetStatus(const QString &status)
{
    ui->mainLabNetStatus->setText(status);
}

void MainForm::deleteOrderItem(QString orderid)
{
    _SetTablesSortEnable(false);
    if(m_order_table_map.contains(orderid))
    {
        QTableWidget *table = m_order_table_map[orderid];
        QPushButton *tabBtn = _GetTabBtn(table);

        for(int i=0; i<table->rowCount(); i++)
        {
            if(!table->item(i, 1)->text().compare(orderid))
            {
                table->removeRow(i);
                QString btnText(tabBtn->property("name").toString());
                btnText = QString("%1\n%2").arg(table->rowCount()).arg(btnText);
                tabBtn->setText(btnText);
            }
        }
    }
    _SetTablesSortEnable(true);
}

void MainForm::onChangeOrderStatus(OrderObject *orderObject)
{
    _SetTablesSortEnable(false);
    QString orderid = orderObject->order_id;

    if(m_order_table_map.contains(orderid))
    {
        QTableWidget *table = m_order_table_map[orderid];
        QPushButton *tabBtn = _GetTabBtn(table);

        for(int i=0; i<table->rowCount(); i++)
        {
            if(!table->item(i, 1)->text().compare(orderObject->order_id))
            {
                table->removeRow(i);
                QString btnText(tabBtn->property("name").toString());
                btnText = QString("%1\n%2").arg(table->rowCount()).arg(btnText);
                tabBtn->setText(btnText);
            }
        }
    }

    int tmpstatus;

    if(orderObject->refund_status == 20 || orderObject->refund_status == 22 ||
            orderObject->refund_status == 100)
        tmpstatus = orderObject->refund_status;
    else
        tmpstatus = orderObject->status;

    // 将数据插入到表中
    QPushButton *tabBtn = _GetTabBtnByOrderStatus(tmpstatus);
    QTableWidget *table = findChild<QTableWidget*>(tabBtn->property("tableName").toString());

    m_order_table_map.insert(orderObject->order_id, table);

    table->insertRow(0);
    QTableWidgetItem *item0 = new QTableWidgetItem(QString::number(orderObject->order_index)+"#"+orderObject->channel_name);
    item0->setTextAlignment(Qt::AlignCenter);
    table->setItem(0, 0, item0);  // 渠道
    QTableWidgetItem *item1 = new QTableWidgetItem(orderObject->order_id);
    item1->setTextAlignment(Qt::AlignCenter);
    table->setItem(0, 1, item1);  // 订单ID
    QTableWidgetItem *item2 = new QTableWidgetItem(QString::number(orderObject->shop_fee/100.0));
    item2->setTextAlignment(Qt::AlignCenter);
    table->setItem(0, 2, item2);  // 金额
    QTableWidgetItem *item3 = new QTableWidgetItem(orderObject->customer);
    item3->setTextAlignment(Qt::AlignCenter);
    table->setItem(0, 3, item3);  // 姓名
    QTableWidgetItem *item4 = new QTableWidgetItem(orderObject->phone);
    item4->setTextAlignment(Qt::AlignCenter);
    table->setItem(0, 4, item4);  // 联系方式
    QTableWidgetItem *item5 = new QTableWidgetItem(QDateTime::fromTime_t(orderObject->create_time).toString("MM-dd hh:mm"));
    item5->setTextAlignment(Qt::AlignCenter);
    table->setItem(0, 5, item5);  // 下单时间
    if(table != ui->mainTableFinsh && table != ui->mainTableOther)
    {
        QWidget *pWdg = new QWidget(table);
        QHBoxLayout *hLayout = new QHBoxLayout(pWdg);
        QPushButton * pBtn = new QPushButton(pWdg);
        pBtn->setFixedSize(70, 30);
        pBtn->setFocusPolicy(Qt::NoFocus);
        pBtn->setObjectName("mainProcBtn");
        pBtn->setProperty("orderId", orderObject->order_id);
        pBtn->setProperty("ordertype", orderObject->order_type);

        if(table->property("operation").toString().compare(OPERATION_MAKEOVER, Qt::CaseInsensitive) == 0 &&
                (orderObject->order_type == 1 || orderObject->order_type == 2))
        {
            pBtn->setProperty("operation", OPERATION_SENDOUT);
            pBtn->setText(QString::fromLocal8Bit(OPERATIONNAME_SENDOUT));
        }
        else
        {
            pBtn->setProperty("operation", table->property("operation").toString());
            pBtn->setText(table->property("operationName").toString());
        }

        hLayout->addWidget(pBtn);
        hLayout->setMargin(0);
        pWdg->setLayout(hLayout);
        table->setCellWidget(0, 6, pWdg);   // 操作按钮

        connect(pBtn, &QPushButton::clicked, this, &MainForm::onMainProcBtnClicked);
    }

    QString btnText = QString("%1\n%2").arg(table->rowCount()).arg(tabBtn->property("name").toString());
    tabBtn->setText(btnText);

    // 检测是否需要提示
    if(ui->mainTableRefund->rowCount() > 0)
    {
        emit startRemind(1);
    }else
    {
        //emit stopRemind();
    }

    _SetTablesSortEnable(true);
}

void MainForm::onShowDeliverPickForm(const QString &orderId, const QList<DeliverObject> &delivers)
{
    m_pickForm->SetDeliversInfo(orderId, delivers);
    m_pickForm->show();
}

void MainForm::on_mainBtnUp_clicked()
{
    m_currentTable->scrollToTop();
}

void MainForm::on_mainBtnDown_clicked()
{
    m_currentTable->scrollToBottom();
}

void MainForm::onMainTableItemClicked(QTableWidgetItem *item)
{
    QString orderId = ((QTableWidget*)sender())->item(item->row(), 1)->text();

    OrderObject order;

    if(!PosOrderPool::GetOrderObject(orderId, order))
        return ;

    onHideAlert();
    m_detailForm->InitData(&order);
    m_detailForm->show();

}

void MainForm::on_mainEdtSearch_clicked()
{
    m_padForm->show();
}

void MainForm::onNumClicked(const QString &num)
{
    ui->mainEdtSearch->setText(ui->mainEdtSearch->text().append(num));
}

void MainForm::onNumDelete()
{
    QString text = ui->mainEdtSearch->text();
    ui->mainEdtSearch->setText(text.left(text.length()-1));
}

void MainForm::onSearchResultItemClicked(QListWidgetItem *item)
{
    ui->mainEdtSearch->clear();
    m_padForm->hide();
    m_resultForm->hide();
    QString str=item->text();
    str=str.mid(4);
    QString y = "  ";
    str=str.mid(0,str.indexOf(y));
    emit getOrderDetails(str);
}
void MainForm::onEntryResult(OrderObject *orderObject, int type)
{
    _SetTablesSortEnable(false);
    QTableWidget *table;
    QPushButton *tabBtn;
    tabBtn = _GetTabBtnByOrderStatus(orderObject->status);
    table = findChild<QTableWidget*>(tabBtn->property("tableName").toString());
    int rowcount=table->rowCount();
    for(int i=0;i<rowcount;i++)
    {
        if(table->item(i,1)->text()==orderObject->order_id)
        {
            if(type==0)
            {
                table->item(i,0)->setTextColor(QColor(255,0,0));
                table->item(i,1)->setTextColor(QColor(255,0,0));
                table->item(i,2)->setTextColor(QColor(255,0,0));
                table->item(i,3)->setTextColor(QColor(255,0,0));
                table->item(i,4)->setTextColor(QColor(255,0,0));
                table->item(i,5)->setTextColor(QColor(255,0,0));
                break;
            }
            if(type==1)
            {
                table->item(i,0)->setTextColor(QColor(98, 98, 98));
                table->item(i,1)->setTextColor(QColor(98, 98, 98));
                table->item(i,2)->setTextColor(QColor(98, 98, 98));
                table->item(i,3)->setTextColor(QColor(98, 98, 98));
                table->item(i,4)->setTextColor(QColor(98, 98, 98));
                table->item(i,5)->setTextColor(QColor(98, 98, 98));
                break;
            }
        }
    }
    _SetTablesSortEnable(true);
}

void MainForm::onSetDailyReportData(QJsonObject json)
{
//    QString error;
//    if(!m_dailyReportForm->Initdata(json,error))
//    {
//        onShowAlert(AlertForm::ERROR,error);
//        return;
//    }
//    m_dailyReportForm->show();
}

void MainForm::on_mainBtnDayReport_clicked()
{
    m_prtForm->show();
}
