MaterialTakeBack.qml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. import QtQuick 2.15
  2. import QtQuick.Controls 2.15
  3. Item {
  4. id: materialmakeback
  5. x: 290
  6. y: 130
  7. width: 1600
  8. height: 920
  9. signal signal_openLock
  10. signal startReader
  11. signal signal_takebackstat(bool stat)
  12. property bool listviewstat : false
  13. property bool takebackstat : false
  14. property bool opendoor : false
  15. property int takebackviewcount: 1
  16. onVisibleChanged: {
  17. proThread.moveCursorTo(0, 0);
  18. }
  19. ListModel {
  20. id: materialsellistModel
  21. }
  22. ListModel {
  23. id: materialModel
  24. }
  25. Rectangle {
  26. id: materialsel
  27. width: 1600
  28. height: 800
  29. color: "#272b7ae9"
  30. radius: 20
  31. clip: true
  32. Rectangle {
  33. x: 50
  34. y: 100
  35. width: parent.width - 100
  36. height: parent.height - 100
  37. clip: true
  38. color: "#002b7ae9"
  39. GridView {
  40. width: parent.width
  41. height: parent.height
  42. cellWidth: 250 // 每个单元格的宽度,这里是平均分配宽度给5列
  43. cellHeight: 350 // 每个单元格的高度
  44. model: materialModel
  45. delegate: Rectangle{
  46. width: 250
  47. height: 350
  48. color: "#00ffffff"
  49. Rectangle {
  50. x: 25
  51. y: 25
  52. width: 200
  53. height: 300
  54. color: model.color
  55. Image {
  56. x: 25
  57. y: 25
  58. width: 150
  59. height: 150
  60. visible: true
  61. source: model.png
  62. fillMode: Image.PreserveAspectFit
  63. }
  64. Text {
  65. x: 0
  66. y: 185
  67. width: parent.width
  68. height: 50
  69. visible: true
  70. text: model.name
  71. font.pixelSize: 30
  72. horizontalAlignment: Text.AlignHCenter
  73. verticalAlignment: Text.AlignVCenter
  74. color: "#ffffff"
  75. }
  76. Text {
  77. x: 0
  78. y: 250
  79. width: parent.width
  80. height: 25
  81. visible: true
  82. text: model.rfid
  83. font.pixelSize: 12
  84. horizontalAlignment: Text.AlignHCenter
  85. verticalAlignment: Text.AlignVCenter
  86. color: "#ffffff"
  87. }
  88. Rectangle {
  89. x: 25
  90. y: 75
  91. width: 150
  92. height: 50
  93. color: {
  94. if (model.status === "0") return "#00ff00"; // 正常 - 绿色
  95. if (model.status === "1") return "#ff0000"; // 损坏 - 红色
  96. if (model.status === "2") return "#ff9900"; // 过期 - 橙色
  97. if (model.status === "3") return "#ff9900"; // 放错柜子 - 橙色
  98. return "gray"; // 默认颜色
  99. }
  100. visible: {
  101. return model.status !== "0";
  102. }
  103. Text {
  104. anchors.centerIn: parent
  105. // text: "待还"
  106. text:{
  107. if (model.status === "0") return "正常";
  108. if (model.status === "1") return "损坏";
  109. if (model.status === "2") return "过期";
  110. if (model.status === "3") return "放错柜子";
  111. return "未知状态"; // 默认值
  112. }
  113. font.pixelSize: 30
  114. horizontalAlignment: Text.AlignHCenter
  115. verticalAlignment: Text.AlignVCenter
  116. color: "#ffffff"
  117. }
  118. }
  119. Rectangle {
  120. x: 25
  121. y: 125
  122. width: 150
  123. height: 50
  124. color: "#ff0000" // 透明背景
  125. visible: model.stat
  126. Text {
  127. anchors.centerIn: parent
  128. text: "待还"
  129. font.pixelSize: 30
  130. horizontalAlignment: Text.AlignHCenter
  131. verticalAlignment: Text.AlignVCenter
  132. color: "#ffffff"
  133. }
  134. }
  135. }
  136. }
  137. }
  138. }
  139. Rectangle {
  140. id: materialselview
  141. width: 1600
  142. height: 100 // 减去顶部圆角矩形的高度
  143. radius: 20
  144. clip: true
  145. color: "#8f2b7ae9"
  146. Grid {
  147. x: 50
  148. y: 0
  149. width: parent.width - 150
  150. height: parent.height
  151. visible: true
  152. verticalItemAlignment: Grid.AlignVCenter
  153. horizontalItemAlignment: Grid.AlignHCenter
  154. columns: 5
  155. spacing: 20
  156. Repeater {
  157. model: materialsellistModel
  158. delegate: Rectangle{
  159. width: 250
  160. height: 100
  161. color: "#00ffffff"
  162. Image {
  163. x: 0
  164. y: 25
  165. width: 50
  166. height: 50
  167. visible: true
  168. source: model.source
  169. fillMode: Image.PreserveAspectFit
  170. }
  171. Text {
  172. x: 55
  173. y: 25
  174. width: parent.width - 55
  175. height: 50
  176. visible: true
  177. text: model.count
  178. font.pixelSize: 25
  179. horizontalAlignment: Text.AlignHCenter
  180. verticalAlignment: Text.AlignVCenter
  181. color: "#ffffff"
  182. }
  183. Canvas {
  184. anchors.fill: parent
  185. visible: model.view
  186. onPaint: {
  187. var ctx = getContext("2d");
  188. ctx.lineWidth = 10; // 设置线的宽度
  189. ctx.strokeStyle = "skyblue"; // 设置线的颜色为白色
  190. ctx.beginPath();
  191. ctx.moveTo(0, 80); // 直线的起点
  192. ctx.lineTo(parent.width, 80); // 直线的终点
  193. ctx.stroke(); // 绘制直线
  194. }
  195. }
  196. MouseArea {
  197. anchors.fill: parent // 让MouseArea覆盖整个Image区域
  198. onClicked: {
  199. sel_materialtype(model.idx)
  200. }
  201. }
  202. }
  203. }
  204. }
  205. Image {
  206. id: viewImage
  207. x: parent.width - 80
  208. y: 20
  209. width: 60
  210. height: 60
  211. source: "qrc:/png/right.png"
  212. fillMode: Image.PreserveAspectFit
  213. MouseArea {
  214. anchors.fill: parent // 让MouseArea覆盖整个Image区域
  215. onClicked: {
  216. if(listviewstat == false)
  217. {
  218. listviewstat = true;
  219. viewImage.rotation = 90;
  220. materialselview.height = materialselview.height + 500
  221. }
  222. else{
  223. listviewstat = false;
  224. viewImage.rotation = 0;
  225. materialselview.height = materialselview.height - 500
  226. }
  227. }
  228. }
  229. }
  230. }
  231. }
  232. Dialog {
  233. id: dialog
  234. title: "操作确认"
  235. x: parent.width / 2 - width / 2
  236. y: parent.height / 2 - height / 2
  237. width: 600
  238. height: 400
  239. clip: true
  240. modal: true
  241. // 自定义背景(带圆角)
  242. background: Rectangle {
  243. color: "white"
  244. clip: true
  245. }
  246. // 自定义标题栏
  247. header: Rectangle {
  248. x: 0
  249. y: 0
  250. width: parent.width
  251. height: 50 // 设置标题栏高度
  252. color: "#ff3968e9" // 设置标题栏背景色
  253. // 标题文本
  254. Text {
  255. x: 20
  256. y: 0
  257. width: 80
  258. height: 50 // 设置标题栏高度
  259. text: dialog.title
  260. font.pixelSize: 25
  261. horizontalAlignment: Text.AlignLeft
  262. verticalAlignment: Text.AlignVCenter
  263. color: "white"
  264. }
  265. }
  266. contentItem: Rectangle {
  267. x: 0
  268. y: 0
  269. width: parent.width
  270. height: 200
  271. color: "white"
  272. Text {
  273. width: parent.width
  274. height: 200
  275. text: "确认要开柜取还物资吗?"
  276. font.pixelSize: 30
  277. horizontalAlignment: Text.AlignHCenter
  278. verticalAlignment: Text.AlignVCenter
  279. }
  280. }
  281. // 自定义 DialogButtonBox
  282. DialogButtonBox {
  283. id: buttonBox
  284. x: 0
  285. y: 250
  286. width: parent.width
  287. height: 100
  288. // 自定义按钮
  289. Button {
  290. implicitWidth: 120
  291. implicitHeight: 50
  292. text: "确认"
  293. background: Rectangle {
  294. color: "green"
  295. radius: 5
  296. }
  297. contentItem: Text {
  298. text: parent.text
  299. font.pixelSize: 30
  300. color: "white"
  301. horizontalAlignment: Text.AlignHCenter
  302. verticalAlignment: Text.AlignVCenter
  303. }
  304. onClicked: {
  305. if(takebackstat === false)
  306. {
  307. takebackstat = true;
  308. pConfig.mtakebackstat = true;
  309. // button_return.enabled = false;
  310. pConfig.imaterworkstat = 0;
  311. signal_openLock()
  312. }
  313. dialog.close()
  314. }
  315. }
  316. Button {
  317. implicitWidth: 120
  318. implicitHeight: 50
  319. text: "取消"
  320. background: Rectangle {
  321. color: "red"
  322. radius: 5
  323. }
  324. contentItem: Text {
  325. text: parent.text
  326. font.pixelSize: 30
  327. color: "white"
  328. horizontalAlignment: Text.AlignHCenter
  329. verticalAlignment: Text.AlignVCenter
  330. }
  331. onClicked: {
  332. dialog.reject()
  333. }
  334. }
  335. }
  336. }
  337. Button {
  338. id: button_openCabinet
  339. x: 1168
  340. y: 835
  341. width: 192
  342. height: 75
  343. background: Rectangle {
  344. color: "#ff0000" // 设置背景为透明
  345. radius: 10 // 可选,设置圆角
  346. }
  347. text: qsTr("开柜")
  348. font.pixelSize: 30
  349. palette.buttonText: "white" // 设置字体颜色为绿色
  350. Connections {
  351. target: button_openCabinet
  352. onClicked: {
  353. dialog.open()
  354. }
  355. }
  356. }
  357. Button {
  358. id: button_return
  359. x: 1408
  360. y: 835
  361. width: 192
  362. height: 75
  363. background: Rectangle {
  364. color: "#055eb3" // 设置背景为透明
  365. radius: 10 // 可选,设置圆角
  366. }
  367. text: qsTr("返回")
  368. font.pixelSize: 30
  369. palette.buttonText: "white" // 设置字体颜色为绿色
  370. Connections {
  371. target: button_return
  372. onClicked: {
  373. if (pConfig.sopenDoor)
  374. {
  375. infoPromptBox.title("提示");
  376. infoPromptBox.message("开柜状态下不允许该操作");
  377. infoPromptBox.button_clear();
  378. infoPromptBox.button_push("#055eb3", "确定", null, null);
  379. infoPromptBox.show();
  380. }
  381. else
  382. {
  383. materialTakeBack.visible = false;
  384. materialSelmodel.visible = true;
  385. }
  386. // if(takebackstat === false && opendoor === false)
  387. // {
  388. // materialTakeBack.visible = false;
  389. // materialSelmodel.visible = true;
  390. // }
  391. }
  392. }
  393. }
  394. Rectangle {
  395. id: delaymatrailtakebacknotice
  396. x: 0
  397. y: 823
  398. width: 300
  399. height: 75 // 减去顶部圆角矩形的高度
  400. color: "#00ffffff"
  401. visible: opendoor
  402. Image {
  403. x: 0
  404. y: 0
  405. width: 75
  406. height: 75
  407. visible: true
  408. source: "qrc:/png/takeback.png"
  409. fillMode: Image.PreserveAspectFit
  410. }
  411. Text {
  412. x: 80
  413. y: 0
  414. width: 220
  415. height: 75
  416. visible: false
  417. text: "等待取还物资......"
  418. font.pixelSize: 30
  419. horizontalAlignment: Text.AlignHCenter
  420. verticalAlignment: Text.AlignVCenter
  421. color: "#ffffff"
  422. }
  423. }
  424. Timer {
  425. interval: 100
  426. running: true
  427. repeat: true
  428. onTriggered: {
  429. if(opendoor == true)
  430. {
  431. if(takebackviewcount > 0)
  432. {
  433. takebackviewcount--;
  434. }
  435. else{
  436. takebackviewcount = 5;
  437. if(delaymatrailtakebacknotice.visible === true)
  438. {
  439. delaymatrailtakebacknotice.visible = false;
  440. }
  441. else{
  442. delaymatrailtakebacknotice.visible = true;
  443. }
  444. }
  445. }
  446. else{
  447. delaymatrailtakebacknotice.visible = false;
  448. }
  449. }
  450. }
  451. function sel_materialtype(idx)
  452. {
  453. var foundItem = null;
  454. for (var i = 0; i < materialsellistModel.count; ++i) {
  455. if (materialsellistModel.get(i).idx === idx) {
  456. foundItem = materialsellistModel.get(i);
  457. foundItem.view = true;
  458. }
  459. else{
  460. materialsellistModel.get(i).view = false;
  461. }
  462. }
  463. materialModel.clear()
  464. var materialname = pConfig.smaterialNameList;
  465. var materialpicture = pConfig.smaterialPictureList;
  466. var materialloanuser = pConfig.smaterialLoanUserList;
  467. var materialloanstate = pConfig.smaterialLoanStateList;
  468. var materialstatus = pConfig.smaterialStatusList;
  469. var materialtype = pConfig.smaterialTypeList;
  470. var userId = pConfig.suserId;
  471. for (var key in materialname)
  472. {
  473. if(foundItem.idx === "ALL")
  474. {
  475. if(materialloanstate[key] === 0)
  476. {
  477. if (materialloanuser[key] === userId)
  478. {
  479. materialModel.append({png:materialpicture[key], name: materialname[key], status: materialstatus[key], rfid: key, color: "#8fffffff", stat: true});
  480. }
  481. else
  482. {
  483. materialModel.append({png:materialpicture[key], name: materialname[key], status: materialstatus[key], rfid: key, color: "#8fffffff", stat: false});
  484. }
  485. }
  486. else
  487. {
  488. materialModel.append({png:materialpicture[key], name: materialname[key], status: materialstatus[key], rfid: key, color: "#00ffffff", stat: false});
  489. }
  490. }
  491. else{
  492. if(foundItem.idx === materialtype[key])
  493. {
  494. if(materialloanstate[key] === 0)
  495. {
  496. if (materialloanuser[key] === userId)
  497. {
  498. materialModel.append({png:materialpicture[key], name: materialname[key], status: materialstatus[key], rfid: key, color: "#8fffffff", stat: true});
  499. }
  500. else
  501. {
  502. materialModel.append({png:materialpicture[key], name: materialname[key], status: materialstatus[key], rfid: key, color: "#8fffffff", stat: false});
  503. }
  504. }
  505. else{
  506. materialModel.append({png:materialpicture[key], name: materialname[key], status: materialstatus[key], rfid: key, color: "#00ffffff", stat: false});
  507. }
  508. }
  509. }
  510. }
  511. }
  512. function lockStat_callback(left, right)
  513. {
  514. if(left === false || right === false)
  515. {
  516. opendoor = true;
  517. if(takebackstat === true)
  518. {
  519. button_openCabinet.visible = false;
  520. signal_takebackstat(true);
  521. }
  522. }
  523. else if(left === true && right === true)
  524. {
  525. opendoor = false;
  526. if(takebackstat === true)
  527. {
  528. // 开始读rfid
  529. startReader();
  530. takebackstat = false;
  531. signal_takebackstat(false);
  532. pConfig.smaterialStock = true;
  533. // button_return.enabled = true;
  534. button_openCabinet.visible = true;
  535. // materialTakeBack.visible = false;
  536. mainScreen.switchViewOffEx();
  537. materialStocktaking.set_userinfo();
  538. materialStocktaking.materiallistclear();
  539. materialStocktaking.visible = true;
  540. mainScreen.resetLogin_timeout();
  541. }
  542. }
  543. }
  544. function slot_updateMaterial()
  545. {
  546. materialsellistModel.clear();
  547. materialModel.clear();
  548. var typecount = pConfig.smaterialTypeCountList;
  549. var typepng = pConfig.smaterialTypePngList;
  550. var idx = 1;
  551. var count = 0;
  552. for (var typekey in typecount)
  553. {
  554. count = count + typecount[typekey];
  555. var viewcount = typekey + "(" + typecount[typekey] + ")";
  556. materialsellistModel.append({idx: typekey, source: typepng[typekey], count: viewcount, view: false});
  557. idx++;
  558. }
  559. materialsellistModel.insert(0, {idx: "ALL", source: "qrc:/png/allsel.png", count: "全部(" + count + ")", view: true});
  560. var materialname = pConfig.smaterialNameList;
  561. var materialpicture = pConfig.smaterialPictureList;
  562. var materialloanuser = pConfig.smaterialLoanUserList;
  563. var materialloanstate = pConfig.smaterialLoanStateList;
  564. var materialstatus = pConfig.smaterialStatusList;
  565. var materialtype = pConfig.smaterialTypeList;
  566. var userId = pConfig.suserId;
  567. for (var key in materialname)
  568. {
  569. if(materialloanstate[key] === 0)
  570. {
  571. if (materialloanuser[key] === userId)
  572. {
  573. materialModel.append({png:materialpicture[key], name: materialname[key], status: materialstatus[key], rfid: key, color: "#8fffffff", stat: true});
  574. }
  575. else
  576. {
  577. materialModel.append({png:materialpicture[key], name: materialname[key], status: materialstatus[key], rfid: key, color: "#8fffffff", stat: false});
  578. }
  579. }
  580. else{
  581. materialModel.append({png:materialpicture[key], name: materialname[key], status: materialstatus[key], rfid: key, color: "#00ffffff", stat: false});
  582. }
  583. }
  584. }
  585. }