#include "configinfo.h"

ConfigInfo::ConfigInfo()
{
    //TODO: 小宋，给每个成员设置默认值
//    baseUrl = "http://erp.itwsw.cn/api";
    baseUrl = "http://xshx.huaxianyun.com/api";
    packId = 0;
    printerName = "TSC TTP-244 Pro";
    portName = "COM1";
    portBaudRate = "9600";
    portType = 0;
    savePrinter = true;
}


void ConfigInfo::load()
{
    QJsonObject obj = PQ::ConfigFile::readObject("Config.json");
    if(obj.isEmpty()) {
        save();
        return;
    }
    baseUrl = obj.value("baseUrl").toString();
    printerName = obj.value("printerName").toString();
    portName = obj.value("portName").toString();
    portBaudRate = obj.value("portBaudRate").toString();
    portType = obj.value("portType").toInt();
    savePrinter = obj.value("savePrinter").toBool();
}

void ConfigInfo::save()
{
    QJsonObject obj;
    obj.insert("baseUrl","http://xshx.huaxianyun.com/api");
    obj.insert("printerName","TSC TTP-244 Pro");
    obj.insert("portName","COM1");
    obj.insert("portBaudRate",9600);
    obj.insert("portType",0);
    obj.insert("savePrinter",true);
    PQ::ConfigFile::writeObject("Config.json",obj);
    emit configUpdate();
}


