relate.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. <template>
  2. <view class="uni-column" style="padding: 24rpx">
  3. <view class="consultation-container ">
  4. <view>
  5. <zb-table :columns="relateColumn" :stripe="true" :fit="false" @dele="dele"
  6. :data="relateList"></zb-table>
  7. </view>
  8. </view>
  9. <view class='btn uni-row'>
  10. <button class='bottom-btn right-btn' type="primary" @click="handleContinue">继续扫码</button>
  11. <button class='bottom-btn right-btn' type="primary" @click="handleConfirm">确认关联</button>
  12. </view>
  13. <QrScanner v-if="showQrCodeReader" @decode="onDecodeHandler" @close="qrReaderClose" />
  14. </view>
  15. <view
  16. style="background-color: #99999999; z-index: 5; position: absolute; left: 0px; right: 0px; top: 0px; bottom: 0px;"
  17. v-if="loading">
  18. </view>
  19. </template>
  20. <script setup>
  21. import {
  22. ref,
  23. onMounted,
  24. getCurrentInstance
  25. } from 'vue'
  26. import {
  27. store
  28. } from '@/store/index.js'
  29. import QrScanner from '../vueQrCode/index.vue'
  30. import {
  31. onShow
  32. } from '@dcloudio/uni-app'
  33. import {
  34. getRelateInspectionByCarrier
  35. } from '@/api/business/processInspection.js'
  36. import {
  37. debounce
  38. } from '../../utils/common';
  39. const lotReporting = ref(null)
  40. const workshopId = ref(null);
  41. const searchRef = ref(null);
  42. const keyword = ref('')
  43. const loading = ref(false)
  44. const relateList = ref([])
  45. const processInspection = ref(null)
  46. const showQrCodeReader = ref(false);
  47. const form = ref([]); //表单数据true
  48. const checkAll = ref(false); //是否全选
  49. // 创建一个引用来存储最后一次请求的时间戳
  50. const lastRequestTimestamp = ref(0);
  51. const listData = ref([]);
  52. const allData = ref([])
  53. const selection = ref([]); //选中数据
  54. const workshopList = ref([]); //车间数据
  55. const relateColumn = ref([{
  56. name: 'lotCode',
  57. label: '批号',
  58. align: 'center',
  59. width: 120
  60. },
  61. {
  62. name: 'allCarriers',
  63. label: '箱号',
  64. align: 'center',
  65. width: 80
  66. },
  67. {
  68. name: 'isMaster',
  69. label: '主检查单',
  70. align: 'center',
  71. width: 80,
  72. filters: {
  73. 0: '否',
  74. 1: '是'
  75. }
  76. },
  77. {
  78. name: 'operation',
  79. type: 'operation',
  80. label: '关联',
  81. align: 'center',
  82. width: 60,
  83. renders: [{
  84. name: '删除',
  85. type: 'warn',
  86. func: "dele",
  87. class: "buttonOp"
  88. }, ]
  89. }
  90. ])
  91. onShow(() => {
  92. init()
  93. })
  94. onMounted(() => {
  95. const instance = getCurrentInstance().proxy
  96. const eventChannel = instance.getOpenerEventChannel();
  97. eventChannel.on('outsourcedInspectionRelation', function(data) {
  98. // console.log(lot.value)
  99. console.log('outsourcedInspectionRelation', data)
  100. // 传入当前报工信息 通过当前报工的产品和工序获取检查指导书和分选标准
  101. relateList.value = data.relateList.map(v => ({
  102. ...v
  103. }))
  104. processInspection.value = data
  105. handleAdd()
  106. })
  107. })
  108. //初始化
  109. function init() {
  110. // console.log(store.curDeptDetails)
  111. // uni.showLoading({
  112. // title: '加载中'
  113. // });
  114. checkAll.value = false
  115. }
  116. // 搜索按钮操作
  117. function handleSearch() {
  118. searchRef.value.open();
  119. }
  120. function refreshSearch(input) {
  121. // console.log(input)
  122. keyword.value = input
  123. handleChangeWorkshop(workshopId.value)
  124. }
  125. //H5扫码器回调
  126. function onDecodeHandler(data) {
  127. showQrCodeReader.value = false;
  128. let vehicleObj = {
  129. carrierCode: data
  130. };
  131. if (!vehicleObj.carrierCode || vehicleObj.carrierCode == "") {
  132. uni.showToast({
  133. icon: "none",
  134. title: "请扫载具码",
  135. duration: 1000
  136. })
  137. return;
  138. }
  139. getRelateInspectionByCarrier({
  140. ...processInspection.value,
  141. carrierCode: vehicleObj.carrierCode,
  142. }).then(res => {
  143. console.log(res)
  144. if (res.code == 200) {
  145. if (res.data.length > 0 && res.data.filter(e => !relateList.value
  146. .some(t => t.lotId === e.lotId)).length > 0) {
  147. relateList.value.push(...res.data.filter(e => !relateList.value.some(t => t
  148. .lotId === e
  149. .lotId)))
  150. } else {
  151. uni.showToast({
  152. title: '载具绑定批次已质检或已绑定',
  153. icon: 'none'
  154. })
  155. }
  156. debounce(handleAdd, 700)
  157. } else {
  158. uni.showToast({
  159. icon: 'none',
  160. title: res.msg,
  161. duration: 2000
  162. })
  163. }
  164. }).catch(err => {
  165. console.log(err)
  166. })
  167. }
  168. //H5扫码器关闭
  169. function qrReaderClose() {
  170. showQrCodeReader.value = false;
  171. }
  172. function handleAdd() {
  173. showQrCodeReader.value = true;
  174. // const mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
  175. // if (mpaasScanModule) {
  176. // // 调用插件的 mpaasScan 方法
  177. // mpaasScanModule.mpaasScan({
  178. // // 扫码识别类型,参数可多选,qrCode、barCode,
  179. // // 如不设置,默认识别所有扫码类型,可能有些许影响识别效率
  180. // scanType: ["qrCode", "barCode"],
  181. // // 是否隐藏相册,默认false不隐藏
  182. // hideAlbum: false,
  183. // },
  184. // (ret) => {
  185. // let vehicleObj = {
  186. // carrierCode: ret.resp_result
  187. // };
  188. // if (!vehicleObj.carrierCode || vehicleObj.carrierCode == "") {
  189. // uni.showToast({
  190. // icon: "none",
  191. // title: "请扫载具码",
  192. // duration: 1000
  193. // })
  194. // return;
  195. // }
  196. // getRelateInspectionByCarrier({
  197. // ...processInspection.value,
  198. // carrierCode: vehicleObj.carrierCode,
  199. // }).then(res => {
  200. // console.log(res)
  201. // if (res.code == 200) {
  202. // if (res.data.length > 0 && res.data.filter(e => !relateList.value
  203. // .some(t => t.lotId === e.lotId)).length > 0) {
  204. // relateList.value.push(...res.data.filter(e => !relateList.value.some(t => t
  205. // .lotId === e
  206. // .lotId)))
  207. // } else {
  208. // uni.showToast({
  209. // title: '载具绑定批次已质检或已绑定',
  210. // icon: 'none'
  211. // })
  212. // }
  213. // debounce(handleAdd, 700)
  214. // } else {
  215. // uni.showToast({
  216. // icon: 'none',
  217. // title: res.msg,
  218. // duration: 2000
  219. // })
  220. // }
  221. // }).catch(err => {
  222. // console.log(err)
  223. // })
  224. // }
  225. // );
  226. // } else {
  227. // // 测试时用
  228. // getRelateInspectionByCarrier({
  229. // carrierCode: '006522',
  230. // ...processInspection.value
  231. // }).then(res => {
  232. // console.log(res)
  233. // if (res.code == 200) {
  234. // console.log(relateList.value)
  235. // console.log(res.data.filter(e => !relateList.value
  236. // .some(t => t.lotId === e.lotId)).length)
  237. // if (res.data.length > 0 && res.data.filter(e => !relateList.value
  238. // .some(t => t.lotId === e.lotId)).length > 0) {
  239. // relateList.value.push(...res.data.filter(e => !relateList.value.some(t => t.lotId === e
  240. // .lotId)))
  241. // } else {
  242. // uni.showToast({
  243. // title: '载具绑定批次已质检或已绑定',
  244. // icon: 'none'
  245. // })
  246. // }
  247. // } else {
  248. // uni.showToast({
  249. // icon: 'none',
  250. // title: res.msg,
  251. // duration: 2000
  252. // })
  253. // }
  254. // }).catch(err => {
  255. // console.log(err)
  256. // })
  257. // }
  258. // lotReporting.value.open(data);
  259. }
  260. function handleContinue() {
  261. // lotReporting.value.open('test')
  262. handleAdd()
  263. }
  264. // 全选按钮操作
  265. function handleAll() {
  266. //清空选中数据
  267. selection.value.length = 0;
  268. if (checkAll.value) {
  269. //变更选中状态
  270. checkAll.value = false;
  271. } else {
  272. checkAll.value = true;
  273. listData.value.findIndex(item => handleSelection(item))
  274. }
  275. }
  276. function handleChangeWorkshop(arg) {
  277. const workshop = workshopList.value.find(v => v.value === arg)
  278. listData.value = allData.value.filter(v => workshop.depts.some(e => e.deptId === v.quickInfo.deptId) && (v.lotCode
  279. .includes(keyword.value) || v.productDescription.includes(keyword.value) || v.carrierName.includes(
  280. keyword.value)))
  281. selection.value = []
  282. }
  283. function isSelected(item) {
  284. return selection.value.includes(item)
  285. }
  286. //
  287. function handleSelection(item) {
  288. const buttonIndex = selection.value.findIndex(selectedItem => selectedItem === item);
  289. if (buttonIndex > -1) {
  290. selection.value.splice(buttonIndex, 1); // 取消选中
  291. } else {
  292. selection.value.push(item); // 选中
  293. }
  294. if (selection.value.length == listData.value.length) {
  295. checkAll.value = true;
  296. } else {
  297. checkAll.value = false;
  298. }
  299. }
  300. function dele(ite, index) {
  301. if (ite.isMaster == 1) {
  302. uni.showToast({
  303. icon: 'none',
  304. title: '主检查单,不可删除'
  305. })
  306. } else {
  307. relateList.value.splice(index, 1);
  308. }
  309. }
  310. function handleConfirm() {
  311. uni.$emit('relateEvent', relateList.value)
  312. uni.navigateBack()
  313. }
  314. </script>
  315. <style lang="scss">
  316. $nav-height: 60rpx;
  317. .bottom-btn-container {
  318. position: fixed;
  319. top: 80%;
  320. right: 20rpx;
  321. left: 20rpx;
  322. .start-batch-btn {
  323. margin-bottom: 24rpx;
  324. border-radius: 8rpx;
  325. background-color: #00e2a6;
  326. width: 80%;
  327. }
  328. }
  329. .active {
  330. flex: 1;
  331. height: 40rpx;
  332. background-color: #5e6eff;
  333. border: 1px solid #5e6eff;
  334. color: #000000;
  335. }
  336. .select {
  337. flex: 1;
  338. height: 40rpx;
  339. // font-size: 20rpx;
  340. background-color: #5e6eff;
  341. border: 1px solid #5e6eff;
  342. color: #ffffff;
  343. }
  344. .btn {
  345. position: fixed;
  346. right: 0;
  347. bottom: 0;
  348. left: 0;
  349. height: 100rpx;
  350. padding: 16rpx 24rpx;
  351. align-items: center;
  352. background-color: #FFFFFF;
  353. justify-content: space-between;
  354. .bottom-btn {
  355. flex: 1;
  356. font-size: 28rpx;
  357. color: #FFFFFF;
  358. &.left-btn {
  359. // background-color: #a4adb3;
  360. }
  361. &.right-btn {
  362. background-color: #1684fc;
  363. margin-left: 24rpx;
  364. }
  365. }
  366. }
  367. .box-bg {
  368. width: 100%;
  369. background-color: #F5F5F5;
  370. padding: 5rpx 0;
  371. justify-content: space-around;
  372. align-items: center;
  373. .input-view {
  374. width: 100%;
  375. flex: 4;
  376. background-color: #f8f8f8;
  377. height: $nav-height;
  378. border: 1rpx solid #999;
  379. border-radius: 15rpx;
  380. padding: 0 15rpx;
  381. flex-wrap: nowrap;
  382. margin: 0 10rpx 20rpx;
  383. line-height: $nav-height;
  384. .input-uni-icon {
  385. line-height: $nav-height;
  386. }
  387. .nav-bar-input {
  388. width: 80%;
  389. height: $nav-height;
  390. line-height: $nav-height;
  391. padding: 0 5rpx;
  392. background-color: #f8f8f8;
  393. }
  394. }
  395. .search {
  396. width: 20%;
  397. text-align: center;
  398. color: #808080;
  399. margin-top: -20rpx;
  400. }
  401. }
  402. .list-item {
  403. background-color: #fff;
  404. position: relative;
  405. padding: 16rpx;
  406. padding-bottom: 24rpx;
  407. border-radius: 24rpx;
  408. margin-bottom: 24rpx;
  409. .title-container {
  410. justify-content: space-between;
  411. margin-top: 8rpx;
  412. margin-bottom: 16rpx;
  413. .title {
  414. height: 48rpx;
  415. align-items: center;
  416. .label {
  417. font-size: 32rpx;
  418. font-weight: bold;
  419. &.code {
  420. margin-left: 8rpx;
  421. }
  422. }
  423. }
  424. .tag {
  425. border: 1px solid #1ce5b0;
  426. background-color: #f6fffd;
  427. padding: 8rpx;
  428. border-radius: 8rpx;
  429. .label {
  430. color: #1ce5b0;
  431. font-size: 24rpx;
  432. }
  433. &.not-start {
  434. border: 1px solid #bbbbbb;
  435. background-color: #f5f5f5;
  436. .label {
  437. color: #bbbbbb;
  438. }
  439. }
  440. }
  441. }
  442. .item-info {
  443. margin-bottom: 8rpx;
  444. .label {
  445. font-size: 28rpx;
  446. width: 150rpx;
  447. color: #808080;
  448. &.right {
  449. flex: 1;
  450. color: #000000;
  451. }
  452. }
  453. }
  454. }
  455. .selected {
  456. border: 1rpx solid #c0c4fc;
  457. background-color: #c0c4fc;
  458. /* 选中之后样式 */
  459. }
  460. </style>