bindingScan.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <template>
  2. <div class="midPopUp" v-if="modelValue">
  3. <div class="container">
  4. <div class="headerTittle">载具绑定</div>
  5. <div class="body">
  6. <div class="boxInfo">
  7. <div class="info">
  8. <div class="titleText">载具名:{{ boxInfoData.vehicleName }}</div>
  9. <div class="describeText">
  10. 载具编号:{{ boxInfoData.vehicleNo }}
  11. </div>
  12. </div>
  13. <div class="scanBox">
  14. <div class="titleText">请扫物料码:</div>
  15. <ScanCodeInput v-model="scanCode" @keyup.enter="enterfnc" />
  16. </div>
  17. <el-table class="infoTable" :data="scanItemArray" border>
  18. <el-table-column prop="materialName" label="物料名称" width="120" />
  19. <el-table-column prop="materialCode" label="物料编号" />
  20. <el-table-column prop="spec" label="规格" />
  21. <el-table-column prop="num" label="数量" align="center" />
  22. <el-table-column prop="batchCode" label="流转卡号/批次号" align="center" />
  23. <el-table-column prop="" label="操作" align="center">
  24. <template #default="scope">
  25. <el-popconfirm title="确认清空?" @confirm="tableDelete(scope.row.materialCode)" confirm-button-text="确定"
  26. cancel-button-text="取消">
  27. <template #reference>
  28. <span class="opera">清空</span>
  29. </template>
  30. </el-popconfirm>
  31. </template>
  32. </el-table-column>
  33. <template #empty>
  34. <Empty />
  35. </template>
  36. </el-table>
  37. </div>
  38. <div class="scan">
  39. <div class="scanBox">
  40. <div class="titleText">搜索记录:</div>
  41. <el-input clearable v-model="seachInput" placeholder="请输入已扫码" />
  42. </div>
  43. <div class="titleText" style="display: flex; justify-content: space-between">
  44. 扫码记录:<span>本次总扫码{{ scanAllNum }}次</span>
  45. <span>目前实际记录{{ recordArray.length }}次</span>
  46. </div>
  47. <el-scrollbar class="scrollbarBox">
  48. <div class="infoBox" v-for="item in showRecordArray">
  49. <div class="describeText textRow">扫码时间:{{ item.time }}</div>
  50. <div class="describeText textRow">
  51. 扫码内容:{{ item.scanCode }}
  52. </div>
  53. <div class="describeText textRow">
  54. 物料名称:{{ item.materialName }}
  55. </div>
  56. <div class="describeText textRow">
  57. 物料编码:{{ item.materialCode }}
  58. </div>
  59. <div class="describeText textRow">物料数量:{{ item.num }}</div>
  60. <div class="describeText delete" @click="recordDelete(index)">
  61. 删除记录
  62. </div>
  63. </div>
  64. <div v-if="showRecordArray.length == 0" class="infoBox titleText">
  65. 暂无内容
  66. </div>
  67. </el-scrollbar>
  68. </div>
  69. </div>
  70. <div class="bottomBtn">
  71. <el-button class="leftBtn" @click="handleClose">取消</el-button>
  72. <el-button class="rightBtn" :disabled="scanItemArray.length < 1" @click="handleSubmit"
  73. type="primary">绑定</el-button>
  74. </div>
  75. </div>
  76. </div>
  77. </template>
  78. <script lang="ts" setup>
  79. import { getMaterialInfo, addOperation } from "@/api/prepare";
  80. import { useCommonStore } from "@/store";
  81. const store = useCommonStore();
  82. const props = defineProps({
  83. modelValue: {
  84. type: Boolean,
  85. },
  86. workOrderCode: {
  87. type: String,
  88. },
  89. operationId: {
  90. type: String,
  91. },
  92. });
  93. const boxInfoData = inject("boxInfoData");
  94. const scanAllNum = ref(0);
  95. const emits = defineEmits(["update:modelValue", "close"]);
  96. //二维码
  97. const scanCode = ref("");
  98. //存放扫码信息总盒子
  99. const recordArray = ref([]);
  100. const seachInput = ref("");
  101. const showRecordArray = computed(() => {
  102. if (seachInput.value != "") {
  103. return recordArray.value.filter(
  104. (item) => item.scanCode == seachInput.value
  105. );
  106. } else {
  107. return recordArray.value;
  108. }
  109. });
  110. //物料表格数据(会根据最近扫码后的结果进行统计展示)
  111. const scanItemArray = computed(() => {
  112. let materialCodeArray = [];
  113. let resArray = [];
  114. // recordArray.value.forEach((item) => {
  115. // if (!materialCodeArray.includes(item.materialCode)) {
  116. // materialCodeArray.push(item.materialCode);
  117. // resArray.push({
  118. // materialCode: item.materialCode,
  119. // materialName: item.materialName,
  120. // num: item.num,
  121. // spec: item.spec,
  122. // batchCode: item.batchCode,
  123. // });
  124. // } else {
  125. // resArray.forEach((res) => {
  126. // if (
  127. // res.materialCode == item.materialCode &&
  128. // res.batchCode == item.batchCode
  129. // ) {
  130. // res.num = Number(res.num) + Number(item.num);
  131. // } else {
  132. // resArray.push({
  133. // materialCode: item.materialCode,
  134. // materialName: item.materialName,
  135. // num: item.num,
  136. // spec: item.spec,
  137. // batchCode: item.batchCode,
  138. // });
  139. // }
  140. // });
  141. // }
  142. // });
  143. for (let i = 0; i < recordArray.value.length; i++) {
  144. if (!materialCodeArray.includes(recordArray.value[i].materialCode)) {
  145. materialCodeArray.push(recordArray.value[i].materialCode);
  146. resArray.push({
  147. materialCode: recordArray.value[i].materialCode,
  148. materialName: recordArray.value[i].materialName,
  149. num: recordArray.value[i].num,
  150. spec: recordArray.value[i].spec,
  151. batchCode: recordArray.value[i].batchCode,
  152. });
  153. } else {
  154. let status = false;
  155. for (let b = 0; b < resArray.length; b++) {
  156. if (
  157. resArray[b].materialCode == recordArray.value[i].materialCode &&
  158. resArray[b].batchCode == recordArray.value[i].batchCode
  159. ) {
  160. resArray[b].num =
  161. Number(resArray[b].num) + Number(recordArray.value[i].num);
  162. status = true;
  163. }
  164. }
  165. if (status == false) {
  166. resArray.push({
  167. materialCode: recordArray.value[i].materialCode,
  168. materialName: recordArray.value[i].materialName,
  169. num: recordArray.value[i].num,
  170. spec: recordArray.value[i].spec,
  171. batchCode: recordArray.value[i].batchCode,
  172. });
  173. }
  174. }
  175. }
  176. return resArray;
  177. });
  178. //清空操作
  179. const tableDelete = (code) => {
  180. recordArray.value = recordArray.value.filter(
  181. (item) => item.materialCode != code
  182. );
  183. };
  184. const recordDelete = (index) => {
  185. recordArray.value.splice(index, 1);
  186. };
  187. const enterfnc = async () => {
  188. const { data, code } = await getMaterialInfo({
  189. materialLabel: scanCode.value,
  190. operationId: props.operationId,
  191. workOrderCode: props.workOrderCode,
  192. });
  193. if (code == "200") {
  194. const obj = {
  195. ...data,
  196. scanCode: scanCode.value,
  197. time: store.currentTimeFormat(),
  198. };
  199. recordArray.value.unshift(obj);
  200. scanCode.value = "";
  201. scanAllNum.value = scanAllNum.value + 1;
  202. ElMessage.success("扫描成功!");
  203. }
  204. };
  205. const addTableSum = computed((code) => {
  206. return;
  207. });
  208. const reset = () => {
  209. scanAllNum.value = 0;
  210. scanCode.value = "";
  211. recordArray.value = [];
  212. seachInput.value = [];
  213. };
  214. const handleClose = () => {
  215. emits("update:modelValue", false);
  216. reset();
  217. };
  218. const handleSubmit = async () => {
  219. const { data, code } = await addOperation({
  220. operationId: props.operationId,
  221. workOrderCode: props.workOrderCode,
  222. processVehicleMaterialList: [...recordArray.value],
  223. vehicleCode: boxInfoData.value.vehicleNo,
  224. vehicleId: boxInfoData.value.vehicleId,
  225. vehicleName: boxInfoData.value.vehicleName,
  226. });
  227. if (code == "200") {
  228. ElMessage.success("绑定成功!");
  229. handleClose();
  230. emits("close");
  231. }
  232. };
  233. </script>
  234. <style lang="scss" scoped>
  235. .midPopUp {
  236. z-index: 4;
  237. }
  238. .opera {
  239. color: var(--el-color-primary);
  240. font-size: $f20;
  241. cursor: pointer;
  242. }
  243. .container {
  244. width: 90vw;
  245. height: 90vh;
  246. background-color: #f1f3f5;
  247. border-radius: 16px;
  248. .body {
  249. display: flex;
  250. .boxInfo {
  251. width: 50%;
  252. padding: 20px;
  253. flex: 1;
  254. .info {
  255. width: 100%;
  256. height: 80px;
  257. border-radius: 16px;
  258. background-color: white;
  259. padding: $p10;
  260. display: flex;
  261. flex-direction: column;
  262. .titleText {
  263. line-height: 30px;
  264. }
  265. .describeText {
  266. text-align: left;
  267. }
  268. }
  269. .infoTable {
  270. width: 100%;
  271. margin-top: $p20;
  272. min-height: 120px;
  273. height: calc(80vh - 310px);
  274. border-radius: 16px;
  275. }
  276. }
  277. .scan {
  278. width: 50%;
  279. padding: 20px;
  280. padding-bottom: 0px;
  281. flex .scanBox {
  282. padding: 0 20px;
  283. width: 100%;
  284. height: 40px;
  285. display: flex;
  286. flex-direction: column;
  287. justify-content: space-evenly;
  288. }
  289. .scrollbarBox {
  290. height: calc(80vh - 226px);
  291. padding: $p20 0;
  292. padding-bottom: 0px;
  293. }
  294. }
  295. }
  296. }
  297. :deep(.el-input__wrapper) {
  298. box-shadow: 0 0 0 0px var(--el-input-border-color, var(--el-border-color)) inset;
  299. cursor: default;
  300. border-radius: 16px;
  301. .el-input__inner {
  302. cursor: default !important;
  303. }
  304. }
  305. .el-table__empty-block {
  306. height: 0 !important;
  307. }
  308. .infoBox {
  309. width: 100%;
  310. background-color: white;
  311. border-radius: 16px;
  312. margin-bottom: $p10;
  313. @include flex;
  314. flex-wrap: wrap;
  315. padding: 20px;
  316. .describeText {
  317. line-height: 22px;
  318. text-align: left;
  319. color: black;
  320. }
  321. .textRow {
  322. height: 22px;
  323. }
  324. .delete {
  325. text-align: right;
  326. color: var(--el-color-primary);
  327. }
  328. }
  329. .bottomBtn {
  330. width: 100%;
  331. height: 70px;
  332. display: flex;
  333. align-items: center;
  334. justify-content: space-between;
  335. padding: $p10 10% 0 10%;
  336. .leftBtn {
  337. height: 55px;
  338. width: 45%;
  339. border-radius: 16px;
  340. font-size: $f20;
  341. color: black;
  342. background-color: #00000015;
  343. border: 0px;
  344. }
  345. .rightBtn {
  346. height: 55px;
  347. width: 45%;
  348. border-radius: 16px;
  349. font-size: $f20;
  350. color: white;
  351. }
  352. }
  353. </style>