relate.vue 9.1 KB

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