index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <template>
  2. <view class='container '>
  3. <view v-if="products.length == 0" style="color: #999;margin: 50% auto;">
  4. <text>扫码添加批次</text>
  5. </view>
  6. <view v-else class='content'>
  7. <text class='title'>{{title}}</text>
  8. <view :class="{'item-table':true, 'selected':isSelected(item)}" scroll-y v-for="(item,index) in products"
  9. @click="handleSelection(item,index)">
  10. <view class="uni-row table-layout">
  11. <text class='tbhead left'>产品描述</text>
  12. <text class='tbhead right'>{{item['productDescription']}}</text>
  13. </view>
  14. <view class="uni-row table-layout">
  15. <text class='tbbody left'>批次</text>
  16. <text class='tbbody right'>{{item['lotCode']}}</Text>
  17. </view>
  18. <view class="uni-row table-layout">
  19. <text class='tbbody left'>箱数</text>
  20. <text class='tbbody right'>{{item['carriers']}}</Text>
  21. </view>
  22. <view class="uni-row table-layout">
  23. <text class='tbbody left'>箱号</text>
  24. <text class='tbbody right'>{{item['carrierName']}}</text>
  25. </view>
  26. </view>
  27. </view>
  28. <view class='btn uni-row'>
  29. <button class='bottom-btn left-btn' type="primary" @click="handleScanCode">扫码添加</button>
  30. <button class='bottom-btn right-btn' type="primary" @click="handleConfirmReceipt">确定领取</button>
  31. </view>
  32. </view>
  33. <dialog-receipt ref="receipt" @submit="handleDoIt"></dialog-receipt>
  34. <QrScanner v-if="showQrCodeReader" @decode="onDecodeHandler" @close="qrReaderClose" />
  35. </template>
  36. <script setup>
  37. import {
  38. ref
  39. } from 'vue'
  40. import {
  41. onLoad
  42. } from '@dcloudio/uni-app'
  43. import {
  44. getDayworkItemByCarrierId,
  45. getDayworkItemByCarrierCode,
  46. updateDayWorkItemBatch
  47. } from '@/api/business/dayWorkItem.js'
  48. import QrScanner from '../vueQrCode/index.vue'
  49. import {
  50. store
  51. } from '@/store/index.js'
  52. const title = ref(null)
  53. const sum = ref(0)
  54. const products = ref([])
  55. const receipt = ref(null)
  56. const flag = ref(false)
  57. const selection = ref([])
  58. const showQrCodeReader = ref(false);
  59. onLoad(() => {})
  60. function init() {}
  61. /*
  62. function handleScanCode() {
  63. // 引入原生插件
  64. const mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
  65. // 调用插件的 mpaasScan 方法
  66. mpaasScanModule.mpaasScan({
  67. // 扫码识别类型,参数可多选,qrCode、barCode,
  68. // 如不设置,默认识别所有扫码类型,可能有些许影响识别效率
  69. scanType: ["qrCode", "barCode"],
  70. // 是否隐藏相册,默认false不隐藏
  71. hideAlbum: false,
  72. },
  73. (ret) => {
  74. let vehicleObj = JSON.parse(ret.resp_result);
  75. if (!vehicleObj.carrierId || vehicleObj.carrierId == "") {
  76. uni.showToast({
  77. icon: "none",
  78. title: "请扫载具码",
  79. })
  80. return;
  81. }
  82. getDayworkItemByCarrierId({
  83. carrierId: vehicleObj.carrierId,
  84. status: 6
  85. }).then(response => {
  86. console.log(response)
  87. if (response.data.length == 0) {
  88. uni.showToast({
  89. icon: 'none',
  90. title: '该批次已被领取'
  91. })
  92. return;
  93. }
  94. for (let i = 0; i < response.data.length; i++) {
  95. if(products.value.some(item => item.id == response.data[i].id)){
  96. uni.showToast({
  97. icon: 'none',
  98. title: '该设批次已存在,请勿重复扫码添加'
  99. })
  100. return;
  101. }
  102. products.value.push(response.data[i]);
  103. console.log(products.value)
  104. }
  105. console.log(products.value)
  106. let sum = 0; //总箱数
  107. for (let i = 0; i < products.value.length; i++) {
  108. products.value[i].carriers = products.value[i].carrierName.split('、').length;
  109. sum += products.value[i].carriers;
  110. }
  111. title.value = products.value[0].deptName + ' (' + sum + '箱)';
  112. console.log(products.value)
  113. init();
  114. })
  115. }
  116. );
  117. }
  118. */
  119. //H5扫码器回调
  120. function onDecodeHandler(data) {
  121. showQrCodeReader.value = false;
  122. let vehicleObj = {carrierCode: data};
  123. if (!vehicleObj.carrierCode || vehicleObj.carrierCode == "") {
  124. uni.showToast({
  125. icon: "none",
  126. title: "请扫载具码",
  127. })
  128. return;
  129. }
  130. getDayworkItemByCarrierCode({
  131. carrierCode: vehicleObj.carrierCode,
  132. status: 6
  133. }).then(response => {
  134. console.log(response)
  135. if (response.data.length == 0) {
  136. uni.showToast({
  137. icon: 'none',
  138. title: '该批次已被领取'
  139. })
  140. return;
  141. }
  142. for (let i = 0; i < response.data.length; i++) {
  143. if(products.value.some(item => item.id == response.data[i].id)){
  144. uni.showToast({
  145. icon: 'none',
  146. title: '该设批次已存在,请勿重复扫码添加'
  147. })
  148. return;
  149. }
  150. products.value.push(response.data[i]);
  151. console.log(products.value)
  152. }
  153. console.log(products.value)
  154. let sum = 0; //总箱数
  155. for (let i = 0; i < products.value.length; i++) {
  156. products.value[i].carriers = products.value[i].carrierName.split('、').length;
  157. sum += products.value[i].carriers;
  158. }
  159. title.value = products.value[0].deptName + ' (' + sum + '箱)';
  160. console.log(products.value)
  161. init();
  162. })
  163. }
  164. //H5扫码器关闭
  165. function qrReaderClose() {
  166. showQrCodeReader.value = false;
  167. }
  168. function handleScanCode() {
  169. showQrCodeReader.value = false;
  170. // 引入原生插件
  171. // const mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
  172. // // 调用插件的 mpaasScan 方法
  173. // mpaasScanModule.mpaasScan({
  174. // // 扫码识别类型,参数可多选,qrCode、barCode,
  175. // // 如不设置,默认识别所有扫码类型,可能有些许影响识别效率
  176. // scanType: ["qrCode", "barCode"],
  177. // // 是否隐藏相册,默认false不隐藏
  178. // hideAlbum: false,
  179. // },
  180. // (ret) => {
  181. // let vehicleObj = {carrierCode: ret.resp_result};
  182. // if (!vehicleObj.carrierCode || vehicleObj.carrierCode == "") {
  183. // uni.showToast({
  184. // icon: "none",
  185. // title: "请扫载具码",
  186. // })
  187. // return;
  188. // }
  189. // getDayworkItemByCarrierCode({
  190. // carrierCode: vehicleObj.carrierCode,
  191. // status: 6
  192. // }).then(response => {
  193. // console.log(response)
  194. // if (response.data.length == 0) {
  195. // uni.showToast({
  196. // icon: 'none',
  197. // title: '该批次已被领取'
  198. // })
  199. // return;
  200. // }
  201. // for (let i = 0; i < response.data.length; i++) {
  202. // if(products.value.some(item => item.id == response.data[i].id)){
  203. // uni.showToast({
  204. // icon: 'none',
  205. // title: '该设批次已存在,请勿重复扫码添加'
  206. // })
  207. // return;
  208. // }
  209. // products.value.push(response.data[i]);
  210. // console.log(products.value)
  211. // }
  212. // console.log(products.value)
  213. // let sum = 0; //总箱数
  214. // for (let i = 0; i < products.value.length; i++) {
  215. // products.value[i].carriers = products.value[i].carrierName.split('、').length;
  216. // sum += products.value[i].carriers;
  217. // }
  218. // title.value = products.value[0].deptName + ' (' + sum + '箱)';
  219. // console.log(products.value)
  220. // init();
  221. // })
  222. // }
  223. // );
  224. }
  225. function handleConfirmReceipt() {
  226. if (selection.value.length > 0) {
  227. receipt.value.open();
  228. }else{
  229. uni.showToast({
  230. icon: 'none',
  231. title: '请选择批次后再确认领取',
  232. duration: 2000
  233. })
  234. }
  235. }
  236. function isSelected(item) {
  237. return selection.value.includes(item);
  238. }
  239. function handleSelection(item, index) {
  240. const buttonIndex = selection.value.findIndex(selectedItem => selectedItem === item);
  241. if (buttonIndex > -1) {
  242. selection.value.splice(buttonIndex, 1); // 取消选中
  243. } else {
  244. selection.value.push(item); // 选中
  245. }
  246. console.log(selection.value, "selection");
  247. }
  248. function handleDoReceipt(data) {
  249. // 设置周转状态
  250. for (var i = 0; i < selection.value.length; i++) {
  251. selection.value[i].status = '7';
  252. selection.value[i].recipientId = store.userInfo.userId;
  253. selection.value[i].place = data;
  254. }
  255. console.log(selection.value)
  256. updateDayWorkItemBatch(selection.value).then(res => {
  257. if (res.code === 200) {
  258. uni.showToast({
  259. icon: 'success',
  260. title: '操作成功',
  261. duration: 2000
  262. });
  263. init();
  264. } else {
  265. uni.showToast({
  266. icon: 'none',
  267. title: '操作失败',
  268. duration: 2000
  269. });
  270. }
  271. })
  272. products.value = [];
  273. selection.value = [];
  274. title.value = null;
  275. }
  276. function handleDoIt(data) {
  277. handleDoReceipt(data);
  278. }
  279. </script>
  280. <style lang="scss">
  281. .container {
  282. height: 100%;
  283. overflow: auto;
  284. background-color: rgba(245, 245, 245, 1);
  285. .content {
  286. width: 94%;
  287. /* height: auto; */
  288. background-color: rgba(255, 255, 255, 1);
  289. margin: 50rpx auto;
  290. border-radius: 12rpx;
  291. .selected {
  292. border: 1px solid #1684fc;
  293. }
  294. .title {
  295. margin-left: 10rpx;
  296. width: 90%;
  297. font-size: 36rpx;
  298. font-weight: bold;
  299. }
  300. .item-table {
  301. margin: 10rpx auto;
  302. width: 90%;
  303. .table-layout {
  304. background-color: rgba(236, 245, 255, 1);
  305. align-items: center;
  306. .tbhead {
  307. background-color: rgba(236, 245, 255, 1);
  308. font-size: 28rpx;
  309. height: 56rpx;
  310. line-height: 56rpx;
  311. padding-left: 6rpx;
  312. border-bottom: 1px solid lightgray;
  313. }
  314. .tbbody {
  315. font-size: 28rpx;
  316. background-color: rgba(238, 240, 245, 1);
  317. width: 70%;
  318. height: 56rpx;
  319. line-height: 56rpx;
  320. padding-left: 6rpx;
  321. border-bottom: 1px solid lightgray;
  322. }
  323. .left {
  324. color: rgba(136, 136, 136, 1);
  325. flex: 1;
  326. }
  327. .right {
  328. flex: 3;
  329. }
  330. }
  331. }
  332. }
  333. .btn {
  334. position: fixed;
  335. right: 0;
  336. bottom: 0;
  337. left: 0;
  338. height: 100rpx;
  339. padding: 16rpx 24rpx;
  340. align-items: center;
  341. background-color: #FFFFFF;
  342. justify-content: space-between;
  343. .bottom-btn {
  344. flex: 1;
  345. font-size: 28rpx;
  346. color: #FFFFFF;
  347. &.left-btn {
  348. // background-color: #a4adb3;
  349. }
  350. &.right-btn {
  351. background-color: #1684fc;
  352. margin-left: 24rpx;
  353. }
  354. }
  355. }
  356. }
  357. </style>