index.vue 9.7 KB

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