#include "refuseForm.h"
#include "ui_refuseForm.h"
#include <QDebug>

RefuseForm::RefuseForm(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::RefuseForm),
    m_orderObject(NULL)
{
    ui->setupUi(this);
    setWindowFlags(this->windowFlags() | Qt::FramelessWindowHint);
    this->setModal(true);
    ui->refuseBtnOk->setEnabled(false);

    m_refDishesForm = new refDishesForm(this);
    ui->reasonNULL->hide();

}

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

void RefuseForm::SetOrderInfo(OrderObject *obj)
{
    _Init();
    m_orderObject = obj;
}


void RefuseForm::on_refuseBtnCancle_clicked()
{
    this->reject();
}

void RefuseForm::on_refuseBtnOk_clicked()
{
    this->accept();
}

void RefuseForm::on_reason1_toggled(bool checked)
{
    if(checked)
    {
        ui->refuseBtnOk->setEnabled(true);
        m_reasonStr=QString::fromLocal8Bit("餐厅已打烊");
        m_reasonCode=2;
    }
}

void RefuseForm::on_reason2_toggled(bool checked)
{
    //TODO
//    if(m_orderObject!=NULL&&checked)
//    {
//        m_refDishesForm->InitData(m_orderObject);
//        if(QDialog::Accepted == m_refDishesForm->exec())
//        {
//            ui->refuseBtnOk->setEnabled(true);
//            m_reasonCode="菜品已售完";
//            on_refuseBtnOk_clicked();
//        }else
//        {
//            _Init();
//        }
//    }
    if(checked)
    {
        ui->refuseBtnOk->setEnabled(true);
        m_reasonStr=QString::fromLocal8Bit("菜品已售完");
        m_reasonCode=3;
    }
}

void RefuseForm::on_reason3_toggled(bool checked)
{
    if(checked)
    {
        ui->refuseBtnOk->setEnabled(true);
        m_reasonStr=QString::fromLocal8Bit("餐厅太忙");
        m_reasonCode=5;
    }
}

void RefuseForm::on_reason4_toggled(bool checked)
{
    if(checked)
    {
        ui->refuseBtnOk->setEnabled(true);
        m_reasonStr=QString::fromLocal8Bit("联系不上客户");
        m_reasonCode=6;
    }
}

void RefuseForm::on_reason5_toggled(bool checked)
{
    if(checked)
    {
        ui->refuseBtnOk->setEnabled(true);
        m_reasonStr=QString::fromLocal8Bit("无人配送");
        m_reasonCode=-1;
    }
}

void RefuseForm::_Init()
{
    qDebug() << __FUNCTION__;
    ui->reasonNULL->toggle();
    ui->refuseBtnOk->setEnabled(false);
}
