index.vue 6.7 KB

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