#include "boxtemlateone.h"
#include "pqQtlib/log/pqlog.h"
BoxTemlateOne::BoxTemlateOne() {}
//默认箱单
QImage BoxTemlateOne::doPrinter(QSharedPointer<BoxInfo> box)
{
    QSharedPointer<PackInfo> pinfo = box->parentPack();
    if (pinfo.isNull())
        return QImage();
    QSize size(MAXWIDTH * 5, MAXHEIGHT * 5);
    QImage image(size, QImage::Format_ARGB32);
    image.fill(qRgba(255, 255, 255, 255));
    QPainter painter(&image);
    painter.drawRect(5 * 5, 5 * 5, 90 * 5, 15 * 5);
    painter.drawRect(5 * 5, 20 * 5, 90 * 5, 35 * 5);

    painter.drawLine(20 * 5, 20 * 5, 20 * 5, 41 * 5);
    painter.drawLine(50 * 5, 20 * 5, 50 * 5, 41 * 5);
    painter.drawLine(66 * 5, 20 * 5, 66 * 5, 41 * 5);

    painter.drawLine(5 * 5, 27 * 5, 95 * 5, 27 * 5);
    painter.drawLine(5 * 5, 34 * 5, 95 * 5, 34 * 5);
    painter.drawLine(5 * 5, 41 * 5, 95 * 5, 41 * 5);
    //    painter.drawLine(5 * 5, 48 * 5, 95 * 5, 48 * 5);
    //    painter.drawRect(5 * 5, 55 * 5, 90 * 5, 7 * 5);
    painter.drawRect(5 * 5, 41 * 5, 90 * 5, 7 * 5);

    //    QRect target(0 * 5, 57 * 5, 100 * 5, 65 * 5);
    //    //    QRect source(-10*5, 0, 65*5, 40*5);
    //    QString bar = box->caseNumber();
    //    code.draw(painter, target, bar);

    //    painter.drawImage(target,barCode.draw(barCode.CodeBinary(bar),bar),source);

    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.setRenderHint(QPainter::TextAntialiasing, true);
    painter.setRenderHint(QPainter::HighQualityAntialiasing, true);
    QFont font;
    font.setFamily("宋体");
    font.setPixelSize(40);
    font.setWeight(QFont::ExtraLight);
    font.setBold(true);
    painter.setFont(font);
    painter.drawText(5 * 5, 5 * 5, 90 * 5, 15 * 5, Qt::AlignCenter, box->parentPack()->customer);

    font.setPixelSize(20);
    font.setBold(true);
    painter.setFont(font);
    painter.drawText(8 * 5, 25 * 5, QStringLiteral("机号"));
    painter.drawText(53 * 5, 25 * 5, QStringLiteral("规格"));
    painter.drawText(8 * 5, 32 * 5, QStringLiteral("批号"));
    painter.drawText(53 * 5, 32 * 5, QStringLiteral("净重"));
    painter.drawText(8 * 5, 39 * 5, QStringLiteral("筒数"));
    painter.drawText(53 * 5, 39 * 5, QStringLiteral("捻向"));

    //    painter.drawText(8 * 5, 46 * 5, QStringLiteral("等级"));
    //    painter.drawText(53 * 5, 46 * 5, QStringLiteral("捻向"));
    //    painter.drawText(8 * 5, 53 * 5, QStringLiteral("箱号"));
    //    painter.drawText(50 * 5, 53 * 5, QStringLiteral("纸管颜色"));

    painter.drawText(21 * 5, 25 * 5, pinfo->info()->machine_no);
    painter.drawText(21 * 5, 32 * 5, pinfo->info()->batch_no);
    painter.drawText(21 * 5, 39 * 5, QString::number(box->tube_number));

    painter.drawText(67 * 5, 25 * 5, pinfo->info()->specs);

    painter.drawText(67 * 5,
                     32 * 5,
                     QString("%1 kg").arg(
                         getDecimalbit(box->net_weight / 1000.00))); // datalist.at(1));

    painter.drawText(67 * 5, 39 * 5, box->twist_type); // datalist.at(2));
    //    painter.drawText(21 * 5, 46 * 5, box->Level);                        // datalist.at(3));
    //    painter.drawText(67 * 5, 46 * 5, box->twist_type);                   // datalist.at(4));
    //    painter.drawText(67 * 5, 53 * 5, box->bucket_color);                 // datalist.at(6));

    //    font.setPixelSize(16);
    //    painter.setFont(font);
    //    painter.drawText(21 * 5, 53 * 5, box->caseNumber()); // datalist.at(5));

    font.setPixelSize(20);
    painter.setFont(font);
    painter.drawText(5 * 5,
                     42 * 5,
                     90 * 5,
                     7 * 5,
                     Qt::AlignLeft | Qt::AlignVCenter,
                     "地址:" + box->parentPack()->address);

    painter.drawText(5 * 5,
                     49 * 5,
                     90 * 5,
                     7 * 5,
                     Qt::AlignCenter,
                     "联系电话:" + box->parentPack()->telephone);
    // painter.drawText(4*5,75*5," 电话:"+ box->parentPack()->telephone);

    //    print(image);

    //    QString path = PQ::PQLogManger::this_()->getSaveFilePath();
    //    image.save(path + "/xiangdan/code" + bar + ".bmp");
    return image;

    //    return img;
}

