index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <view class='container '>
  3. <view class='content'>
  4. <text class='title'>{{title}}</text>
  5. <view :class="{'item-table':true, 'selected':isSelected(item)}" scroll-y v-for="(item,index) in products"
  6. @click="handleSelection(item,index)">
  7. <view class="uni-row table-layout">
  8. <text class='tbhead left'>产品描述</text>
  9. <text class='tbhead right'>{{item['productDescription']}}</text>
  10. </view>
  11. <view class="uni-row table-layout">
  12. <text class='tbbody left'>批次</text>
  13. <text class='tbbody right'>{{item['lotCode']}}</Text>
  14. </view>
  15. <view class="uni-row table-layout">
  16. <text class='tbbody left'>箱数</text>
  17. <text class='tbbody right'>{{item['carriers']}}</Text>
  18. </view>
  19. <view class="uni-row table-layout">
  20. <text class='tbbody left'>箱号</text>
  21. <text class='tbbody right'>{{item['carrierName']}}</text>
  22. </view>
  23. </view>
  24. </view>
  25. <view class='btn uni-row'>
  26. <button class='bottom-btn left-btn' type="primary" @click="handleScanCode">扫码添加</button>
  27. <button class='bottom-btn right-btn' type="primary" @click="handleConfirmReceipt">确定领取</button>
  28. </view>
  29. </view>
  30. <dialog-receipt ref="receipt" @submit="handleDoIt"></dialog-receipt>
  31. </template>
  32. <script setup>
  33. import {
  34. ref
  35. } from 'vue'
  36. import {
  37. onLoad
  38. } from '@dcloudio/uni-app'
  39. import {
  40. getDayworkItemByCarrierId,
  41. updateDayWorkItemBatch
  42. } from '@/api/business/dayWorkItem.js'
  43. import {
  44. store
  45. } from '@/store/index.js'
  46. const title = ref(null)
  47. const sum = ref(0)
  48. const products = ref([])
  49. const receipt = ref(null)
  50. const flag = ref(false)
  51. const selection = ref([])
  52. onLoad(() => {})
  53. function init() {}
  54. function handleScanCode() {
  55. // 引入原生插件
  56. const mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
  57. // 调用插件的 mpaasScan 方法
  58. mpaasScanModule.mpaasScan({
  59. // 扫码识别类型,参数可多选,qrCode、barCode,
  60. // 如不设置,默认识别所有扫码类型,可能有些许影响识别效率
  61. scanType: ["qrCode", "barCode"],
  62. // 是否隐藏相册,默认false不隐藏
  63. hideAlbum: false,
  64. },
  65. (ret) => {
  66. let vehicleObj = JSON.parse(ret.resp_result);
  67. if (!vehicleObj.carrierId || vehicleObj.carrierId == "") {
  68. uni.showToast({
  69. icon: "error",
  70. title: "请扫载具码",
  71. duration: 1000
  72. })
  73. return;
  74. }
  75. getDayworkItemByCarrierId({
  76. carrierId: vehicleObj.carrierId,
  77. status: 6
  78. }).then(response => {
  79. console.log(response)
  80. if (response.data.length == 0) {
  81. uni.showToast({
  82. icon: 'none',
  83. title: '该批次已被领取'
  84. })
  85. return;
  86. }
  87. for (let i = 0; i < response.data.length; i++) {
  88. products.value.push(response.data[i]);
  89. console.log(products.value)
  90. }
  91. console.log(products.value)
  92. let sum = 0; //总箱数
  93. for (let i = 0; i < products.value.length; i++) {
  94. products.value[i].carriers = products.value[i].carrierName.split('、').length;
  95. sum += products.value[i].carriers;
  96. }
  97. title.value = products.value[0].deptName + ' (' + sum + '箱)';
  98. console.log(products.value)
  99. init();
  100. })
  101. }
  102. );
  103. }
  104. function handleConfirmReceipt() {
  105. receipt.value.open();
  106. if (selection.value.length > 0) {
  107. receipt.value.open();
  108. }
  109. }
  110. function isSelected(item) {
  111. return selection.value.includes(item);
  112. }
  113. function handleSelection(item, index) {
  114. const buttonIndex = selection.value.findIndex(selectedItem => selectedItem === item);
  115. if (buttonIndex > -1) {
  116. selection.value.splice(buttonIndex, 1); // 取消选中
  117. } else {
  118. selection.value.push(item); // 选中
  119. }
  120. console.log(selection.value, "selection");
  121. }
  122. function handleDoReceipt(data) {
  123. // 设置周转状态
  124. for (var i = 0; i < selection.value.length; i++) {
  125. selection.value[i].status = '7';
  126. selection.value[i].recipientId = store.userInfo.userId;
  127. selection.value[i].placeId = data.id;
  128. selection.value[i].place = data.code;
  129. }
  130. console.log(selection.value)
  131. updateDayWorkItemBatch(selection.value).then(res => {
  132. if (res.code === 200) {
  133. uni.showToast({
  134. icon: 'success',
  135. title: '操作成功',
  136. duration: 2000
  137. });
  138. init();
  139. } else {
  140. uni.showToast({
  141. icon: 'error',
  142. title: '操作失败',
  143. duration: 2000
  144. });
  145. }
  146. })
  147. products.value = [];
  148. selection.value = [];
  149. title.value = null;
  150. }
  151. function handleDoIt(data) {
  152. handleDoReceipt(data);
  153. }
  154. </script>
  155. <style lang="scss">
  156. .container {
  157. height: 100%;
  158. overflow: auto;
  159. background-color: rgba(245, 245, 245, 1);
  160. .content {
  161. width: 94%;
  162. /* height: auto; */
  163. background-color: rgba(255, 255, 255, 1);
  164. margin: 50rpx auto;
  165. border-radius: 12rpx;
  166. .selected {
  167. border: 1px solid #1684fc;
  168. }
  169. .title {
  170. margin-left: 10rpx;
  171. width: 90%;
  172. font-size: 36rpx;
  173. font-weight: bold;
  174. }
  175. .item-table {
  176. margin: 10rpx auto;
  177. width: 90%;
  178. .table-layout {
  179. background-color: rgba(236, 245, 255, 1);
  180. align-items: center;
  181. .tbhead {
  182. background-color: rgba(236, 245, 255, 1);
  183. font-size: 28rpx;
  184. height: 56rpx;
  185. line-height: 56rpx;
  186. padding-left: 6rpx;
  187. border-bottom: 1px solid lightgray;
  188. }
  189. .tbbody {
  190. font-size: 28rpx;
  191. background-color: rgba(238, 240, 245, 1);
  192. width: 70%;
  193. height: 56rpx;
  194. line-height: 56rpx;
  195. padding-left: 6rpx;
  196. border-bottom: 1px solid lightgray;
  197. }
  198. .left {
  199. color: rgba(136, 136, 136, 1);
  200. flex: 1;
  201. }
  202. .right {
  203. flex: 3;
  204. }
  205. }
  206. }
  207. }
  208. .btn {
  209. position: fixed;
  210. right: 0;
  211. bottom: 0;
  212. left: 0;
  213. height: 100rpx;
  214. padding: 16rpx 24rpx;
  215. align-items: center;
  216. background-color: #FFFFFF;
  217. justify-content: space-between;
  218. .bottom-btn {
  219. flex: 1;
  220. font-size: 28rpx;
  221. color: #FFFFFF;
  222. &.left-btn {
  223. // background-color: #a4adb3;
  224. }
  225. &.right-btn {
  226. background-color: #1684fc;
  227. margin-left: 24rpx;
  228. }
  229. }
  230. }
  231. }
  232. </style>