index.vue 6.1 KB

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