index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <view class="uni-column container">
  3. <scroll-view class="scroll-container" scroll-y>
  4. <view v-for="(item, index) in listData" :key="index"
  5. :class="{'list-item':true,'selected':isSelected(item)}">
  6. <!-- @click="handleSelection(item,index)" -->
  7. <view class="title-container uni-row">
  8. <view class="title uni-row">
  9. <text class="label">{{ item['dictDataLabel'] }}</text>
  10. <text class="label code">{{ item['preDeptName'] }}</text>
  11. <text class="label code" style="margin-left: 16rpx;">→</text>
  12. <text class="label code" style="margin-left: 16rpx;">{{ item['deptName'] }}</text>
  13. </view>
  14. <view class="right-info uni-row">
  15. <view class="uni-row"><text class="label right" @click="handleDeleteTurnover(item)">删除</text>
  16. </view>
  17. </view>
  18. </view>
  19. <view class="item-info uni-row"> <text class="label ">产品描述</text>
  20. <text class="label right" style="color: #000000;">{{ item['productDescription'] }}</text>
  21. </view>
  22. <view class="item-info uni-row"> <text class="label">批次</text>
  23. <text class="label right ">{{ item['lotCode'] }}</text>
  24. </view>
  25. <view class="item-info uni-row">
  26. <text class="label">箱数</text>
  27. <text class="label right">{{ item['carriers'] }}</text>
  28. </view>
  29. <view class="item-info uni-row">
  30. <text class="label">箱号</text>
  31. <text class="label right">{{ item['carrierName']}}</text>
  32. </view>
  33. </view>
  34. </scroll-view>
  35. <view class="bottom uni-row">
  36. <button class="bottom-btn left-btn" @click="HandleScanCode">扫码添加</button>
  37. <button class="bottom-btn right-btn" @click="handleStartTurnover" :disabled="flag">确认周转</button>
  38. </view>
  39. <dialog-turnoverTask ref="turnoverTaskDialog" />
  40. </view>
  41. <dialog-turnoverTask ref="turnoverTask"></dialog-turnoverTask>
  42. </template>
  43. <script setup>
  44. import {
  45. ref
  46. } from 'vue'
  47. import {
  48. onLoad,
  49. } from '@dcloudio/uni-app'
  50. import {
  51. getDayworkItemByCarrierId
  52. } from '@/api/business/dayWorkItem.js'
  53. const active = ref(false)
  54. const selection = ref([])
  55. const turnoverTaskDialog = ref(null)
  56. const listData = ref([])
  57. const turnoverTask = ref(null)
  58. const flag = ref(false);
  59. onLoad(() => {
  60. init();
  61. uni.$on('dayworkItemUpdate', () => {
  62. init(curSubPlan.value.id);
  63. })
  64. uni.$once('clearListData',() => {
  65. listData.value = [];
  66. })
  67. })
  68. function init() {
  69. flag.value = listData.value.length > 0 ? false : true;
  70. }
  71. function HandleScanCode() {
  72. uni.scanCode({
  73. scanType: ['qrCode'],
  74. onlyFromCamera: true, // 只允许相机扫码
  75. autoZoom: false,
  76. success: function(res) {
  77. console.log(res.result)
  78. let vehicleObj = JSON.parse(res.result);
  79. if (!vehicleObj.carrierId || vehicleObj.carrierId == "") {
  80. uni.showToast({
  81. icon: "error",
  82. title: "请扫载具码",
  83. duration: 1000
  84. })
  85. return;
  86. }
  87. getDayworkItemByCarrierId({
  88. carrierId: vehicleObj.carrierId,
  89. status: 4
  90. }).then(response => {
  91. console.log(response)
  92. for (let i = 0; i < listData.value.length; i++) {
  93. if (listData.value[i].lotCode === response.data[0].lotCode) {
  94. uni.showToast({
  95. icon: "error",
  96. title: "该批次已存在"
  97. })
  98. console.log("该批次已存在")
  99. return;
  100. }
  101. }
  102. for (let i = 0; i < response.data.length; i++) {
  103. listData.value.push(response.data[i]);
  104. }
  105. for (let i = 0; i < listData.value.length; i++) {
  106. listData.value[i].carriers = listData.value[i].carrierName.split('、').length;
  107. }
  108. console.log(listData.value);
  109. init();
  110. })
  111. }
  112. });
  113. }
  114. function handleStartTurnover() {
  115. // 调用子组件中的方法
  116. turnoverTask.value.open(listData.value);
  117. }
  118. function isSelected(item) {
  119. return selection.value.includes(item);
  120. }
  121. function handleSelection(item, index) {
  122. const buttonIndex = selection.value.findIndex(selectedItem => selectedItem === item);
  123. if (buttonIndex > -1) {
  124. selection.value.splice(buttonIndex, 1); // 取消选中
  125. } else {
  126. selection.value.push(item); // 选中
  127. }
  128. console.log(selection.value, "selection");
  129. }
  130. function handleDeleteTurnover(item) {
  131. uni.showModal({
  132. title: '提示', // 标题
  133. content: '是否删除此条周转', // 提示内容
  134. cancelText: "取消", // 取消按钮的文字
  135. confirmText: "确认", // 确认按钮的文字
  136. //点击确定之后执行的代码
  137. success(res) {
  138. if (res.confirm) {
  139. const checkIndex = listData.value.findIndex(selectedItem => selectedItem === item);
  140. if (checkIndex > -1) {
  141. listData.value.splice(checkIndex, 1);
  142. }
  143. }
  144. }
  145. });
  146. }
  147. </script>
  148. <style lang="scss">
  149. .container {
  150. height: 100%;
  151. background-color: #f5f5f5;
  152. }
  153. .scroll-container {
  154. position: absolute;
  155. top: 24rpx;
  156. right: 0;
  157. bottom: 160rpx;
  158. left: 0;
  159. }
  160. .selected {
  161. border: 1px solid #1684fc;
  162. }
  163. .list-item {
  164. background-color: #fff;
  165. position: relative;
  166. padding: 16rpx;
  167. padding-bottom: 24rpx;
  168. margin: 0 24rpx;
  169. margin-bottom: 24rpx;
  170. border-radius: 8rpx;
  171. .title-container {
  172. justify-content: space-between;
  173. margin-top: 8rpx;
  174. margin-bottom: 16rpx;
  175. .title {
  176. height: 48rpx;
  177. align-items: center;
  178. .label {
  179. color: #1684fc;
  180. font-size: 32rpx;
  181. font-weight: bold;
  182. &.code {
  183. color: #000000;
  184. margin-left: 32rpx;
  185. }
  186. }
  187. }
  188. }
  189. .item-info {
  190. margin-bottom: 16rpx;
  191. .label {
  192. font-size: 28rpx;
  193. width: 152rpx;
  194. color: #808080;
  195. &.right {
  196. flex: 1;
  197. color: #808080;
  198. }
  199. }
  200. }
  201. .right-info {
  202. justify-content: flex-end;
  203. margin-top: 2rpx;
  204. .label {
  205. font-size: 28rpx;
  206. color: #ff0000;
  207. }
  208. }
  209. }
  210. .bottom {
  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: #1684fc;
  226. }
  227. &.right-btn {
  228. background-color: rgb(255, 121, 1);
  229. margin-left: 24rpx;
  230. }
  231. }
  232. }
  233. </style>