index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. import { getDayworkCarrierList } from '@/api/business/dayworkCarrier.js'
  31. import { saveDayWork } from '@/api/business/dayWork.js'
  32. import { store } from '@/store/index.js'
  33. const vehicleList = ref([])
  34. let dayWorkInfo = store.dayworkInfo;
  35. onLoad(() => {
  36. let reqParam = {
  37. dayworkId: dayWorkInfo.id,
  38. isChanged: 0
  39. }
  40. init(reqParam);
  41. })
  42. function init(data){
  43. console.log(data)
  44. getDayworkCarrierList(data).then(res => {
  45. console.log(res)
  46. if(res.code == 200){
  47. vehicleList.value = res.rows;
  48. console.log(vehicleList.value)
  49. }
  50. })
  51. }
  52. function handleDelVehicleNo(item) {
  53. vehicleList.value.splice(item, 1);
  54. }
  55. function handleScanCode() {
  56. uni.scanCode({
  57. scanType: ['qrCode'], // 条形码扫描
  58. onlyFromCamera: true, // 只允许相机扫码
  59. success: function(res) {
  60. let vehicleObj = JSON.parse(res.result);
  61. if(!vehicleObj.carrierId || vehicleObj.carrierId == ""){
  62. uni.showToast({
  63. icon: "error",
  64. title: "载具码错误",
  65. duration: 2000
  66. })
  67. return;
  68. }
  69. for (let i = 0; i < vehicleList.value.length; i++) {
  70. if (vehicleList.value[i].carrierId === vehicleObj.carrierId) {
  71. uni.showToast({
  72. icon: "error",
  73. title: "载具已存在",
  74. duration: 2000
  75. })
  76. return;
  77. }
  78. }
  79. vehicleList.value.push(JSON.parse(res.result));
  80. }
  81. });
  82. }
  83. function handleSubmit() {
  84. dayWorkInfo.dayworkCarriers = vehicleList.value;
  85. console.log(dayWorkInfo);
  86. saveDayWork(dayWorkInfo).then(res => {
  87. if (res.code === 200) {
  88. uni.showToast({
  89. icon: 'success',
  90. title: '添加成功',
  91. duration: 2000
  92. });
  93. uni.$emit('batchReporting-addBatch')
  94. uni.navigateBack({
  95. url: '/pages/batchReporting/index'
  96. })
  97. } else {
  98. uni.showToast({
  99. icon: 'error',
  100. title: '添加失败',
  101. duration: 2000
  102. });
  103. }
  104. })
  105. }
  106. </script>
  107. <style lang="scss">
  108. .container {
  109. height: 100%;
  110. background-color: #f5f5f5;
  111. }
  112. .bottom {
  113. background-color: white;
  114. width: 100%;
  115. height: 100rpx;
  116. position: fixed;
  117. bottom: 0;
  118. align-items: center;
  119. }
  120. .submit {
  121. margin: 0 auto;
  122. width: 80%;
  123. height: 80rpx;
  124. line-height: 80rpx;
  125. padding-left: 0;
  126. }
  127. .code {
  128. background-color: rgba(0, 226, 166, 1);
  129. color: white;
  130. }
  131. .content {
  132. width: 90%;
  133. height: 1000rpx;
  134. background-color: rgba(255, 255, 255, 1);
  135. margin: 50rpx auto;
  136. padding-bottom: 50rpx;
  137. border-radius: 12rpx;
  138. .vehicleList {
  139. justify-content: flex-start;
  140. flex-wrap: wrap;
  141. width: 100%;
  142. height: 120rpx;
  143. overflow: auto;
  144. padding: 0 80rpx;
  145. .vehicleNo {
  146. padding: 0 10rpx;
  147. margin: 10rpx;
  148. justify-content: space-between;
  149. align-items: center;
  150. width: 230rpx;
  151. height: 60rpx;
  152. border: 1px solid rgba(213, 213, 213, 1);
  153. border-radius: 6rpx;
  154. }
  155. }
  156. }
  157. .title {
  158. margin: 30rpx auto;
  159. width: 30%;
  160. font-size: 36rpx;
  161. font-weight: bold;
  162. }
  163. .btn {
  164. position: fixed;
  165. top: 940rpx;
  166. left: 0;
  167. right: 0;
  168. }
  169. .segment {
  170. width: 280rpx;
  171. height: 1rpx;
  172. border: 1px solid rgba(187, 187, 187, 1);
  173. }
  174. </style>