//默认箱单2
QImage BoxTemlateOne::doPrinter1(QSharedPointer<BoxInfo> box)
{
    QSharedPointer<PackInfo> pinfo = box->parentPack();
    if (pinfo.isNull())
        return QImage();
    QSize size(MAXWIDTH * 5, MAXHEIGHT * 5);
    QImage image(size, QImage::Format_ARGB32);
    image.fill(qRgba(255, 255, 255, 255));
    QPainter painter(&image);
    painter.drawRect(5 * 5, 5 * 5, 90 * 5, 60 * 5);
    painter.drawLine(5 * 5, 14 * 5, 95 * 5, 14 * 5);
    painter.drawLine(5 * 5, 23 * 5, 95 * 5, 23 * 5);
    painter.drawLine(5 * 5, 32 * 5, 95 * 5, 32 * 5);
    painter.drawLine(5 * 5, 41 * 5, 95 * 5, 41 * 5);
    painter.drawLine(5 * 5, 50 * 5, 95 * 5, 50 * 5);
    painter.drawLine(50 * 5, 32 * 5, 50 * 5, 60 * 5);
    painter.drawLine(20 * 5, 5 * 5, 20 * 5, 60 * 5);
    painter.drawLine(65 * 5, 32 * 5, 65 * 5, 60 * 5);
    painter.drawRect(5 * 5, 60 * 5, 90 * 5, 15 * 5);
    //    painter.drawRect(5*5,70*5,90*5,7*5);

    QRect target(0 * 5, 62 * 5, 100 * 5, 70 * 5);
    //    QRect source(-10*5, 0, 65*5, 40*5);
    QString bar = box->caseNumber();
    code.draw(painter, target, bar);
    //    painter.drawImage(target,barCode.draw(barCode.CodeBinary(bar),bar),source);

    //    painter.setRenderHint(QPainter::Antialiasing,true);
    //    painter.setRenderHint(QPainter::TextAntialiasing,true);
    //    painter.setRenderHint(QPainter::HighQualityAntialiasing,true);
    QFont font;
    font.setFamily("宋体");
    font.setPixelSize(18);
    font.setBold(true);
    painter.setFont(font);
    painter.drawText(6 * 5, 11 * 5, QStringLiteral("品   种"));
    painter.drawText(6 * 5, 20 * 5, QStringLiteral("规   格"));
    painter.drawText(6 * 5, 29 * 5, QStringLiteral("批   号"));
    painter.drawText(6 * 5, 38 * 5, QStringLiteral("等   级"));
    painter.drawText(6 * 5, 47 * 5, QStringLiteral("净   重"));
    painter.drawText(6 * 5, 56 * 5, QStringLiteral("筒   数"));
    painter.drawText(50 * 5, 38 * 5, QStringLiteral("纸管颜色"));
    painter.drawText(51 * 5, 47 * 5, QStringLiteral("毛   重"));
    painter.drawText(51 * 5, 56 * 5, QStringLiteral("箱   号"));
    //    painter.drawRect(text1);

    font.setPixelSize(20);
    painter.setFont(font);
    painter.drawText(QRect(20 * 5, 5 * 5, 75 * 5, 9 * 5),
                     Qt::AlignCenter | Qt::AlignHCenter,
                     pinfo->info()->product_type_code);
    painter.drawText(QRect(20 * 5, 14 * 5, 75 * 5, 9 * 5),
                     Qt::AlignCenter | Qt::AlignHCenter,
                     pinfo->info()->specs);
    painter.drawText(QRect(20 * 5, 23 * 5, 75 * 5, 9 * 5),
                     Qt::AlignCenter | Qt::AlignHCenter,
                     pinfo->info()->batch_no);
    painter.drawText(QRect(20 * 5, 32 * 5, 30 * 5, 9 * 5),
                     Qt::AlignCenter | Qt::AlignHCenter,
                     box->Level);
    painter.drawText(QRect(20 * 5, 41 * 5, 30 * 5, 9 * 5),
                     Qt::AlignCenter | Qt::AlignHCenter,
                     QString("%1 kg").arg(getDecimalbit(box->net_weight / 1000.00)));
    painter.drawText(QRect(20 * 5, 50 * 5, 30 * 5, 9 * 5),
                     Qt::AlignCenter | Qt::AlignHCenter,
                     QString::number(box->tube_number));
    painter.drawText(QRect(65 * 5, 32 * 5, 30 * 5, 9 * 5),
                     Qt::AlignCenter | Qt::AlignHCenter,
                     pinfo->info()->bucket_color);
    painter.drawText(QRect(65 * 5, 41 * 5, 30 * 5, 9 * 5),
                     Qt::AlignCenter | Qt::AlignHCenter,
                     QString("%1 kg").arg(getDecimalbit(box->gross_weight / 1000.00)));
    font.setPixelSize(18);
    painter.setFont(font);
    painter.drawText(QRect(65 * 5, 50 * 5, 30 * 5, 9 * 5),
                     Qt::AlignCenter | Qt::AlignHCenter,
                     box->caseNumber());

    //    print(image);

    QString path = PQ::PQLogManger::this_()->getSaveFilePath();
    image.save(path + "/xiangdan/code" + bar + ".bmp");
    return image;

    //    return img;
}

