Commit 0b5a3989 by NitefullWind

1. 代金券使用异步方式加载。 2. 修改了部分代金券界面、登陆界面的代码。

parent 58fb2639
...@@ -19,19 +19,27 @@ QByteArray TaskPay::doTask() ...@@ -19,19 +19,27 @@ QByteArray TaskPay::doTask()
} }
this->_session = preTask->session(); this->_session = preTask->session();
del_p(preTask); TaskCouponThread couponThread(posReqJsonObj, _session, this);
preTask = new TaskCoupon(posReqJsonObj, _session, this); couponThread.start();
QByteArray couponRst = preTask->doTask(); connect(&couponThread, SIGNAL(finished(Session*)), SLOT(onGetCoupons(Session*)));
if(preTask->error() != FM_API_SUCCESS) {
return couponRst;
}
this->_session = preTask->session();
return FMTask::doTask(); return FMTask::doTask();
} }
void TaskPay::onGetCoupons(Session* session)
{
_session->addData(PosProps.CouponMap, session->getCouponMap(PosProps.CouponMap));
if(_window != nullptr) {
qobject_cast<FMVipOrder*>(_window)->initCouponItems();
_window->setIsBusy(false);
_window->setEnabled(true);
}
}
void TaskPay::setWindow() void TaskPay::setWindow()
{ {
_window = new FMVipOrder; _window = new FMVipOrder;
_window->setIsBusy();
_window->setEnabled(false);
for (QString prop : {PosProps.OrderAmount, PosProps.PaidAmount, PosProps.StandardAmount}) { for (QString prop : {PosProps.OrderAmount, PosProps.PaidAmount, PosProps.StandardAmount}) {
session()->addData(prop, getPosJsonValue(prop).toInt()); session()->addData(prop, getPosJsonValue(prop).toInt());
...@@ -107,3 +115,16 @@ void TaskPay::onPay() ...@@ -107,3 +115,16 @@ void TaskPay::onPay()
sendToServer(); sendToServer();
closeWindow(); closeWindow();
} }
//TaskPay::TaskCouponThread::TaskCouponThread(QJsonObject &jsonObj, Session *session, QObject *parent):
// _session(session),
// QThread(parent)
//{
// task = new TaskCoupon(jsonObj, session, parent);
//}
//void TaskPay::TaskCouponThread::run()
//{
// task->doTask();
// _session = task->session();
//}
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
#define TASKPAY_H #define TASKPAY_H
#include "fmtask.h" #include "fmtask.h"
#include "../reader.h" #include "../reader.h"
#include <QThread>
#include "taskothers.h"
class TaskPay : public FMTask class TaskPay : public FMTask
{ {
...@@ -16,6 +18,32 @@ public: ...@@ -16,6 +18,32 @@ public:
private slots: private slots:
void onPay(); void onPay();
void onGetCoupons(Session *session);
};
// 加载代金券的线程类
class TaskCouponThread : public QThread
{
Q_OBJECT
public:
TaskCouponThread(QJsonObject &jsonObj, Session *session, QObject *parent = 0) {
_session = session;
task = new TaskCoupon(jsonObj, session, parent);
}
~TaskCouponThread() {
del_p(task);
del_p(_session);
}
void run() {
task->doTask();
emit finished(_session);
}
TaskCoupon *task;
Session *_session;
signals:
void finished(Session*);
}; };
#endif // TASKPAY_H #endif // TASKPAY_H
...@@ -42,7 +42,6 @@ void FMVipOrder::initWnd(Session *session) ...@@ -42,7 +42,6 @@ void FMVipOrder::initWnd(Session *session)
double standard_amount = session->data(PosProps.StandardAmount).toInt() / 100.0; double standard_amount = session->data(PosProps.StandardAmount).toInt() / 100.0;
orderInfo = new FMVipOrder::OrderInfo(amount_str, score_str, needPay_str); orderInfo = new FMVipOrder::OrderInfo(amount_str, score_str, needPay_str);
orderInfo->setCouponMap(session->getCouponMap(PosProps.CouponMap));
ui->operator_label->setText(operator_id); ui->operator_label->setText(operator_id);
ui->bd_label->setText(business_date); ui->bd_label->setText(business_date);
...@@ -54,7 +53,6 @@ void FMVipOrder::initWnd(Session *session) ...@@ -54,7 +53,6 @@ void FMVipOrder::initWnd(Session *session)
ui->bir_label->setText(birthday); ui->bir_label->setText(birthday);
initCouponItems(); initCouponItems();
connect(ui->coupon_page, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(onItemClicked(QListWidgetItem*)));
ui->pay_chk->setText(QString("使用积分抵用 %1 元").arg(orderInfo->getScoreAmount())); ui->pay_chk->setText(QString("使用积分抵用 %1 元").arg(orderInfo->getScoreAmount()));
...@@ -114,16 +112,22 @@ void FMVipOrder::onItemClicked(QListWidgetItem *item) ...@@ -114,16 +112,22 @@ void FMVipOrder::onItemClicked(QListWidgetItem *item)
void FMVipOrder::initCouponItems() void FMVipOrder::initCouponItems()
{ {
orderInfo->setCouponMap(_session->getCouponMap(PosProps.CouponMap));
for(Coupon coupon : orderInfo->couponMap().values()) for(Coupon coupon : orderInfo->couponMap().values())
{ {
auto item = new QListWidgetItem(); auto item = new QListWidgetItem();
item->setData(Qt::UserRole, coupon.code); item->setData(Qt::UserRole, coupon.code);
ui->coupon_page->addItem(item);
ui->coupon_page->update();
auto itemWidget = new FMCouponWidget(coupon); auto itemWidget = new FMCouponWidget(coupon);
ui->coupon_page->setItemWidget(item, itemWidget);
//item大小 //item大小
item->setSizeHint (itemWidget->size()); item->setSizeHint (itemWidget->size());
ui->coupon_page->addItem(item);
ui->coupon_page->setItemWidget(item, itemWidget);
}
if(ui->coupon_page->count() > 0) {
connect(ui->coupon_page, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(onItemClicked(QListWidgetItem*)));
} }
} }
......
...@@ -19,6 +19,7 @@ public: ...@@ -19,6 +19,7 @@ public:
~FMVipOrder(); ~FMVipOrder();
void initWnd(Session *session); void initWnd(Session *session);
void initCouponItems();
void setWillPayText(); void setWillPayText();
signals: signals:
...@@ -156,8 +157,6 @@ private: ...@@ -156,8 +157,6 @@ private:
QString oldPayText; QString oldPayText;
void initCouponItems();
FMNumPad *numpad; FMNumPad *numpad;
}; };
......
...@@ -10,6 +10,18 @@ ...@@ -10,6 +10,18 @@
<height>116</height> <height>116</height>
</rect> </rect>
</property> </property>
<property name="minimumSize">
<size>
<width>220</width>
<height>116</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>220</width>
<height>116</height>
</size>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
......
...@@ -430,6 +430,12 @@ font: 13px &quot;微软雅黑&quot;; ...@@ -430,6 +430,12 @@ font: 13px &quot;微软雅黑&quot;;
</layout> </layout>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<tabstops>
<tabstop>login_edit</tabstop>
<tabstop>login_btn</tabstop>
<tabstop>login_key</tabstop>
<tabstop>close_btn</tabstop>
</tabstops>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment