import QtQuick 2.15
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.14
import QtQuick.Controls.Styles 1.2
import Qt.labs.platform 1.1
import TService 1.0


Rectangle {
    id:leakage_root

    //implicitWidth: 600
    //implicitHeight: 400
    width: 600
    height: 240
    radius: 6

    property  string title_str:"油气密封点泄漏值录入"
    property double value_couplevalve: -100.0
    property double value_manhole: -100.0
    property  string carplate


    function pad_with_zeroes(number, length) {
        var my_string = '' + number;
        while (my_string.length < length) {
            my_string = '0' + my_string;
        }
        return my_string;
    }

    function getWordSaveFileName( para){
        var date = new Date;
        var year = date.getFullYear()
        var month = pad_with_zeroes(date.getMonth()+1,2)
        var day = pad_with_zeroes(date.getDate(),2)
        var hour = pad_with_zeroes(date.getHours(),2)
        var minute = pad_with_zeroes(date.getMinutes(),2)
        var second = pad_with_zeroes(date.getSeconds(),2)

        var time = year+month+day+hour+minute+second
        return "file:///"+time+"_"+para
    }



    DynamicGroupBox{
        id:dgroupbox
        //x:width
        //x:0

        anchors.centerIn: parent
        anchors.fill: parent

        title: title_str


        FileDialog {
            id: saveWordDialog
            title: "保存为"
            //nameFilters: [ "Word files (*.doc)"]
            nameFilters: [ "Text files (*.pdf)"]
            fileMode: FileDialog.SaveFile
            onAccepted: {
                var savePath = file.toString().substring(8)

                console.log("saveWordDialog savePath:")
                console.log(savePath)

                //reportWord.generateBreatheValveWord(savePath,para,obj1,obj2,obj3)
                testService.genReport(savePath, "D:/tmp/")
            }
        }


        Column{
            spacing:20
            anchors.centerIn: parent
            width: 560

            Row{
                spacing:10
                height: 80

                Column{
                    spacing:10
                    Row{
                        //spacing:10
                        InputLine{
                            id:vrs_couplevalve
                            paraName: "油气回收耦合阀 : "
                            paraLength: 170
                            validator:RegExpValidator {
                                regExp: /[0-9]*/
                            }
                            onTextChanged: {
                                if(text.length > 0){
                                    value_couplevalve = Number(text)
                                }else{
                                    value_couplevalve = -100.0
                                }
                            }
                        }

                        Text {
                            text: "（μmol/mol）";
                            //font.bold: true;
                            font.pointSize: 20;
                        }

                    }

                    Row{
                        //spacing:10
                        InputLine{
                            id:manhole_cover
                            paraName: "人孔盖（含紧急泄放装置）: "
                            paraLength: 80
                            validator:RegExpValidator {
                                regExp: /[0-9]*/
                            }
                            onTextChanged: {
                                if(text.length > 0){
                                    value_manhole = Number(text)
                                }else{
                                    value_manhole = -100.0
                                }
                            }
                        }

                        Text {
                            text: "（μmol/mol）";
                            //font.bold: true;
                            font.pointSize: 20;
                        }

                    }

                }

            }


            Row{
                spacing:100
                height: 80
                padding: 80

                UserButton {
                    id: report_button;
                    text: "生成检测报告";
                    font.pixelSize: 20

                    anchors.verticalCenter: parent.verticalCenter

                    width: 160
                    height: 45

                    onClicked: {

                            var lvJson={}
                            lvJson.couplevalve = value_couplevalve
                            lvJson.manhole = value_manhole
                            testService.set_leakage_value(JSON.stringify(lvJson))


                            var fileName = leakage_root.carplate
                            var text = getWordSaveFileName(fileName)
                            console.log(text)

                            saveWordDialog.currentFile = getWordSaveFileName(fileName)
                            saveWordDialog.open()

                    }
                }

                UserButton {
                    id: close_button;
                    text: "退出";
                    font.pixelSize: 20

                    anchors.verticalCenter: parent.verticalCenter

                    width: 120
                    height: 45

                    onClicked: {
                        popupCenter.close()
                    }
                }
            }

        }

    }

    Component.onCompleted: {


    }

}