QImage BoxTemlateOne::doPrinter(QSharedPointer<BoxInfo> box, int ModelIndex)
{
    boxM = GlobalInfo::this_()->BoxModelList().at(ModelIndex);

    QSharedPointer<PackInfo> pinfo = box->parentPack();
    QJsonObject info = pinfo->info()->toObject();
    QJsonObject obj = box->toObject();
    if (pinfo.isNull())
        return QImage();
    QSize size(MAXWIDTH * 5, MAXHEIGHT * 5);
    QImage image(size, QImage::Format_ARGB32);
    image.fill(qRgba(255, 255, 255, 255));
    QPainter painter(&image);
    painter.drawRect(5 * 5, 5 * 5, 90 * 5, 15 * 5);
    painter.drawRect(5 * 5, 20 * 5, 90 * 5, 35 * 5);
    painter.drawLine(20 * 5, 20 * 5, 20 * 5, 55 * 5);
    painter.drawLine(50 * 5, 20 * 5, 50 * 5, 55 * 5);
    painter.drawLine(66 * 5, 20 * 5, 66 * 5, 55 * 5);
    painter.drawLine(5 * 5, 27 * 5, 95 * 5, 27 * 5);
    painter.drawLine(5 * 5, 34 * 5, 95 * 5, 34 * 5);
    painter.drawLine(5 * 5, 41 * 5, 95 * 5, 41 * 5);
    painter.drawLine(5 * 5, 48 * 5, 95 * 5, 48 * 5);
    painter.drawRect(5 * 5, 55 * 5, 90 * 5, 15 * 5);
    painter.drawRect(5 * 5, 70 * 5, 90 * 5, 7 * 5);

    QRect target(0 * 5, 57 * 5, 100 * 5, 65 * 5);
    //    QRect source(-10*5, 0, 65*5, 40*5);
    QString bar = box->caseNumber();
    code.draw(painter, target, bar);
    //    painter.drawImage(target,barCode.draw(barCode.CodeBinary(bar),bar),source);

    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.setRenderHint(QPainter::TextAntialiasing, true);
    painter.setRenderHint(QPainter::HighQualityAntialiasing, true);
    QFont font;
    font.setFamily("宋体");
    font.setPixelSize(40);
    font.setWeight(QFont::ExtraLight);
    painter.setFont(font);
    font.setPixelSize(20);
    font.setBold(true);
    painter.drawText(6 * 5, 15 * 5, box->parentPack()->customer);

    font.setPixelSize(20);
    font.setBold(true);
    painter.setFont(font);
    //    painter.drawText(8*5,25*5,boxM->text1_1);
    //    painter.drawText(53*5,25*5,boxM->text1_2);
    //    painter.drawText(8*5,32*5,boxM->text2_1);
    //    painter.drawText(53*5,32*5,boxM->text2_2);
    //    painter.drawText(8*5,39*5,boxM->text3_1);
    //    painter.drawText(53*5,39*5,boxM->text3_2);
    //    painter.drawText(8*5,46*5,boxM->text4_1);
    //    painter.drawText(53*5,46*5,boxM->text4_2);
    //    painter.drawText(8*5,53*5,boxM->text5_1);
    //    painter.drawText(50*5,53*5,boxM->text5_2);

    painter.drawText(8 * 5, 25 * 5, boxM->Type_Name.at(0).toString());
    painter.drawText(53 * 5, 25 * 5, boxM->Type_Name.at(5).toString());
    painter.drawText(8 * 5, 32 * 5, boxM->Type_Name.at(1).toString());
    painter.drawText(53 * 5, 32 * 5, boxM->Type_Name.at(6).toString());
    painter.drawText(8 * 5, 39 * 5, boxM->Type_Name.at(2).toString());
    painter.drawText(53 * 5, 39 * 5, boxM->Type_Name.at(7).toString());
    painter.drawText(8 * 5, 46 * 5, boxM->Type_Name.at(3).toString());
    painter.drawText(53 * 5, 46 * 5, boxM->Type_Name.at(8).toString());
    painter.drawText(8 * 5, 53 * 5, boxM->Type_Name.at(4).toString());
    painter.drawText(53 * 5, 53 * 5, boxM->Type_Name.at(9).toString());
    //    painter.drawText(50*5,53*5,boxM->Type_Name.at(9).toString());

    painter.drawText(21 * 5, 25 * 5, FindData(box, boxM->Type_Data.at(0).toString()));
    painter.drawText(21 * 5, 32 * 5, FindData(box, boxM->Type_Data.at(1).toString()));
    painter.drawText(21 * 5, 39 * 5, FindData(box, boxM->Type_Data.at(2).toString()));
    painter.drawText(21 * 5, 46 * 5, FindData(box, boxM->Type_Data.at(3).toString()));
    painter.drawText(21 * 5, 53 * 5, FindData(box, boxM->Type_Data.at(4).toString()));
    painter.drawText(67 * 5,
                     25 * 5,
                     FindData(box, boxM->Type_Data.at(5).toString())); // datalist.at(0));
    painter.drawText(67 * 5, 32 * 5, FindData(box, boxM->Type_Data.at(6).toString()));
    painter.drawText(67 * 5,
                     39 * 5,
                     FindData(box, boxM->Type_Data.at(7).toString())); // datalist.at(2));
    painter.drawText(67 * 5,
                     46 * 5,
                     FindData(box, boxM->Type_Data.at(8).toString())); // datalist.at(4));
    painter.drawText(67 * 5,
                     53 * 5,
                     FindData(box, boxM->Type_Data.at(9).toString())); // datalist.at(6));

    font.setPixelSize(17);
    painter.setFont(font);

    painter.drawText(QRect(4 * 5, 75 * 5, 100 * 5, 65 * 5),
                     Qt::AlignCenter,
                     "服务电话:" + box->parentPack()->telephone);

    //    QString path = PQ::PQLogManger::this_()->getSaveFilePath();
    //        image.save(path+"/xiangdan/code"+bar+".bmp");
    return image;
}

