index.vue 8.0 KB

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