relate.vue 9.4 KB

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