QString BoxTemlateOne::FindData(QSharedPointer<BoxInfo> box, QString data)
{
    QSharedPointer<PackInfo> pinfo = box->parentPack();
    //    QJsonObject info = pinfo->info()->toObject();
    //    QJsonObject obj =  box->toObject();
    if (data == "品名") {
        return pinfo->info()->product_type_code;
    } else if (data == "批号") {
        return pinfo->info()->batch_no;
    } else if (data == "规格") {
        return pinfo->info()->specs;
    } else if (data == "毛重") {
        return QString("%1 kg").arg(getDecimalbit(box->gross_weight / 1000.00));
    } else if (data == "净重") {
        return QString("%1 kg").arg(getDecimalbit(box->net_weight / 1000.00));
    } else if (data == "筒数") {
        return QString::number(box->tube_number);
    } else if (data == "等级") {
        return box->Level;
    } else if (data == "捻向") {
        return box->twist_type;
    } else if (data == "管色") {
        return box->bucket_color;
    } else if (data == "箱号") {
        return box->caseNumber();
    } else if (data == "类型") {
        return pinfo->info()->category;
    } else if (data == "旦数") {
        return pinfo->info()->denier;
    } else if (data == "分特") {
        return pinfo->info()->dtex;
    } else if (data == "孔数") {
        return pinfo->info()->fiber;
    } else if (data == "颜色") {
        return pinfo->info()->color;
    } else if (data == "皮重") {
        return pinfo->info()->box_weight;
    } else if (data == "筒重") {
        return pinfo->info()->bucket_weight;
    } else if (data != "空") {
        return data;
    }

    return "";
}

