index.vue 10 KB

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