index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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-easyinput v-if="item.inpShow" v-model="item.abandonmentReason" focus placeholder="请输入废箱原因"
  29. style="width: 240rpx;"></uni-easyinput>
  30. <uni-data-select v-else v-model="item.abandonmentReason" :localdata="abanonmentList"
  31. style="width: 240rpx;" :clear="false"
  32. @change="abandonmentReasonChange(item)"></uni-data-select>
  33. </view>
  34. <!-- 占空位用 -->
  35. <view class="uni-row" v-if="!item.checked">
  36. <view style="width: 240rpx;"></view>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. <view class='bottom uni-row'>
  42. <button class='bottom-btn left-btn' @click="handleScanCode">扫码</button>
  43. <button class='bottom-btn right-btn' type=primary @click="debounce(handleSubmit,300)">提交</button>
  44. </view>
  45. </view>
  46. </template>
  47. <script setup>
  48. import {
  49. ref
  50. } from 'vue'
  51. import {
  52. onLoad,
  53. onReady
  54. } from '@dcloudio/uni-app'
  55. import {
  56. getDictInfoByType
  57. } from '@/api/dict/dict.js'
  58. import {
  59. getDayworkCarrierList
  60. } from '@/api/business/dayworkCarrier.js'
  61. import {
  62. saveDayWork
  63. } from '@/api/business/dayWork.js'
  64. import {
  65. store
  66. } from '@/store/index.js'
  67. import {
  68. debounce
  69. } from '@/utils/common.js'
  70. import {
  71. addCarrierReject,
  72. checkCarrier,
  73. checkCarrierNew
  74. } from '@/api/business/carrier.js'
  75. const bindList = ref([])
  76. const newBindList = ref([])
  77. const discardVehicleList = ref([])
  78. const abanonmentList = ref([])
  79. let dayWorkInfo = store.dayworkInfo;
  80. onLoad(() => {
  81. let reqParam = {
  82. dayworkId: dayWorkInfo.id,
  83. isChanged: 0
  84. }
  85. init(reqParam);
  86. })
  87. function init(data) {
  88. console.log(data)
  89. getDayworkCarrierList(data).then(res => {
  90. console.log(res)
  91. if (res.code == 200) {
  92. bindList.value = [...res.rows];
  93. newBindList.value = res.rows;
  94. }
  95. })
  96. getDictInfoByType('reason_for_abandonment').then((res) => {
  97. for (var i = 0; i < res.data.length; i++) {
  98. abanonmentList.value[i] = {
  99. text: res.data[i].dictLabel,
  100. value: res.data[i].dictLabel
  101. }
  102. }
  103. })
  104. }
  105. function handleSwitchChange(item) {
  106. item.checked = !item.checked
  107. }
  108. function abandonmentReasonChange(item) {
  109. if (item.abandonmentReason == '其他原因') {
  110. item.inpShow = true;
  111. } else {
  112. item.inpShow = false;
  113. }
  114. }
  115. // function handleSelectRejectReason(item) {
  116. // for (var i = 0; i < abanonmentList.value.length; i++) {
  117. // if(abanonmentList.value[i].value == item.reason ) {
  118. // item.reason = abanonmentList.value[i].text
  119. // }
  120. // }
  121. // }
  122. function handleDelVehicleNo(item, index) {
  123. if (bindList.value.some(carrier => carrier.carrierCode == item.carrierCode)) {
  124. console.log(bindList.value)
  125. newBindList.value.splice(index, 1);
  126. let discardVehicleInfo = {
  127. carrierCode: item.carrierCode,
  128. checked: false,
  129. reason: '',
  130. carrierId: item.carrierId,
  131. isAbandoned: 1,
  132. operationDate: new Date()
  133. }
  134. discardVehicleList.value.push(discardVehicleInfo)
  135. } else {
  136. newBindList.value.splice(index, 1);
  137. }
  138. }
  139. function handleDelDiscardVehicleList(item, index) {
  140. discardVehicleList.value.splice(index, 1)
  141. newBindList.value.push(item)
  142. item.inpShow = false;
  143. }
  144. function handleScanCode() {
  145. // 引入原生插件
  146. const mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
  147. // 调用插件的 mpaasScan 方法
  148. mpaasScanModule.mpaasScan({
  149. // 扫码识别类型,参数可多选,qrCode、barCode,
  150. // 如不设置,默认识别所有扫码类型,可能有些许影响识别效率
  151. scanType: ["qrCode", "barCode"],
  152. // 是否隐藏相册,默认false不隐藏
  153. hideAlbum: false,
  154. },
  155. (ret) => {
  156. let vehicleObj = JSON.parse(ret.resp_result);
  157. if (!vehicleObj.carrierId || vehicleObj.carrierId == "") {
  158. uni.showToast({
  159. icon: "none",
  160. title: "请扫载具码"
  161. })
  162. return;
  163. }
  164. for (let i = 0; i < newBindList.value.length; i++) {
  165. if (newBindList.value[i].carrierId === vehicleObj.carrierId) {
  166. uni.showToast({
  167. icon: "none",
  168. title: "载具已存在"
  169. })
  170. return;
  171. }
  172. }
  173. const checkData = {
  174. ...dayWorkInfo,
  175. dayworkCarriers: newBindList.value,
  176. newCarrierId: vehicleObj.carrierId
  177. }
  178. checkCarrierNew(checkData).then(response => {
  179. console.log(response)
  180. // uni.showToast({
  181. // icon: 'none',
  182. // title: response.msg
  183. // })
  184. if (response.code == 200) {
  185. newBindList.value.push(JSON.parse(ret.resp_result));
  186. } else {
  187. uni.showToast({
  188. icon: 'none',
  189. title: response.msg
  190. })
  191. return;
  192. }
  193. }).catch(err => {
  194. uni.showToast({
  195. icon: 'none',
  196. title: '箱码检测检测错误' + err.message
  197. })
  198. })
  199. // checkCarrier(vehicleObj.carrierId).then(response => {
  200. // console.log(response)
  201. // if (response.code == 200) {
  202. // newBindList.value.push(JSON.parse(ret.resp_result));
  203. // } else {
  204. // uni.showToast({
  205. // icon: 'none',
  206. // title: response.msg
  207. // })
  208. // return;
  209. // }
  210. // })
  211. }
  212. );
  213. }
  214. function handleSubmit() {
  215. let carrierRejectList = []
  216. for (var i = 0; i < discardVehicleList.value.length; i++) {
  217. if (discardVehicleList.value[i].checked && discardVehicleList.value[i].abandonmentReason == "") {
  218. uni.showToast({
  219. icon: 'none',
  220. title: '第' + (i + 1) + '条未选择废弃原因'
  221. });
  222. return;
  223. }
  224. if (discardVehicleList.value[i].checked && discardVehicleList.value[i].abandonmentReason !== "") {
  225. carrierRejectList.push(discardVehicleList.value[i])
  226. }
  227. }
  228. if (carrierRejectList.length > 0 && newBindList.value.length > 0) {
  229. addCarrierReject(carrierRejectList).then((response) => {
  230. if (response.code == 200) {
  231. uni.showToast({
  232. icon: 'success',
  233. title: '操作成功',
  234. });
  235. } else {
  236. uni.showToast({
  237. icon: 'none',
  238. title: '添加失败',
  239. });
  240. }
  241. })
  242. }
  243. dayWorkInfo.dayworkCarriers = newBindList.value;
  244. saveDayWork(dayWorkInfo).then(res => {
  245. if (res.code === 200) {
  246. uni.showToast({
  247. icon: 'success',
  248. title: '添加成功',
  249. });
  250. uni.navigateBack({
  251. delta: 1
  252. });
  253. } else {
  254. uni.showToast({
  255. icon: 'none',
  256. title: res.msg,
  257. duration: 2500
  258. });
  259. }
  260. })
  261. }
  262. </script>
  263. <style lang="scss">
  264. .container {
  265. height: 100%;
  266. background-color: #f5f5f5;
  267. }
  268. .bottom {
  269. position: fixed;
  270. right: 0;
  271. bottom: 0;
  272. left: 0;
  273. height: 100rpx;
  274. padding: 16rpx 24rpx;
  275. align-items: center;
  276. background-color: #FFFFFF;
  277. justify-content: space-between;
  278. .bottom-btn {
  279. flex: 1;
  280. font-size: 28rpx;
  281. color: #FFFFFF;
  282. &.left-btn {
  283. background-color: rgba(0, 226, 166, 1);
  284. }
  285. &.right-btn {
  286. margin-left: 24rpx;
  287. }
  288. }
  289. }
  290. .content {
  291. width: 90%;
  292. height: calc(100% - 100rpx - 100rpx - 80rpx);
  293. background-color: rgba(255, 255, 255, 1);
  294. margin: 50rpx auto;
  295. padding-bottom: 50rpx;
  296. border-radius: 12rpx;
  297. .vehicleList {
  298. justify-content: baseline;
  299. align-content: flex-start;
  300. flex-wrap: wrap;
  301. width: 100%;
  302. height: 480rpx;
  303. padding: 0 64rpx;
  304. overflow: auto;
  305. .vehicleNo {
  306. padding: 0 10rpx;
  307. margin: 10rpx;
  308. justify-content: space-between;
  309. align-items: center;
  310. width: 230rpx;
  311. height: 60rpx;
  312. border: 1px solid rgba(213, 213, 213, 1);
  313. border-radius: 6rpx;
  314. }
  315. }
  316. .disuseList {
  317. border-top: 2rpx solid #e1e1e1;
  318. height: calc(100% - 480rpx - 20rpx);
  319. overflow: auto;
  320. width: 90%;
  321. margin: 0 auto;
  322. padding-top: 20rpx;
  323. }
  324. }
  325. .discardVehicleNo {
  326. padding: 0 10rpx;
  327. margin: 10rpx;
  328. justify-content: space-between;
  329. align-items: center;
  330. width: 150rpx;
  331. height: 60rpx;
  332. border: 1px solid rgba(213, 213, 213, 1);
  333. border-radius: 6rpx;
  334. }
  335. .title {
  336. margin: 30rpx auto;
  337. width: 30%;
  338. font-size: 36rpx;
  339. font-weight: bold;
  340. }
  341. // .btn {
  342. // position: fixed;
  343. // top: 940rpx;
  344. // left: 0;
  345. // right: 0;
  346. // }
  347. // .segment {
  348. // width: 280rpx;
  349. // height: 1rpx;
  350. // border: 1px solid rgba(187, 187, 187, 1);
  351. // }
  352. </style>