QSize BoxTemlateOne::printSize()
{
    return QSize(100, 80);
}

QImage BoxTemlateOne::Boxmodel()
{
    QSize size(MAXWIDTH * 5, MAXHEIGHT * 5);
    QImage image(size, QImage::Format_ARGB32);
    image.fill(qRgba(255, 255, 255, 255));
    QPainter painter(&image);
    painter.drawRect(5 * 5, 5 * 5, 90 * 5, 15 * 5);
    painter.drawRect(5 * 5, 20 * 5, 90 * 5, 35 * 5);
    painter.drawLine(20 * 5, 20 * 5, 20 * 5, 55 * 5);
    painter.drawLine(50 * 5, 20 * 5, 50 * 5, 55 * 5);
    painter.drawLine(66 * 5, 20 * 5, 66 * 5, 55 * 5);
    painter.drawLine(5 * 5, 27 * 5, 95 * 5, 27 * 5);
    painter.drawLine(5 * 5, 34 * 5, 95 * 5, 34 * 5);
    painter.drawLine(5 * 5, 41 * 5, 95 * 5, 41 * 5);
    painter.drawLine(5 * 5, 48 * 5, 95 * 5, 48 * 5);
    painter.drawRect(5 * 5, 55 * 5, 90 * 5, 15 * 5);
    painter.drawRect(5 * 5, 70 * 5, 90 * 5, 7 * 5);

    QRect target(0 * 5, 57 * 5, 100 * 5, 65 * 5);
    QString bar = "200324155812001";
    code.draw(painter, target, bar);

    QFont font;
    font.setPixelSize(40);
    painter.setFont(font);
    painter.drawText(5 * 5, 15 * 5, "公司名称");

    font.setPixelSize(17);
    painter.setFont(font);
    //    painter.drawText(4*5,75*5," 电话:11111111111");
    painter.drawText(QRect(4 * 5, 75 * 5, 100 * 5, 65 * 5), Qt::AlignCenter, "服务电话:11111111111");
    //    QString path = PQ::PQLogManger::this_()->getSaveFilePath();
    //    if(save)
    //        image.save(path+"/xiangdan/code"+"11111"+".bmp");
    return image;
}

