index.vue 7.5 KB

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