Commit 5f349cc2 by NitefullWind

1. 重新实现代金券界面和逻辑。

parent 7e265bef
...@@ -38,7 +38,10 @@ SOURCES += \ ...@@ -38,7 +38,10 @@ SOURCES += \
fmvipdispatcher.cpp \ fmvipdispatcher.cpp \
fmp_ve_handlers.cpp \ fmp_ve_handlers.cpp \
fmp_vip_server.cpp \ fmp_vip_server.cpp \
fmp_vip_settings.cpp fmp_vip_settings.cpp \
task/coupon.cpp \
windows/couponmodel.cpp \
windows/itemdelegate.cpp
HEADERS +=\ HEADERS +=\
fmp_vip.h \ fmp_vip.h \
...@@ -69,7 +72,10 @@ HEADERS +=\ ...@@ -69,7 +72,10 @@ HEADERS +=\
global.h \ global.h \
fmp_ve_handlers.h \ fmp_ve_handlers.h \
fmp_vip_server.h \ fmp_vip_server.h \
fmp_vip_settings.h fmp_vip_settings.h \
task/coupon.h \
windows/couponmodel.h \
windows/itemdelegate.h
unix { unix {
target.path = /usr/lib target.path = /usr/lib
......
...@@ -36,6 +36,15 @@ enum FM_TYPE { ...@@ -36,6 +36,15 @@ enum FM_TYPE {
FM_Refund_Pay, FM_Refund_Pay,
FM_Refund_Order FM_Refund_Order
}; };
enum Member_Type {
Unknow = 0,
PayCode,
Phone,
Account,
OriginalCard
};
// 会员服务端请求URL // 会员服务端请求URL
#ifndef FMREQURLMAP #ifndef FMREQURLMAP
#define FMREQURLMAP #define FMREQURLMAP
...@@ -72,7 +81,8 @@ struct PP{ ...@@ -72,7 +81,8 @@ struct PP{
Account = "account"; Account = "account";
Type_code = "type_code"; Type_code = "type_code";
Type_name = "type_name"; Type_name = "type_name";
Member_type = "member_type";
Name = "name"; Name = "name";
Sex = "sex"; Sex = "sex";
Birthday = "birthday"; Birthday = "birthday";
...@@ -98,6 +108,7 @@ struct PP{ ...@@ -98,6 +108,7 @@ struct PP{
Transaction = "transactions"; Transaction = "transactions";
OrderAmount = "order_amount"; OrderAmount = "order_amount";
PaidAmount = "paid_amount"; PaidAmount = "paid_amount";
UndisAmount = "undis_amount";
NeedAmount = "need_amount"; NeedAmount = "need_amount";
StandardAmount = "standard_amount"; StandardAmount = "standard_amount";
Fm_id = "fm_id"; Fm_id = "fm_id";
...@@ -146,6 +157,7 @@ struct PP{ ...@@ -146,6 +157,7 @@ struct PP{
QString Account ; QString Account ;
QString Type_code ; QString Type_code ;
QString Type_name ; QString Type_name ;
QString Member_type ;
QString Name ; QString Name ;
QString Sex ; QString Sex ;
...@@ -174,6 +186,7 @@ struct PP{ ...@@ -174,6 +186,7 @@ struct PP{
QString OrderAmount ; QString OrderAmount ;
QString NeedAmount ; QString NeedAmount ;
QString PaidAmount ; QString PaidAmount ;
QString UndisAmount ;
QString StandardAmount ; QString StandardAmount ;
QString Fm_id ; QString Fm_id ;
QString Settlement ; QString Settlement ;
......
#include "coupon.h"
#include <QPainter>
#include <QPalette>
#include <QDebug>
const int PaintingWidth = 220;
const int PaintingHeight = 116;
Coupon::Coupon(QString name, QString code, double disAmount, double limitAmount, bool isCompatible) :
_name(name),
_code(code),
_disAmount(disAmount),
_limitAmount(limitAmount),
_isCompatible(isCompatible)
{
}
void Coupon::paint(QPainter *painter, const QRect &rect, const QPalette &palette) const
{
Q_UNUSED(palette);
painter->save();
painter->setRenderHint(QPainter::Antialiasing, true);
// 白色背景
painter->fillRect(rect, Qt::white);
// 左边橘黄色矩形
painter->fillRect(QRect(rect.x(), rect.y(), 5, rect.height()), QColor(255, 170, 37));
int centerY = rect.y()+rect.height()/2;
// 中间虚线
painter->setPen(Qt::DotLine);
painter->drawLine(rect.x()+10, centerY, rect.x()+rect.width()-10, centerY);
// 抵扣金额
QPen pen;
pen.setColor(QColor(229, 11, 72));
painter->setPen(pen);
QFont font("Microsoft YaHei", 30, 500);
painter->setFont(font);
QString disStr = QString::number(this->_disAmount, 'f', 2);
QRect topRect(rect.x(), rect.y(), rect.width(), rect.height()/2);
painter->drawText(topRect, Qt::AlignCenter, disStr);
// ¥标识
QString flagStr = QString::fromLocal8Bit("¥");
int fontWidth = painter->fontMetrics().width(disStr);
font.setPixelSize(11);
painter->setFont(font);
int flagWidth = painter->fontMetrics().width(flagStr);
int flagHeight = painter->fontMetrics().height();
painter->drawText(rect.x()+(rect.width()-fontWidth)/2-flagWidth, topRect.center().y()+flagHeight, flagStr);
// 满额条件
pen.setColor(QColor(127,127,127));
painter->setPen(pen);
font.setPixelSize(10);
font.setWeight(1);
painter->setFont(font);
QRect limitRect(rect.x(), rect.y(), rect.width(), rect.height()-flagHeight);
QString limitStr = QString::fromLocal8Bit("满 %1 元可用").arg(this->limitAmount());
painter->drawText(limitRect, Qt::AlignCenter, limitStr);
// 优惠券名
font.setPixelSize(15);
painter->setFont(font);
pen.setColor(Qt::white);
painter->setPen(pen);
fontWidth = painter->fontMetrics().width(this->_name)+20;
int fontHeight = painter->fontMetrics().height();
QRect nameRect(rect.x()+(rect.width()-fontWidth)/2, centerY+10, fontWidth, fontHeight);
painter->fillRect(nameRect, QColor(229, 11, 72));
painter->drawText(nameRect, Qt::AlignCenter, this->_name);
// 券码
font.setPixelSize(12);
painter->setFont(font);
pen.setColor(QColor(127,127,127));
painter->setPen(pen);
fontHeight = painter->fontMetrics().height();
QRect codeRect(rect.x(), rect.y()+rect.height()-fontHeight-5, rect.width(), fontHeight);
painter->drawText(codeRect, Qt::AlignCenter, this->_code);
painter->restore();
}
QSize Coupon::sizeHint() const
{
return QSize(PaintingWidth, PaintingHeight);
}
#ifndef COUPON_H
#define COUPON_H
#include <QVariant>
#include <QString>
#include <QPolygonF>
class QPainter;
class Coupon
{
public:
explicit Coupon(QString name="", QString code="", double disAmount=0, double limitAmount=0, bool isCompatible=true);
void paint(QPainter *painter, const QRect &rect,
const QPalette &palette) const;
QSize sizeHint() const;
QString name() const {return _name;}
QString code() const {return _code;}
double disAmount() const {return _disAmount;}
double limitAmount() const {return _limitAmount;}
bool isCompatible() const {return _isCompatible;}
private:
QString _name;
QString _code;
double _disAmount;
double _limitAmount;
bool _isCompatible;
};
Q_DECLARE_METATYPE(Coupon)
#endif // COUPON_H
...@@ -30,7 +30,7 @@ void Session::addData(const QString key, const QMap<QString, Coupon> couponMap) ...@@ -30,7 +30,7 @@ void Session::addData(const QString key, const QMap<QString, Coupon> couponMap)
foreach(const Coupon coupon , couponMap) { foreach(const Coupon coupon , couponMap) {
QVariant v; QVariant v;
v.setValue(coupon); v.setValue(coupon);
v_couponMap[coupon.code] = v; v_couponMap[coupon.code()] = v;
} }
addData(key, v_couponMap); addData(key, v_couponMap);
} }
...@@ -41,7 +41,7 @@ QMap<QString, Coupon> Session::getCouponMap(const QString key) ...@@ -41,7 +41,7 @@ QMap<QString, Coupon> Session::getCouponMap(const QString key)
QMap<QString, Coupon> couponMap; QMap<QString, Coupon> couponMap;
foreach(const QVariant v_coupon , v_couponMap) { foreach(const QVariant v_coupon , v_couponMap) {
Coupon coupon = v_coupon.value<Coupon>(); Coupon coupon = v_coupon.value<Coupon>();
couponMap[coupon.code] = coupon; couponMap[coupon.code()] = coupon;
} }
return couponMap; return couponMap;
} }
...@@ -3,31 +3,7 @@ ...@@ -3,31 +3,7 @@
#include <QVariant> #include <QVariant>
#include "global.h" #include "global.h"
#include "coupon.h"
// 代金券结构体
struct Coupon
{
Coupon() {
code = "";
disAmount = 0.0;
desc = "";
}
Coupon(const Coupon& C) {
code = C.code;
disAmount = C.disAmount;
desc = C.desc;
}
Coupon(const QString &c, const double amount, const QString &d) {
code = c;
disAmount = amount;
desc = d;
}
QString code;
double disAmount;
QString desc;
};
Q_DECLARE_METATYPE(Coupon) // 使Coupon类型可以和QVariant类型互相转换
class Session class Session
{ {
...@@ -48,6 +24,7 @@ public: ...@@ -48,6 +24,7 @@ public:
void addData(const QString key, const QVariant value); void addData(const QString key, const QVariant value);
void addData(const QString key, const QMap<QString, Coupon> couponMap); void addData(const QString key, const QMap<QString, Coupon> couponMap);
bool contains(const QString key) {return _sessionDataMap.contains(key);}
QMap<QString, Coupon> getCouponMap(const QString key); QMap<QString, Coupon> getCouponMap(const QString key);
QMap<QString, QVariant> sessionDataMap() const { return this->_sessionDataMap;} QMap<QString, QVariant> sessionDataMap() const { return this->_sessionDataMap;}
......
...@@ -77,7 +77,7 @@ void TaskLogin::onLogin() ...@@ -77,7 +77,7 @@ void TaskLogin::onLogin()
double amount = couponOb[ServerProps(PosProps.Coupon_disAmount)].toInt() / 100.0; double amount = couponOb[ServerProps(PosProps.Coupon_disAmount)].toInt() / 100.0;
QString desc = couponOb[ServerProps(PosProps.Coupon_desc)].toString(); QString desc = couponOb[ServerProps(PosProps.Coupon_desc)].toString();
Coupon c(code, amount, desc); Coupon c(desc, code, amount, 0, 1);
QVariant v; QVariant v;
v.setValue(c); v.setValue(c);
couponMap[code] = v; couponMap[code] = v;
......
#include "taskothers.h" #include "taskothers.h"
TaskCoupon::TaskCoupon(QJsonObject &jsonObj, QObject *parent) TaskCoupon::TaskCoupon(QJsonObject &jsonObj, Session *session, QObject *parent)
:FMTaskNoWnd(jsonObj, FM_Coupon, 0, parent) :FMTaskNoWnd(jsonObj, FM_Coupon, session, parent)
{ {
} }
......
...@@ -8,7 +8,7 @@ class TaskCoupon : public FMTaskNoWnd ...@@ -8,7 +8,7 @@ class TaskCoupon : public FMTaskNoWnd
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit TaskCoupon(QJsonObject &jsonObj, QObject *parent = 0); explicit TaskCoupon(QJsonObject &jsonObj, Session *session, QObject *parent = 0);
void packageServerReq(); void packageServerReq();
void packagePOSRsp(); void packagePOSRsp();
}; };
......
...@@ -7,8 +7,6 @@ TaskPay::TaskPay(QJsonObject &jsonObj, Session *session, QObject *parent) ...@@ -7,8 +7,6 @@ TaskPay::TaskPay(QJsonObject &jsonObj, Session *session, QObject *parent)
{ {
} }
}
QByteArray TaskPay::doTask() QByteArray TaskPay::doTask()
{ {
preTask = new TaskLogin(posReqJsonObj, _session, this); preTask = new TaskLogin(posReqJsonObj, _session, this);
...@@ -18,9 +16,25 @@ QByteArray TaskPay::doTask() ...@@ -18,9 +16,25 @@ QByteArray TaskPay::doTask()
return loginRst; return loginRst;
} }
this->_session = preTask->session(); this->_session = preTask->session();
// couponThread = new TaskCouponThread(posReqJsonObj, _session, this);
// couponThread->start();
// connect(couponThread, SIGNAL(finished(Session*)), SLOT(onGetCoupons(Session*)));
return FMTask::doTask(); return FMTask::doTask();
} }
void TaskPay::onGetCoupons(Session* session)
{
// couponThread->exit();
_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;
...@@ -28,7 +42,6 @@ void TaskPay::setWindow() ...@@ -28,7 +42,6 @@ void TaskPay::setWindow()
std::vector<QString> p; std::vector<QString> p;
p.push_back(PosProps.OrderAmount); p.push_back(PosProps.OrderAmount);
p.push_back(PosProps.PaidAmount); p.push_back(PosProps.PaidAmount);
p.push_back(PosProps.StandardAmount);
foreach (QString prop , p) { foreach (QString prop , p) {
session()->addData(prop, getPosJsonValue(prop).toInt()); session()->addData(prop, getPosJsonValue(prop).toInt());
} }
...@@ -60,32 +73,47 @@ void TaskPay::packagePOSRsp() ...@@ -60,32 +73,47 @@ void TaskPay::packagePOSRsp()
p.push_back(PosProps.StatusCode); p.push_back(PosProps.StatusCode);
p.push_back(PosProps.Msg); p.push_back(PosProps.Msg);
p.push_back(PosProps.Fm_id); p.push_back(PosProps.Fm_id);
p.push_back(PosProps.Fm_transId);
foreach (QString prop , p) { foreach (QString prop , p) {
posRspJsonObj[prop] = getServerJsonValue(prop); posRspJsonObj[prop] = getServerJsonValue(prop);
} }
posRspJsonObj[PosProps.Prompt] = 1; posRspJsonObj[PosProps.Prompt] = 1;
posRspJsonObj[PosProps.Fm_open_id] = session()->data(PosProps.Fm_open_id).toString(); posRspJsonObj[PosProps.Fm_open_id] = session()->data(PosProps.Fm_open_id).toString();
int total_amount = 0;
QJsonArray pay_ids; QJsonArray pay_ids;
QJsonObject pay_id; QJsonObject pay_id;
pay_id[PosProps.Pay_id] = "24"; pay_id[PosProps.Pay_id] = "20001";
pay_id[PosProps.Pay_str] = QString::fromLocal8Bit("会员储值金支付"); pay_id[PosProps.Pay_str] = QString::fromLocal8Bit("会员储值金支付");
pay_id[PosProps.Paid_total_amount] = getServerJsonValue(PosProps.CodeAmount); int codeAmount = getServerJsonValue(PosProps.CodeAmount).toInt();
pay_id[PosProps.Pay_amount] = codeAmount;
pay_ids.append(pay_id); pay_ids.append(pay_id);
pay_id[PosProps.Pay_id] = "25"; total_amount += codeAmount;
pay_id[PosProps.Pay_id] = "20002";
pay_id[PosProps.Pay_str] = QString::fromLocal8Bit("会员积分支付"); pay_id[PosProps.Pay_str] = QString::fromLocal8Bit("会员积分支付");
pay_id[PosProps.Paid_total_amount] = getServerJsonValue(PosProps.ScoreAmount); int scoreAmount = getServerJsonValue(PosProps.ScoreAmount).toInt();
pay_id[PosProps.Pay_amount] = scoreAmount;
pay_ids.append(pay_id); pay_ids.append(pay_id);
total_amount += scoreAmount;
int couponAmount = 0;
foreach(auto coupon , getServerJsonValue(PosProps.Coupons).toArray()) { foreach(auto coupon , getServerJsonValue(PosProps.Coupons).toArray()) {
QJsonObject cp = coupon.toObject(); QJsonObject cp = coupon.toObject();
pay_id[PosProps.Pay_id] = "77"; pay_id[PosProps.Pay_id] = "20003";
pay_id[PosProps.Pay_str] = QString::fromLocal8Bit("代金券支付"); pay_id[PosProps.Pay_str] = QString::fromLocal8Bit("代金券支付");
pay_id[PosProps.Paid_total_amount] = cp[PosProps.Coupon_disAmount]; int disAmount = cp[ServerProps(PosProps.Coupon_disAmount)].toInt();
pay_id[PosProps.Pay_amount] = disAmount;
pay_id[PosProps.Coupon_code] = cp[ServerProps(PosProps.Coupon_code)]; pay_id[PosProps.Coupon_code] = cp[ServerProps(PosProps.Coupon_code)];
pay_ids.append(pay_id); pay_ids.append(pay_id);
couponAmount += disAmount;
} }
posRspJsonObj[PosProps.Pay_id] = pay_ids; total_amount += couponAmount;
posRspJsonObj[PosProps.Pay_ids] = pay_ids;
posRspJsonObj[PosProps.Paid_total_amount] = total_amount;
posRspJsonObj["invoice_amount"] = total_amount;
posRspJsonObj["discount_amount"] = 0;
posRspJsonObj["forward"] = posReqJsonObj["forward"]; posRspJsonObj["forward"] = posReqJsonObj["forward"];
} }
......
#ifndef TASKPAY_H #ifndef TASKPAY_H
#define TASKPAY_H #define TASKPAY_H
#include "fmtask.h" #include "fmtask.h"
#include "taskothers.h"
#include <QThread>
class TaskCouponThread;
class TaskPay : public FMTask class TaskPay : public FMTask
{ {
...@@ -14,6 +18,33 @@ public: ...@@ -14,6 +18,33 @@ public:
private slots: private slots:
void onPay(); void onPay();
void onGetCoupons(Session* session);
private:
TaskCouponThread *couponThread;
}; };
// شȯ߳
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);
}
void run() {
task->doTask();
emit finished(_session);
}
TaskCoupon *task;
Session *_session;
signals:
void finished(Session*);
};
#endif // TASKPAY_H #endif // TASKPAY_H
#include "couponmodel.h"
#include <QModelIndex>
#include <QDebug>
CouponModel::CouponModel(QObject *parent) : QAbstractListModel(parent)
{
}
int CouponModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return couponList.length();
}
QVariant CouponModel::data(const QModelIndex &index, int role) const
{
if(!index.isValid()) {
return QVariant();
}
if(role == Qt::TextAlignmentRole) {
return int(Qt::AlignRight | Qt::AlignVCenter);
} else if(role == Qt::DisplayRole) {
QVariant v = QVariant::fromValue(couponList.at(index.row()));
return v;
}
return QVariant();
}
Coupon CouponModel::coupon(const QModelIndex &index)
{
if(!index.isValid()) {
return Coupon();
}
return couponList.at(index.row());
}
void CouponModel::push_back(Coupon coupon)
{
int rowNum = rowCount();
QModelIndex beginIndex = index(rowNum);
beginInsertRows(beginIndex, rowNum, rowNum);
couponList.append(coupon);
endInsertRows();
}
#ifndef COUPONMODEL_H
#define COUPONMODEL_H
#include <QObject>
#include <QAbstractListModel>
#include <QList>
#include "coupon.h"
class CouponModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit CouponModel(QObject *parent = 0);
int rowCount(const QModelIndex &parent=QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override;
Coupon coupon(const QModelIndex &index);
void push_back(Coupon coupon);
private:
QList<Coupon> couponList;
};
#endif // COUPONMODEL_H
...@@ -7,9 +7,9 @@ FMCouponWidget::FMCouponWidget(Coupon conpon, QWidget *parent) : ...@@ -7,9 +7,9 @@ FMCouponWidget::FMCouponWidget(Coupon conpon, QWidget *parent) :
ui(new Ui::FMCouponWidget) ui(new Ui::FMCouponWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->code_lab->setText(conpon.code); ui->code_lab->setText(conpon.code());
ui->amount_lab->setText(QString::number(conpon.disAmount/100, 'f', 2)); ui->amount_lab->setText(QString::number(conpon.disAmount(), 'f', 2));
ui->desc_lab->setText(conpon.desc); ui->desc_lab->setText(conpon.name());
} }
FMCouponWidget::~FMCouponWidget() FMCouponWidget::~FMCouponWidget()
......
...@@ -14,7 +14,7 @@ FMVipFund::~FMVipFund() ...@@ -14,7 +14,7 @@ FMVipFund::~FMVipFund()
delete ui; delete ui;
} }
void FMVipFund::initWnd(Session *session) bool FMVipFund::initWnd(Session *session)
{ {
_session = session; _session = session;
...@@ -39,6 +39,7 @@ void FMVipFund::initWnd(Session *session) ...@@ -39,6 +39,7 @@ void FMVipFund::initWnd(Session *session)
ui->name_label->setText(name); ui->name_label->setText(name);
ui->fund_btn->setFocus(); ui->fund_btn->setFocus();
return true;
} }
void FMVipFund::on_fund_btn_clicked() void FMVipFund::on_fund_btn_clicked()
......
...@@ -16,7 +16,7 @@ public: ...@@ -16,7 +16,7 @@ public:
~FMVipFund(); ~FMVipFund();
void initWnd(Session *session); bool initWnd(Session *session);
signals: signals:
void fund(); void fund();
public slots: public slots:
......
...@@ -17,7 +17,7 @@ FMVipLogin::~FMVipLogin() ...@@ -17,7 +17,7 @@ FMVipLogin::~FMVipLogin()
delete ui; delete ui;
} }
void FMVipLogin::initWnd(Session *session) bool FMVipLogin::initWnd(Session *session)
{ {
this->_session = session; this->_session = session;
...@@ -32,6 +32,7 @@ void FMVipLogin::initWnd(Session *session) ...@@ -32,6 +32,7 @@ void FMVipLogin::initWnd(Session *session)
ui->operator_label->setText(session->data(PosProps.OperatorId).toString()); ui->operator_label->setText(session->data(PosProps.OperatorId).toString());
ui->bd_label->setText(session->data(PosProps.BussinessDate).toString()); ui->bd_label->setText(session->data(PosProps.BussinessDate).toString());
ui->login_edit->setPlaceholderText(placeText); ui->login_edit->setPlaceholderText(placeText);
return true;
} }
QString FMVipLogin::getVersionInfo() QString FMVipLogin::getVersionInfo()
...@@ -51,8 +52,26 @@ QString FMVipLogin::getVersionInfo() ...@@ -51,8 +52,26 @@ QString FMVipLogin::getVersionInfo()
void FMVipLogin::on_login_btn_clicked() void FMVipLogin::on_login_btn_clicked()
{ {
QString id = ui->login_edit->text(); QString id = ui->login_edit->text();
switch (id.length()) {
case 20:
session()->addData(PosProps.Member_type, PayCode);
break;
case 18:
session()->addData(PosProps.Member_type, OriginalCard);
break;
case 11:
session()->addData(PosProps.Member_type, Phone);
break;
case 10:
session()->addData(PosProps.Member_type, Account);
break;
default:
session()->addData(PosProps.Member_type, Unknow);
break;
}
_session->addData(PosProps.Member_sign, id); _session->addData(PosProps.Member_sign, id);
_session->addData(PosProps.Member_type, session()->data(PosProps.Member_type));
this->setEnabled(false); this->setEnabled(false);
......
...@@ -19,7 +19,7 @@ public: ...@@ -19,7 +19,7 @@ public:
QString getVersionInfo(); QString getVersionInfo();
void initWnd(Session *session); bool initWnd(Session *session);
protected: protected:
void resetWnd(); void resetWnd();
signals: signals:
......
#include "fmviporder.h" #include "fmviporder.h"
#include "fmmsgwnd.h" #include "fmmsgwnd.h"
#include "fmcouponwidget.h"
#include "ui_fmviporder.h" #include "ui_fmviporder.h"
#include "itemdelegate.h"
#include "couponmodel.h"
#include <QScrollBar> #include <QScrollBar>
#include <QItemSelectionModel>
FMVipOrder::FMVipOrder(QDialog *parent) : FMVipOrder::FMVipOrder(QDialog *parent) :
FMVipWnd(parent), FMVipWnd(parent),
...@@ -17,27 +19,29 @@ FMVipOrder::~FMVipOrder() ...@@ -17,27 +19,29 @@ FMVipOrder::~FMVipOrder()
delete ui; delete ui;
} }
void FMVipOrder::initWnd(Session *session) bool FMVipOrder::initWnd(Session *session)
{ {
this->_session = session; this->_session = session;
QString operator_id = session->data(PosProps.OperatorId).toString(); QString operator_id = session->data(PosProps.OperatorId).toString();
QString business_date = session->data(PosProps.BussinessDate).toString(); QString business_date = session->data(PosProps.BussinessDate).toString();
QString fm_id = session->data(PosProps.Fm_open_id).toString(); QString fm_id = session->data(PosProps.Account).toString();
QString name = session->data(PosProps.Name).toString(); QString name = session->data(PosProps.Name).toString();
QString birthday = session->data(PosProps.Birthday).toString();
QString amount_str = QString::number(session->data(PosProps.Amount).toInt()); QString amount_str = QString::number(session->data(PosProps.Amount).toInt());
QString score_str = QString::number(session->data(PosProps.Score).toInt()); QString score_str = QString::number(session->data(PosProps.Score).toInt());
int needPay = session->data(PosProps.OrderAmount).toInt() - session->data(PosProps.PaidAmount).toInt(); int orderAmount = session->data(PosProps.OrderAmount).toInt();
int needPay = orderAmount - session->data(PosProps.PaidAmount).toInt();
QString needPay_str = QString::number(needPay); QString needPay_str = QString::number(needPay);
double standard_amount = session->data(PosProps.StandardAmount).toInt() / 100.0;
orderInfo = new FMVipOrder::OrderInfo(amount_str, score_str, needPay_str); // 积分可抵扣金额(分)
orderInfo->setCouponMap(session->getCouponMap(PosProps.CouponMap)); int socre_value = session->data(PosProps.Score).toInt();
orderInfo = new FMVipOrder::OrderInfo(amount_str, socre_value, needPay_str);
double maxDisAmount = (orderAmount - session->data(PosProps.UndisAmount).toInt()) / 100.0;
orderInfo->setMaxDisAmount(maxDisAmount);
ui->store_label->setText(session->data(PosProps.StoreId).toString());
ui->pos_label->setText(session->data(PosProps.PosId).toString());
ui->operator_label->setText(operator_id); ui->operator_label->setText(operator_id);
ui->bd_label->setText(business_date); ui->bd_label->setText(business_date);
ui->id_label->setText(fm_id); ui->id_label->setText(fm_id);
...@@ -46,30 +50,30 @@ void FMVipOrder::initWnd(Session *session) ...@@ -46,30 +50,30 @@ void FMVipOrder::initWnd(Session *session)
ui->price_label->setText(orderInfo->getNeedPayStr()); ui->price_label->setText(orderInfo->getNeedPayStr());
ui->name_label->setText(name); ui->name_label->setText(name);
couponModel = new CouponModel(this);
ui->coupon_page->setModel(couponModel);
ItemDelegate *delegate = new ItemDelegate(this);
ui->coupon_page->setItemDelegate(delegate);
selectionModel = ui->coupon_page->selectionModel();
connect(selectionModel, &QItemSelectionModel::selectionChanged, this, &FMVipOrder::onSelectionChanged);
initCouponItems(); initCouponItems();
connect(ui->coupon_page, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(onItemClicked(QListWidgetItem*)));
ui->pay_chk->setText(QString::fromLocal8Bit("使用积分抵用 %1 元").arg(orderInfo->getScoreAmount())); ui->pay_chk->setText(QString::fromLocal8Bit("使用积分抵用 %1 元").arg(orderInfo->getScoreAmount()));
if(standard_amount > 0) {
ui->standard_label->setText(QString::fromLocal8Bit("满 %1 元可享受储值金满额优惠").arg(standard_amount));
} else {
ui->standard_label->setText("");
}
oldPayText = DOUBLE_STR(orderInfo->getMaxWillPay()); oldPayText = DOUBLE_STR(orderInfo->getMaxWillPay());
ui->pay_edit->setText(oldPayText); ui->pay_edit->setText(oldPayText);
QRegExp regexp("^[0-9]+(.[0-9]{2})?$"); QRegExp regexp("^[0-9]+(.[0-9]{2})?$");
ui->pay_edit->setValidator(new QRegExpValidator(regexp)); ui->pay_edit->setValidator(new QRegExpValidator(regexp));
setWillPayText(); setWillPayText();
return true;
} }
void FMVipOrder::on_pay_btn_clicked() void FMVipOrder::on_pay_btn_clicked()
{ {
session()->addData(PosProps.CouponMap, orderInfo->selectCouponMap); session()->addData(PosProps.CouponMap, orderInfo->selectCouponMap);
int codeAmount = orderInfo->getPayAmount(ui->pay_edit->text()); QString codeAmountStr = orderInfo->getPayAmountStr(ui->pay_edit->text());
session()->addData(PosProps.CodeAmount, codeAmount); session()->addData(PosProps.CodeAmount, codeAmountStr.toInt());
session()->addData(PosProps.IsUseScore, orderInfo->isUseScore());
this->setEnabled(false); this->setEnabled(false);
...@@ -80,43 +84,75 @@ void FMVipOrder::on_pay_btn_clicked() ...@@ -80,43 +84,75 @@ void FMVipOrder::on_pay_btn_clicked()
void FMVipOrder::on_pay_chk_clicked(bool checked) void FMVipOrder::on_pay_chk_clicked(bool checked)
{ {
int is = checked ? 1 : 0;
session()->addData(ServerProps(PosProps.IsUseScore), is);
orderInfo->setUseScore(checked); orderInfo->setUseScore(checked);
setWillPayText(); setWillPayText();
} }
void FMVipOrder::onItemClicked(QListWidgetItem *item)
//! 点击元素时选中/取消选中代金券
void FMVipOrder::on_coupon_page_clicked(const QModelIndex &index)
{ {
QString code = item->data(Qt::UserRole).toString(); // 如果选中状态则取消选中
if(selectionModel->isSelected(index)) {
// 如果代金券已被选中则取消,否则选中 selectionModel->select(index, QItemSelectionModel::Deselect);
if(orderInfo->selectCouponMap.contains(code)) { } else {
ui->coupon_page->itemWidget(item)->setStyleSheet("#FMCouponWidget{background-color: rgb(255, 255, 255); border: none; border-left: 5 solid rgb(255, 170, 37);}"); // 如果已经有一个选中的,则判断选中的这个是否是不可叠加券
orderInfo->selectCouponMap.remove(code); if(selectionModel->selectedIndexes().length() == 1) {
orderInfo->enoughCoupon(); // 计算一下当前代金券金额 QModelIndex firstIndex = selectionModel->selectedIndexes().first();
}else{ if(!couponModel->coupon(firstIndex).isCompatible()) {
ui->coupon_page->itemWidget(item)->setStyleSheet("#FMCouponWidget{background-color: rgb(255, 255, 255); border: none; border-image: url(:/coupon_select.png);}"); FMMsgWnd::FailureWnd(QString::fromLocal8Bit("已经选中了一张不可叠加券,不能再选用其他代金券"));
orderInfo->selectCouponMap[code] = orderInfo->couponMap()[code]; return;
if(orderInfo->enoughCoupon()) }
{ }
FMMsgWnd::WarningWnd(QString::fromLocal8Bit("请注意代金券总额已超过待付金额!"), this); Coupon coupon = couponModel->coupon(index);
// 判断是否满足使用条件
if(orderInfo->getMaxDisAmount() < coupon.limitAmount()) {
FMMsgWnd::FailureWnd(QString::fromLocal8Bit("该代金券不满足使用条件"));
return;
}
// 处理不可叠加券
if(!coupon.isCompatible()) {
if(!selectionModel->selectedIndexes().isEmpty()) {
FMMsgWnd::FailureWnd("该代金券不可与其他代金券叠加使用,请取消选中其他代金券");
return;
}
selectionModel->select(index, QItemSelectionModel::ClearAndSelect);
} else {
selectionModel->select(index, QItemSelectionModel::Select);
} }
} }
setWillPayText();
} }
void FMVipOrder::initCouponItems() void FMVipOrder::initCouponItems()
{ {
foreach(Coupon coupon , orderInfo->couponMap().values()) orderInfo->setCouponMap(_session->getCouponMap(PosProps.CouponMap));
foreach(Coupon coupon, orderInfo->couponMap().values())
{ {
auto item = new QListWidgetItem(); couponModel->push_back(coupon);
item->setData(Qt::UserRole, coupon.code); }
ui->coupon_page->addItem(item);
ui->coupon_page->update(); ui->pay_edit->setFocus();
auto itemWidget = new FMCouponWidget(coupon); ui->pay_edit->selectAll();
ui->coupon_page->setItemWidget(item, itemWidget); }
//item大小
item->setSizeHint (itemWidget->size()); void FMVipOrder::onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
{
foreach (QModelIndex index, selected.indexes()) {
Coupon coupon = couponModel->coupon(index);
orderInfo->selectCouponMap[coupon.code()] = orderInfo->couponMap()[coupon.code()];
orderInfo->setMaxDisAmount(orderInfo->getMaxDisAmount() - coupon.limitAmount());
} }
foreach (QModelIndex index, deselected.indexes()) {
Coupon coupon = couponModel->coupon(index);
orderInfo->selectCouponMap.remove(coupon.code());
orderInfo->setMaxDisAmount(orderInfo->getMaxDisAmount() + coupon.limitAmount());
}
orderInfo->enoughCoupon();
setWillPayText();
} }
void FMVipOrder::setWillPayText() void FMVipOrder::setWillPayText()
......
#ifndef FMVIPORDER_H #ifndef FMVIPORDER_H
#define FMVIPORDER_H #define FMVIPORDER_H
#include <QListWidgetItem> #include <QListWidgetItem>
#include <QModelIndex>
#include "fmvipwnd.h" #include "fmvipwnd.h"
#include "global.h"
class CouponModel;
class QItemSelectionModel;
#define MIN(a,b) ((a<b) ? a : b) #define MIN(a,b) ((a<b) ? a : b)
#define MAX(a,b) ((a<b) ? b : a) #define MAX(a,b) ((a<b) ? b : a)
...@@ -19,7 +24,8 @@ public: ...@@ -19,7 +24,8 @@ public:
explicit FMVipOrder(QDialog *parent = 0); explicit FMVipOrder(QDialog *parent = 0);
~FMVipOrder(); ~FMVipOrder();
void initWnd(Session *session); bool initWnd(Session *session);
void initCouponItems();
void setWillPayText(); void setWillPayText();
signals: signals:
...@@ -29,8 +35,6 @@ public slots: ...@@ -29,8 +35,6 @@ public slots:
void on_pay_btn_clicked(); void on_pay_btn_clicked();
void on_pay_chk_clicked(bool checked); void on_pay_chk_clicked(bool checked);
void onItemClicked(QListWidgetItem*);
private slots: private slots:
void on_coupon_prev_btn_clicked(); void on_coupon_prev_btn_clicked();
...@@ -38,23 +42,25 @@ private slots: ...@@ -38,23 +42,25 @@ private slots:
void on_pay_edit_textChanged(const QString &text); void on_pay_edit_textChanged(const QString &text);
void onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
void on_coupon_page_clicked(const QModelIndex &index);
private: private:
class OrderInfo class OrderInfo
{ {
public: public:
OrderInfo() OrderInfo()
{ {
_amountStr = _scoreStr = _needPayStr = ""; _amountStr = _needPayStr = "";
_amount = _score = _needPay = _maxWillPay = _useScore = _couponAmount = 0; _amount = _score = _needPay = _maxWillPay = _useScore = _couponAmount = 0;
} }
OrderInfo(QString amountStr, QString scoreStr, QString needPayStr) OrderInfo(QString amountStr, int score, QString needPayStr)
{ {
this->_amountStr = amountStr; this->_amountStr = amountStr;
this->_scoreStr = scoreStr;
this->_needPayStr = needPayStr; this->_needPayStr = needPayStr;
_amount = _amountStr.toInt() / 100.0; _amount = _amountStr.toInt() / 100.0;
_score = _scoreStr.toInt() / 100.0; _score = score / 100.0;
_needPay = _needPayStr.toInt() / 100.0; _needPay = _needPayStr.toInt() / 100.0;
_maxWillPay = _useScore = _couponAmount = 0; _maxWillPay = _useScore = _couponAmount = 0;
...@@ -76,19 +82,19 @@ private: ...@@ -76,19 +82,19 @@ private:
return DOUBLE_STR(MIN(_score, _needPay)); return DOUBLE_STR(MIN(_score, _needPay));
} }
int getPayAmount(QString amountStr) QString getPayAmountStr(QString amountStr)
{ {
int payAmount = MIN(_needPay, (amountStr.toDouble() + _couponAmount + _useScore)) * 100; double payAmount = MIN(_needPay, (amountStr.toDouble() + _couponAmount + _useScore)) * 100;
return payAmount; return QString::number(payAmount);
} }
// 代金券总额超过待付时返回true // 代金券总额超过待付时返回true
bool enoughCoupon() bool enoughCoupon()
{ {
_couponAmount = 0.0; _couponAmount = 0.0;
foreach(auto coupon , selectCouponMap) foreach(auto coupon, selectCouponMap)
{ {
_couponAmount += coupon.disAmount; _couponAmount += coupon.disAmount();
} }
bool isEnough = (_couponAmount > _needPay); bool isEnough = (_couponAmount > _needPay);
setMaxWillPay(); setMaxWillPay();
...@@ -105,11 +111,6 @@ private: ...@@ -105,11 +111,6 @@ private:
setMaxWillPay(); setMaxWillPay();
} }
int isUseScore()
{
return (_useScore == 0 ? 0 : 1);
}
// 设置付款金额的最大值 // 设置付款金额的最大值
void setMaxWillPay() void setMaxWillPay()
{ {
...@@ -121,6 +122,16 @@ private: ...@@ -121,6 +122,16 @@ private:
return _maxWillPay; return _maxWillPay;
} }
// 设置/获得最大可优惠金额
void setMaxDisAmount(double amount)
{
this->_maxDisAmount = amount;
}
double getMaxDisAmount()
{
return _maxDisAmount;
}
/// 代金券列表 /// 代金券列表
void setCouponMap(QMap<QString, Coupon> couponMap) void setCouponMap(QMap<QString, Coupon> couponMap)
{ {
...@@ -138,12 +149,12 @@ private: ...@@ -138,12 +149,12 @@ private:
QMap<QString, Coupon> selectCouponMap; QMap<QString, Coupon> selectCouponMap;
private: private:
QString _amountStr, _scoreStr, _needPayStr; QString _amountStr, _needPayStr;
double _amount, _score, _needPay; double _amount, _score, _needPay;
QMap<QString, Coupon> _couponMap; QMap<QString, Coupon> _couponMap;
int _maxPage, _nowPage; int _maxPage, _nowPage;
// 代金券金额 使用积分金额 余额将付金额 // 代金券金额 使用积分金额 余额将付金额 最大可优惠金额
double _couponAmount, _useScore, _maxWillPay; double _couponAmount, _useScore, _maxWillPay, _maxDisAmount;
}; };
private: private:
...@@ -153,7 +164,9 @@ private: ...@@ -153,7 +164,9 @@ private:
QString oldPayText; QString oldPayText;
void initCouponItems(); QItemSelectionModel *selectionModel;
CouponModel *couponModel;
QModelIndex selectedIndex;
}; };
#endif // FMVIPORDER_H #endif // FMVIPORDER_H
...@@ -19,7 +19,7 @@ FMVipPanel::~FMVipPanel() ...@@ -19,7 +19,7 @@ FMVipPanel::~FMVipPanel()
delete ui; delete ui;
} }
void FMVipPanel::initWnd(Session *session) bool FMVipPanel::initWnd(Session *session)
{ {
this->_session = session; this->_session = session;
ui->store_label->setText(session->data(PosProps.StoreId).toString()); ui->store_label->setText(session->data(PosProps.StoreId).toString());
...@@ -31,6 +31,7 @@ void FMVipPanel::initWnd(Session *session) ...@@ -31,6 +31,7 @@ void FMVipPanel::initWnd(Session *session)
ui->name_label->setText(session->data("name").toString()); ui->name_label->setText(session->data("name").toString());
ui->fund_btn->setFocus(); ui->fund_btn->setFocus();
return true;
} }
void FMVipPanel::on_fund_btn_clicked() void FMVipPanel::on_fund_btn_clicked()
......
...@@ -15,7 +15,7 @@ public: ...@@ -15,7 +15,7 @@ public:
explicit FMVipPanel(QDialog *parent = 0); explicit FMVipPanel(QDialog *parent = 0);
~FMVipPanel(); ~FMVipPanel();
void initWnd(Session *session); bool initWnd(Session *session);
public slots: public slots:
void on_fund_btn_clicked(); void on_fund_btn_clicked();
......
...@@ -21,7 +21,7 @@ public: ...@@ -21,7 +21,7 @@ public:
int exec(); int exec();
bool close(); bool close();
virtual void initWnd(Session* session) {this->_session = session;} virtual bool initWnd(Session* session) {this->_session = session; return true;}
Session* session() const {return _session;} Session* session() const {return _session;}
public slots: public slots:
......
...@@ -204,11 +204,11 @@ ...@@ -204,11 +204,11 @@
} }
#pay_chk::indicator:unchecked { #pay_chk::indicator:unchecked {
image: url(:/chk_unchecked.png); image: url(:/img/chk_unchecked.png);
} }
#pay_chk::indicator:checked { #pay_chk::indicator:checked {
image: url(:/chk_checked.png); image: url(:/img/chk_checked.png);
} }
#pay_btn { #pay_btn {
...@@ -550,7 +550,7 @@ ...@@ -550,7 +550,7 @@
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QListWidget" name="coupon_page"> <widget class="QListView" name="coupon_page">
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
...@@ -566,8 +566,11 @@ ...@@ -566,8 +566,11 @@
<property name="autoScroll"> <property name="autoScroll">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode"> <property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum> <enum>QAbstractItemView::NoSelection</enum>
</property> </property>
<property name="verticalScrollMode"> <property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerItem</enum> <enum>QAbstractItemView::ScrollPerItem</enum>
...@@ -596,12 +599,6 @@ ...@@ -596,12 +599,6 @@
<property name="uniformItemSizes"> <property name="uniformItemSizes">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="currentRow">
<number>-1</number>
</property>
<property name="widgetResizable" stdset="0">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
......
#include "itemdelegate.h"
#include "coupon.h"
#include <QPainter>
#include <QStyleOptionViewItem>
#include <QModelIndex>
#include <QApplication>
#include <QDebug>
ItemDelegate::ItemDelegate(QWidget *parent) :
QStyledItemDelegate(parent)
{
}
void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if(index.data().canConvert<Coupon>()) {
Coupon coupon = qvariant_cast<Coupon>(index.data());
QRect rect = QRect(option.rect.x(), option.rect.y(), option.rect.width(), option.rect.height());
coupon.paint(painter, rect, option.palette);
if (option.state & QStyle::State_Selected) {
painter->drawImage(option.rect, QImage(":/img/coupon_select.png"));
}
} else {
QStyledItemDelegate::paint(painter, option, index);
}
}
QSize ItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if(index.data().canConvert<Coupon>()) {
Coupon coupon = qvariant_cast<Coupon>(index.data());
return coupon.sizeHint();
} else {
return QStyledItemDelegate::sizeHint(option, index);
}
}
#ifndef ITEMDELEGATE_H
#define ITEMDELEGATE_H
#include <QStyledItemDelegate>
class ItemDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
ItemDelegate(QWidget *parent = 0);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
};
#endif // ITEMDELEGATE_H
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