DeviceInspectionDialog.ets 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. //设备点检
  2. import ProcessRequest from '../common/util/request/ProcessRequest'
  3. import ProcessDeviceDailyCheck from '../viewmodel/process/ProcessDeviceDailyCheck'
  4. import DictValue from '../viewmodel/DictValue'
  5. import promptAction from '@ohos.promptAction'
  6. import HashMap from '@ohos.util.HashMap'
  7. import RequestParamModel from '../viewmodel/RequestParamModel'
  8. import TimeUtil from '../common/util/TimeUtil'
  9. @CustomDialog
  10. export struct DeviceInspectionDialog {
  11. private scrollerDevice: Scroller = new Scroller()
  12. //查找设备编码
  13. @State queryDeviceNo: string = 'test000'
  14. //当前日期
  15. @State currentDate: string = ''
  16. // 设备点检列表
  17. @Link deviceChecks: ProcessDeviceDailyCheck[]
  18. //选中设备索引
  19. @State selectDeviceIndex: number=-1
  20. // 设备类型(key为数据字典值,value为数据字典标签)
  21. @State deviceTypes: HashMap<string, string> = new HashMap()
  22. deleteIds: string[] = []
  23. @Consume('stationIp') stationIp: string
  24. controller: CustomDialogController
  25. onConfirm: () => void = () => {}
  26. deviceTypeDictCode: string = 'device_type'
  27. async aboutToAppear() {
  28. this.deleteIds = []
  29. let deviceDicts: DictValue[] = await ProcessRequest.get(`/api/v1/sys/dictData/queryByType/${this.deviceTypeDictCode}`)
  30. if (deviceDicts) {
  31. for (const dict of deviceDicts) {
  32. this.deviceTypes.set(dict.dictValue!, dict.dictLabel!);
  33. }
  34. }
  35. this.deviceChecks = await ProcessRequest.post('/api/v1/process/deviceDailyCheck/list', {
  36. stationIp: this.stationIp,
  37. createDate: TimeUtil.getCurrentDate()
  38. } as RequestParamModel)
  39. }
  40. build() {
  41. Column() {
  42. Column() {
  43. Text("设备点检")
  44. .fontColor($r('app.color.FFFFFF'))
  45. .fontSize($r('app.float.fontSize_30'))
  46. }
  47. .height('8%')
  48. .width('100%')
  49. .justifyContent(FlexAlign.Center)
  50. Column() {
  51. Text("扫描设备 ")
  52. .fontColor($r('app.color.FFFFFF'))
  53. .fontSize($r('app.float.fontSize_24'))
  54. Row(){
  55. Row() {
  56. // 左侧二维码图标
  57. Image($r('app.media.material_qr_code'))
  58. .width($r('app.float.virtualSize_32'))
  59. .height($r('app.float.virtualSize_32'))
  60. .fillColor($r('app.color.FFFFFF'))
  61. .objectFit(ImageFit.Contain)
  62. .margin({left:'2%'})
  63. // 扫码输入框
  64. TextInput({text:this.queryDeviceNo, placeholder: '请扫描设备编码' })
  65. .type(InputType.Normal)
  66. .placeholderFont({ size: $r('app.float.fontSize_16') })
  67. .placeholderColor($r('app.color.30FFFFFF'))
  68. .fontSize($r('app.float.fontSize_16'))
  69. .fontColor($r('app.color.FFFFFF'))
  70. .enableKeyboardOnFocus(false)
  71. .onSubmit(async () => {
  72. if (this.deviceChecks) {
  73. for (const element of this.deviceChecks) {
  74. if (element.deviceNo === this.queryDeviceNo) {
  75. promptAction.showToast({
  76. message: `设备今日已点检,无需重复点检!`,
  77. duration: 1500,
  78. bottom: 100
  79. })
  80. return
  81. }
  82. }
  83. }
  84. let check: ProcessDeviceDailyCheck = await ProcessRequest.get(`/api/v1/process/deviceDailyCheck/getServiceLifeByDeviceNo/${this.queryDeviceNo}`)
  85. this.deviceChecks.unshift(check)
  86. })
  87. .onChange((value: string) => {
  88. this.queryDeviceNo = value;
  89. //this.onQueryDeviceCode()
  90. })
  91. }
  92. .height('100%')
  93. .width('65%')
  94. .borderRadius($r('app.float.virtualSize_16'))
  95. .backgroundColor($r('app.color.000000'))
  96. Text(this.currentDate)
  97. .fontColor($r('app.color.FFFFFF'))
  98. .fontSize($r('app.float.fontSize_16'))
  99. .margin({left:'3%'})
  100. }
  101. .height('8%')
  102. .width('50%')
  103. .margin({bottom:'1%',top:'1%'})
  104. List({scroller: this.scrollerDevice }) {
  105. ForEach(this.deviceChecks, (item: ProcessDeviceDailyCheck, index) => {
  106. ListItem() {
  107. Row() {
  108. Column(){
  109. Text(this.deviceTypes && item.deviceType && this.deviceTypes.hasKey(item.deviceType) ? this.deviceTypes.get(item.deviceType) : '')
  110. .fontSize($r('app.float.fontSize_24'))
  111. .fontColor($r('app.color.FFFFFF'))
  112. Text(`名称:${item.deviceName!}`)
  113. .fontSize($r('app.float.fontSize_16'))
  114. .fontColor($r('app.color.FFFFFF'))
  115. .fontWeight(FontWeight.Lighter)
  116. .margin({top:'2%',bottom:'1%'})
  117. Text(`编码:${item.deviceNo!}`)
  118. .fontSize($r('app.float.fontSize_16'))
  119. .fontColor($r('app.color.FFFFFF'))
  120. .fontWeight(FontWeight.Lighter)
  121. }
  122. .width('30%')
  123. .height('100%')
  124. .justifyContent(FlexAlign.Center)
  125. .alignItems(HorizontalAlign.Start)
  126. .margin({right:'16%'})
  127. Column({space:5}){
  128. Text(`计量有效期:`)
  129. .fontSize($r('app.float.fontSize_16'))
  130. .fontColor($r('app.color.FFFFFF'))
  131. .fontWeight(FontWeight.Lighter)
  132. Row(){
  133. Image(item.meteringState! === 1 ? $r('app.media.device_normal') : $r('app.media.device_expire'))
  134. .width($r('app.float.virtualSize_24'))
  135. .height($r('app.float.virtualSize_24'))
  136. .margin({left:'2%'})
  137. Text(item.meteringDate ? `${item.meteringDate}` : '长期有效')
  138. .fontSize($r('app.float.fontSize_16'))
  139. .fontColor(item.meteringState! === 1 ? $r('app.color.30D158') : $r('app.color.FF453A'))
  140. .margin({left:'2%'})
  141. }
  142. .width('65%')
  143. .borderRadius($r('app.float.virtualSize_16'))
  144. .backgroundColor($r('app.color.000000'))
  145. .height('25%')
  146. .alignItems(VerticalAlign.Center)
  147. }
  148. .width('22%')
  149. .height('100%')
  150. .justifyContent(FlexAlign.Center)
  151. .alignItems(HorizontalAlign.Start)
  152. Column({space:5}){
  153. Text(`维保有效期:`)
  154. .fontSize($r('app.float.fontSize_16'))
  155. .fontColor($r('app.color.FFFFFF'))
  156. .fontWeight(FontWeight.Lighter)
  157. Row(){
  158. Image(item.warrantyState! === 1 ? $r('app.media.device_normal') :$r('app.media.device_expire'))
  159. .width($r('app.float.virtualSize_24'))
  160. .height($r('app.float.virtualSize_24'))
  161. .margin({left:'2%'})
  162. Text(item.warrantyPeriod ? `${item.warrantyPeriod}` : '长期有效')
  163. .fontSize($r('app.float.fontSize_16'))
  164. .fontColor(item.warrantyState! === 1 ? $r('app.color.30D158') : $r('app.color.FF453A'))
  165. .margin({left:'2%'})
  166. }
  167. .width('65%')
  168. .borderRadius($r('app.float.virtualSize_16'))
  169. .backgroundColor($r('app.color.000000'))
  170. .height('25%')
  171. .alignItems(VerticalAlign.Center)
  172. }
  173. .width('22%')
  174. .height('100%')
  175. .justifyContent(FlexAlign.Center)
  176. .alignItems(HorizontalAlign.Start)
  177. Column(){
  178. Image($r('app.media.process_delete_seq'))
  179. .width($r('app.float.virtualSize_48'))
  180. .height($r('app.float.virtualSize_48'))
  181. .fillColor($r('app.color.FF453A'))
  182. .onClick(()=>{
  183. let deleteCheck: ProcessDeviceDailyCheck = this.deviceChecks.splice(index, 1)[0];
  184. if (deleteCheck.id) {
  185. this.deleteIds.push(deleteCheck.id)
  186. }
  187. })
  188. }
  189. .width('10%')
  190. .height('100%')
  191. .justifyContent(FlexAlign.Center)
  192. }
  193. .height('90%')
  194. .width('95%')
  195. .justifyContent(FlexAlign.Start)
  196. }
  197. .height('18%')
  198. .width('100%')
  199. .margin({ bottom: 8})
  200. .borderRadius($r('app.float.virtualSize_16'))
  201. .backgroundColor($r('app.color.10FFFFFF'))
  202. })
  203. }.height('82%')
  204. }
  205. .width('96%')
  206. .height('84%')
  207. .alignItems(HorizontalAlign.Start)
  208. .justifyContent(FlexAlign.Start)
  209. .margin({left:'2%',right:'2%'})
  210. Column() {
  211. Divider()
  212. .vertical(false)
  213. .strokeWidth(1)
  214. .color($r('app.color.15FFFFFF'))
  215. Row() {
  216. Row() {
  217. Text('取消')
  218. .fontColor($r('app.color.60FFFFFF'))
  219. .fontSize($r('app.float.fontSize_30'))
  220. }
  221. .justifyContent(FlexAlign.Center)
  222. .width('50%')
  223. .onClick(() => this.controller.close())
  224. Divider()
  225. .vertical(true)
  226. .strokeWidth(1)
  227. .color($r('app.color.15FFFFFF'))
  228. Row() {
  229. Text('确定')
  230. .fontColor($r('app.color.007AFF'))
  231. .fontSize($r('app.float.fontSize_30'))
  232. }
  233. .justifyContent(FlexAlign.Center)
  234. .width('50%')
  235. .onClick(async () => {
  236. if (this.deleteIds && this.deleteIds.length > 0) {
  237. await ProcessRequest.post('/api/v1/process/deviceDailyCheck/batchDel', {
  238. ids: this.deleteIds
  239. } as RequestParamModel)
  240. this.deleteIds = []
  241. }
  242. if (!this.deviceChecks || this.deviceChecks.length <= 0) {
  243. this.controller.close();
  244. return
  245. }
  246. for (const check of this.deviceChecks) {
  247. check.stationIp = this.stationIp
  248. }
  249. await ProcessRequest.post('/api/v1/process/deviceDailyCheck/batchSave', this.deviceChecks)
  250. this.controller.close();
  251. })
  252. }
  253. }
  254. .width('100%')
  255. .height('8%')
  256. }
  257. .height('71%')
  258. .width('62%')
  259. .backgroundColor($r('app.color.2A2A2A'))
  260. .justifyContent(FlexAlign.End)
  261. .alignItems(HorizontalAlign.Start)
  262. .borderColor($r('app.color.000000'))
  263. .borderWidth(1)
  264. .borderRadius($r('app.float.virtualSize_16'))
  265. }
  266. }