ChemicalLabelingActivity.kt 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  1. package xn.hxp.ui.warehousing
  2. import android.os.CountDownTimer
  3. import android.os.Handler
  4. import android.os.Looper
  5. import android.view.View
  6. import android.widget.AdapterView
  7. import androidx.core.content.ContextCompat
  8. import androidx.recyclerview.widget.LinearLayoutManager
  9. import androidx.viewbinding.ViewBinding
  10. import com.blankj.utilcode.util.LogUtils
  11. import com.bumptech.glide.Glide
  12. import com.bumptech.glide.load.engine.DiskCacheStrategy
  13. import com.bumptech.glide.request.RequestOptions
  14. import com.rc.core.ui.activity.BaseActivity
  15. import com.rc.httpcore.HttpConfig
  16. import com.rc.httpcore.bean.LockVoListBean
  17. import com.rc.httpcore.bean.ReturnDetailsBean
  18. import com.rc.httpcore.client.ApiRepository
  19. import com.rc.httpcore.client.HttpTool
  20. import com.sun.jna.Pointer
  21. import xn.hxp.R
  22. import xn.hxp.app.ChemicalApp
  23. import xn.hxp.comm.Constants
  24. import xn.hxp.databinding.ActivityChemicalLabelingBinding
  25. import xn.hxp.ui.PrintBean
  26. import xn.hxp.ui.adapter.ChemicalLabelingAdapter
  27. import xn.hxp.ui.adapter.CustomSpinnerTwoAdapter
  28. import xn.hxp.ui.verify.TwoVerificationActivity
  29. import xn.hxp.utils.AudioPlayer
  30. import xn.hxp.utils.HandlerUtil
  31. import xn.hxp.utils.PrintTool
  32. import xn.hxp.utils.SharedPreferencesHelper
  33. import xn.hxp.utils.TimeUpdater
  34. import xn.hxp.utils.UiManager
  35. import xn.hxp.weidith.AirBottleDialog
  36. import xn.hxp.weidith.AirBottleNewDialog
  37. import xn.hxp.weidith.CustomDialog
  38. import xn.hxp.weidith.StorageDialog
  39. import xn.hxp.weidith.TextTool
  40. //标签列表
  41. class ChemicalLabelingActivity : BaseActivity() {
  42. private val mAdapter by lazy { ChemicalLabelingAdapter(this) }
  43. private lateinit var timeUpdater: TimeUpdater
  44. private lateinit var mData: ReturnDetailsBean
  45. private var mCabinetId: String? = null
  46. private var mDoorId: String? = null
  47. private val sPrinDate: MutableList<String> = mutableListOf()
  48. private var mCabinetLockVoList: List<LockVoListBean>? = null //柜锁会又多个
  49. private var mLockStr = ArrayList<String>() // 需要打开得柜锁数量
  50. private val handlerUtil = HandlerUtil.getInstance()
  51. private var mPages = 1 //总页码
  52. private var mDataPage = -1 //返回得总条数
  53. private var page = 1
  54. private var pageSize = 10
  55. private var mPosition = 0
  56. private var mAdIndex = -1
  57. var h = Pointer.NULL
  58. lateinit var viewBinding: ActivityChemicalLabelingBinding
  59. override fun setViewBinding(): ViewBinding {
  60. viewBinding = ActivityChemicalLabelingBinding.inflate(layoutInflater)
  61. return viewBinding
  62. }
  63. override fun onInit() {
  64. val sPinner = viewBinding.sPinner
  65. viewBinding.rvInventory.layoutManager = LinearLayoutManager(this)
  66. viewBinding.rvInventory.adapter = mAdapter
  67. viewBinding.tvReturn.text = "返回${ChemicalApp.confs!!.backTime}s"
  68. viewBinding.tvOutLogin.setOnClickListener {
  69. HttpTool.logout()
  70. }
  71. viewBinding.tvReturn.setOnClickListener {
  72. finish()
  73. }
  74. mAdapter.setOnItemClickListener { adapter, view, position ->
  75. mAdapter.data.forEach { it.isType = false }
  76. mAdapter.data[position].isType = true
  77. mAdapter.notifyDataSetChanged()
  78. getIdDate("${mAdapter.data[position].id}")
  79. mAdIndex = position
  80. }
  81. viewBinding.cabinetName.setOnClickListener {
  82. getCabinet()
  83. }
  84. viewBinding.reSou.setOnClickListener {
  85. page = 1
  86. labelingData()
  87. }
  88. viewBinding.resetting.setOnClickListener {
  89. page = 1
  90. mCabinetId = null
  91. mDoorId = null
  92. viewBinding.edCont.setText("")
  93. viewBinding.cabinetName.text = "化学品柜"
  94. sPinner.setSelection(0)
  95. labelingData()
  96. }
  97. viewBinding.reLabel.setOnClickListener {
  98. //补打标签
  99. val print = PrintBean()
  100. print.tag = mData.tagCode //化学品编码
  101. print.wxCode = mData.wxCode!! //化学品编码
  102. print.name = mData.chemicalName!! //化学品名称
  103. if (mData.casNum != null) {
  104. print.casNo = mData.casNum!! //cas号
  105. } else {
  106. print.casNo = ""
  107. }
  108. // if (mDataBean.topicGroup) {
  109. // print.person = mDataBean.topicGroupName //归属人
  110. // } else {
  111. // print.person = mDataBean.applyUserName //归属人
  112. // }
  113. print.person = mData.belongName
  114. //管控 1 非管控 2
  115. if (mData.chemicalLevel == 1) {
  116. print.level = "管控"
  117. } else {
  118. print.level = "非管控"
  119. }
  120. //
  121. print.types = "${mData.chemicalCategoryName}"
  122. PrintTool.INSTANCE.print(mData.isGr, mData.belongType == 2, print)
  123. }
  124. viewBinding.replaceLabel.setOnClickListener {
  125. if (viewBinding.replaceLabel.text.toString().startsWith("更")) {
  126. val airBottleNewDialog =
  127. AirBottleNewDialog(this, mData.rfidCode, object : AirBottleNewDialog.ILintDate {
  128. override fun onLintDate(cont: String) {
  129. if (mData.rfidCode!! != cont) {
  130. updateRfid(mData.stockDetailsId, cont)
  131. } else {
  132. showToast("更换的标签不能重复")
  133. }
  134. }
  135. })
  136. airBottleNewDialog.show()
  137. } else {
  138. //RFID打印
  139. var airBottleDialog = AirBottleDialog(this, object : AirBottleDialog.ILintDate {
  140. override fun onLintDate(cont: String) {
  141. if (cont.isNotEmpty()) {
  142. updateRfid(mData.stockDetailsId, cont)
  143. }
  144. }
  145. })
  146. airBottleDialog.show()
  147. }
  148. }
  149. viewBinding.openLok.setOnClickListener {
  150. val toString = viewBinding.openLok.text.toString()
  151. if (toString == "打开柜门") {
  152. //打开柜门
  153. if (mData.verify) {
  154. // //跳转认证
  155. // //需要双人认证
  156. // val map = mutableMapOf<String, Any>()
  157. // //当前 管控类型
  158. // map["chemicalLevel"] = mData.chemicalLevel //管控类型
  159. // map["doorId"] = "${mData.doorId}" //柜子id
  160. // map["stockId"] = "${mData.chemicalId}" //化学品id
  161. // map["mTag"] = 1
  162. // UiManager.switcher(
  163. // this,
  164. // map,
  165. // SwipeCodeTwoActivity::class.java,
  166. // Constants.REQUEST_CODE
  167. // )
  168. //需要双人认证
  169. if (ChemicalApp.confs!!.verifyType.length == 1) {
  170. val map = mutableMapOf<String, Any>()
  171. map["chemicalLevel"] = mData.chemicalLevel //管控类型
  172. // map["doorId"] = "$mDoorId" //柜子id
  173. map["doorId"] = "${mData.doorId}" //柜子id
  174. map["mTag"] = 1
  175. when (ChemicalApp.confs!!.verifyType) {
  176. "1" -> {//人脸
  177. map["mVerTyps"] = 1
  178. }
  179. "2" -> {//刷卡
  180. map["mVerTyps"] = 2
  181. }
  182. "3" -> {//扫码
  183. map["mVerTyps"] = 3
  184. }
  185. }
  186. UiManager.switcher(
  187. this,
  188. map,
  189. TwoVerificationActivity::class.java
  190. )
  191. } else {
  192. //多类型双人认证
  193. verifyChecking()
  194. }
  195. } else {
  196. if (mCabinetLockVoList != null && mCabinetLockVoList!!.size > 0) {
  197. mLockStr.clear()
  198. mCabinetLockVoList!!.forEach { it ->
  199. when (it.unlockingMethod) {
  200. 2 -> { //智能锁
  201. mLockStr.add("${it.lockNum}")
  202. }
  203. }
  204. }
  205. if (mLockStr != null && mLockStr.size > 0) {
  206. openLock(mLockStr)
  207. }
  208. } else {
  209. //没有锁 不需要开锁
  210. AudioPlayer.getInstance().play(R.raw.gui_men_yi_kai_qu_chu_hxp)
  211. }
  212. // //不需要认证
  213. // if (mLockStr != null && mLockStr.size > 0) {
  214. // openLock(mLockStr)
  215. // } else {
  216. // //没有锁 不需要开锁
  217. // AudioPlayer.getInstance().play(R.raw.quchuhuaxuepin)
  218. // }
  219. }
  220. } else {
  221. //不需要认证
  222. if (mCabinetLockVoList != null && mCabinetLockVoList!!.size > 0) {
  223. mLockStr.clear()
  224. mCabinetLockVoList!!.forEach { it ->
  225. when (it.unlockingMethod) {
  226. 2 -> { //智能锁
  227. mLockStr.add("${it.lockNum}")
  228. }
  229. }
  230. }
  231. if (mLockStr != null && mLockStr.size > 0) {
  232. openLock(mLockStr)
  233. }
  234. } else {
  235. //没有锁 不需要开锁
  236. AudioPlayer.getInstance().play(R.raw.gui_men_yi_kai_qu_chu_hxp)
  237. }
  238. }
  239. }
  240. sPrinDate.add("级别")
  241. sPrinDate.add("管控")
  242. sPrinDate.add("非管控")
  243. LogUtils.i("=======当前级别条数${sPrinDate.size}")
  244. val customAdapter = CustomSpinnerTwoAdapter(this, sPrinDate!!)
  245. sPinner.adapter = customAdapter
  246. sPinner.setSelection(0)
  247. sPinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
  248. override fun onItemSelected(
  249. parent: AdapterView<*>?,
  250. view: View?,
  251. position: Int,
  252. id: Long
  253. ) {
  254. // 当用户选择某一项时被调用
  255. LogUtils.i("=======当前选择下标 ${sPrinDate!![position]}")
  256. mPosition = position
  257. // 在这里可以使用 selectedPosition 来执行相应的操作
  258. }
  259. override fun onNothingSelected(parent: AdapterView<*>?) {
  260. // 当没有任何项被选择时被调用
  261. LogUtils.i("=======DUOC")
  262. }
  263. }
  264. //获取列表信息
  265. labelingData()
  266. viewBinding.butUpper.setOnClickListener {
  267. //上一页
  268. if (mDataPage != 0) {
  269. if (page != 1) {
  270. page--
  271. labelingData()
  272. }
  273. }
  274. }
  275. viewBinding.butNext.setOnClickListener {
  276. //下一页
  277. if (mDataPage != 0) {
  278. if (mDataPage != page) {
  279. page++
  280. labelingData()
  281. }
  282. }
  283. }
  284. val handler = Handler(Looper.getMainLooper())
  285. timeUpdater = TimeUpdater(handler) { currentTime ->
  286. viewBinding.nowTime.text = "$currentTime"
  287. }
  288. // 启动定时更新
  289. timeUpdater.startUpdating()
  290. viewBinding.tvName.text = ChemicalApp.userData!!.userName
  291. val imageView = viewBinding.imageName
  292. // 使用 Glide 加载网络图片
  293. Glide.with(this)
  294. .load("${HttpConfig.API_BASE_IMG_URL}${ChemicalApp.userData!!.avatar}")
  295. .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
  296. .into(imageView)
  297. // 使用 Glide 加载网络图片
  298. viewBinding.deptName.text = "${ChemicalApp.confs!!.deptName}-${ChemicalApp.confs!!.roomNum}"
  299. Glide.with(this)
  300. .load("${HttpConfig.API_BASE_IMG_URL}${ChemicalApp.confs!!.circularLogo}")
  301. .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
  302. .into(viewBinding.image)
  303. }
  304. override fun onBackPressed() {
  305. super.onBackPressed()
  306. finish()
  307. }
  308. override fun cdTime(cd: Int) {
  309. viewBinding.tvReturn.text = "返回${cd}s"
  310. }
  311. override fun onResume() {
  312. super.onResume()
  313. try {
  314. if (Constants.AUTHENTICATION) {
  315. if (mCabinetLockVoList != null && mCabinetLockVoList!!.size > 0) {
  316. mLockStr.clear()
  317. mCabinetLockVoList!!.forEach { it ->
  318. when (it.unlockingMethod) {
  319. 2 -> { //智能锁
  320. mLockStr.add("${it.lockNum}")
  321. }
  322. }
  323. }
  324. if (mLockStr != null && mLockStr.size > 0) {
  325. openLock(mLockStr)
  326. }
  327. } else {
  328. //没有锁 不需要开锁
  329. AudioPlayer.getInstance().play(R.raw.gui_men_yi_kai_qu_chu_hxp)
  330. }
  331. Constants.AUTHENTICATION = false
  332. }
  333. } catch (e: Exception) {
  334. Constants.AUTHENTICATION = false
  335. }
  336. }
  337. //验证方式
  338. private fun verifyChecking() {
  339. val map = mutableMapOf<String, Any>()
  340. map["chemicalLevel"] = mData.chemicalLevel //管控类型
  341. map["doorId"] = "${mData.doorId}" //柜子id
  342. map["mTag"] = 1
  343. map["mVerTyps"] = 0
  344. if (ChemicalApp.confs!!.verifyType == "1,2" || ChemicalApp.confs!!.verifyType == "2,1") {
  345. //人脸+刷卡
  346. map["hides"] = 1
  347. // UiManager.switcher(this, map, TwoVerificationActivity::class.java)
  348. } else if (ChemicalApp.confs!!.verifyType == "1,3" || ChemicalApp.confs!!.verifyType == "3,1") {
  349. //人脸+扫码
  350. map["hides"] = 2
  351. // UiManager.switcher(this, map, TwoVerificationActivity::class.java)
  352. } else if (ChemicalApp.confs!!.verifyType == "2,3" || ChemicalApp.confs!!.verifyType == "3,2") {
  353. map["hides"] = 3
  354. // UiManager.switcher(
  355. // this,
  356. // map,
  357. // TwoVerificationActivity::class.java,
  358. // Constants.REQUEST_CODE
  359. // )
  360. } else {
  361. //人脸+刷卡+扫码
  362. map["hides"] = 4
  363. // UiManager.switcher(this, map, TwoVerificationActivity::class.java)
  364. }
  365. UiManager.switcher(
  366. this,
  367. map,
  368. TwoVerificationActivity::class.java,
  369. Constants.REQUEST_CODE
  370. )
  371. }
  372. // override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
  373. // super.onActivityResult(requestCode, resultCode, data)
  374. // if (requestCode == Constants.REQUEST_CODE && resultCode == Activity.RESULT_OK) {
  375. // val value = data?.getBooleanExtra("isLogin", false) // 获取返回的参数
  376. // if (value == true) {
  377. // //1无锁,2是智能锁,3是钥匙柜
  378. // when (mData.unlockingMethod) {
  379. // 1 -> {
  380. // //1无锁
  381. //
  382. // }
  383. // 2 -> {
  384. // //2是智能锁
  385. // openLock()
  386. // }
  387. // 3 -> {
  388. // //是钥匙柜
  389. //
  390. // }
  391. // }
  392. // } else {
  393. // showToast("认证失败!!")
  394. // }
  395. // }
  396. // }
  397. private fun updateRfid(
  398. ids: String,
  399. rfid: String
  400. ) {
  401. showLoading("操作中...")
  402. val disposable = ApiRepository.updateRfid(ids, rfid).subscribe({ data ->
  403. dismissLoading()
  404. customDialogView(1, "更换成功")
  405. //补打标签
  406. val print = PrintBean()
  407. print.tag = mData.tagCode //化学品编码
  408. print.wxCode = mData.wxCode!! //化学品编码
  409. print.name = mData.chemicalName!! //化学品名称
  410. if (mData.casNum != null) {
  411. print.casNo = mData.casNum!! //cas号
  412. } else {
  413. print.casNo = ""
  414. }
  415. // if (mDataBean.topicGroup) {
  416. // print.person = mDataBean.topicGroupName //归属人
  417. // } else {
  418. // print.person = mDataBean.applyUserName //归属人
  419. // }
  420. print.person = mData.belongName
  421. //管控 1 非管控 2
  422. if (mData.chemicalLevel == 1) {
  423. print.level = "管控"
  424. } else {
  425. print.level = "非管控"
  426. }
  427. //
  428. print.types = "${mData.chemicalCategoryName}"
  429. PrintTool.INSTANCE.print(mData.isGr, mData.belongType == 2, print)
  430. mAdapter.data[mAdIndex].rfidCode = rfid
  431. mAdapter.notifyItemChanged(mAdIndex)
  432. }, { throwable ->
  433. dismissLoading()
  434. showNetError(throwable)
  435. })
  436. addDisposable(disposable)
  437. }
  438. /**
  439. * 0 没有图标 1 绿色(成功) 2红色(失败)
  440. * 失败或者成功的弹框
  441. */
  442. private fun customDialogView(types: Int, msg: String) {
  443. if (!this.isFinishing && !this.isDestroyed) {
  444. val customDialog = CustomDialog(this, types, msg)
  445. customDialog.show()
  446. }
  447. }
  448. private fun labelingData() {
  449. showLoading("查询中...")
  450. val map = mutableMapOf<String, Any>()
  451. map["subId"] = "${ChemicalApp.subjectId}"
  452. if (mPosition == 1 || mPosition == 2) {
  453. map["chemicalLevel"] = "$mPosition"
  454. }
  455. // map["chemicalLevel"] = ""
  456. if (mCabinetId != null) {
  457. map["cabinetId"] = mCabinetId!!
  458. }
  459. if (mDoorId != null) {
  460. map["doorId"] = mDoorId!!
  461. }
  462. val toString = viewBinding.edCont.text.toString()
  463. if (toString.isNotEmpty()) {
  464. map["searchValue"] = toString
  465. }
  466. map["page"] = "$page"
  467. map["pageSize"] = "$pageSize"
  468. val disposable = ApiRepository.tagDetailsList(map)
  469. .subscribe({ data ->
  470. dismissLoading()
  471. LogUtils.i("====列表==成功")
  472. mDataPage = data.pages //总页
  473. if (mAdapter.data != null) {
  474. mAdapter.data.clear()
  475. mAdapter.notifyDataSetChanged()
  476. initPagesView(data.pages)
  477. }
  478. if (data.pages != 0) {
  479. if (data.pages > 1 && data.current > 1) {
  480. //当前需要更新页码
  481. upPagesView(data.pages, data.current)
  482. mAdapter.setList(data.records.toMutableList())
  483. } else {
  484. mAdapter.setNewInstance(data.records.toMutableList())
  485. initPagesView(data.pages)
  486. }
  487. }
  488. }, { throwable ->
  489. dismissLoading()
  490. showNetError(throwable)
  491. LogUtils.i("====列表==失败")
  492. })
  493. addDisposable(disposable)
  494. }
  495. /**
  496. * 总页码 当前页 初始化
  497. */
  498. private fun initPagesView(pages: Int) {
  499. mPages = pages
  500. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_page)
  501. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  502. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  503. viewBinding.one.setTextColor(ContextCompat.getColor(this, R.color.white))
  504. viewBinding.two.setTextColor(ContextCompat.getColor(this, R.color.black))
  505. when (pages) {
  506. 1 -> {
  507. viewBinding.one.visibility = View.VISIBLE
  508. }
  509. 2 -> {
  510. viewBinding.two.visibility = View.VISIBLE
  511. }
  512. 3 -> {
  513. viewBinding.two.visibility = View.VISIBLE
  514. viewBinding.three.visibility = View.VISIBLE
  515. }
  516. else -> {
  517. viewBinding.two.visibility = View.VISIBLE
  518. viewBinding.three.visibility = View.VISIBLE
  519. viewBinding.drop.visibility = View.VISIBLE
  520. viewBinding.many.visibility = View.VISIBLE
  521. viewBinding.many.text = "$pages"
  522. }
  523. }
  524. if (pages == 1 || pages == 0) {
  525. viewBinding.two.visibility = View.GONE
  526. viewBinding.three.visibility = View.GONE
  527. viewBinding.many.visibility = View.GONE
  528. viewBinding.drop.visibility = View.GONE
  529. }
  530. if (pages < 4) {
  531. when (pages) {
  532. 1 -> {
  533. viewBinding.two.visibility = View.GONE
  534. viewBinding.three.visibility = View.GONE
  535. viewBinding.many.visibility = View.GONE
  536. viewBinding.drop.visibility = View.GONE
  537. }
  538. 2 -> {
  539. viewBinding.three.visibility = View.GONE
  540. viewBinding.many.visibility = View.GONE
  541. viewBinding.drop.visibility = View.GONE
  542. }
  543. 3 -> {
  544. viewBinding.many.visibility = View.GONE
  545. viewBinding.drop.visibility = View.GONE
  546. }
  547. }
  548. }
  549. }
  550. //更新页码
  551. private fun upPagesView(pages: Int, current: Int) {
  552. LogUtils.i("======2")
  553. if (pages < 4) {
  554. // viewBinding.one.visibility = View.VISIBLE
  555. when (pages) {
  556. 1 -> {
  557. viewBinding.two.visibility = View.GONE
  558. viewBinding.three.visibility = View.GONE
  559. viewBinding.many.visibility = View.GONE
  560. viewBinding.drop.visibility = View.GONE
  561. }
  562. 2 -> {
  563. viewBinding.three.visibility = View.GONE
  564. viewBinding.many.visibility = View.GONE
  565. viewBinding.drop.visibility = View.GONE
  566. }
  567. 3 -> {
  568. viewBinding.many.visibility = View.GONE
  569. viewBinding.drop.visibility = View.GONE
  570. }
  571. }
  572. when (current) {
  573. 1 -> {
  574. viewBinding.one.setTextColor(
  575. ContextCompat.getColor(
  576. this,
  577. R.color.white
  578. )
  579. )
  580. viewBinding.two.setTextColor(
  581. ContextCompat.getColor(
  582. this,
  583. R.color.black
  584. )
  585. )
  586. viewBinding.three.setTextColor(
  587. ContextCompat.getColor(
  588. this,
  589. R.color.black
  590. )
  591. )
  592. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_page)
  593. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  594. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  595. }
  596. 2 -> {
  597. // viewBinding.two.visibility = View.VISIBLE
  598. viewBinding.one.setTextColor(
  599. ContextCompat.getColor(
  600. this,
  601. R.color.black
  602. )
  603. )
  604. viewBinding.two.setTextColor(
  605. ContextCompat.getColor(
  606. this,
  607. R.color.white
  608. )
  609. )
  610. viewBinding.three.setTextColor(
  611. ContextCompat.getColor(
  612. this,
  613. R.color.black
  614. )
  615. )
  616. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  617. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_page)
  618. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  619. }
  620. 3 -> {
  621. // viewBinding.three.visibility = View.VISIBLE
  622. viewBinding.one.setTextColor(
  623. ContextCompat.getColor(
  624. this,
  625. R.color.black
  626. )
  627. )
  628. viewBinding.two.setTextColor(
  629. ContextCompat.getColor(
  630. this,
  631. R.color.black
  632. )
  633. )
  634. viewBinding.three.setTextColor(
  635. ContextCompat.getColor(
  636. this,
  637. R.color.white
  638. )
  639. )
  640. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  641. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  642. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_page)
  643. }
  644. }
  645. } else {
  646. // viewBinding.many.visibility = View.VISIBLE
  647. viewBinding.three.text = "3"
  648. when (current) {
  649. 1 -> {
  650. viewBinding.one.setTextColor(
  651. ContextCompat.getColor(
  652. this,
  653. R.color.white
  654. )
  655. )
  656. viewBinding.two.setTextColor(
  657. ContextCompat.getColor(
  658. this,
  659. R.color.black
  660. )
  661. )
  662. viewBinding.three.setTextColor(
  663. ContextCompat.getColor(
  664. this,
  665. R.color.black
  666. )
  667. )
  668. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_page)
  669. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  670. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  671. }
  672. 2 -> {
  673. viewBinding.one.setTextColor(
  674. ContextCompat.getColor(
  675. this,
  676. R.color.black
  677. )
  678. )
  679. viewBinding.two.setTextColor(
  680. ContextCompat.getColor(
  681. this,
  682. R.color.white
  683. )
  684. )
  685. viewBinding.three.setTextColor(
  686. ContextCompat.getColor(
  687. this,
  688. R.color.black
  689. )
  690. )
  691. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  692. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_page)
  693. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  694. }
  695. 3 -> {
  696. viewBinding.one.setTextColor(
  697. ContextCompat.getColor(
  698. this,
  699. R.color.black
  700. )
  701. )
  702. viewBinding.two.setTextColor(
  703. ContextCompat.getColor(
  704. this,
  705. R.color.black
  706. )
  707. )
  708. viewBinding.three.setTextColor(
  709. ContextCompat.getColor(
  710. this,
  711. R.color.white
  712. )
  713. )
  714. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  715. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  716. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_page)
  717. }
  718. else -> {
  719. viewBinding.three.text = "$current"
  720. if (pages == current) {
  721. viewBinding.three.text = "${current - 1}"
  722. viewBinding.one.setTextColor(
  723. ContextCompat.getColor(
  724. this,
  725. R.color.black
  726. )
  727. )
  728. viewBinding.two.setTextColor(
  729. ContextCompat.getColor(
  730. this,
  731. R.color.black
  732. )
  733. )
  734. viewBinding.three.setTextColor(
  735. ContextCompat.getColor(
  736. this,
  737. R.color.black
  738. )
  739. )
  740. viewBinding.many.setTextColor(
  741. ContextCompat.getColor(
  742. this,
  743. R.color.white
  744. )
  745. )
  746. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  747. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  748. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  749. viewBinding.many.setBackgroundResource(R.drawable.bg_sou_suo_page)
  750. } else {
  751. viewBinding.one.setTextColor(
  752. ContextCompat.getColor(
  753. this,
  754. R.color.black
  755. )
  756. )
  757. viewBinding.two.setTextColor(
  758. ContextCompat.getColor(
  759. this,
  760. R.color.black
  761. )
  762. )
  763. viewBinding.three.setTextColor(
  764. ContextCompat.getColor(
  765. this,
  766. R.color.white
  767. )
  768. )
  769. viewBinding.many.setTextColor(
  770. ContextCompat.getColor(
  771. this,
  772. R.color.black
  773. )
  774. )
  775. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  776. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  777. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_page)
  778. viewBinding.many.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  779. }
  780. }
  781. }
  782. }
  783. }
  784. private fun getIdDate(id: String) {
  785. showLoading("查询中...")
  786. val disposable = ApiRepository.getDetailsById(id)
  787. .subscribe({ data ->
  788. dismissLoading()
  789. upView(data)
  790. }, { throwable ->
  791. dismissLoading()
  792. showNetError(throwable)
  793. })
  794. addDisposable(disposable)
  795. }
  796. private fun upView(data: ReturnDetailsBean) {
  797. viewBinding.relOne.visibility = View.GONE
  798. viewBinding.linTow.visibility = View.VISIBLE
  799. viewBinding.chemicalName.text = "${data.chemicalName}"
  800. viewBinding.chemicalName.setOnClickListener {
  801. TextTool.showPop(
  802. this,
  803. viewBinding.chemicalName
  804. )
  805. }
  806. viewBinding.tagCode.text = "编码${data.tagCode}"
  807. viewBinding.chemicalLevelName.text = "${data.chemicalLevelName}"
  808. viewBinding.chemicalCategoryName.text = "${data.chemicalCategoryName}"
  809. viewBinding.spec.text = "${data.specNum}${data.specUnit}/${data.packUnit}"
  810. viewBinding.belongName.text = "${data.belongName}"
  811. viewBinding.surplus.text = "${data.surplus}${data.specUnit}"
  812. viewBinding.expireTime.text = ""//清除之前得数据
  813. if (data.expireTime != null) {
  814. viewBinding.expireTime.text = "${data.expireTime}"
  815. }
  816. viewBinding.cabinet.text = "${data.cabinetName}-${data.doorName}-${data.layers}层"
  817. mData = data
  818. if (mData.rfidCode == null) {
  819. viewBinding.replaceLabel.text = "绑定RFID"
  820. } else {
  821. viewBinding.replaceLabel.text = "更换RFID"
  822. }
  823. mCabinetLockVoList = mData.cabinetLockVoList //柜锁信息
  824. if (mCabinetLockVoList != null && mCabinetLockVoList!!.size > 0) {
  825. var isLock = false
  826. mCabinetLockVoList!!.forEach { it ->
  827. if (it.unlockingMethod == 2) {
  828. isLock = true
  829. return@forEach
  830. }
  831. }
  832. if (isLock) {
  833. viewBinding.openLok.visibility = View.VISIBLE
  834. }
  835. }
  836. }
  837. private fun openLock(mLockStr: ArrayList<String>) {
  838. val map = mutableMapOf<String, Any>()
  839. map["subId"] = mData.subId
  840. map["subName"] = mData.subName
  841. map["cabinetId"] = "${mData.cabinetId}"
  842. map["cabinetName"] = "${mData.cabinetName}"
  843. map["doorId"] = "${mData.doorId}"
  844. map["doorName"] = "${mData.doorName}"
  845. map["lockNumList"] = mLockStr
  846. map["operationType"] = 7
  847. if (ChemicalApp.subRoom != null) {
  848. map["subRoom"] = ChemicalApp.subRoom!!
  849. }
  850. map["type"] = true
  851. try {// 从 SharedPreferences 中取出集合
  852. val retrievedList = SharedPreferencesHelper.getList(this)
  853. if (retrievedList != null && retrievedList.size > 0) {
  854. LogUtils.i("从本地取出得双人信息${retrievedList[0].name}")
  855. map["oneUserId"] = "${retrievedList[0].userId}"
  856. map["oneUserName"] = "${retrievedList[0].name}"
  857. map["twoUserId"] = "${retrievedList[1].userId}"
  858. map["twoUserName"] = "${retrievedList[1].name}"
  859. // 清空 SharedPreferences 中的集合
  860. // SharedPreferencesHelper.clearList(this)
  861. }
  862. } catch (e: Exception) {
  863. }
  864. showLoading("加载中...")
  865. val disposable = ApiRepository.lockOperate(map)
  866. .subscribe({ data ->
  867. dismissLoading()
  868. val containsFalse =
  869. mCabinetLockVoList!!.any { it.isOk == false && it.unlockingMethod == 2 }
  870. if (containsFalse) {
  871. showLoading("查询中...")
  872. // 开始执行任务,每 3 秒执行一次
  873. startCountdownLock()
  874. handlerUtil.startTask(task, 1000)
  875. } else {
  876. dismissLoading()
  877. //柜门已开去除化学品
  878. customDialogView(1, "柜门已开,请取出化学品")
  879. AudioPlayer.getInstance().play(R.raw.gui_men_yi_kai_qu_chu_hxp)
  880. handlerUtil.stopAllTasks()
  881. countdownTimer?.cancel()
  882. viewBinding.openLok.text = "再次开门"
  883. }
  884. }, { throwable ->
  885. dismissLoading()
  886. LogUtils.i("=========开始调用解析失败")
  887. showNetError(throwable)
  888. })
  889. addDisposable(disposable)
  890. }
  891. private var countdownTimer: CountDownTimer? = null
  892. private fun startCountdownLock() {
  893. val totalTime = 30 * 1000 // 30秒
  894. val interval = 1000 // 每秒更新一次
  895. countdownTimer = object : CountDownTimer(totalTime.toLong(), interval.toLong()) {
  896. override fun onTick(millisUntilFinished: Long) {
  897. val secondsLeft = millisUntilFinished / 1000
  898. println("剩余时间: $secondsLeft 秒")
  899. }
  900. override fun onFinish() {
  901. println("倒计时结束!")
  902. mCabinetLockVoList = null
  903. mLockStr.clear()
  904. showToast("开锁超时,可重新操作")
  905. dismissLoading()
  906. handlerUtil.stopAllTasks()
  907. // 在这里执行合适的操作,比如退出应用程序
  908. }
  909. }
  910. println("倒计时开始...")
  911. countdownTimer?.start()
  912. }
  913. override fun onDestroy() {
  914. super.onDestroy()
  915. try {
  916. handlerUtil.stopAllTasks()
  917. countdownTimer?.cancel()
  918. } catch (e: Exception) {
  919. }
  920. try {
  921. timeUpdater.stopUpdating()
  922. } catch (e: Exception) {
  923. }
  924. }
  925. override fun cdFinish() {
  926. finish()
  927. }
  928. //查询柜子 存储位置 默认第一个
  929. private fun getCabinet() {
  930. showLoading("查询中...")
  931. val disposable = ApiRepository.getCabinetList(ChemicalApp.subjectId!!)
  932. .subscribe({ data ->
  933. dismissLoading()
  934. val storageDialog =
  935. StorageDialog(
  936. ct = this,
  937. listData = data!!,
  938. lint = object : StorageDialog.IonClickListener {
  939. override fun onClick(
  940. cabinetId: String,
  941. cabinetName: String,
  942. doorName: String,
  943. doorId: String,
  944. cabinetLockVoList: List<LockVoListBean>,
  945. layers: Int,
  946. lockNum: String,
  947. ) {
  948. mCabinetId = cabinetId
  949. mDoorId = doorId
  950. viewBinding.cabinetName.text = "$cabinetName"
  951. }
  952. override fun onClose() {
  953. mCabinetId = null
  954. mDoorId = null
  955. viewBinding.cabinetName.text = "化学品柜"
  956. }
  957. })
  958. storageDialog.show()
  959. }, { throwable ->
  960. dismissLoading()
  961. showNetError(throwable)
  962. })
  963. addDisposable(disposable)
  964. }
  965. private val task = Runnable {
  966. //判断所有的锁开锁成功
  967. val containsFalse = mCabinetLockVoList!!.any { it.isOk == false && it.unlockingMethod == 2 }
  968. LogUtils.i("=======查询调用开锁状态====$containsFalse")
  969. if (containsFalse) {
  970. getLocks()
  971. } else {
  972. dismissLoading()
  973. //柜门已开去除化学品
  974. customDialogView(1, "柜门已开,请取出化学品")
  975. AudioPlayer.getInstance().play(R.raw.gui_men_yi_kai_qu_chu_hxp)
  976. handlerUtil.stopAllTasks()
  977. countdownTimer?.cancel()
  978. viewBinding.openLok.text = "再次开门"
  979. }
  980. }
  981. //查询开锁信息
  982. private fun getLocks() {
  983. mCabinetLockVoList!!.forEachIndexed { index, fruit ->
  984. if (fruit.isOk == false && fruit.unlockingMethod == 2) {
  985. getLocksDate(index, fruit.lockNum)
  986. }
  987. }
  988. }
  989. //查询开锁状态
  990. private fun getLocksDate(index: Int, fruit: String) {
  991. val disposable = ApiRepository.getLocks(ChemicalApp.subjectId!!, fruit)
  992. .subscribe({ data ->
  993. LogUtils.i("=======开锁查询成功")
  994. if (data) {
  995. mCabinetLockVoList!![index].isOk = true
  996. LogUtils.i("=======设置成功")
  997. }
  998. }, { throwable ->
  999. LogUtils.i("=======开锁查询成功 解析失败")
  1000. dismissLoading()
  1001. showNetError(throwable)
  1002. })
  1003. addDisposable(disposable)
  1004. }
  1005. }