index.vue 5.8 KB

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