summary.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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/audio.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. getAuditParam,
  58. getSaveParam,
  59. getSubmitParam
  60. } from '../../utils/params';
  61. import submitHelper from '../../utils/commonSubmitHelper.js';
  62. import {
  63. executeSql
  64. } from '../../utils/database';
  65. export default {
  66. data() {
  67. return {
  68. indexList: [],
  69. billSummary: [], // 这里存放处理后的每个 FBillNo 的统计结果
  70. selectedItemId: null,
  71. stageLists: [],
  72. tableName: "common_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. },
  80. computed: {
  81. },
  82. mounted() {
  83. this.calculateSummary()
  84. console.log(this.billSummary)
  85. },
  86. onBackPress(e) {
  87. console.log("监听返回按钮事件", e);
  88. if (e.from == "backbutton") {
  89. this.goBack()
  90. return true
  91. }
  92. },
  93. methods: {
  94. calculateSummary() {
  95. const summary = {};
  96. // 遍历数据,统计每个 FBillNo 的总条数和 smzt=1 的数量
  97. this.indexList.forEach(item => {
  98. const {
  99. FID,
  100. FBillNo,
  101. smzt
  102. } = item;
  103. if (!summary[FBillNo]) {
  104. summary[FBillNo] = {
  105. FID: FID,
  106. FBillNo: FBillNo,
  107. totalEntries: 0,
  108. smzt1Count: 0
  109. };
  110. }
  111. summary[FBillNo].totalEntries++;
  112. if (smzt === 1) {
  113. summary[FBillNo].smzt1Count++;
  114. }
  115. });
  116. // 将 summary 对象转为数组,便于在模板中遍历展示
  117. this.billSummary = Object.values(summary);
  118. },
  119. goBack() {
  120. let vm = this
  121. uni.navigateBack({
  122. success: function() {
  123. // 传递数据给上一页
  124. uni.$emit('summary', vm.indexList);
  125. }
  126. });
  127. },
  128. onScroll(e) {
  129. const scrollLeft = e.detail.scrollLeft;
  130. this.headerLeft = -scrollLeft; // 更新表头左侧位置,实现横向滚动时的对齐效果
  131. },
  132. async handleSubmit(FID) {
  133. if (this.selectedItemId == null) {
  134. uni.showToast({
  135. title: '请选择单据',
  136. duration: 3000,
  137. icon: "error"
  138. })
  139. playVoice(audioUrls.failVoiceUrl)
  140. return
  141. }
  142. const selectedItem = this.billSummary.find(item => item.FID === this.selectedItemId);
  143. const areEqual = selectedItem ? selectedItem.totalEntries === selectedItem.smzt1Count : false;
  144. if (!areEqual) {
  145. uni.showToast({
  146. title: '单据未全扫描',
  147. duration: 3000,
  148. icon: "error"
  149. })
  150. playVoice(audioUrls.failVoiceUrl)
  151. return
  152. }
  153. try {
  154. // await submitHelper.submit(FormId,FID, this.indexList);
  155. const FormId = uni.getStorageSync('formId')
  156. await submitHelper.submit(FormId, this.selectedItemId, this.indexList);
  157. this.indexList = this.indexList.filter(item => item.FID !== this.selectedItemId);
  158. this.billSummary = this.billSummary.filter(item => item.FID !==
  159. this.selectedItemId)
  160. console.log(this.indexList)
  161. if (this.stageLists.length != 0) {
  162. // 处理每个对象
  163. this.stageLists.forEach(item => {
  164. // 过滤掉 FID 匹配的对象
  165. item.data = item.data.filter(obj => obj.FID !== this.selectedItemId);
  166. // 检查 data 数组是否为空
  167. if (item.data.length === 0) {
  168. console.log("data 数组为空"); //删除暂存
  169. this.deleteStages(item.id)
  170. } else {
  171. console.log("data 数组不为空");
  172. }
  173. })
  174. console.log(this.stageLists)
  175. }
  176. } catch (error) {
  177. this.handleError(error)
  178. }
  179. },
  180. async deleteStages(id) {
  181. let condition = `id = (${id})`
  182. let sql = `delete from ${this.tableName} where ${condition}`
  183. executeSql(sql).then(result => {
  184. console.log('结果:', result);
  185. // this.handleDeleteSuccess()
  186. })
  187. .catch(error => {
  188. console.error('捕获错误:', error); // 输出: 捕获错误: 失败的结果
  189. // this.handleDeleteFail(error)
  190. })
  191. },
  192. handleError(error) {
  193. playVoice(audioUrls.failVoiceUrl)
  194. console.error('操作失败:', error);
  195. modal.confirm(error.message || '操作失败').then(res => {
  196. if (res) {
  197. } else {
  198. // 用户点击取消,不执行任何操作
  199. }
  200. })
  201. // uni.showToast({
  202. // title: error.message || '操作失败',
  203. // duration: 3000,
  204. // icon: "none"
  205. // });
  206. // playVoice(audioUrls.failVoiceUrl)
  207. // console.error('操作失败:', error);
  208. },
  209. handleCheckboxClick(itemId) {
  210. console.log(itemId)
  211. // 取消之前选中的项
  212. if (this.selectedItemId === itemId) {
  213. this.selectedItemId = null;
  214. this.billSummary.forEach(item => {
  215. item.checked = false;
  216. });
  217. console.log(this.billSummary)
  218. } else {
  219. // 更新选中项
  220. this.selectedItemId = itemId;
  221. this.billSummary.forEach(item => {
  222. item.checked = (item.FID === itemId);
  223. });
  224. console.log(this.billSummary)
  225. }
  226. console.log(this.selectedItemId)
  227. this.$forceUpdate()
  228. },
  229. }
  230. };
  231. </script>
  232. <style>
  233. .table-container {
  234. width: 100%;
  235. height: 100%;
  236. display: flex;
  237. flex-direction: column;
  238. }
  239. .container {
  240. display: flex;
  241. flex-direction: column;
  242. }
  243. .search-container {
  244. display: flex;
  245. justify-content: flex-start;
  246. flex-direction: row;
  247. align-items: stretch;
  248. /* padding: 2px; */
  249. border-bottom: 1px solid #ccc;
  250. flex-wrap: wrap;
  251. }
  252. .search-input {
  253. /* padding: 8px; */
  254. margin-right: 10px;
  255. border: 1px solid #ccc;
  256. border-radius: 4px;
  257. width: 200px;
  258. }
  259. .search-button {
  260. /* padding: 8px 16px; */
  261. border: none;
  262. border-radius: 4px;
  263. background-color: #007bff;
  264. color: #fff;
  265. cursor: pointer;
  266. }
  267. .search-button:hover {
  268. background-color: #0056b3;
  269. }
  270. .table-scroll {
  271. /* position: absolute; */
  272. flex: 1;
  273. overflow-x: auto;
  274. overflow-y: hidden;
  275. }
  276. .table-header {
  277. position: sticky;
  278. top: 0;
  279. background-color: #f0f0f0;
  280. font-weight: bold;
  281. border-bottom: 1px solid #ccc;
  282. display: flex;
  283. z-index: 1;
  284. /* 确保表头在内容之上 */
  285. }
  286. .table-cell1 {
  287. min-width: 160px;
  288. display: flex;
  289. justify-content: left;
  290. align-items: center;
  291. border-right: 1px solid #ccc;
  292. }
  293. .table-cell1-1 {
  294. min-width: 160px;
  295. display: flex;
  296. justify-content: center;
  297. align-items: center;
  298. border-right: 1px solid #ccc;
  299. }
  300. .table-cell {
  301. min-width: 100px;
  302. padding: 10px;
  303. display: flex;
  304. justify-content: center;
  305. align-items: center;
  306. border-right: 1px solid #ccc;
  307. }
  308. .header-cell {
  309. border-right: none;
  310. /* 取消最后一列的右边框 */
  311. }
  312. .table-body {
  313. flex: 1;
  314. width: fit-content;
  315. /* 使内容宽度适应内容的宽度 */
  316. }
  317. .table-row {
  318. display: flex;
  319. border-bottom: 1px solid #ccc;
  320. }
  321. .checkbox {
  322. width: 100%;
  323. height: 100%;
  324. display: flex;
  325. justify-content: center;
  326. align-items: center;
  327. }
  328. .bottom-bar {
  329. display: flex;
  330. /* justify-content: center; */
  331. justify-content: flex-end;
  332. /* 将按钮靠右对齐 */
  333. align-items: center;
  334. /* padding: 10px; */
  335. padding: 3px;
  336. background-color: #f0f0f0;
  337. }
  338. .button {
  339. margin: 0 10px;
  340. /* padding: 10px 20px; */
  341. }
  342. .cancel-btn {
  343. background-color: #ff0000;
  344. /* 取消按钮样式 */
  345. color: #fff;
  346. }
  347. .confirm-btn {
  348. background-color: #00ff00;
  349. /* 确认按钮样式 */
  350. color: #fff;
  351. }
  352. .checkbox-container {
  353. display: flex;
  354. align-items: center;
  355. margin-left: 10px;
  356. margin-right: 10px;
  357. /* 可根据需要调整间距 */
  358. }
  359. </style>