index.vue 3.6 KB

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