index.vue 3.8 KB

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