index.vue 7.0 KB

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