index.vue 5.6 KB

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