PackTemlateOne::PackTemlateOne() {}
//默认码单
QImage PackTemlateOne::doPrinter(QSharedPointer<PackInfo> pack)
{
    // TODO: 小宋，迁移打印 码单的逻辑

    QSize size(MAXWIDTH * 5, MAXHEIGHT * 5);
    QImage image(size, QImage::Format_ARGB32);
    image.fill(qRgba(255, 255, 255, 255));
    QPainter painter(&image);
    painter.drawRect(4 * 5, 4 * 5, 92 * 5, 68 * 5);

    QFont font;
    font.setFamily("宋体");
    font.setPixelSize(30);
    font.setWeight(QFont::ExtraLight);
    painter.setFont(font);
    painter.drawText(38 * 5, 10 * 5, QStringLiteral("入 库 单"));

    font.setPixelSize(20);
    painter.setFont(font);
    painter.drawText(8 * 5, 15 * 5, QStringLiteral("规格:"));
    painter.drawText(59 * 5, 15 * 5, QStringLiteral("类型:"));
    painter.drawText(8 * 5, 21 * 5, QStringLiteral("批号:"));
    painter.drawText(59 * 5, 21 * 5, QStringLiteral("等级:"));

    font.setPixelSize(15);
    painter.setFont(font);

    painter.drawText(8 * 5, 64 * 5, QStringLiteral("总数"));
    painter.drawText(38 * 5, 64 * 5, QStringLiteral("总重量"));
    painter.drawText(68 * 5, 64 * 5, QStringLiteral("总筒数"));

    //    QFont font;
    font.setPixelSize(15);
    painter.setFont(font);
    int boxSize = pack->boxes().size();
    for (int i = 0; i < boxSize; ++i) {
        int line = i / 5;
        int cloun = i % 5;
        painter.drawText((9 + line * 19) * 5, (27 + cloun * 6) * 5, QString("%1.").arg(i + 1));
    }

    QRect target(0 * 5, 67 * 5, 100 * 5, 75 * 5);
    QString bar = pack->codeSingle();
    code.draw(painter, target, bar);
    font.setPixelSize(20);
    font.setFamily("黑体");

    painter.setFont(font);
    painter.drawText(19 * 5, 15 * 5, pack->info()->specs);    // QStringLiteral("规格"));
    painter.drawText(70 * 5, 15 * 5, pack->info()->category); // QStringLiteral("类型"));
    painter.drawText(19 * 5, 21 * 5, pack->info()->batch_no); // QStringLiteral("批号"));
    painter.drawText(70 * 5, 21 * 5, pack->level);            // info.at(0));
    for (int i = 0; i < boxSize; ++i) {
        QString code = getDecimalbit(pack->boxes().at(i)->net_weight / 1000.00);
        int line = i / 5;
        int cloun = i % 5;
        painter.drawText((13 + line * 19) * 5, (27.5 + cloun * 6) * 5, code);
    }

    painter.drawText(15 * 5, 64 * 5, QString::number(pack->boxes().size()));
    painter.drawText(48 * 5,
                     64 * 5,
                     QString("%1 kg").arg(getDecimalbit(pack->net_weight() / 1000.00)));
    painter.drawText(78 * 5, 64 * 5, QString::number(pack->tube_number()));

    //    QString path = PQ::PQLogManger::this_()->getSaveFilePath();
    //        image.save(path+"/rukudan/code"+bar+".bmp");

    return image;
}

