index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <view class='container'>
  3. <view class='content'>
  4. <view>
  5. <text class='title'>当前箱号</text>
  6. <view class="vehicleList uni-row" style="height: 100%;">
  7. <view class="vehicleNo uni-row" v-for="(item,index) in vehicleList">
  8. <text>{{item.carrierCode}}</text>
  9. <text @click="handleDelVehicleNo(item)">×</text>
  10. </view>
  11. </view>
  12. </view>
  13. <view class="btn">
  14. <button class='submit code' @click="handleScanCode()">扫码</button>
  15. </view>
  16. </view>
  17. <view class='bottom uni-row'>
  18. <button class='submit' type=primary @click="handleSubmit">提交</button>
  19. </view>
  20. </view>
  21. </template>
  22. <script setup>
  23. import {
  24. ref
  25. } from 'vue'
  26. import {
  27. onLoad,
  28. onReady
  29. } from '@dcloudio/uni-app'
  30. const vehicleList = ref([{ // 载具列表
  31. carrierId: '1731475038666575873',
  32. carrierCode: '000001'
  33. },
  34. {
  35. carrierId: '1731467623237767169',
  36. carrierCode: '000002'
  37. }
  38. ])
  39. onLoad(() => {})
  40. function init(){
  41. }
  42. function handleDelVehicleNo(item) {
  43. vehicleList.value.splice(item, 1);
  44. }
  45. function handleScanCode() {
  46. uni.scanCode({
  47. scanType: ['qrCode'], // 条形码扫描
  48. onlyFromCamera: true, // 只允许相机扫码
  49. success: function(res) {
  50. let vehicleObj = JSON.parse(res.result);
  51. for (let i = 0; i < vehicleList.value.length; i++) {
  52. if (Object.entries(vehicleList.value[i]).toString() === Object.entries(vehicleObj)
  53. .toString()) {
  54. uni.showToast({
  55. icon: "error",
  56. title: "载具已存在"
  57. })
  58. return;
  59. }
  60. }
  61. vehicleList.value.push(JSON.parse(res.result));
  62. }
  63. });
  64. }
  65. function handleSubmit() {
  66. }
  67. </script>
  68. <style lang="scss">
  69. .container {
  70. height: 100%;
  71. background-color: #f5f5f5;
  72. }
  73. .bottom {
  74. background-color: white;
  75. width: 100%;
  76. height: 100rpx;
  77. position: fixed;
  78. bottom: 0;
  79. align-items: center;
  80. }
  81. .submit {
  82. margin: 0 auto;
  83. width: 80%;
  84. height: 80rpx;
  85. line-height: 80rpx;
  86. padding-left: 0;
  87. }
  88. .code {
  89. background-color: rgba(0, 226, 166, 1);
  90. color: white;
  91. }
  92. .content {
  93. width: 90%;
  94. height: 1000rpx;
  95. background-color: rgba(255, 255, 255, 1);
  96. margin: 50rpx auto;
  97. padding-bottom: 50rpx;
  98. border-radius: 12rpx;
  99. .vehicleList {
  100. justify-content: flex-start;
  101. flex-wrap: wrap;
  102. width: 100%;
  103. height: 120rpx;
  104. overflow: auto;
  105. padding: 0 80rpx;
  106. .vehicleNo {
  107. padding: 0 10rpx;
  108. margin: 10rpx;
  109. justify-content: space-between;
  110. align-items: center;
  111. width: 230rpx;
  112. height: 60rpx;
  113. border: 1px solid rgba(213, 213, 213, 1);
  114. border-radius: 6rpx;
  115. }
  116. }
  117. }
  118. .title {
  119. margin: 30rpx auto;
  120. width: 30%;
  121. font-size: 36rpx;
  122. font-weight: bold;
  123. }
  124. .btn {
  125. position: fixed;
  126. top: 940rpx;
  127. left: 0;
  128. right: 0;
  129. }
  130. .segment {
  131. width: 280rpx;
  132. height: 1rpx;
  133. border: 1px solid rgba(187, 187, 187, 1);
  134. }
  135. </style>