index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. })
  54. function init() {
  55. }
  56. function handleScanCode() {
  57. uni.scanCode({
  58. scanType: ['qrCode'],
  59. onlyFromCamera: true, // 只允许相机扫码
  60. autoZoom: false,
  61. success: function(res) {
  62. console.log(res.result)
  63. let vehicleObj = JSON.parse(res.result);
  64. if (!vehicleObj.carrierId || vehicleObj.carrierId == "") {
  65. uni.showToast({
  66. icon: "error",
  67. title: "请扫载具码",
  68. duration: 1000
  69. })
  70. return;
  71. }
  72. getDayworkItemByCarrierId({
  73. carrierId: vehicleObj.carrierId,
  74. status: 6
  75. }).then(response => {
  76. console.log(response)
  77. // for (let i = 0; i < products.value.length; i++) {
  78. // if (products.value[i].lotCode === res.data[0].lotCode) {
  79. // console.log(products.value[i].lotCode);
  80. // console.log(res.data[0].lotCode)
  81. // uni.showToast({
  82. // icon: "error",
  83. // title: "该批次已存在"
  84. // })
  85. // console.log("该批次已存在")
  86. // return;
  87. // }
  88. // }
  89. for (let i = 0; i < response.data.length; i++) {
  90. products.value.push(response.data[i]);
  91. console.log(products.value)
  92. }
  93. console.log(products.value)
  94. let sum = 0; //总箱数
  95. for (let i = 0; i < products.value.length; i++) {
  96. products.value[i].carriers = products.value[i].carrierName.split('、').length;
  97. sum += products.value[i].carriers;
  98. }
  99. title.value = products.value[0].deptName + ' (' + sum + '箱)';
  100. console.log(products.value)
  101. init();
  102. })
  103. }
  104. });
  105. }
  106. function handleConfirmReceipt() {
  107. // receipt.value.open();
  108. if (selection.value.length > 0) {
  109. receipt.value.open();
  110. }
  111. }
  112. function isSelected(item) {
  113. return selection.value.includes(item);
  114. }
  115. function handleSelection(item, index) {
  116. const buttonIndex = selection.value.findIndex(selectedItem => selectedItem === item);
  117. if (buttonIndex > -1) {
  118. selection.value.splice(buttonIndex, 1); // 取消选中
  119. } else {
  120. selection.value.push(item); // 选中
  121. }
  122. console.log(selection.value, "selection");
  123. }
  124. function handleDoReceipt(data) {
  125. // 设置周转状态
  126. for (var i = 0; i < selection.value.length; i++) {
  127. selection.value[i].status = '7';
  128. selection.value[i].recipientId = store.userInfo.userId;
  129. selection.value[i].placeId = data.id;
  130. selection.value[i].place = data.code;
  131. }
  132. console.log(selection.value)
  133. updateDayWorkItemBatch(selection.value).then(res => {
  134. if (res.code === 200) {
  135. uni.showToast({
  136. icon: 'success',
  137. title: '操作成功',
  138. duration: 2000
  139. });
  140. init();
  141. } else {
  142. uni.showToast({
  143. icon: 'error',
  144. title: '操作失败',
  145. duration: 2000
  146. });
  147. }
  148. })
  149. products.value = [];
  150. selection.value = [];
  151. title.value = null;
  152. }
  153. function handleDoIt(data) {
  154. handleDoReceipt(data);
  155. }
  156. </script>
  157. <style lang="scss">
  158. .container {
  159. height: 100%;
  160. overflow: auto;
  161. background-color: rgba(245, 245, 245, 1);
  162. .content {
  163. width: 94%;
  164. /* height: auto; */
  165. background-color: rgba(255, 255, 255, 1);
  166. margin: 50rpx auto;
  167. border-radius: 12rpx;
  168. .selected {
  169. border: 1px solid #1684fc;
  170. }
  171. .title {
  172. margin-left: 10rpx;
  173. width: 90%;
  174. font-size: 36rpx;
  175. font-weight: bold;
  176. }
  177. .item-table {
  178. margin: 10rpx auto;
  179. width: 90%;
  180. .table-layout {
  181. background-color: rgba(236, 245, 255, 1);
  182. align-items: center;
  183. .tbhead {
  184. background-color: rgba(236, 245, 255, 1);
  185. font-size: 28rpx;
  186. height: 56rpx;
  187. line-height: 56rpx;
  188. padding-left: 6rpx;
  189. border-bottom: 1px solid lightgray;
  190. }
  191. .tbbody {
  192. font-size: 28rpx;
  193. background-color: rgba(238, 240, 245, 1);
  194. width: 70%;
  195. height: 56rpx;
  196. line-height: 56rpx;
  197. padding-left: 6rpx;
  198. border-bottom: 1px solid lightgray;
  199. }
  200. .left {
  201. color: rgba(136, 136, 136, 1);
  202. flex: 1;
  203. }
  204. .right {
  205. flex: 3;
  206. }
  207. }
  208. }
  209. }
  210. .btn {
  211. position: fixed;
  212. right: 0;
  213. bottom: 0;
  214. left: 0;
  215. height: 100rpx;
  216. padding: 16rpx 24rpx;
  217. align-items: center;
  218. background-color: #FFFFFF;
  219. justify-content: space-between;
  220. .bottom-btn {
  221. flex: 1;
  222. font-size: 28rpx;
  223. color: #FFFFFF;
  224. &.left-btn {
  225. // background-color: #a4adb3;
  226. }
  227. &.right-btn {
  228. background-color: #1684fc;
  229. margin-left: 24rpx;
  230. }
  231. }
  232. }
  233. }
  234. </style>