processcode-scan.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <view class="bg-white page">
  3. <form @submit="onSubmit">
  4. <view class="border flex form-container ">
  5. <input v-if='showClear' type="text" v-model="form.barcode" name='barcode' disabled :placeholder="barcodekey" class="width-100 form-item-input px-1"/>
  6. <scan-btn
  7. sourcename="form"
  8. :barcodekey="barcodekey"
  9. keyname="barcode"
  10. :scaning="scaning"
  11. :show-clear="showClear"
  12. @scan="onScan"
  13. @clear="onClearValue"
  14. @close="onCloseScanPage"
  15. clearIconClass="form-item-icon"
  16. :class="showClear ? '' : 'width-100'"
  17. >
  18. <view class="flex">
  19. <view class="form-item-input font-mmd flex-1 text-left pl-2">{{barcodekey}}</view>
  20. <view class="iconfont form-item-icon icon-ziyuan"></view>
  21. </view>
  22. </scan-btn>
  23. </view>
  24. <view class="px-5">
  25. <button type="primary" form-type="submit">确认</button>
  26. </view>
  27. </form>
  28. </view>
  29. </template>
  30. <script>
  31. import scanBtn from "@/components/common/scan-btn.vue"
  32. import {onErrorbarcodeKey} from "@/common/utils/common.js"
  33. import {onScanMixin} from "@/common/utils/mixins.js"
  34. const graceChecker = require("../../common/utils/graceChecker.js");
  35. export default {
  36. mixins:[onScanMixin],
  37. components:{
  38. scanBtn
  39. },
  40. data () {
  41. return {
  42. barcodekey:null, // 条形码关键字
  43. nextUrl:null,
  44. form:{
  45. barcode:""
  46. },
  47. }
  48. },
  49. computed:{
  50. // 是否显示删除按钮
  51. showClear () {
  52. return Boolean(this.form.barcode)
  53. }
  54. },
  55. onLoad (e) {
  56. if (e.title) {
  57. uni.setNavigationBarTitle({
  58. title:e.title
  59. })
  60. }
  61. if (e.nextUrl) {
  62. this.nextUrl=e.nextUrl
  63. }
  64. this.barcodekey=e.barcodekey
  65. },
  66. onUnload () {
  67. this.removeListenerFn()
  68. this.onClearValue()
  69. },
  70. onShow () {
  71. this.addListenerFn()
  72. },
  73. onHide () {
  74. this.removeListenerFn()
  75. this.onClearValue()
  76. },
  77. methods:{
  78. // 清除数据
  79. onClearValue () {
  80. this.form.barcode=null
  81. },
  82. // 确认
  83. onSubmit (e) {
  84. const rules=[
  85. {name:"barcode",checkType:"notnull",errorMsg:"请填写条形码"},
  86. ]
  87. const formData=e.detail.value
  88. const checkRes=graceChecker.check(formData,rules)
  89. if(checkRes){
  90. const nextUrl=this.nextUrl ? this.nextUrl : "index"
  91. uni.navigateTo({
  92. url:`/pages/${nextUrl}/${nextUrl}?barcode=${formData.barcode}`
  93. })
  94. }else{
  95. this.form={
  96. barcode:null
  97. }
  98. return uni.showToast({
  99. title:graceChecker.error,
  100. icon:"none"
  101. })
  102. }
  103. }
  104. }
  105. }
  106. </script>
  107. <style scoped>
  108. .form-container{
  109. margin-top:100px;
  110. margin-bottom:80px ;
  111. }
  112. .form-item-icon{
  113. background-color: #eee;
  114. }
  115. </style>