QImage PackTemlateOne::doPrinter(QSharedPointer<PackInfo> pack, int ModelIndex)
{
    // TODO: 小宋，迁移打印 码单的逻辑

    packM = GlobalInfo::this_()->PackModelList().at(ModelIndex);

    QSize size(MAXWIDTH * 5, MAXHEIGHT * 5);
    QImage image(size, QImage::Format_ARGB32);
    image.fill(qRgba(255, 255, 255, 255));
    QPainter painter(&image);
    painter.drawRect(4 * 5, 4 * 5, 92 * 5, 68 * 5);

    QFont font;
    font.setFamily("宋体");
    font.setPixelSize(30);
    font.setWeight(QFont::ExtraLight);
    painter.setFont(font);
    painter.drawText(38 * 5, 10 * 5, QStringLiteral("入 库 单"));

    font.setPixelSize(20);
    painter.setFont(font);
    painter.drawText(8 * 5, 15 * 5, packM->Type_Name.at(0).toString());
    painter.drawText(59 * 5, 15 * 5, packM->Type_Name.at(1).toString());
    painter.drawText(8 * 5, 21 * 5, packM->Type_Name.at(2).toString());
    painter.drawText(59 * 5, 21 * 5, packM->Type_Name.at(3).toString());

    font.setPixelSize(15);
    painter.setFont(font);

    painter.drawText(8 * 5, 64 * 5, packM->Type_Name.at(4).toString());
    painter.drawText(38 * 5, 64 * 5, packM->Type_Name.at(5).toString());
    painter.drawText(68 * 5, 64 * 5, packM->Type_Name.at(6).toString());

    //    QFont font;
    font.setPixelSize(15);
    painter.setFont(font);
    int boxSize = pack->boxes().size();
    for (int i = 0; i < boxSize; ++i) {
        int line = i / 5;
        int cloun = i % 5;
        painter.drawText((9 + line * 19) * 5, (27 + cloun * 6) * 5, QString("%1.").arg(i + 1));
    }

    QRect target(0 * 5, 67 * 5, 100 * 5, 75 * 5);
    QString bar = pack->codeSingle();
    code.draw(painter, target, bar);
    font.setPixelSize(20);
    font.setFamily("黑体");

    painter.setFont(font);
    painter.drawText(19 * 5,
                     15 * 5,
                     FindData(pack, packM->Type_Data.at(0).toString())); // QStringLiteral("规格"));
    painter.drawText(70 * 5,
                     15 * 5,
                     FindData(pack, packM->Type_Data.at(1).toString())); // QStringLiteral("类型"));
    painter.drawText(19 * 5,
                     21 * 5,
                     FindData(pack, packM->Type_Data.at(2).toString())); // QStringLiteral("批号"));
    painter.drawText(70 * 5,
                     21 * 5,
                     FindData(pack, packM->Type_Data.at(3).toString())); // info.at(0));
    for (int i = 0; i < boxSize; ++i) {
        QString code = Find20Data(pack, packM->Type_Data.at(4).toString(), i);
        int line = i / 5;
        int cloun = i % 5;
        painter.drawText((13 + line * 19) * 5, (27.5 + cloun * 6) * 5, code);
    }

    painter.drawText(15 * 5, 64 * 5, FindData(pack, packM->Type_Data.at(5).toString()));
    painter.drawText(48 * 5, 64 * 5, FindData(pack, packM->Type_Data.at(6).toString()));
    painter.drawText(78 * 5, 64 * 5, FindData(pack, packM->Type_Data.at(7).toString()));

    //    QString path = PQ::PQLogManger::this_()->getSaveFilePath();
    //        image.save(path+"/rukudan/code"+bar+".bmp");

    return image;
}

