index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <view class='container'>
  3. <view class='content'>
  4. <view>
  5. <text class='title'>当前箱号</text>
  6. <view class="vehicleList uni-row" style="overflow: auto;">
  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 style="border-top:1rpx solid #e1e1e1; height: 500rpx; overflow: auto; width: 90%;margin: 0 auto">
  13. <view class="uni-row" style="align-items: center;">
  14. <view style="flex: 3;margin-left: 60rpx;">箱号</view>
  15. <view style="flex: 3;">是否废弃</view>
  16. <view style="flex: 4; ">废弃原因</view>
  17. </view>
  18. <view class="vehicleNo uni-row" v-for="(item,index) in discardVehicleList"
  19. style="align-items: center;justify-content: space-around;">
  20. <view class="uni-row discardVehicleNo"><text>{{item.carrierCode}}</text>
  21. <text @click="handleDelDiscardVehicleList(item)">×</text>
  22. </view>
  23. <view class="uni-row">
  24. <switch color="#ff0000" style="transform:scale(0.7)" @change="handleSwitchChange(item)" />
  25. </view>
  26. <view class="uni-row">
  27. <uni-data-select v-model="item.reason" :localdata="abanonmentList" style="width: 240rpx;"
  28. :clear="false"></uni-data-select>
  29. </view>
  30. </view>
  31. </view>
  32. <view class="btn">
  33. <button class='submit code' @click="handleScanCode">扫码</button>
  34. </view>
  35. </view>
  36. <view class='bottom uni-row'>
  37. <button class='submit' type=primary @click="debounce(handleSubmit,300)">提交</button>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <script setup>
  43. import {
  44. ref
  45. } from 'vue'
  46. import {
  47. onLoad,
  48. onReady
  49. } from '@dcloudio/uni-app'
  50. import {
  51. getDictInfoByType
  52. } from '@/api/dict/dict.js'
  53. import {
  54. getDayworkCarrierList
  55. } from '@/api/business/dayworkCarrier.js'
  56. import {
  57. saveDayWork
  58. } from '@/api/business/dayWork.js'
  59. import {
  60. store
  61. } from '@/store/index.js'
  62. import {
  63. debounce
  64. } from '@/utils/common.js'
  65. import {
  66. addCarrierReject
  67. } from '@/api/business/carrier.js'
  68. const vehicleList = ref([])
  69. const discardVehicleList = ref([])
  70. const abanonmentList = ref([])
  71. let dayWorkInfo = store.dayworkInfo;
  72. onLoad(() => {
  73. let reqParam = {
  74. dayworkId: dayWorkInfo.id,
  75. isChanged: 0
  76. }
  77. init(reqParam);
  78. })
  79. function init(data) {
  80. console.log(data)
  81. getDayworkCarrierList(data).then(res => {
  82. console.log(res)
  83. if (res.code == 200) {
  84. vehicleList.value = res.rows;
  85. console.log(vehicleList.value)
  86. }
  87. })
  88. getDictInfoByType('reason_for_abandonment').then((res) => {
  89. for (var i = 0; i < res.data.length; i++) {
  90. abanonmentList.value[i] = {
  91. text: res.data[i].dictLabel,
  92. value: res.data[i].dictValue
  93. }
  94. }
  95. })
  96. }
  97. function handleSwitchChange(item) {
  98. item.checked = !item.checked
  99. }
  100. // function handleSelectRejectReason(item) {
  101. // for (var i = 0; i < abanonmentList.value.length; i++) {
  102. // if(abanonmentList.value[i].value == item.reason ) {
  103. // item.reason = abanonmentList.value[i].text
  104. // }
  105. // }
  106. // }
  107. function handleDelVehicleNo(item) {
  108. vehicleList.value.splice(item, 1);
  109. let discardVehicleInfo = {
  110. carrierCode: item.carrierCode,
  111. checked: false,
  112. reason: '',
  113. carrierId: item.carrierId
  114. }
  115. discardVehicleList.value.push(discardVehicleInfo)
  116. }
  117. function handleDelDiscardVehicleList(item) {
  118. discardVehicleList.value.splice(item, 1)
  119. vehicleList.value.push(item)
  120. }
  121. function handleScanCode() {
  122. uni.scanCode({
  123. scanType: ['qrCode'], // 条形码扫描
  124. onlyFromCamera: true, // 只允许相机扫码
  125. autoZoom: false,
  126. success: function(res) {
  127. let vehicleObj = JSON.parse(res.result);
  128. if (!vehicleObj.carrierId || vehicleObj.carrierId == "") {
  129. uni.showToast({
  130. icon: "error",
  131. title: "请扫载具码",
  132. duration: 1000
  133. })
  134. return;
  135. }
  136. for (let i = 0; i < vehicleList.value.length; i++) {
  137. if (vehicleList.value[i].carrierId === vehicleObj.carrierId) {
  138. uni.showToast({
  139. icon: "error",
  140. title: "载具已存在",
  141. duration: 1000
  142. })
  143. return;
  144. }
  145. }
  146. vehicleList.value.push(JSON.parse(res.result));
  147. }
  148. });
  149. }
  150. function handleSubmit() {
  151. dayWorkInfo.dayworkCarriers = vehicleList.value;
  152. saveDayWork(dayWorkInfo).then(res => {
  153. if (res.code === 200) {
  154. uni.showToast({
  155. icon: 'success',
  156. title: '添加成功'
  157. });
  158. // uni.$emit('batchReporting-addBatch')
  159. uni.$emit('dayworkItemUpdate');
  160. uni.navigateBack({
  161. url: '/pages/batchReporting/index'
  162. })
  163. } else {
  164. uni.showToast({
  165. icon: 'error',
  166. title: res.msg
  167. });
  168. }
  169. })
  170. let carrierRejectList = []
  171. let flag = true;
  172. for (var i = 0; i < discardVehicleList.value.length; i++) {
  173. if (discardVehicleList.value[i].checked && discardVehicleList.value[i].reason == "") {
  174. uni.showToast({
  175. icon: 'error',
  176. title: '第' + (i + 1) + '条未选择废弃原因'
  177. });
  178. flag = false;
  179. }
  180. if (discardVehicleList.value[i].checked && discardVehicleList.value[i].reason !== "") {
  181. carrierRejectList.push(discardVehicleList.value[i])
  182. }
  183. }
  184. if(carrierRejectList.length > 0 && flag){
  185. addCarrierReject(carrierRejectList).then((response) => {
  186. if (response.code == 200) {
  187. } else {
  188. uni.showToast({
  189. icon: 'error',
  190. title: '添加失败',
  191. });
  192. }
  193. })
  194. }
  195. }
  196. </script>
  197. <style lang="scss">
  198. .container {
  199. height: 100%;
  200. background-color: #f5f5f5;
  201. }
  202. .bottom {
  203. background-color: white;
  204. width: 100%;
  205. height: 100rpx;
  206. position: fixed;
  207. bottom: 0;
  208. align-items: center;
  209. }
  210. .submit {
  211. margin: 0 auto;
  212. width: 80%;
  213. height: 80rpx;
  214. line-height: 80rpx;
  215. padding-left: 0;
  216. }
  217. .code {
  218. background-color: rgba(0, 226, 166, 1);
  219. color: white;
  220. }
  221. .content {
  222. width: 90%;
  223. height: 1000rpx;
  224. background-color: rgba(255, 255, 255, 1);
  225. margin: 50rpx auto;
  226. padding-bottom: 50rpx;
  227. border-radius: 12rpx;
  228. .vehicleList {
  229. justify-content: flex-start;
  230. flex-wrap: wrap;
  231. width: 100%;
  232. height: 45%;
  233. // max-height: 300rpx;
  234. overflow: auto;
  235. padding: 0 80rpx;
  236. .vehicleNo {
  237. padding: 0 10rpx;
  238. margin: 10rpx;
  239. justify-content: space-between;
  240. align-items: center;
  241. width: 230rpx;
  242. height: 60rpx;
  243. border: 1px solid rgba(213, 213, 213, 1);
  244. border-radius: 6rpx;
  245. }
  246. }
  247. }
  248. .discardVehicleNo {
  249. padding: 0 10rpx;
  250. margin: 10rpx;
  251. justify-content: space-between;
  252. align-items: center;
  253. width: 150rpx;
  254. height: 60rpx;
  255. border: 1px solid rgba(213, 213, 213, 1);
  256. border-radius: 6rpx;
  257. }
  258. .title {
  259. margin: 30rpx auto;
  260. width: 30%;
  261. font-size: 36rpx;
  262. font-weight: bold;
  263. }
  264. .btn {
  265. position: fixed;
  266. top: 940rpx;
  267. left: 0;
  268. right: 0;
  269. }
  270. .segment {
  271. width: 280rpx;
  272. height: 1rpx;
  273. border: 1px solid rgba(187, 187, 187, 1);
  274. }
  275. </style>