MaterialReplace.qml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Layouts
  4. // import com.InteractiveCore 1.0
  5. import com.InteractiveTask 1.0
  6. Item {
  7. id: materialreplace
  8. x: 290
  9. y: 130
  10. width: 1600
  11. height: 920
  12. property bool takebackstat : false
  13. property bool opendoor : false
  14. signal startReader();
  15. signal signal_openLock();
  16. signal signal_takebackstat(bool stat);
  17. onVisibleChanged:
  18. {
  19. if (visible)
  20. {
  21. proThread.moveCursorTo(0, 0);
  22. materialreplace_btn_hand.visible = false;
  23. materialreplace_rect_table_body.visible = false;
  24. materialreplace_text_plan_title.visible = false;
  25. waitPromptBox.show();
  26. // 先刷新数据缓存,然后调用视图刷新
  27. console.log("准备从服务器获取消息(1)");
  28. var taskType = InteractiveTask.TypeMaterialInfoListRefresh;
  29. interactiveCore.appendTask(
  30. taskType, null, ()=>{
  31. console.log("准备赋值model(4)");
  32. var taskType = InteractiveTask.TypeMaterialReplaceRefreshListModel;
  33. interactiveCore.appendTask(
  34. taskType, "0", ()=>{
  35. // 界面显示
  36. console.log("根据model是否为空,确定界面是否显示(6)");
  37. if(materialreplace_modelMaterialInfo.count() === 0)
  38. {
  39. materialreplace_btn_hand.visible = false;
  40. materialreplace_rect_table_body.visible = false;
  41. materialreplace_text_plan_title.visible = true;
  42. }
  43. else
  44. {
  45. materialreplace_btn_hand.visible = true;
  46. materialreplace_rect_table_body.visible = true;
  47. materialreplace_text_plan_title.visible = false;
  48. }
  49. });
  50. waitPromptBox.hide();
  51. });
  52. }
  53. else {
  54. proThread.slot_getMaterial();
  55. }
  56. }
  57. // 标题区域
  58. Text {
  59. id: materialreplace_text_plan_title
  60. x: 0
  61. y: 0
  62. width: 1600
  63. height: 90
  64. text: "当前没有要更换的物资"
  65. font.pixelSize: 30
  66. color: "#d7d7d2"
  67. horizontalAlignment: Text.AlignLeft
  68. verticalAlignment: Text.AlignVCenter
  69. leftPadding: 20 // 添加左边距使文本不紧贴边缘
  70. }
  71. Rectangle {
  72. id: materialreplace_rect_autoreplace
  73. x: 0
  74. y: 823
  75. width: 300
  76. height: 75 // 减去顶部圆角矩形的高度
  77. color: "#00ffffff"
  78. visible: false
  79. Image {
  80. x: 0
  81. y: 0
  82. width: 75
  83. height: 75
  84. visible: true
  85. source: "qrc:/png/takeback.png"
  86. fillMode: Image.PreserveAspectFit
  87. }
  88. Text {
  89. x: 140
  90. y: 0
  91. width: 220
  92. height: 75
  93. visible: true
  94. text: "等待维修更换物资......"
  95. font.pixelSize: 30
  96. horizontalAlignment: Text.AlignHCenter
  97. verticalAlignment: Text.AlignVCenter
  98. color: "#ffffff"
  99. }
  100. }
  101. // 手动更换
  102. Button {
  103. id: materialreplace_btn_hand
  104. x: 928
  105. y: 835
  106. width: 192
  107. height: 75
  108. background: Rectangle {
  109. color: "#ff9900"
  110. radius: 10 // 可选,设置圆角
  111. }
  112. text: qsTr("手动操作")
  113. font.pixelSize: 30
  114. palette.buttonText: "white" // 设置字体颜色为绿色
  115. Connections {
  116. target: materialreplace_btn_hand
  117. onClicked: {
  118. infoPromptBox.title("提示");
  119. infoPromptBox.message("确定要手动操作吗?");
  120. infoPromptBox.button_clear();
  121. infoPromptBox.button_push("red", "取消", null, null);
  122. infoPromptBox.button_push(
  123. "#055eb3", "确定", ()=>{
  124. // materialreplace_rect_table_hand.visible = true;
  125. materialManualReplace.visible = true;
  126. materialReplace.visible = false;
  127. }, null);
  128. infoPromptBox.show();
  129. }
  130. }
  131. }
  132. // 自动更换
  133. Button {
  134. id: materialreplace_btn_auto
  135. x: 1168
  136. y: 835
  137. width: 192
  138. height: 75
  139. background: Rectangle {
  140. color: "#ff0000"
  141. radius: 10
  142. }
  143. text: qsTr("自动更换")
  144. font.pixelSize: 30
  145. palette.buttonText: "white" // 设置字体颜色为绿色
  146. Connections {
  147. target: materialreplace_btn_auto
  148. onClicked: {
  149. // materialreplace_dialog_autosubmit_prompt.open();
  150. infoPromptBox.title("提示");
  151. infoPromptBox.message("确定要自动更换物资吗?");
  152. infoPromptBox.button_clear();
  153. infoPromptBox.button_push("red", "取消", null, null);
  154. infoPromptBox.button_push(
  155. "#055eb3", "确定", ()=>{
  156. materialreplace_rect_autoreplace.visible = true;
  157. takebackstat = true;
  158. pConfig.mtakebackstat = true;
  159. pConfig.imaterworkstat = 2;
  160. signal_openLock();
  161. }, null);
  162. infoPromptBox.show();
  163. }
  164. }
  165. }
  166. // 返回按钮
  167. Button {
  168. id: materialreplace_btn_return
  169. x: 1408
  170. y: 835
  171. width: 192
  172. height: 75
  173. background: Rectangle {
  174. color: "#055eb3"
  175. radius: 10
  176. }
  177. text: qsTr("返回")
  178. font.pixelSize: 30
  179. palette.buttonText: "white" // 设置字体颜色为绿色
  180. Connections {
  181. target: materialreplace_btn_return
  182. onClicked: {
  183. if (pConfig.sopenDoor)
  184. {
  185. infoPromptBox.title("提示");
  186. infoPromptBox.message("柜门打开时不允许返回");
  187. infoPromptBox.button_clear();
  188. infoPromptBox.button_push("#055eb3", "确定", null, null);
  189. infoPromptBox.show();
  190. }
  191. else
  192. {
  193. materialReplace.visible = false;
  194. materialSelmodel.visible = true;
  195. mainScreen.resetLogin_timeout();
  196. }
  197. }
  198. }
  199. }
  200. // 主体表格
  201. Rectangle {
  202. id: materialreplace_rect_table_body
  203. width: 1600
  204. height: 800
  205. color: "#272b7ae9"
  206. radius: 20
  207. clip: true
  208. visible: true
  209. Rectangle {
  210. x: 50
  211. y: 100
  212. width: parent.width - 100
  213. height: parent.height - 100
  214. clip: true
  215. color: "#002b7ae9"
  216. GridView {
  217. width: parent.width
  218. height: parent.height
  219. cellWidth: 250 // 每个单元格的宽度,这里是平均分配宽度给5列
  220. cellHeight: 350 // 每个单元格的高度
  221. model: materialreplace_modelMaterialInfo
  222. delegate: Rectangle{
  223. width: 250
  224. height: 350
  225. color: "#00ffffff"
  226. Rectangle {
  227. x: 25
  228. y: 25
  229. width: 200
  230. height: 300
  231. color: "#8fffffff"
  232. Image {
  233. x: 25
  234. y: 25
  235. width: 150
  236. height: 150
  237. visible: true
  238. source: model.materialsTypePicture
  239. fillMode: Image.PreserveAspectFit
  240. }
  241. Text {
  242. x: 0
  243. y: 185
  244. width: parent.width
  245. height: 50
  246. visible: true
  247. text: model.materialsName
  248. font.pixelSize: 30
  249. horizontalAlignment: Text.AlignHCenter
  250. verticalAlignment: Text.AlignVCenter
  251. color: "#ffffff"
  252. }
  253. Text {
  254. x: 0
  255. y: 250
  256. width: parent.width
  257. height: 25
  258. visible: true
  259. text: model.materialsRfid
  260. font.pixelSize: 12
  261. horizontalAlignment: Text.AlignHCenter
  262. verticalAlignment: Text.AlignVCenter
  263. color: "#ffffff"
  264. }
  265. Rectangle {
  266. x: 25
  267. y: 125
  268. width: 150
  269. height: 50
  270. color: {
  271. if (model.status === "0") return "#00ff00"; // 正常 - 绿色
  272. if (model.status === "1") return "#ff0000"; // 损坏 - 红色
  273. if (model.status === "2") return "#ff9900"; // 过期 - 橙色
  274. if (model.status === "3") return "#ff9900"; // 放错柜子 - 橙色
  275. return "gray"; // 默认颜色
  276. }
  277. visible: {
  278. return model.status !== "0";
  279. }
  280. Text {
  281. anchors.centerIn: parent
  282. // text: "待还"
  283. text:{
  284. if (model.status === "0") return "正常";
  285. if (model.status === "1") return "损坏";
  286. if (model.status === "2") return "过期";
  287. if (model.status === "3") return "放错柜子";
  288. return "未知状态"; // 默认值
  289. }
  290. font.pixelSize: 30
  291. horizontalAlignment: Text.AlignHCenter
  292. verticalAlignment: Text.AlignVCenter
  293. color: "#ffffff"
  294. }
  295. }
  296. }
  297. }
  298. }
  299. }
  300. // 表格头
  301. Rectangle {
  302. id: materialreplace_rect_table_head
  303. width: 1600
  304. height: 100 // 减去顶部圆角矩形的高度
  305. radius: 20
  306. clip: true
  307. color: "#8f2b7ae9"
  308. Grid {
  309. x: 50
  310. y: 0
  311. width: parent.width - 150
  312. height: parent.height
  313. visible: true
  314. verticalItemAlignment: Grid.AlignVCenter
  315. horizontalItemAlignment: Grid.AlignHCenter
  316. columns: 5
  317. spacing: 20
  318. Repeater {
  319. model: materialreplace_modelMaterialType
  320. delegate: Rectangle{
  321. width: 250
  322. height: 100
  323. color: "#00ffffff"
  324. Image {
  325. x: 0
  326. y: 25
  327. width: 50
  328. height: 50
  329. visible: true
  330. source: model.materialsTypeIcon
  331. fillMode: Image.PreserveAspectFit
  332. }
  333. Text {
  334. x: 55
  335. y: 25
  336. width: parent.width - 55
  337. height: 50
  338. visible: true
  339. text: model.materialsTypeName + "(" + model.materialsTypeError + ")"
  340. font.pixelSize: 25
  341. horizontalAlignment: Text.AlignHCenter
  342. verticalAlignment: Text.AlignVCenter
  343. color: "#ffffff"
  344. }
  345. Canvas {
  346. anchors.fill: parent
  347. visible: model.materialsTypeSelected
  348. onPaint: {
  349. var ctx = getContext("2d");
  350. ctx.lineWidth = 10; // 设置线的宽度
  351. ctx.strokeStyle = "skyblue"; // 设置线的颜色为白色
  352. ctx.beginPath();
  353. ctx.moveTo(0, 90); // 直线的起点
  354. ctx.lineTo(parent.width, 90); // 直线的终点
  355. ctx.stroke(); // 绘制直线
  356. }
  357. }
  358. MouseArea {
  359. anchors.fill: parent // 让MouseArea覆盖整个Image区域
  360. onClicked: {
  361. var taskType = InteractiveTask.TypeMaterialReplaceRefreshListModel;
  362. interactiveCore.appendTask(taskType, model.materialsTypeId, null);
  363. mainScreen.resetLogin_timeout();
  364. }
  365. }
  366. }
  367. }
  368. }
  369. Image {
  370. id: viewImage
  371. x: parent.width - 80
  372. y: 20
  373. width: 60
  374. height: 60
  375. source: "qrc:/png/right.png"
  376. fillMode: Image.PreserveAspectFit
  377. MouseArea {
  378. anchors.fill: parent // 让MouseArea覆盖整个Image区域
  379. onClicked: {
  380. var bIsUnfolding = (materialreplace_rect_table_head.height === 100 ? true : false);
  381. if(bIsUnfolding)
  382. {
  383. viewImage.rotation = 90;
  384. materialreplace_rect_table_head.height = 600;
  385. }
  386. else
  387. {
  388. viewImage.rotation = 0;
  389. materialreplace_rect_table_head.height = 100;
  390. }
  391. mainScreen.resetLogin_timeout();
  392. }
  393. }
  394. }
  395. }
  396. }
  397. function lockStat_callback(left, right)
  398. {
  399. if (pConfig.imaterworkstat === 2)
  400. {
  401. if(left === false || right === false)
  402. {
  403. opendoor = true;
  404. if(takebackstat === true)
  405. {
  406. signal_takebackstat(true);
  407. materialreplace_btn_hand.visible = false;
  408. materialreplace_btn_auto.visible = false;
  409. // materialreplace_btn_return.enabled = false;
  410. }
  411. }
  412. else if(left === true && right === true)
  413. {
  414. opendoor = false;
  415. if(takebackstat === true)
  416. {
  417. startReader();
  418. takebackstat = false;
  419. signal_takebackstat(false);
  420. pConfig.smaterialStock = true;
  421. materialreplace_btn_hand.visible = true;
  422. materialreplace_btn_auto.visible = true;
  423. // materialreplace_btn_return.enabled = true;
  424. // 开始读rfid
  425. // materialReplace.visible = false;
  426. mainScreen.switchViewOffEx();
  427. materialStocktaking.set_userinfo();
  428. materialStocktaking.materiallistclear();
  429. materialStocktaking.visible = true;
  430. materialreplace_rect_autoreplace.visible = false;
  431. mainScreen.resetLogin_timeout();
  432. }
  433. }
  434. }
  435. }
  436. function slot_requestertakebackMaterial()
  437. {
  438. }
  439. function slot_updateMaterialHand()
  440. {
  441. var taskType = InteractiveTask.TypeMaterialReplaceRefreshListModel;
  442. interactiveCore.appendTask(taskType, "-1", null);
  443. }
  444. // 刷新 list 视图
  445. function refreshListModel()
  446. {
  447. // 先刷新数据缓存,然后调用视图刷新
  448. var taskType = InteractiveTask.TypeMaterialReplaceRefreshListModel;
  449. interactiveCore.appendTask(taskType, "0", null);
  450. }
  451. }