QImage PackTemlateOne::Packmodel()
{
    QSize size(MAXWIDTH * 5, MAXHEIGHT * 5);
    QImage image(size, QImage::Format_ARGB32);
    image.fill(qRgba(255, 255, 255, 255));
    QPainter painter(&image);
    painter.drawRect(4 * 5, 4 * 5, 92 * 5, 68 * 5);

    QFont font;
    font.setFamily("宋体");
    font.setPixelSize(30);
    font.setWeight(QFont::ExtraLight);
    painter.setFont(font);
    painter.drawText(38 * 5, 10 * 5, QStringLiteral("入 库 单"));

    QRect target(0 * 5, 67 * 5, 100 * 5, 75 * 5);
    QString bar = "0000200313170054032";
    code.draw(painter, target, bar);
    font.setPixelSize(20);
    font.setFamily("黑体");

    return image;
}

QString PackTemlateOne::FindData(QSharedPointer<PackInfo> pack, QString data)
{
    if (data == "批号") {
        return pack->info()->batch_no;
    } else if (data == "类型") {
        return pack->info()->category;
    } else if (data == "品种") {
        return pack->info()->product_type_code;
    } else if (data == "旦数") {
        return pack->info()->denier;
    } else if (data == "分特") {
        return pack->info()->dtex;
    } else if (data == "等级") {
        return pack->level;
    } else if (data == "孔数") {
        return pack->info()->fiber;
    } else if (data == "规格") {
        return pack->info()->specs;
    } else if (data == "颜色") {
        return pack->info()->color;
    } else if (data == "捻向") {
        return pack->info()->twist_type;
    } else if (data == "管色") {
        return pack->info()->bucket_color;
    } else if (data == "皮重") {
        return pack->info()->box_weight;
    } else if (data == "机台") {
        return pack->info()->machine_no;
    } else if (data == "纸箱") {
        return pack->info()->carton_type;
    } else if (data == "总筒数") {
        return QString::number(pack->tube_number());
    } else if (data == "总毛重") {
        return QString("%1 kg").arg(getDecimalbit(pack->gross_weight() / 1000.00));
    } else if (data == "总净重") {
        return QString("%1 kg").arg(getDecimalbit(pack->net_weight() / 1000.00));
    } else if (data != "空") {
        return data;
    }

    return "";
}

QString PackTemlateOne::Find20Data(QSharedPointer<PackInfo> pack, QString data, int index)
{
    if (data == "毛重") {
        return QString("%1 kg").arg(getDecimalbit(pack->boxInfoAt(index)->gross_weight / 1000.00));
    } else if (data == "净重") {
        return QString("%1 kg").arg(getDecimalbit(pack->boxInfoAt(index)->net_weight / 1000.00));
    } else if (data == "筒重") {
        return QString::number(pack->boxInfoAt(index)->tube_number);
    } else if (data == "捻向") {
        return pack->boxInfoAt(index)->twist_type;
    } else if (data == "管色") {
        return pack->boxInfoAt(index)->bucket_color;
    } else if (data == "总筒重") {
        return QString("%1 kg").arg(getDecimalbit(pack->boxInfoAt(index)->bucket_weight / 1000.00));
    } else if (data == "筒数") {
        return QString::number(pack->boxInfoAt(index)->tube_number);
    } else if (data != "空") {
        return data;
    }

    return "";
}

QSize PackTemlateOne::printSize()
{
    return QSize(100, 80);
}
