AssetInventorySelect.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. // 注册 Vant 组件
  2. Vue.use(vant.NavBar);
  3. Vue.use(vant.Steps);
  4. Vue.use(vant.Step);
  5. Vue.use(vant.Search);
  6. Vue.use(vant.Radio);
  7. Vue.use(vant.RadioGroup);
  8. Vue.use(vant.Button);
  9. Vue.use(vant.List);
  10. Vue.use(vant.Toast);
  11. Vue.use(vant.Dialog);
  12. var app = new Vue({
  13. el: "#app",
  14. data: {
  15. // 搜索关键字
  16. searchKeyword: '',
  17. // 选中的盘点单ID
  18. selectedId: null,
  19. // 选中的盘点单对象
  20. selectedItem: null,
  21. // 所有盘点单数据
  22. allInventoryList: [],
  23. // 过滤后的列表
  24. filteredList: [],
  25. // 当前显示的列表
  26. displayedList: [],
  27. // 当前加载到第几页
  28. currentPage: 0,
  29. // 每页显示数量
  30. pageSize: 10,
  31. // 是否正在加载
  32. loading: false,
  33. // 是否加载完毕
  34. finished: false,
  35. // IndexDB 数据库实例
  36. checkVouchDb: null,
  37. },
  38. methods: {
  39. /**
  40. * 返回上一页
  41. */
  42. goBack: function () {
  43. history.go(-1);
  44. },
  45. /**
  46. * 去同步页面
  47. */
  48. goToSync: function () {
  49. window.location.href = './DataSync.html';
  50. },
  51. /**
  52. * 从 IndexDB 加载盘点单数据
  53. */
  54. loadInventoryData: function () {
  55. var _self = this;
  56. if (!_self.checkVouchDb) {
  57. vant.Toast.fail('数据库未初始化');
  58. return;
  59. }
  60. _self.checkVouchDb.getAll('checkVouchList', function (dataList) {
  61. if (dataList && dataList.length > 0) {
  62. // 转换数据格式
  63. _self.allInventoryList = dataList.map(function (item) {
  64. return {
  65. id: item.checkVouchId,
  66. checkVouchId: item.checkVouchId,
  67. name: item.name,
  68. documentNo: item.documentNo,
  69. warehouseId: item.warehouseId,
  70. warehouseName: item.warehouseName,
  71. description: item.description,
  72. inventoryStartDate: item.inventoryStartDate || '',
  73. inventoryEndDate: item.inventoryEndDate || '',
  74. cfCheckVouchsResponses: item.cfCheckVouchsResponses || []
  75. };
  76. });
  77. _self.filteredList = _self.allInventoryList;
  78. console.log('从 IndexDB 加载了 ' + dataList.length + ' 条盘点单数据');
  79. } else {
  80. console.log('IndexDB 中没有盘点单数据');
  81. _self.allInventoryList = [];
  82. _self.filteredList = [];
  83. }
  84. }, function (error) {
  85. console.error('从 IndexDB 加载盘点单数据失败:', error);
  86. vant.Toast.fail('加载盘点单数据失败');
  87. _self.allInventoryList = [];
  88. _self.filteredList = [];
  89. });
  90. },
  91. /**
  92. * 格式化日期
  93. */
  94. formatDate: function (date) {
  95. var year = date.getFullYear();
  96. var month = String(date.getMonth() + 1).padStart(2, '0');
  97. var day = String(date.getDate()).padStart(2, '0');
  98. var hours = String(date.getHours()).padStart(2, '0');
  99. var minutes = String(date.getMinutes()).padStart(2, '0');
  100. var seconds = String(date.getSeconds()).padStart(2, '0');
  101. return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
  102. },
  103. /**
  104. * 搜索处理
  105. */
  106. onSearch: function () {
  107. var _self = this;
  108. var keyword = _self.searchKeyword.trim().toLowerCase();
  109. if (!keyword) {
  110. // 如果搜索关键字为空,显示全部
  111. _self.filteredList = _self.allInventoryList;
  112. } else {
  113. // 前端搜索:根据名称、单据号搜索
  114. _self.filteredList = _self.allInventoryList.filter(function (item) {
  115. return item.name.toLowerCase().indexOf(keyword) > -1 ||
  116. item.documentNo.toLowerCase().indexOf(keyword) > -1;
  117. });
  118. }
  119. // 重置分页
  120. _self.resetPagination();
  121. },
  122. /**
  123. * 重置分页
  124. */
  125. resetPagination: function () {
  126. var _self = this;
  127. _self.currentPage = 0;
  128. _self.displayedList = [];
  129. _self.finished = false;
  130. _self.loading = true;
  131. // 触发加载
  132. _self.onLoad();
  133. },
  134. /**
  135. * 加载更多数据
  136. */
  137. onLoad: function () {
  138. var _self = this;
  139. // 模拟加载延迟
  140. setTimeout(function () {
  141. var startIndex = _self.currentPage * _self.pageSize;
  142. var endIndex = startIndex + _self.pageSize;
  143. // 获取当前页的数据
  144. var pageData = _self.filteredList.slice(startIndex, endIndex);
  145. if (pageData.length > 0) {
  146. // 追加到显示列表
  147. _self.displayedList = _self.displayedList.concat(pageData);
  148. _self.currentPage++;
  149. _self.loading = false;
  150. // 判断是否加载完毕
  151. if (_self.displayedList.length >= _self.filteredList.length) {
  152. _self.finished = true;
  153. }
  154. } else {
  155. // 没有更多数据了
  156. _self.finished = true;
  157. _self.loading = false;
  158. }
  159. }, 300);
  160. },
  161. /**
  162. * 选择盘点单
  163. */
  164. selectItem: function (item) {
  165. var _self = this;
  166. _self.selectedId = item.id;
  167. _self.selectedItem = item;
  168. },
  169. /**
  170. * 下一步
  171. */
  172. goNext: function () {
  173. var _self = this;
  174. if (!_self.selectedItem) {
  175. vant.Toast.fail('请先选择盘点单');
  176. return;
  177. }
  178. // 保存选中的盘点单到localStorage
  179. localStorage.setItem('selectedInventory', JSON.stringify(_self.selectedItem));
  180. // 跳转到盘点页面
  181. window.location.href = './AssetInventoryCheck.html';
  182. },
  183. /**
  184. * 初始化
  185. */
  186. init: function () {
  187. var _self = this;
  188. // 初始化 IndexDB 数据库
  189. var objectStoreDefines = [
  190. {
  191. name: 'checkVouchList',
  192. defineOption: { keyPath: 'checkVouchId' },
  193. indexDefineList: null
  194. },
  195. {
  196. name: 'uploadQueue',
  197. defineOption: { keyPath: 'checkVouchId' },
  198. indexDefineList: null
  199. }
  200. ];
  201. _self.checkVouchDb = new IndexDbFactory('checkVouchDB', objectStoreDefines, 1);
  202. _self.checkVouchDb.open(function () {
  203. console.log('盘点数据库初始化成功');
  204. // 数据库初始化成功后,加载盘点单数据
  205. _self.loadInventoryData();
  206. }, function () {
  207. console.error('盘点数据库初始化失败');
  208. vant.Dialog.alert({
  209. title: '错误',
  210. message: '数据库初始化失败,请先进行数据同步。',
  211. theme: 'round-button',
  212. });
  213. });
  214. }
  215. },
  216. created: function () {
  217. console.log('AssetInventorySelect Vue实例创建完成');
  218. },
  219. mounted: function () {
  220. var _self = this;
  221. _self.init();
  222. console.log('AssetInventorySelect页面加载完成');
  223. // 隐藏页面加载指示器
  224. setTimeout(function() {
  225. var loadingElement = document.getElementById('pageLoading');
  226. if (loadingElement) {
  227. loadingElement.style.display = 'none';
  228. }
  229. }, 100);
  230. }
  231. });