AssetInventoryCheck.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. // 注册 Vant 组件
  2. Vue.use(vant.NavBar);
  3. Vue.use(vant.Steps);
  4. Vue.use(vant.Step);
  5. Vue.use(vant.Tabs);
  6. Vue.use(vant.Tab);
  7. Vue.use(vant.List);
  8. Vue.use(vant.Icon);
  9. Vue.use(vant.Toast);
  10. Vue.use(vant.Dialog);
  11. var app = new Vue({
  12. el: "#app",
  13. data: {
  14. // 盘点单信息
  15. inventoryInfo: {
  16. id: null,
  17. checkVouchId: null,
  18. name: '',
  19. documentNo: '',
  20. inventoryStartDate: '',
  21. inventoryEndDate: ''
  22. },
  23. // 当前激活的Tab
  24. activeTab: 0,
  25. // 待盘明细相关
  26. allPendingList: [], // 所有待盘数据(cfCheckVouchsResponses)
  27. displayedPendingList: [], // 当前显示的待盘数据
  28. pendingPage: 0, // 当前页
  29. pendingLoading: false, // 是否正在加载
  30. pendingFinished: false, // 是否加载完毕
  31. pendingTotal: 0, // 待盘总数
  32. // 已盘相关
  33. allCheckedList: [], // 所有已盘数据
  34. displayedCheckedList: [], // 当前显示的已盘数据
  35. checkedPage: 0, // 当前页
  36. checkedLoading: false, // 是否正在加载
  37. checkedFinished: false, // 是否加载完毕
  38. checkedTotal: 0, // 已盘总数
  39. // 每页显示数量
  40. pageSize: 10,
  41. // IndexDB 数据库实例
  42. checkVouchDb: null,
  43. // RFID 扫描状态
  44. isScanning: false,
  45. // === 扫描优化相关 ===
  46. // EPC扫描缓冲区(用于批量处理)
  47. scanBuffer: [],
  48. // 批量处理定时器
  49. batchProcessTimer: null,
  50. // 批量处理间隔(毫秒)
  51. batchProcessInterval: 500,
  52. // UI更新定时器
  53. uiUpdateTimer: null,
  54. // UI更新间隔(毫秒)
  55. uiUpdateInterval: 1000,
  56. // 待盘数据Map索引(key: epc, value: item)
  57. pendingMap: {},
  58. // 已盘数据Map索引(key: checkVouchsId, value: true)
  59. checkedMap: {},
  60. // 待更新UI标记
  61. needsUIUpdate: false,
  62. // 新增已盘数量(用于实时显示)
  63. newCheckedCount: 0,
  64. },
  65. methods: {
  66. /**
  67. * 返回上一页
  68. */
  69. goBack: function () {
  70. history.go(-1);
  71. },
  72. /**
  73. * 去同步页面 - 确保数据已保存
  74. */
  75. goToSync: function () {
  76. var _self = this;
  77. // 停止扫描
  78. if (_self.isScanning) {
  79. _self.stopRfidScan();
  80. }
  81. // 确保最新数据已保存
  82. _self.saveToUploadQueue();
  83. // 显示提示并跳转
  84. if (_self.allCheckedList && _self.allCheckedList.length > 0) {
  85. vant.Toast.success('已盘数据已保存,即将跳转到同步页面');
  86. } else {
  87. vant.Toast('当前没有已盘数据');
  88. }
  89. setTimeout(function () {
  90. window.location.href = './DataSync.html';
  91. }, 800);
  92. },
  93. /**
  94. * 初始化盘点单信息并加载待盘数据
  95. */
  96. initInventoryInfo: function () {
  97. var _self = this;
  98. // 从localStorage获取选中的盘点单
  99. var selectedInventory = localStorage.getItem('selectedInventory');
  100. if (!selectedInventory) {
  101. vant.Toast.fail('请先选择盘点单');
  102. setTimeout(function () {
  103. _self.goBack();
  104. }, 1500);
  105. return;
  106. }
  107. var inventory = JSON.parse(selectedInventory);
  108. _self.inventoryInfo = {
  109. id: inventory.id,
  110. checkVouchId: inventory.checkVouchId,
  111. name: inventory.name,
  112. documentNo: inventory.documentNo,
  113. inventoryStartDate: inventory.inventoryStartDate || '',
  114. inventoryEndDate: inventory.inventoryEndDate || ''
  115. };
  116. // 从 IndexDB 加载完整的盘点单数据
  117. if (_self.checkVouchDb) {
  118. _self.checkVouchDb.get('checkVouchList', inventory.checkVouchId, function (data) {
  119. if (data && data.cfCheckVouchsResponses) {
  120. // 根据 checkVouchDate 区分已盘数据和待盘数据
  121. var pendingList = [];
  122. var checkedList = [];
  123. data.cfCheckVouchsResponses.forEach(function (item) {
  124. var itemData = {
  125. id: item.checkVouchsId,
  126. checkVouchsId: item.checkVouchsId,
  127. assetName: item.inventoryName,
  128. no: item.inventoryNo,
  129. epc: item.inventoryEpc,
  130. positionId: item.positionId,
  131. positionName: item.positionName,
  132. positionNo: item.positionNo,
  133. warehouseId: item.warehouseId,
  134. warehouseName: item.warehouseName,
  135. warehouseNo: item.warehouseNo,
  136. inventoryId: item.inventoryId
  137. };
  138. // 根据 checkVouchDate 判断是已盘还是待盘
  139. if (item.checkVouchDate) {
  140. // 有 checkVouchDate,是已盘数据
  141. itemData.checkTime = item.checkVouchDate;
  142. itemData.userName = item.userName || '';
  143. checkedList.push(itemData);
  144. // 构建已盘Map索引
  145. _self.checkedMap[item.checkVouchsId] = true;
  146. } else {
  147. // 没有 checkVouchDate,是待盘数据
  148. pendingList.push(itemData);
  149. // 构建待盘Map索引
  150. if (itemData.epc) {
  151. _self.pendingMap[itemData.epc] = itemData;
  152. }
  153. }
  154. });
  155. _self.allPendingList = pendingList;
  156. _self.allCheckedList = checkedList;
  157. _self.pendingTotal = pendingList.length;
  158. _self.checkedTotal = checkedList.length;
  159. console.log('数据加载完成 - 待盘:', pendingList.length, '条,已盘:', checkedList.length, '条');
  160. }
  161. // 加载本地新盘的数据(如果有的话,需要与服务器已盘数据合并)
  162. _self.loadLocalCheckedData(inventory.checkVouchId);
  163. }, function (error) {
  164. console.error('加载盘点单数据失败:', error);
  165. });
  166. }
  167. },
  168. /**
  169. * 加载本地新盘的数据(如果有的话,需要与服务器已盘数据合并)
  170. */
  171. loadLocalCheckedData: function (checkVouchId) {
  172. var _self = this;
  173. _self.checkVouchDb.get('uploadQueue', checkVouchId, function (uploadData) {
  174. if (uploadData && uploadData.cfCheckVouchsRequests && uploadData.cfCheckVouchsRequests.length > 0) {
  175. console.log('发现本地新盘数据:', uploadData.cfCheckVouchsRequests.length, '条(需要与服务器已盘数据合并)');
  176. // 将本地新盘数据与服务器已盘数据合并
  177. // 使用 checkVouchsId 去重
  178. var existingIds = {};
  179. _self.allCheckedList.forEach(function (item) {
  180. existingIds[item.checkVouchsId] = true;
  181. });
  182. // 添加本地新盘的数据(不在服务器已盘列表中的)
  183. uploadData.cfCheckVouchsRequests.forEach(function (item) {
  184. if (!existingIds[item.checkVouchsId]) {
  185. // 从待盘列表中查找完整信息
  186. var foundPending = null;
  187. for (var i = 0; i < _self.allPendingList.length; i++) {
  188. if (_self.allPendingList[i].checkVouchsId === item.checkVouchsId) {
  189. foundPending = _self.allPendingList[i];
  190. break;
  191. }
  192. }
  193. var checkedItem = {
  194. id: item.checkVouchsId,
  195. checkVouchsId: item.checkVouchsId,
  196. checkTime: item.checkVouchTime
  197. };
  198. // 补充完整信息
  199. if (foundPending) {
  200. checkedItem.assetName = foundPending.assetName;
  201. checkedItem.no = foundPending.no;
  202. checkedItem.epc = foundPending.epc;
  203. checkedItem.positionId = foundPending.positionId;
  204. checkedItem.positionName = foundPending.positionName;
  205. checkedItem.inventoryId = foundPending.inventoryId;
  206. }
  207. // 添加到已盘列表
  208. _self.allCheckedList.push(checkedItem);
  209. // 构建已盘Map索引
  210. _self.checkedMap[item.checkVouchsId] = true;
  211. existingIds[item.checkVouchsId] = true;
  212. }
  213. });
  214. _self.checkedTotal = _self.allCheckedList.length;
  215. console.log('合并后的已盘数据总数:', _self.checkedTotal, '条');
  216. } else {
  217. console.log('没有本地新盘数据');
  218. }
  219. }, function (error) {
  220. console.log('加载本地新盘数据失败(可能是首次盘点):', error);
  221. });
  222. },
  223. /**
  224. * 处理 RFID 扫描到的 EPC
  225. * @param {String} epc - 扫描到的 EPC
  226. */
  227. addEpc: function (epc) {
  228. var _self = this;
  229. // 将EPC添加到缓冲区
  230. _self.scanBuffer.push(epc);
  231. // 如果定时器未启动,启动批量处理定时器
  232. if (!_self.batchProcessTimer) {
  233. _self.batchProcessTimer = setInterval(function () {
  234. _self.processScanBuffer();
  235. }, _self.batchProcessInterval);
  236. }
  237. },
  238. /**
  239. * 批量处理扫描缓冲区中的EPC数据
  240. */
  241. processScanBuffer: function () {
  242. var _self = this;
  243. // 如果缓冲区为空,直接返回
  244. if (_self.scanBuffer.length === 0) {
  245. return;
  246. }
  247. var processStartTime = Date.now();
  248. var batchSize = _self.scanBuffer.length;
  249. console.log('开始批量处理 ' + batchSize + ' 条扫描数据');
  250. // 临时存储本次批量处理的新增已盘项
  251. var newCheckedItems = [];
  252. var duplicateCount = 0;
  253. var notFoundCount = 0;
  254. // 批量处理缓冲区中的所有EPC
  255. for (var i = 0; i < batchSize; i++) {
  256. var epc = _self.scanBuffer[i];
  257. // 使用Map快速查找待盘数据
  258. var foundItem = _self.pendingMap[epc];
  259. if (foundItem) {
  260. // 使用Map快速检查是否已经盘点过
  261. if (!_self.checkedMap[foundItem.checkVouchsId]) {
  262. // 添加到已盘列表
  263. var checkedItem = {
  264. id: foundItem.checkVouchsId,
  265. checkVouchsId: foundItem.checkVouchsId,
  266. assetName: foundItem.assetName,
  267. no: foundItem.no,
  268. epc: foundItem.epc,
  269. checkTime: _self.formatDateTime(new Date()),
  270. positionId: foundItem.positionId,
  271. positionName: foundItem.positionName,
  272. inventoryId: foundItem.inventoryId
  273. };
  274. // 添加到已盘列表
  275. _self.allCheckedList.push(checkedItem);
  276. // 更新已盘Map索引
  277. _self.checkedMap[foundItem.checkVouchsId] = true;
  278. // 添加到本次批量新增列表
  279. newCheckedItems.push(checkedItem);
  280. } else {
  281. duplicateCount++;
  282. }
  283. } else {
  284. notFoundCount++;
  285. }
  286. }
  287. // 清空缓冲区
  288. _self.scanBuffer = [];
  289. // 更新已盘总数
  290. _self.checkedTotal = _self.allCheckedList.length;
  291. _self.newCheckedCount += newCheckedItems.length;
  292. var processEndTime = Date.now();
  293. console.log('批量处理完成: 新增 ' + newCheckedItems.length + ' 条, 重复 ' + duplicateCount + ' 条, 未找到 ' + notFoundCount + ' 条, 耗时 ' + (processEndTime - processStartTime) + 'ms');
  294. // 标记需要更新UI
  295. if (newCheckedItems.length > 0) {
  296. _self.needsUIUpdate = true;
  297. _self.scheduleUIUpdate();
  298. // 实时保存已盘数据到 IndexDB
  299. _self.saveToUploadQueue();
  300. }
  301. },
  302. /**
  303. * 实时保存已盘数据到 IndexDB 的 uploadQueue
  304. * 注意:新盘数据会与服务器已盘数据合并,不会覆盖服务器数据
  305. */
  306. saveToUploadQueue: function () {
  307. var _self = this;
  308. // 如果没有数据库实例或没有已盘数据,不保存
  309. if (!_self.checkVouchDb || !_self.allCheckedList || _self.allCheckedList.length === 0) {
  310. return;
  311. }
  312. // 构建上传数据结构(allCheckedList已经包含了服务器已盘数据和新盘数据)
  313. var uploadData = {
  314. checkVouchId: _self.inventoryInfo.checkVouchId,
  315. cfCheckVouchsRequests: _self.allCheckedList.map(function (item) {
  316. return {
  317. checkVouchsId: item.checkVouchsId,
  318. checkVouchTime: item.checkTime
  319. };
  320. })
  321. };
  322. // 保存到 IndexDB 的上传队列(使用 put 会覆盖同一 checkVouchId 的旧数据)
  323. _self.checkVouchDb.put('uploadQueue', uploadData, function () {
  324. console.log('已盘数据已实时保存到上传队列,数量: ' + _self.allCheckedList.length);
  325. }, function (error) {
  326. console.error('保存已盘数据失败:', error);
  327. });
  328. },
  329. /**
  330. * 安排UI更新(节流)
  331. */
  332. scheduleUIUpdate: function () {
  333. var _self = this;
  334. // 如果已经有UI更新定时器,不重复创建
  335. if (_self.uiUpdateTimer) {
  336. return;
  337. }
  338. // 设置UI更新定时器
  339. _self.uiUpdateTimer = setTimeout(function () {
  340. _self.performUIUpdate();
  341. _self.uiUpdateTimer = null;
  342. }, _self.uiUpdateInterval);
  343. },
  344. /**
  345. * 执行UI更新
  346. */
  347. performUIUpdate: function () {
  348. var _self = this;
  349. if (!_self.needsUIUpdate) {
  350. return;
  351. }
  352. // 只有当前在已盘tab时才更新显示列表
  353. if (_self.activeTab === 1) {
  354. _self.refreshCheckedList();
  355. }
  356. _self.needsUIUpdate = false;
  357. console.log('UI更新完成,当前已盘总数: ' + _self.checkedTotal);
  358. },
  359. /**
  360. * 格式化日期时间
  361. */
  362. formatDateTime: function (date) {
  363. var year = date.getFullYear();
  364. var month = String(date.getMonth() + 1).padStart(2, '0');
  365. var day = String(date.getDate()).padStart(2, '0');
  366. var hours = String(date.getHours()).padStart(2, '0');
  367. var minutes = String(date.getMinutes()).padStart(2, '0');
  368. var seconds = String(date.getSeconds()).padStart(2, '0');
  369. return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
  370. },
  371. /**
  372. * Tab切换
  373. */
  374. onTabChange: function (name) {
  375. var _self = this;
  376. console.log('切换到Tab:', name);
  377. // 如果切换到已盘tab
  378. if (name === 1) {
  379. // 如果有待更新的数据,立即更新UI
  380. if (_self.needsUIUpdate) {
  381. // 取消定时器,立即更新
  382. if (_self.uiUpdateTimer) {
  383. clearTimeout(_self.uiUpdateTimer);
  384. _self.uiUpdateTimer = null;
  385. }
  386. _self.performUIUpdate();
  387. } else if (_self.displayedCheckedList.length < _self.allCheckedList.length) {
  388. // 检查是否有新数据需要刷新
  389. _self.refreshCheckedList();
  390. }
  391. }
  392. },
  393. /**
  394. * 刷新已盘列表(重新加载所有数据)
  395. */
  396. refreshCheckedList: function () {
  397. var _self = this;
  398. // 重置分页
  399. _self.checkedPage = 0;
  400. _self.displayedCheckedList = [];
  401. _self.checkedFinished = false;
  402. // 触发加载
  403. _self.checkedLoading = true;
  404. _self.onLoadChecked();
  405. },
  406. /**
  407. * 加载待盘数据
  408. */
  409. onLoadPending: function () {
  410. var _self = this;
  411. // 模拟加载延迟
  412. setTimeout(function () {
  413. var startIndex = _self.pendingPage * _self.pageSize;
  414. var endIndex = startIndex + _self.pageSize;
  415. // 获取当前页的数据
  416. var pageData = _self.allPendingList.slice(startIndex, endIndex);
  417. if (pageData.length > 0) {
  418. // 追加到显示列表
  419. _self.displayedPendingList = _self.displayedPendingList.concat(pageData);
  420. _self.pendingPage++;
  421. _self.pendingLoading = false;
  422. // 判断是否加载完毕
  423. if (_self.displayedPendingList.length >= _self.allPendingList.length) {
  424. _self.pendingFinished = true;
  425. }
  426. } else {
  427. // 没有更多数据了
  428. _self.pendingFinished = true;
  429. _self.pendingLoading = false;
  430. }
  431. }, 300);
  432. },
  433. /**
  434. * 加载已盘数据
  435. */
  436. onLoadChecked: function () {
  437. var _self = this;
  438. // 模拟加载延迟
  439. setTimeout(function () {
  440. var startIndex = _self.checkedPage * _self.pageSize;
  441. var endIndex = startIndex + _self.pageSize;
  442. // 获取当前页的数据(倒序显示,最新的在前面)
  443. var reversedList = _self.allCheckedList.slice().reverse();
  444. var pageData = reversedList.slice(startIndex, endIndex);
  445. if (pageData.length > 0) {
  446. // 追加到显示列表
  447. _self.displayedCheckedList = _self.displayedCheckedList.concat(pageData);
  448. _self.checkedPage++;
  449. _self.checkedLoading = false;
  450. // 判断是否加载完毕
  451. if (_self.displayedCheckedList.length >= _self.allCheckedList.length) {
  452. _self.checkedFinished = true;
  453. }
  454. } else {
  455. // 没有更多数据了
  456. _self.checkedFinished = true;
  457. _self.checkedLoading = false;
  458. }
  459. }, 300);
  460. },
  461. /**
  462. * 重置待盘分页
  463. */
  464. resetPendingPagination: function () {
  465. var _self = this;
  466. _self.pendingPage = 0;
  467. _self.displayedPendingList = [];
  468. _self.pendingFinished = false;
  469. _self.pendingLoading = true;
  470. },
  471. /**
  472. * 重置已盘分页
  473. */
  474. resetCheckedPagination: function () {
  475. var _self = this;
  476. _self.checkedPage = 0;
  477. _self.displayedCheckedList = [];
  478. _self.checkedFinished = false;
  479. _self.checkedLoading = false; // 不自动触发加载,等待van-list组件触发
  480. },
  481. /**
  482. * 启动 RFID 扫描
  483. */
  484. startRfidScan: function () {
  485. var _self = this;
  486. if (!plugin || !plugin.rfidMiddleware) {
  487. console.error('RFID 插件未加载');
  488. return;
  489. }
  490. // 重置计数器和缓冲区
  491. _self.newCheckedCount = 0;
  492. _self.scanBuffer = [];
  493. _self.isScanning = true;
  494. plugin.rfidMiddleware.start();
  495. plugin.rfidMiddleware.readEvent = function (epc) {
  496. _self.addEpc(epc);
  497. return "success";
  498. };
  499. console.log('RFID 扫描已启动');
  500. },
  501. /**
  502. * 停止 RFID 扫描
  503. */
  504. stopRfidScan: function () {
  505. var _self = this;
  506. if (!plugin || !plugin.rfidMiddleware) {
  507. return;
  508. }
  509. _self.isScanning = false;
  510. plugin.rfidMiddleware.stop();
  511. plugin.rfidMiddleware.stopInventory();
  512. // 清理批量处理定时器
  513. if (_self.batchProcessTimer) {
  514. clearInterval(_self.batchProcessTimer);
  515. _self.batchProcessTimer = null;
  516. }
  517. // 处理剩余缓冲区数据
  518. if (_self.scanBuffer.length > 0) {
  519. console.log('处理剩余缓冲区数据: ' + _self.scanBuffer.length + ' 条');
  520. _self.processScanBuffer();
  521. }
  522. // 清理UI更新定时器
  523. if (_self.uiUpdateTimer) {
  524. clearTimeout(_self.uiUpdateTimer);
  525. _self.uiUpdateTimer = null;
  526. }
  527. // 如果有待更新的UI,立即更新
  528. if (_self.needsUIUpdate) {
  529. _self.performUIUpdate();
  530. }
  531. console.log('RFID 扫描已停止,总计扫描: ' + _self.newCheckedCount + ' 条新数据');
  532. },
  533. /**
  534. * 清理所有定时器
  535. */
  536. cleanupTimers: function () {
  537. var _self = this;
  538. if (_self.batchProcessTimer) {
  539. clearInterval(_self.batchProcessTimer);
  540. _self.batchProcessTimer = null;
  541. }
  542. if (_self.uiUpdateTimer) {
  543. clearTimeout(_self.uiUpdateTimer);
  544. _self.uiUpdateTimer = null;
  545. }
  546. },
  547. /**
  548. * 获取扫描统计信息
  549. */
  550. getScanStats: function () {
  551. var _self = this;
  552. return {
  553. pendingTotal: _self.pendingTotal,
  554. checkedTotal: _self.checkedTotal,
  555. newCheckedCount: _self.newCheckedCount,
  556. bufferSize: _self.scanBuffer.length,
  557. scanProgress: _self.pendingTotal > 0 ?
  558. ((_self.checkedTotal / _self.pendingTotal) * 100).toFixed(2) : '0.00'
  559. };
  560. },
  561. /**
  562. * 保存盘点数据到 IndexDB(兼容旧版调用,实际调用 saveToUploadQueue)
  563. * @param {Function} callback - 保存成功后的回调
  564. */
  565. saveInventoryData: function (callback) {
  566. var _self = this;
  567. // 调用实时保存方法
  568. _self.saveToUploadQueue();
  569. // 执行回调
  570. if (callback) {
  571. callback();
  572. }
  573. },
  574. /**
  575. * 初始化
  576. */
  577. init: function () {
  578. var _self = this;
  579. // 初始化 IndexDB 数据库
  580. var objectStoreDefines = [
  581. {
  582. name: 'checkVouchList',
  583. defineOption: { keyPath: 'checkVouchId' },
  584. indexDefineList: null
  585. },
  586. {
  587. name: 'uploadQueue',
  588. defineOption: { keyPath: 'checkVouchId' },
  589. indexDefineList: null
  590. }
  591. ];
  592. _self.checkVouchDb = new IndexDbFactory('checkVouchDB', objectStoreDefines, 1);
  593. _self.checkVouchDb.open(function () {
  594. console.log('盘点数据库初始化成功');
  595. // 数据库初始化成功后,初始化盘点单信息
  596. _self.initInventoryInfo();
  597. // 启动 RFID 扫描
  598. _self.startRfidScan();
  599. }, function () {
  600. console.error('盘点数据库初始化失败');
  601. vant.Dialog.alert({
  602. title: '错误',
  603. message: '数据库初始化失败,请先进行数据同步。',
  604. theme: 'round-button',
  605. });
  606. });
  607. }
  608. },
  609. created: function () {
  610. console.log('AssetInventoryCheck Vue实例创建完成');
  611. },
  612. mounted: function () {
  613. var _self = this;
  614. _self.init();
  615. console.log('AssetInventoryCheck页面加载完成');
  616. // 隐藏页面加载指示器
  617. setTimeout(function() {
  618. var loadingElement = document.getElementById('pageLoading');
  619. if (loadingElement) {
  620. loadingElement.style.display = 'none';
  621. }
  622. }, 100);
  623. },
  624. beforeDestroy: function () {
  625. var _self = this;
  626. // 停止 RFID 扫描(会自动清理定时器)
  627. _self.stopRfidScan();
  628. // 保存盘点数据
  629. _self.saveInventoryData();
  630. },
  631. destroyed: function () {
  632. var _self = this;
  633. // 确保停止 RFID 扫描
  634. _self.stopRfidScan();
  635. // 清理所有定时器
  636. _self.cleanupTimers();
  637. }
  638. });