import QtQuick 2.15 import QtQuick.Controls 2.15 Item { id: materialmakeback x: 290 y: 130 width: 1600 height: 920 signal signal_openLock signal startReader signal signal_takebackstat(bool stat) property bool listviewstat : false property bool takebackstat : false property bool opendoor : false property int takebackviewcount: 1 onVisibleChanged: { proThread.moveCursorTo(0, 0); } ListModel { id: materialsellistModel } ListModel { id: materialModel } Rectangle { id: materialsel width: 1600 height: 800 color: "#272b7ae9" radius: 20 clip: true Rectangle { x: 50 y: 100 width: parent.width - 100 height: parent.height - 100 clip: true color: "#002b7ae9" GridView { width: parent.width height: parent.height cellWidth: 250 // 每个单元格的宽度,这里是平均分配宽度给5列 cellHeight: 350 // 每个单元格的高度 model: materialModel delegate: Rectangle{ width: 250 height: 350 color: "#00ffffff" Rectangle { x: 25 y: 25 width: 200 height: 300 color: model.color Image { x: 25 y: 25 width: 150 height: 150 visible: true source: model.png fillMode: Image.PreserveAspectFit } Text { x: 0 y: 185 width: parent.width height: 50 visible: true text: model.name font.pixelSize: 30 horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter color: "#ffffff" } Text { x: 0 y: 250 width: parent.width height: 25 visible: true text: model.rfid font.pixelSize: 12 horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter color: "#ffffff" } Rectangle { x: 25 y: 75 width: 150 height: 50 color: { if (model.status === "0") return "#00ff00"; // 正常 - 绿色 if (model.status === "1") return "#ff0000"; // 损坏 - 红色 if (model.status === "2") return "#ff9900"; // 过期 - 橙色 if (model.status === "3") return "#ff9900"; // 放错柜子 - 橙色 return "gray"; // 默认颜色 } visible: { return model.status !== "0"; } Text { anchors.centerIn: parent // text: "待还" text:{ if (model.status === "0") return "正常"; if (model.status === "1") return "损坏"; if (model.status === "2") return "过期"; if (model.status === "3") return "放错柜子"; return "未知状态"; // 默认值 } font.pixelSize: 30 horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter color: "#ffffff" } } Rectangle { x: 25 y: 125 width: 150 height: 50 color: "#ff0000" // 透明背景 visible: model.stat Text { anchors.centerIn: parent text: "待还" font.pixelSize: 30 horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter color: "#ffffff" } } } } } } Rectangle { id: materialselview width: 1600 height: 100 // 减去顶部圆角矩形的高度 radius: 20 clip: true color: "#8f2b7ae9" Grid { x: 50 y: 0 width: parent.width - 150 height: parent.height visible: true verticalItemAlignment: Grid.AlignVCenter horizontalItemAlignment: Grid.AlignHCenter columns: 5 spacing: 20 Repeater { model: materialsellistModel delegate: Rectangle{ width: 250 height: 100 color: "#00ffffff" Image { x: 0 y: 25 width: 50 height: 50 visible: true source: model.source fillMode: Image.PreserveAspectFit } Text { x: 55 y: 25 width: parent.width - 55 height: 50 visible: true text: model.count font.pixelSize: 25 horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter color: "#ffffff" } Canvas { anchors.fill: parent visible: model.view onPaint: { var ctx = getContext("2d"); ctx.lineWidth = 10; // 设置线的宽度 ctx.strokeStyle = "skyblue"; // 设置线的颜色为白色 ctx.beginPath(); ctx.moveTo(0, 80); // 直线的起点 ctx.lineTo(parent.width, 80); // 直线的终点 ctx.stroke(); // 绘制直线 } } MouseArea { anchors.fill: parent // 让MouseArea覆盖整个Image区域 onClicked: { sel_materialtype(model.idx) } } } } } Image { id: viewImage x: parent.width - 80 y: 20 width: 60 height: 60 source: "qrc:/png/right.png" fillMode: Image.PreserveAspectFit MouseArea { anchors.fill: parent // 让MouseArea覆盖整个Image区域 onClicked: { if(listviewstat == false) { listviewstat = true; viewImage.rotation = 90; materialselview.height = materialselview.height + 500 } else{ listviewstat = false; viewImage.rotation = 0; materialselview.height = materialselview.height - 500 } } } } } } Dialog { id: dialog title: "操作确认" x: parent.width / 2 - width / 2 y: parent.height / 2 - height / 2 width: 600 height: 400 clip: true modal: true // 自定义背景(带圆角) background: Rectangle { color: "white" clip: true } // 自定义标题栏 header: Rectangle { x: 0 y: 0 width: parent.width height: 50 // 设置标题栏高度 color: "#ff3968e9" // 设置标题栏背景色 // 标题文本 Text { x: 20 y: 0 width: 80 height: 50 // 设置标题栏高度 text: dialog.title font.pixelSize: 25 horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter color: "white" } } contentItem: Rectangle { x: 0 y: 0 width: parent.width height: 200 color: "white" Text { width: parent.width height: 200 text: "确认要开柜取还物资吗?" font.pixelSize: 30 horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter } } // 自定义 DialogButtonBox DialogButtonBox { id: buttonBox x: 0 y: 250 width: parent.width height: 100 // 自定义按钮 Button { implicitWidth: 120 implicitHeight: 50 text: "确认" background: Rectangle { color: "green" radius: 5 } contentItem: Text { text: parent.text font.pixelSize: 30 color: "white" horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter } onClicked: { if(takebackstat === false) { takebackstat = true; pConfig.mtakebackstat = true; // button_return.enabled = false; pConfig.imaterworkstat = 0; signal_openLock() } dialog.close() } } Button { implicitWidth: 120 implicitHeight: 50 text: "取消" background: Rectangle { color: "red" radius: 5 } contentItem: Text { text: parent.text font.pixelSize: 30 color: "white" horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter } onClicked: { dialog.reject() } } } } Button { id: button_openCabinet x: 1168 y: 835 width: 192 height: 75 background: Rectangle { color: "#ff0000" // 设置背景为透明 radius: 10 // 可选,设置圆角 } text: qsTr("开柜") font.pixelSize: 30 palette.buttonText: "white" // 设置字体颜色为绿色 Connections { target: button_openCabinet onClicked: { dialog.open() } } } Button { id: button_return x: 1408 y: 835 width: 192 height: 75 background: Rectangle { color: "#055eb3" // 设置背景为透明 radius: 10 // 可选,设置圆角 } text: qsTr("返回") font.pixelSize: 30 palette.buttonText: "white" // 设置字体颜色为绿色 Connections { target: button_return onClicked: { if (pConfig.sopenDoor) { infoPromptBox.title("提示"); infoPromptBox.message("开柜状态下不允许该操作"); infoPromptBox.button_clear(); infoPromptBox.button_push("#055eb3", "确定", null, null); infoPromptBox.show(); } else { materialTakeBack.visible = false; materialSelmodel.visible = true; } // if(takebackstat === false && opendoor === false) // { // materialTakeBack.visible = false; // materialSelmodel.visible = true; // } } } } Rectangle { id: delaymatrailtakebacknotice x: 0 y: 823 width: 300 height: 75 // 减去顶部圆角矩形的高度 color: "#00ffffff" visible: opendoor Image { x: 0 y: 0 width: 75 height: 75 visible: true source: "qrc:/png/takeback.png" fillMode: Image.PreserveAspectFit } Text { x: 80 y: 0 width: 220 height: 75 visible: false text: "等待取还物资......" font.pixelSize: 30 horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter color: "#ffffff" } } Timer { interval: 100 running: true repeat: true onTriggered: { if(opendoor == true) { if(takebackviewcount > 0) { takebackviewcount--; } else{ takebackviewcount = 5; if(delaymatrailtakebacknotice.visible === true) { delaymatrailtakebacknotice.visible = false; } else{ delaymatrailtakebacknotice.visible = true; } } } else{ delaymatrailtakebacknotice.visible = false; } } } function sel_materialtype(idx) { var foundItem = null; for (var i = 0; i < materialsellistModel.count; ++i) { if (materialsellistModel.get(i).idx === idx) { foundItem = materialsellistModel.get(i); foundItem.view = true; } else{ materialsellistModel.get(i).view = false; } } materialModel.clear() var materialname = pConfig.smaterialNameList; var materialpicture = pConfig.smaterialPictureList; var materialloanuser = pConfig.smaterialLoanUserList; var materialloanstate = pConfig.smaterialLoanStateList; var materialstatus = pConfig.smaterialStatusList; var materialtype = pConfig.smaterialTypeList; var userId = pConfig.suserId; for (var key in materialname) { if(foundItem.idx === "ALL") { if(materialloanstate[key] === 0) { if (materialloanuser[key] === userId) { materialModel.append({png:materialpicture[key], name: materialname[key], status: materialstatus[key], rfid: key, color: "#8fffffff", stat: true}); } else { materialModel.append({png:materialpicture[key], name: materialname[key], status: materialstatus[key], rfid: key, color: "#8fffffff", stat: false}); } } else { materialModel.append({png:materialpicture[key], name: materialname[key], status: materialstatus[key], rfid: key, color: "#00ffffff", stat: false}); } } else{ if(foundItem.idx === materialtype[key]) { if(materialloanstate[key] === 0) { if (materialloanuser[key] === userId) { materialModel.append({png:materialpicture[key], name: materialname[key], status: materialstatus[key], rfid: key, color: "#8fffffff", stat: true}); } else { materialModel.append({png:materialpicture[key], name: materialname[key], status: materialstatus[key], rfid: key, color: "#8fffffff", stat: false}); } } else{ materialModel.append({png:materialpicture[key], name: materialname[key], status: materialstatus[key], rfid: key, color: "#00ffffff", stat: false}); } } } } } function lockStat_callback(left, right) { if(left === false || right === false) { opendoor = true; if(takebackstat === true) { button_openCabinet.visible = false; signal_takebackstat(true); } } else if(left === true && right === true) { opendoor = false; if(takebackstat === true) { // 开始读rfid startReader(); takebackstat = false; signal_takebackstat(false); pConfig.smaterialStock = true; // button_return.enabled = true; button_openCabinet.visible = true; // materialTakeBack.visible = false; mainScreen.switchViewOffEx(); materialStocktaking.set_userinfo(); materialStocktaking.materiallistclear(); materialStocktaking.visible = true; mainScreen.resetLogin_timeout(); } } } function slot_updateMaterial() { materialsellistModel.clear(); materialModel.clear(); var typecount = pConfig.smaterialTypeCountList; var typepng = pConfig.smaterialTypePngList; var idx = 1; var count = 0; for (var typekey in typecount) { count = count + typecount[typekey]; var viewcount = typekey + "(" + typecount[typekey] + ")"; materialsellistModel.append({idx: typekey, source: typepng[typekey], count: viewcount, view: false}); idx++; } materialsellistModel.insert(0, {idx: "ALL", source: "qrc:/png/allsel.png", count: "全部(" + count + ")", view: true}); var materialname = pConfig.smaterialNameList; var materialpicture = pConfig.smaterialPictureList; var materialloanuser = pConfig.smaterialLoanUserList; var materialloanstate = pConfig.smaterialLoanStateList; var materialstatus = pConfig.smaterialStatusList; var materialtype = pConfig.smaterialTypeList; var userId = pConfig.suserId; for (var key in materialname) { if(materialloanstate[key] === 0) { if (materialloanuser[key] === userId) { materialModel.append({png:materialpicture[key], name: materialname[key], status: materialstatus[key], rfid: key, color: "#8fffffff", stat: true}); } else { materialModel.append({png:materialpicture[key], name: materialname[key], status: materialstatus[key], rfid: key, color: "#8fffffff", stat: false}); } } else{ materialModel.append({png:materialpicture[key], name: materialname[key], status: materialstatus[key], rfid: key, color: "#00ffffff", stat: false}); } } } }