scan-clothing.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  1. <template>
  2. <view class="container" style="width: 100%;">
  3. <view class="top-section">
  4. <u-toast ref="uToast"></u-toast>
  5. <uni-easyinput v-model="clothValue" placeholder="扫描成衣条码" @confirm="scanCloth" :focus="isFocus"
  6. @blur="isFocus = false"></uni-easyinput>
  7. </view>
  8. <scroll-view class="scroll-view" scroll-y="true" show-scrollbar="true" @scroll="scroll"
  9. :scroll-into-view="scrollIndex">
  10. <!-- <view class="m-content"> -->
  11. <uni-swipe-action ref="swipeAction">
  12. <uni-swipe-action-item :ref="'swipeItem'+index" :id="'scroll'+index" v-for="(item, index) in clist"
  13. :key="item.FUniqueCode" :right-options="options" @click="click($event,index)">
  14. <view class="swipe-action u-border-top u-border-bottom">
  15. <view class="swipe-action__content">
  16. <text class="item-text"
  17. :style="boxData.BillType === 'AJHZX' && item.scan > item.FQty || item.isNew ||item.isErr?'color:red' : ''">
  18. 计划跟踪号:{{item.FMoto}}
  19. 尺码:{{item.FSize}},
  20. <span v-if="(boxData.BillType === 'AJHZX')">
  21. 数量:{{item.FQty}},
  22. </span>已扫描{{item.scan}}</text>
  23. </view>
  24. </view>
  25. </uni-swipe-action-item>
  26. </uni-swipe-action>
  27. <u-divider textColor="#2979ff" lineColor="#61a0ff" text="没有更多了"></u-divider>
  28. <!-- </view> -->
  29. </scroll-view>
  30. <view class="bottom-section">
  31. <uni-popup ref="inputDialog" type="dialog">
  32. <uni-popup-dialog ref="inputClose" mode="input" title="输入修改数量" v-model="updateVal"
  33. @confirm="dialogInputConfirm"></uni-popup-dialog>
  34. </uni-popup>
  35. <button @click="back" class="cu-btn bg-blue lg shadow" style="font-size: 60rpx;">上一步</button>
  36. <button @click="toCreat" :disabled="isClicked" ref="cButton" class="cu-btn bg-blue lg shadow"
  37. style="font-size: 60rpx;">生成</button>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import {
  43. GetClothesEnchaseByBarCode,
  44. GenerateClothesEnchase,
  45. GenerateClothesEnchaseCheck
  46. } from "../../api/enchase";
  47. export default {
  48. data() {
  49. return {
  50. isFocus: true,
  51. scrollTop: 0,
  52. old: {
  53. scrollTop: 0
  54. },
  55. scrollIndex: '',
  56. keyboardHideTimer: null,
  57. isScl: true,
  58. isPlan:true,
  59. isClicked: false,
  60. clist: [],
  61. clothValue: '',
  62. updateVal: '',
  63. currentIndex: '',
  64. bgColor: '',
  65. boxData: {
  66. IsExistCheck: true,
  67. PrdOrgId: '',
  68. BillType: '',
  69. EnchaseId: '',
  70. WorkShop: '',
  71. OrderNo: '',
  72. BoxNo: '',
  73. MatchNo: '',
  74. EnchaseTypeId: '',
  75. EnchaseType: '',
  76. Note: '',
  77. CustomId: '',
  78. CreatorNumber: '',
  79. FEntity: []
  80. },
  81. audioContext: null, // 存储音频上下文实例
  82. allSuccessUrl: "../../static/y1809.mp3",
  83. options: [{
  84. text: '编辑',
  85. style: {
  86. backgroundColor: '#007aff'
  87. }
  88. },
  89. {
  90. text: '删除',
  91. style: {
  92. backgroundColor: '#dd524d'
  93. }
  94. }
  95. ]
  96. };
  97. },
  98. //获取上一页传过来的参数
  99. onLoad(option) {
  100. let box_invType = uni.getStorageSync('box_invType')
  101. const Info = JSON.parse(decodeURIComponent(option.Info))
  102. if ("ZXRGJC" == box_invType) {
  103. console.log("手工检查----")
  104. this.boxData.BillType = Info.BillType;
  105. this.boxData.CreatorNumber = uni.getStorageSync('username')
  106. this.boxData.PrdOrgId = uni.getStorageSync('box_org')
  107. this.boxData.BoxNo = Info.EnchaseId
  108. this.boxData.WorkShop = uni.getStorageSync('box_workshopCode');
  109. this.boxData.EnchaseType = uni.getStorageSync('box_packType');
  110. this.boxData.EnchaseTypeId = uni.getStorageSync('box_packTypeId');
  111. uni.setStorageSync("plist", [])
  112. // console.log(this.boxData)
  113. } else {
  114. console.log("按计划装箱校验----")
  115. this.boxData.CreatorNumber = uni.getStorageSync('username')
  116. this.boxData.PrdOrgId = Info.PrdOrgId
  117. this.boxData.EnchaseId = Info.EnchaseId
  118. this.boxData.WorkShop = Info.WorkShopId
  119. this.boxData.OrderNo = Info.OrderNo
  120. this.boxData.CustomId = Info.FCustId
  121. this.boxData.FPlanQty = Info.FPlanQty
  122. this.boxData.BoxNo = Info.BoxNo
  123. this.boxData.MatchNo = Info.MatchNo
  124. this.boxData.EnchaseTypeId = Info.EnchaseTypeId
  125. this.boxData.EnchaseType = Info.EnchaseType
  126. this.boxData.Note = Info.Note
  127. this.boxData.BillType = Info.BillType;
  128. let plist = Info.FEntity.map(item => {
  129. return {
  130. FMoto: item.FMoto,
  131. FSize: item.FSize,
  132. FQty: item.FQty,
  133. scan: 0,
  134. isNew: false,
  135. isErr: false,
  136. show: 'none',
  137. FUniqueCode: item.FUniqueStr || '',
  138. FMaterialNum: item.FMaterialNum || '',
  139. FFabricPatternNo: item.FColorNo || '',
  140. }
  141. })
  142. uni.setStorageSync("plist", plist)
  143. this.clist = plist
  144. this.boxData.FEntity = plist
  145. console.log(this.boxData.FEntity)
  146. }
  147. //定时器隐藏软键盘
  148. // this.startKeyboardHideTimer();
  149. },
  150. // onReady() {
  151. // let Info = uni.getStorageSync("Info")
  152. // console.log(Info)
  153. // //判断装箱方式
  154. // if ("ZXRGJC" == Info.BillType) {
  155. // } else {
  156. // }
  157. // },
  158. computed: {
  159. shouldWatchData() {
  160. // 计算属性,决定是否应该监听clist的变化
  161. return this.boxData.BillType === 'AJHZX';
  162. },
  163. },
  164. methods: {
  165. click(e, index) {
  166. console.log("eeeeeeee" + index)
  167. if ("编辑" == e.content.text) {
  168. this.update(index)
  169. return
  170. }
  171. if ("删除" == e.content.text) {
  172. this.del(index)
  173. }
  174. },
  175. open(index) {
  176. // 先将正在被操作的swipeAction标记为打开状态,否则由于props的特性限制,
  177. // 原本为'false',再次设置为'false'会无效
  178. this.list[index].show = true;
  179. this.list.map((val, idx) => {
  180. if (index != idx) this.list[idx].show = false;
  181. })
  182. },
  183. focusPoint() {
  184. console.log("执行了")
  185. this.clothValue = ""
  186. this.isFocus = false;
  187. this.$nextTick(() => {
  188. this.clothValue = ""
  189. this.isFocus = true;
  190. // console.log("执行了2")
  191. });
  192. },
  193. //定位错误行
  194. findAndScrollToItem(index) {
  195. if (index > -1) {
  196. this.scrollIndex = ''
  197. setTimeout(() => {
  198. this.$nextTick(() => {
  199. this.scrollIndex = 'scroll' + index
  200. })
  201. }, 300);
  202. }
  203. },
  204. scroll: function(e) {
  205. console.log(e)
  206. this.old.scrollTop = e.detail.scrollTop
  207. },
  208. // onInputTap() {
  209. // // 清除定时器,允许键盘正常弹出
  210. // this.clearKeyboardInterval()
  211. // // 手动聚焦输入框
  212. // this.$refs.myInput.focus();
  213. // },
  214. // startKeyboardHideTimer() {
  215. // // 设置定时器尝试隐藏软键盘
  216. // this.keyboardHideTimer = setInterval(() => {
  217. // uni.hideKeyboard();
  218. // }, 50);
  219. // },
  220. // clearKeyboardInterval() {
  221. // // 页面销毁前清除定时器,防止内存泄漏
  222. // clearInterval(this.keyboardHideTimer);
  223. // this.keyboardHideTimer = null;
  224. // },
  225. //扫描成衣
  226. async scanCloth() {
  227. let that = this
  228. let data = '';
  229. console.log(this.clothValue);
  230. if (this.clothValue == "") {
  231. // this.playvoice()
  232. uni.showToast({
  233. title: '请扫描成衣条码',
  234. icon: 'none',
  235. duration: 3000
  236. })
  237. this.focusPoint()
  238. return
  239. }
  240. // if(!that.clothValue){
  241. // this.$modal.msgError("成衣扫描失败");
  242. // return
  243. // }
  244. this.checkCloth();
  245. try {
  246. let res = []
  247. if(this.isPlan){
  248. res = await GetClothesEnchaseByBarCode(this.clothValue,this.boxData.OrderNo)
  249. }else{
  250. res = await GetClothesEnchaseByBarCode(this.clothValue)
  251. }
  252. console.log(res);
  253. if (res && res[0]) {
  254. data = res[0]
  255. }
  256. } catch (e) {
  257. this.showToastError('请检查网络连接');
  258. console.error('GetClothesEnchaseByQRCode', e);
  259. }
  260. if (!data) {
  261. this.showToastError("成衣明细读取异常!");
  262. return
  263. }
  264. console.log(data);
  265. this.updateClist(data);
  266. },
  267. //手工单个检查
  268. checkOne(data) {
  269. if (this.clist.length < 1) {
  270. return true
  271. }
  272. let one = this.clist[0]
  273. if (this.boxData.EnchaseType.includes("独款")) {
  274. if (data.FMaterialNum != one.FMaterialNum) {
  275. console.log("检查装箱方式---one---》独款false")
  276. return false
  277. }
  278. }
  279. if (this.boxData.EnchaseType.includes("独色")) {
  280. if (data.FMoto != one.FMoto || data.FFabricPatternNo != one.FFabricPatternNo) {
  281. console.log("检查装箱方式---one---》独色false")
  282. return false
  283. }
  284. }
  285. if (this.boxData.EnchaseType.includes("独码")) {
  286. if (data.FSize != one.FSize) {
  287. console.log("检查装箱方式---one---》独码false")
  288. return false
  289. }
  290. }
  291. return true
  292. },
  293. //手工检查装箱方式
  294. checkAll() {
  295. if (this.clist.length < 2) {
  296. return true
  297. }
  298. let one = this.clist[0]
  299. console.log("检查装箱方式---one---》" + one.FUniqueCode)
  300. if (this.boxData.EnchaseType.includes("独款")) {
  301. if (!this.clist.every(item => item.FMaterialNum === one.FMaterialNum)) {
  302. // this.boxData.IsExistCheck = false;
  303. console.log("检查装箱方式---one---》独款false")
  304. return false
  305. }
  306. }
  307. if (this.boxData.EnchaseType.includes("独色")) {
  308. if (!this.clist.every(item => item.FMoto === one.FMoto) || !this.clist.every(item => item
  309. .FFabricPatternNo === one.FFabricPatternNo)) {
  310. // this.boxData.IsExistCheck = false;
  311. console.log("检查装箱方式---one---》独色false")
  312. return false
  313. }
  314. }
  315. if (this.boxData.EnchaseType.includes("独码")) {
  316. if (!this.clist.every(item => item.FSize === one.FSize)) {
  317. // this.boxData.IsExistCheck = false;
  318. console.log("检查装箱方式---one---》独码false")
  319. return false
  320. }
  321. }
  322. return true
  323. },
  324. //第一步检查
  325. checkCloth() {
  326. //判断是否是扫描列表中的成衣
  327. this.isScl = this.clist.find(item => item.FUniqueCode == this.clothValue)
  328. // //判断是否是计划中的成衣
  329. let plist = uni.getStorageSync("plist")
  330. this.isPlan = plist.find(item => item.FUniqueCode == this.clothValue)
  331. },
  332. //第二步更新列表
  333. updateClist(data) {
  334. let vm = this
  335. if ("AJHZX" == this.boxData.BillType) {
  336. if (this.isScl) {
  337. for (let i = 0; i < this.clist.length; i++) {
  338. console.log(this.clist[i])
  339. let FUniqueCode = this.clist[i].FUniqueCode;
  340. let fqty = this.clist[i].FQty || 0;
  341. if (FUniqueCode == data.FUniqueCode) {
  342. if (!this.clist[i].scan) {
  343. this.clist[i].scan = 0
  344. }
  345. this.$set(this.clist[i], "scan", this.clist[i].scan + 1)
  346. this.$set(this.clist[i], "FUniqueCode", data.FUniqueCode)
  347. this.$set(this.clist[i], "FMaterialNum", data.FMaterialNum)
  348. this.$set(this.clist[i], "FFabricPatternNo", data.FFabricPatternNo)
  349. this.$set(this.clist[i], "FSize", data.FSize)
  350. if (this.clist[i].scan > fqty) {
  351. this.scanError(i, '请检查扫描数量!')
  352. //定位错误行
  353. break;
  354. } else {
  355. this.scanSuccess()
  356. break;
  357. }
  358. }
  359. }
  360. } else {
  361. //新增一行
  362. let size = this.clist.length;
  363. console.log(size + "新增一条")
  364. this.clist[size] = data
  365. this.clist[size].scan = 1
  366. this.clist[size].isNew = true;
  367. this.scanError(size, "不在计划中!")
  368. }
  369. } else {
  370. if (this.isScl) {
  371. for (let i in this.clist) {
  372. console.log(this.clist[i].FUniqueCode)
  373. let FUniqueCode = this.clist[i].FUniqueCode;
  374. let fqty = this.clist[i].FQty || 0;
  375. if (FUniqueCode == data.FUniqueCode) {
  376. this.clist[i].scan += 1;
  377. if (i === 0 && this.clist[i].scan === 1) {
  378. this.scanSuccess()
  379. break;
  380. } else {
  381. if (!this.checkAll()) {
  382. this.scanError(i, "请检查装箱方式!")
  383. break;
  384. }
  385. this.scanSuccess()
  386. }
  387. }
  388. }
  389. } else {
  390. let size = this.clist.length;
  391. console.log(size + "新增一条")
  392. this.clist[size] = data
  393. this.clist[size].scan = 1
  394. if (!this.checkOne(data)) {
  395. this.clist[size].isErr = true
  396. this.scanError(size, "请检查装箱方式!")
  397. } else {
  398. if (!this.checkAll()) {
  399. this.scanError(size, "请检查装箱方式!")
  400. } else {
  401. this.scanSuccess()
  402. }
  403. }
  404. }
  405. }
  406. },
  407. scanSuccess() {
  408. this.showToastSuccess('扫描成功!')
  409. this.playvoiceGood()
  410. this.$forceUpdate();
  411. this.focusPoint();
  412. },
  413. scanError(index, message) {
  414. this.showToastError(message)
  415. this.playvoiceError()
  416. this.$forceUpdate();
  417. //定位错误行
  418. console.log(index);
  419. this.findAndScrollToItem(index)
  420. },
  421. async toCreat() {
  422. if (this.isClicked) return;
  423. this.isClicked = true;
  424. uni.showLoading({
  425. title: '正在生成...',
  426. });
  427. try {
  428. if (!this.clist || this.clist.length == 0) {
  429. this.showToastError("扫描列表为空")
  430. return
  431. }
  432. if ("ZXRGJC" == this.boxData.BillType) {
  433. if (!this.checkAll()) {
  434. this.showToastError("装箱方式不合规")
  435. this.playvoiceError()
  436. return
  437. } else {
  438. //封装装箱数据
  439. let scanSum = 0
  440. for (let i = 0; i < this.clist.length; i++) {
  441. console.log(this.clist[i].FUniqueCode)
  442. scanSum = scanSum + this.clist[i].scan || 0;
  443. }
  444. this.boxData.ScanQty = scanSum
  445. this.boxData.FEntity = this.clist
  446. this.boxData.OrderNo = this.clist[0].FOrderNo
  447. this.boxData.CustomId = this.clist[0].FCustId
  448. //生成装箱
  449. let param = this.transParam(this.boxData);
  450. console.log(param)
  451. await this.generateClothesEnchase(param);
  452. }
  453. } else {
  454. //封装装箱数据
  455. let scanSum = 0
  456. for (let i = 0; i < this.clist.length; i++) {
  457. console.log(this.clist[i].FUniqueCode)
  458. scanSum = scanSum + this.clist[i].scan || 0;
  459. }
  460. this.boxData.ScanQty = scanSum
  461. this.boxData.FEntity = this.clist
  462. //计划装箱校验
  463. let param = this.transParam(this.boxData);
  464. console.log(param)
  465. let check = await this.generateClothesEnchaseCheck(param)
  466. if (check.Flag) {
  467. //生成装箱
  468. await this.generateClothesEnchase(param);
  469. } else {
  470. console.log(check.Flag)
  471. console.log(check.IsInteractive)
  472. console.log(check.Message)
  473. let vm = this
  474. //根据提示是否弹窗提醒
  475. if (check.IsInteractive) {
  476. await uni.showModal({
  477. title: '提示',
  478. content: check.Message,
  479. success: function(res) {
  480. if (res.confirm) {
  481. console.log('用户点击确定');
  482. vm.generateClothesEnchase(param);
  483. } else if (res.cancel) {
  484. console.log('用户点击取消');
  485. return
  486. }
  487. }
  488. });
  489. } else {
  490. this.showToastError(check.Message)
  491. this.playvoiceError()
  492. return
  493. }
  494. }
  495. }
  496. } catch (e) {
  497. console.log(e);
  498. } finally {
  499. this.isClicked = false;
  500. // this.$refs.cButton.disabled = false;
  501. uni.hideLoading()
  502. console.log('处理完成');
  503. }
  504. },
  505. transParam(data) {
  506. let Entity = data.FEntity.map(item => {
  507. return {
  508. UniqueNoId: item.FUniqueCode,
  509. ScanQty: item.scan
  510. }
  511. })
  512. let param = {
  513. "IsExistCheck": data.IsExistCheck,
  514. "PrdOrgId": data.PrdOrgId,
  515. "BillType": data.BillType,
  516. "EnchaseId": data.EnchaseId,
  517. "WorkShop": data.WorkShop,
  518. "OrderNo": data.OrderNo,
  519. "BoxNo": data.BoxNo,
  520. "MatchNo": data.MatchNo,
  521. "EnchaseTypeId": data.EnchaseTypeId,
  522. "EnchaseType": data.EnchaseType,
  523. "Note": data.Note,
  524. "CustomId": data.CustomId,
  525. "CreatorNumber": data.CreatorNumber,
  526. "FEntity": Entity
  527. }
  528. return param
  529. },
  530. back() {
  531. let vm = this
  532. //检查扫描数据
  533. if (this.clist.length != 0) {
  534. uni.showModal({
  535. title: '提示',
  536. content: '已经有扫描数据,是否放弃扫描结果?',
  537. cancelText: '否',
  538. confirmText: '是',
  539. success: function(res) {
  540. if (res.confirm) {
  541. console.log('用户点击确定');
  542. // vm.clearKeyboardInterval()
  543. uni.reLaunch({
  544. url: "/pages/index/scan-box"
  545. })
  546. } else if (res.cancel) {
  547. console.log('用户点击取消');
  548. }
  549. }
  550. });
  551. } else {
  552. // vm.clearKeyboardInterval()
  553. uni.reLaunch({
  554. url: "/pages/index/scan-box"
  555. })
  556. }
  557. },
  558. update(index) {
  559. // this.clearKeyboardInterval()
  560. let val = this.clist[index].scan || 0
  561. this.updateVal = val;
  562. this.currentIndex = index;
  563. this.$refs.inputDialog.open()
  564. },
  565. dialogInputConfirm(val) {
  566. if (isNaN(val)) {
  567. this.showToastError('请输入正确的数量!');
  568. } else {
  569. this.clist[this.currentIndex].scan = parseInt(val);
  570. }
  571. if ("AJHZX" == this.boxData.BillType) {
  572. if (parseInt(val) > this.clist[this.currentIndex].FQty) {
  573. this.clist[this.currentIndex].setRed = true;
  574. } else {
  575. this.clist[this.currentIndex].setRed = false;
  576. }
  577. }
  578. // 关闭窗口
  579. this.$refs.inputDialog.close()
  580. this.$forceUpdate();
  581. this.$refs.swipeAction.closeAll()
  582. },
  583. del(index) {
  584. console.log(index)
  585. if (this.clist[index].FQty > 0) {
  586. this.$refs.uToast.show({
  587. message: '不可以删除计划内的成衣!',
  588. type: 'warning',
  589. icon: true
  590. })
  591. return
  592. }
  593. this.clist.splice(index, 1)
  594. let isPlay = false;
  595. if (index === 0 && "ZXRGJC" == this.boxData.BillType) {
  596. for (let i in this.clist) {
  597. let data = this.clist[i]
  598. if (!this.checkOne(data)) {
  599. this.clist[i].isErr = true
  600. isPlay = true;
  601. } else {
  602. this.clist[i].isErr = false
  603. }
  604. }
  605. if (isPlay) {
  606. this.showToastError("删除成功!请检查装箱方式!")
  607. this.playvoiceError()
  608. return
  609. }
  610. }
  611. this.$refs.uToast.show({
  612. message: '删除成功',
  613. type: 'success',
  614. icon: true,
  615. position: 'top'
  616. })
  617. this.playvoiceGood()
  618. this.$forceUpdate();
  619. },
  620. playvoiceGood() {
  621. console.log('good-----shengyin', this.audioContext)
  622. if (this.audioContext) {
  623. try {
  624. this.audioContext.pause();
  625. this.audioContext.destroy()
  626. this.audioContext = null
  627. } catch (e) {
  628. //TODO handle the exception
  629. }
  630. this.audioContext = uni.createInnerAudioContext();
  631. this.audioContext.autoplay = true;
  632. this.audioContext.src = '../../static/success.mp3';
  633. this.audioContext.onPlay(() => {
  634. console.log('开始播放');
  635. });
  636. } else {
  637. // 如果音频上下文实例不存在,则创建新的实例并播放
  638. this.audioContext = uni.createInnerAudioContext();
  639. this.audioContext.autoplay = true;
  640. this.audioContext.src = '../../static/success.mp3';
  641. this.audioContext.onPlay(() => {
  642. console.log('开始播放');
  643. });
  644. }
  645. },
  646. playvoiceError() {
  647. console.log('error-----shengyin', this.audioContext)
  648. if (this.audioContext) {
  649. try {
  650. this.audioContext.pause();
  651. this.audioContext.destroy()
  652. this.audioContext = null
  653. } catch (e) {
  654. //TODO handle the exception
  655. }
  656. this.audioContext = uni.createInnerAudioContext();
  657. this.audioContext.autoplay = true;
  658. this.audioContext.src = '../../static/error.mp3';
  659. this.audioContext.onPlay(() => {
  660. console.log('开始播放');
  661. });
  662. } else {
  663. // 如果音频上下文实例不存在,则创建新的实例并播放
  664. this.audioContext = uni.createInnerAudioContext();
  665. this.audioContext.autoplay = true;
  666. this.audioContext.src = '../../static/error.mp3';
  667. this.audioContext.onPlay(() => {
  668. console.log('开始播放');
  669. });
  670. }
  671. },
  672. showToastSuccess(message) {
  673. this.$refs.uToast.show({
  674. message: message,
  675. type: 'success',
  676. icon: true,
  677. position: 'top'
  678. });
  679. },
  680. showToastError(message) {
  681. this.$refs.uToast.show({
  682. message: message,
  683. type: 'error',
  684. icon: true,
  685. position: 'top'
  686. });
  687. },
  688. async generateClothesEnchaseCheck(param) {
  689. return await GenerateClothesEnchaseCheck(JSON.stringify(param))
  690. },
  691. async generateClothesEnchase(param) {
  692. try {
  693. const res = await GenerateClothesEnchase(JSON.stringify(param))
  694. if (res) {
  695. if (res.Flag) {
  696. uni.reLaunch({
  697. url: "/pages/index/scan-box"
  698. })
  699. this.showToastSuccess("生成装箱成功!")
  700. this.playvoiceGood()
  701. } else {
  702. uni.showModal({
  703. title: '提示',
  704. content: res.Message,
  705. showCancel: false,
  706. success: function(res) {
  707. if (res.confirm) {
  708. console.log('用户点击确定');
  709. return
  710. } else if (res.cancel) {
  711. console.log('用户点击取消');
  712. return
  713. }
  714. }
  715. })
  716. this.playvoiceError()
  717. }
  718. } else {
  719. console.error('装箱接口连接失败')
  720. uni.showModal({
  721. title: '提示',
  722. content: '接口连接失败',
  723. showCancel: false,
  724. success: function(res) {
  725. if (res.confirm) {
  726. console.log('用户点击确定');
  727. return
  728. } else if (res.cancel) {
  729. console.log('用户点击取消');
  730. return
  731. }
  732. }
  733. });
  734. this.playvoiceError()
  735. }
  736. } catch (error) {
  737. console.error('GenerateClothesEnchase', error);
  738. uni.showModal({
  739. title: '生成装箱错误',
  740. content: error.errMsg,
  741. showCancel: false,
  742. success: function(res) {
  743. if (res.confirm) {
  744. console.log('用户点击确定');
  745. return
  746. } else if (res.cancel) {
  747. console.log('用户点击取消');
  748. return
  749. }
  750. }
  751. });
  752. this.playvoiceError()
  753. }
  754. }
  755. },
  756. }
  757. </script>
  758. <style lang="scss" scoped>
  759. .container {
  760. display: flex;
  761. flex-direction: column;
  762. height: 100%; // 填满整个视口高度
  763. // overflow-y: hidden;
  764. .top-section {
  765. flex: 1;
  766. flex-shrink: 0; // 确保 input 总是在顶部
  767. padding: 20rpx 20rpx 1rpx; // 添加适当的内边距
  768. }
  769. .scroll-view {
  770. flex: 5;
  771. overflow-y: auto;
  772. height: 500rpx;
  773. padding: 1rpx 20rpx 10rpx;
  774. // .m-content {
  775. // /* 示例高度,可以根据实际内容调整 */
  776. .item-text {
  777. font-size: 15px;
  778. }
  779. // }
  780. }
  781. .bottom-section {
  782. flex: 1;
  783. flex-shrink: 0; // 确保按钮总是在底部
  784. display: flex;
  785. justify-content: space-evenly; // 按钮之间均匀分布
  786. padding: 20rpx; // 添加适当的内边距
  787. }
  788. }
  789. </style>