summary.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. <template>
  2. <view class="table-container">
  3. <!-- 查询框 -->
  4. <view class="container">
  5. <view class="search-container">
  6. </view>
  7. </view>
  8. <!-- 表格容器 -->
  9. <scroll-view class="table-scroll" scroll-x scroll-y @scroll="onScroll">
  10. <!-- 表头 -->
  11. <view class="table-header" ref="tableHeader">
  12. <view class="table-cell1-1">单据编号</view>
  13. <view class="table-cell">单据总条数</view>
  14. <view class="table-cell"
  15. style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">已扫描条数</view>
  16. <view class="table-cell"
  17. style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">未扫描条数</view>
  18. </view>
  19. <!-- 表格内容 -->
  20. <view class="table-body">
  21. <!-- <checkbox-group @change="checkboxChange"> -->
  22. <view class="table-row" v-for="(item, index) in billSummary" :key="item.FID">
  23. <view class="table-cell1">
  24. <!-- <checkbox :value="item.FID" :checked="item.checked" />{{ item.FBillNo}} -->
  25. <view class="checkbox-container">
  26. <checkbox :value="item.FID" :checked="item.checked" @tap="handleCheckboxClick(item.FID)" />
  27. </view>
  28. <view>{{ item.FBillNo}}</view>
  29. </view>
  30. <view class="table-cell">{{ item.totalEntries }}</view>
  31. <view class="table-cell">{{ item.smzt1Count }}</view>
  32. <view class="table-cell">{{ item.totalEntries- item.smzt1Count }}</view>
  33. </view>
  34. <!-- </checkbox-group> -->
  35. </view>
  36. </scroll-view>
  37. <!-- 底部按钮 -->
  38. <view class="bottom-bar">
  39. <button class="mini-btn button" type="primary" size="default" @click="handleSubmit">提交</button>
  40. <button class="mini-btn button" type="primary" size="default" @click="goBack">返回</button>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import {
  46. playVoice,
  47. audioUrls
  48. } from '@/utils/audio2.js'
  49. import {
  50. audit,
  51. getBillList,
  52. save,
  53. submit
  54. } from '../../api/production_replenishment';
  55. import modal from '../../plugins/modal';
  56. import {
  57. executeSql
  58. } from '../../utils/database';
  59. import {
  60. getAuditParam,
  61. getSaveParam,
  62. getSubmitParam
  63. } from '../../utils/params';
  64. import submitHelper from '../../utils/submitHelper';
  65. export default {
  66. data() {
  67. return {
  68. indexList: [],
  69. billSummary: [], // 这里存放处理后的每个 FBillNo 的统计结果
  70. selectedItemId: null,
  71. stageLists: [],
  72. tableName: "bill",
  73. };
  74. },
  75. onLoad(option) {
  76. this.indexList = JSON.parse(decodeURIComponent(option.Info))
  77. this.stageLists = JSON.parse(decodeURIComponent(option.stageInfo))
  78. console.log(this.indexList)
  79. console.log(this.stageLists)
  80. },
  81. computed: {
  82. },
  83. mounted() {
  84. this.calculateSummary()
  85. console.log(this.billSummary)
  86. },
  87. onBackPress(e) {
  88. console.log("监听返回按钮事件", e);
  89. if (e.from == "backbutton") {
  90. this.goBack()
  91. return true
  92. }
  93. },
  94. methods: {
  95. calculateSummary() {
  96. const summary = {};
  97. // 遍历数据,统计每个 FBillNo 的总条数和 smzt=1 的数量
  98. this.indexList.forEach(item => {
  99. const {
  100. FID,
  101. FBillNo,
  102. smzt
  103. } = item;
  104. if (!summary[FBillNo]) {
  105. summary[FBillNo] = {
  106. FID: FID,
  107. FBillNo: FBillNo,
  108. totalEntries: 0,
  109. smzt1Count: 0
  110. };
  111. }
  112. summary[FBillNo].totalEntries++;
  113. if (smzt === 1) {
  114. summary[FBillNo].smzt1Count++;
  115. }
  116. });
  117. // 将 summary 对象转为数组,便于在模板中遍历展示
  118. this.billSummary = Object.values(summary);
  119. },
  120. goBack() {
  121. let vm = this
  122. uni.navigateBack({
  123. success: function() {
  124. // 传递数据给上一页
  125. uni.$emit('summary', vm.indexList);
  126. }
  127. });
  128. },
  129. onScroll(e) {
  130. const scrollLeft = e.detail.scrollLeft;
  131. this.headerLeft = -scrollLeft; // 更新表头左侧位置,实现横向滚动时的对齐效果
  132. },
  133. async handleSubmit(FID) {
  134. if (this.selectedItemId == null) {
  135. uni.showToast({
  136. title: '请选择单据',
  137. duration: 3000,
  138. icon: "error"
  139. })
  140. playVoice(audioUrls.failVoiceUrl)
  141. return
  142. }
  143. const selectedItem = this.billSummary.find(item => item.FID === this.selectedItemId);
  144. const areEqual = selectedItem ? selectedItem.totalEntries === selectedItem.smzt1Count : false;
  145. if (!areEqual) {
  146. uni.showToast({
  147. title: '单据未全扫描',
  148. duration: 3000,
  149. icon: "error"
  150. })
  151. playVoice(audioUrls.failVoiceUrl)
  152. return
  153. }
  154. try {
  155. await submitHelper.submit(this.selectedItemId, this.indexList);
  156. this.indexList = this.indexList.filter(item => item.FID !== this.selectedItemId);
  157. this.billSummary = this.billSummary.filter(item => item.FID !==
  158. this.selectedItemId)
  159. console.log(this.indexList)
  160. if (this.stageLists.length != 0) {
  161. // 处理每个对象
  162. this.stageLists.forEach(item => {
  163. // 过滤掉 FID 匹配的对象
  164. item.data = item.data.filter(obj => obj.FID !== this.selectedItemId);
  165. // 检查 data 数组是否为空
  166. if (item.data.length === 0) {
  167. console.log("data 数组为空"); //删除暂存
  168. this.deleteStages(item.id)
  169. } else {
  170. console.log("data 数组不为空");
  171. }
  172. })
  173. console.log(this.stageLists)
  174. }
  175. } catch (error) {
  176. this.handleError(error)
  177. }
  178. },
  179. async deleteStages(id) {
  180. let condition = `id = (${id})`
  181. let sql = `delete from ${this.tableName} where ${condition}`
  182. executeSql(sql).then(result => {
  183. console.log('结果:', result);
  184. // this.handleDeleteSuccess()
  185. })
  186. .catch(error => {
  187. console.error('捕获错误:', error); // 输出: 捕获错误: 失败的结果
  188. // this.handleDeleteFail(error)
  189. })
  190. },
  191. handleError(error) {
  192. playVoice(audioUrls.failVoiceUrl)
  193. console.error('操作失败:', error);
  194. modal.confirm(error.message || '操作失败').then(res => {
  195. if (res) {
  196. } else {
  197. // 用户点击取消,不执行任何操作
  198. }
  199. })
  200. // uni.showToast({
  201. // title: error.message || '操作失败',
  202. // duration: 3000,
  203. // icon: "none"
  204. // });
  205. // playVoice(audioUrls.failVoiceUrl)
  206. // console.error('操作失败:', error);
  207. },
  208. // submit() {
  209. // if (this.selectedItemId == null) {
  210. // uni.showToast({
  211. // title: '请选择单据',
  212. // duration: 3000,
  213. // icon: "error"
  214. // })
  215. // playVoice(audioUrls.failVoiceUrl)
  216. // return
  217. // }
  218. // const selectedItem = this.billSummary.find(item => item.FID === this.selectedItemId);
  219. // const areEqual = selectedItem ? selectedItem.totalEntries === selectedItem.smzt1Count : false;
  220. // if (!areEqual) {
  221. // uni.showToast({
  222. // title: '单据未全扫描',
  223. // duration: 3000,
  224. // icon: "error"
  225. // })
  226. // playVoice(audioUrls.failVoiceUrl)
  227. // return
  228. // }
  229. // const savaParam = getSaveParam(this.selectedItemId, this.indexList)
  230. // console.log(savaParam)
  231. // let vm = this
  232. // save(JSON.stringify(savaParam)).then( //保存
  233. // res => {
  234. // console.log(res)
  235. // if (res.Result.ResponseStatus.IsSuccess == true) {
  236. // const FID = res.Result.NeedReturnData[0]["FID"]
  237. // console.log(FID)
  238. // const submitParam = getSubmitParam(FID)
  239. // console.log(submitParam)
  240. // submit(JSON.stringify(submitParam)).then( //提交
  241. // res => {
  242. // console.log(res)
  243. // if (res.Result.ResponseStatus.IsSuccess == true) {
  244. // const Id = res.Result.ResponseStatus.SuccessEntitys[0]["Id"]
  245. // console.log(Id)
  246. // const auditParam = getAuditParam(Id)
  247. // audit(JSON.stringify(auditParam)).then( //提交
  248. // res => {
  249. // console.log(res)
  250. // if (res.Result.ResponseStatus.IsSuccess == true) {
  251. // vm.indexList = vm.indexList.filter(item => item.FID !==
  252. // FID)
  253. // vm.billSummary = vm.billSummary.filter(item => item.FID !==
  254. // FID)
  255. // uni.showModal({
  256. // title: "提示",
  257. // content: "提交成功",
  258. // showCancel: true,
  259. // success: function(res) {
  260. // if (res.confirm) {
  261. // // vm.submit(FID)
  262. // } else {
  263. // // 执行取消后的操作
  264. // }
  265. // }
  266. // })
  267. // playVoice(audioUrls.successVoiceUrl)
  268. // } else {
  269. // uni.showToast({
  270. // title: res.Result.ResponseStatus.Errors[0]
  271. // .Message,
  272. // duration: 2000,
  273. // icon: "error"
  274. // })
  275. // }
  276. // }
  277. // ).catch(error => {
  278. // // 处理失败的情况
  279. // console.error('audit failed:', error);
  280. // uni.showToast({
  281. // title: error,
  282. // duration: 3000,
  283. // icon: "none"
  284. // })
  285. // })
  286. // } else {
  287. // uni.showToast({
  288. // title: res.Result.ResponseStatus.Errors[0].Message,
  289. // duration: 2000,
  290. // icon: "error"
  291. // })
  292. // }
  293. // }
  294. // ).catch(error => {
  295. // playVoice(audioUrls.failVoiceUrl)
  296. // uni.showModal({
  297. // title: "提示",
  298. // content: error,
  299. // showCancel: true,
  300. // success: function(res) {
  301. // if (res.confirm) {
  302. // // vm.submit(FID)
  303. // } else {
  304. // // 执行取消后的操作
  305. // }
  306. // }
  307. // })
  308. // // 处理失败的情况
  309. // console.error('Submit failed:', error);
  310. // })
  311. // } else {
  312. // uni.showToast({
  313. // title: res.Result.ResponseStatus.Errors[0].Message,
  314. // duration: 2000,
  315. // icon: "error"
  316. // })
  317. // }
  318. // }
  319. // ).catch(error => {
  320. // // 处理失败的情况
  321. // console.error('Sava failed:', error);
  322. // playVoice(audioUrls.failVoiceUrl)
  323. // uni.showModal({
  324. // title: "提示",
  325. // content: error,
  326. // showCancel: true,
  327. // success: function(res) {
  328. // if (res.confirm) {
  329. // // vm.submit(FID)
  330. // } else {
  331. // // 执行取消后的操作
  332. // }
  333. // }
  334. // })
  335. // })
  336. // },
  337. handleCheckboxClick(itemId) {
  338. console.log(itemId)
  339. // 取消之前选中的项
  340. if (this.selectedItemId === itemId) {
  341. this.selectedItemId = null;
  342. this.billSummary.forEach(item => {
  343. item.checked = false;
  344. });
  345. console.log(this.billSummary)
  346. } else {
  347. // 更新选中项
  348. this.selectedItemId = itemId;
  349. this.billSummary.forEach(item => {
  350. item.checked = (item.FID === itemId);
  351. });
  352. console.log(this.billSummary)
  353. }
  354. console.log(this.selectedItemId)
  355. this.$forceUpdate()
  356. },
  357. }
  358. };
  359. </script>
  360. <style>
  361. .table-container {
  362. width: 100%;
  363. height: 100%;
  364. display: flex;
  365. flex-direction: column;
  366. }
  367. .container {
  368. display: flex;
  369. flex-direction: column;
  370. }
  371. .search-container {
  372. display: flex;
  373. justify-content: flex-start;
  374. flex-direction: row;
  375. align-items: stretch;
  376. /* padding: 2px; */
  377. border-bottom: 1px solid #ccc;
  378. flex-wrap: wrap;
  379. }
  380. .search-input {
  381. /* padding: 8px; */
  382. margin-right: 10px;
  383. border: 1px solid #ccc;
  384. border-radius: 4px;
  385. width: 200px;
  386. }
  387. .search-button {
  388. /* padding: 8px 16px; */
  389. border: none;
  390. border-radius: 4px;
  391. background-color: #007bff;
  392. color: #fff;
  393. cursor: pointer;
  394. }
  395. .search-button:hover {
  396. background-color: #0056b3;
  397. }
  398. .table-scroll {
  399. /* position: absolute; */
  400. flex: 1;
  401. overflow-x: auto;
  402. overflow-y: hidden;
  403. }
  404. .table-header {
  405. position: sticky;
  406. top: 0;
  407. background-color: #f0f0f0;
  408. font-weight: bold;
  409. border-bottom: 1px solid #ccc;
  410. display: flex;
  411. z-index: 1;
  412. /* 确保表头在内容之上 */
  413. }
  414. .table-cell1 {
  415. min-width: 160px;
  416. display: flex;
  417. justify-content: left;
  418. align-items: center;
  419. border-right: 1px solid #ccc;
  420. }
  421. .table-cell1-1 {
  422. min-width: 160px;
  423. display: flex;
  424. justify-content: center;
  425. align-items: center;
  426. border-right: 1px solid #ccc;
  427. }
  428. .table-cell {
  429. min-width: 100px;
  430. padding: 10px;
  431. display: flex;
  432. justify-content: center;
  433. align-items: center;
  434. border-right: 1px solid #ccc;
  435. }
  436. .header-cell {
  437. border-right: none;
  438. /* 取消最后一列的右边框 */
  439. }
  440. .table-body {
  441. flex: 1;
  442. width: fit-content;
  443. /* 使内容宽度适应内容的宽度 */
  444. }
  445. .table-row {
  446. display: flex;
  447. border-bottom: 1px solid #ccc;
  448. }
  449. .checkbox {
  450. width: 100%;
  451. height: 100%;
  452. display: flex;
  453. justify-content: center;
  454. align-items: center;
  455. }
  456. .bottom-bar {
  457. display: flex;
  458. /* justify-content: center; */
  459. justify-content: flex-end;
  460. /* 将按钮靠右对齐 */
  461. align-items: center;
  462. /* padding: 10px; */
  463. padding: 3px;
  464. background-color: #f0f0f0;
  465. }
  466. .button {
  467. margin: 0 10px;
  468. /* padding: 10px 20px; */
  469. }
  470. .cancel-btn {
  471. background-color: #ff0000;
  472. /* 取消按钮样式 */
  473. color: #fff;
  474. }
  475. .confirm-btn {
  476. background-color: #00ff00;
  477. /* 确认按钮样式 */
  478. color: #fff;
  479. }
  480. .checkbox-container {
  481. display: flex;
  482. align-items: center;
  483. margin-left: 10px;
  484. margin-right: 10px;
  485. /* 可根据需要调整间距 */
  486. }
  487. </style>