index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. <template>
  2. <view class="page-container uni-column">
  3. <view class="search-container uni-row">
  4. <input type="text" v-model="quer.keyword" placeholder="请输入关键字" />
  5. <view class="btn uni-row" @click="handleSearch">搜索</view>
  6. <!-- <uni-icons type="scan" size="24" /> -->
  7. </view>
  8. <view class="time-controls"
  9. style="margin-top: 10rpx;display: flex;margin-right: 0px;background-color: #ffffff;">
  10. <view class="uni-row sta">
  11. <span style="align-items: center;display: flex;font-size: 16px;margin-left: 12rpx;">检查日期:</span>
  12. <view class="uni-row" style="flex: 1;width: 100%;">
  13. <input v-model="startTime" type="date" @input="timeSizer"
  14. style="flex: 1;width: 100%;padding-top: 12px;" />
  15. <span style="align-items: center;display: flex;">—</span>
  16. <input v-model="endTime" type="date" @input="timeSizer" style="padding-top: 12px;" />
  17. </view>
  18. </view>
  19. </view>
  20. <view class="uni-row" style="margin-top: 10rpx;">
  21. <view class="scan-btn " style="background-color: #aaaaff;min-height: 80rpx;" @click="handleScan">扫码</view>
  22. </view>
  23. <view class="daywork-item uni-column" v-for="(item, index) in inspecionList" :key="index"
  24. @click="handleSelection(item)">
  25. <view class="lot-code uni-row">
  26. <text>批次号:{{ item.lotCode }}</text>
  27. <text :style="selectType(item)">{{ selectText(item) }}</text>
  28. <text v-if="delable(item)" class="fa fa-trash" style="font-size: 16; color: red;"
  29. @click.stop="deleteItem(item)"></text>
  30. <text v-else class="fa fa-trash" style="font-size: 16; color: white;"></text>
  31. </view>
  32. <view class="info">
  33. <view class="info-row uni-row">
  34. <view class="label">检查箱号:</view>
  35. <view class="value">{{ item.carrierCode }}</view>
  36. <view class="label">检察员:</view>
  37. <view class="value">{{ item.technicianName }}</view>
  38. </view>
  39. <view class="info-row uni-row">
  40. <view class="label">检查数量:</view>
  41. <view class="value">{{ item.examiningNum }}</view>
  42. <view class="label">不良品量:</view>
  43. <view class="value">{{ item.disqualificationNum }}</view>
  44. </view>
  45. <view class="info-row uni-row">
  46. <view class="label">产品描述:</view>
  47. <view class="value">{{ item.productDescription }}</view>
  48. </view>
  49. <view class="info-row uni-row">
  50. <view class="label">检测载具:</view>
  51. <view class="value">{{ item.inspectionCarrierCode }}
  52. {{ item.isInspectionCarrierChanged == 1 ? '(已解绑)' : ''}}
  53. </view>
  54. <button class="reporting-tag" size="mini" type="primary"
  55. @click.stop="changeCheckCarrier(item)">检测载具</button>
  56. </view>
  57. </view>
  58. </view>
  59. <QrScanner v-if="showQrCodeReader" @decode="onDecodeHandler" @close="qrReaderClose" />
  60. </view>
  61. </template>
  62. <script setup>
  63. import {
  64. ref,
  65. getCurrentInstance
  66. } from 'vue'
  67. import {
  68. getProcessInspecionList,
  69. getLotInfo,
  70. delProcessInspection
  71. } from '@/api/business/processInspection.js'
  72. import QrScanner from '../vueQrCode/index.vue'
  73. import {
  74. timestampToTime,
  75. toHHmmss
  76. } from '@/utils/common.js'
  77. import {
  78. onLoad,
  79. onReady,
  80. onUnload,
  81. onShow,
  82. onReachBottom
  83. } from '@dcloudio/uni-app'
  84. import {
  85. store
  86. } from '@/store/index.js'
  87. const keyword = ref('')
  88. const inspecionList = ref([]); //时间后筛选数组
  89. const startTime = ref(new Date().toISOString().split("T")[0])
  90. const endTime = ref(new Date().toISOString().split("T")[0])
  91. const shouldCallList = ref(false)
  92. const pageSize = ref(10)
  93. const pageNum = ref(1)
  94. const status = ref(true)
  95. const showQrCodeReader = ref(false);
  96. const range = [{
  97. value: 0,
  98. text: "待确认",
  99. type: "color: #fcab53"
  100. }, {
  101. value: 1,
  102. text: "合格",
  103. type: "color: #55ff7f"
  104. }, {
  105. value: 2,
  106. text: "不合格",
  107. type: "color: #ff0c2c"
  108. }]
  109. const quer = ref({}) //用于查询
  110. /***************************** 页面生命周期函数 *****************************/
  111. onShow(() => {
  112. console.log(inspecionList.value, 15151)
  113. inspecionList.value = []
  114. shouldCallList.value = false
  115. const instance = getCurrentInstance().proxy;
  116. const eventChannel = instance.getOpenerEventChannel();
  117. // 声明一个变量来保存 setTimeout 的 ID
  118. let timeoutId;
  119. // 监听 'inspectionChamberInfo' 事件
  120. eventChannel.on('inspectionChamberInfo', function(data) {
  121. console.log("Event received with data:", data);
  122. // 事件触发时取消 setTimeout
  123. clearTimeout(timeoutId);
  124. // 更新状态
  125. quer.value.inspectionChamberId = data.data;
  126. shouldCallList.value = true;
  127. // 事件触发时执行的逻辑
  128. getList();
  129. });
  130. // 设置 setTimeout,在没有接收到事件的情况下调用 getList
  131. timeoutId = setTimeout(() => {
  132. if (!shouldCallList.value) {
  133. console.log("777 - No event received, calling getList");
  134. getList();
  135. }
  136. }, 1000); // 例如,1 秒后执行
  137. })
  138. onReachBottom(() => {
  139. console.log(status.value)
  140. if (status.value) {
  141. pageNum.value += 1
  142. quer.value.pageNum = pageNum.value
  143. quer.value.pageSize = pageSize.value
  144. getProcessInspecionList(quer.value).then(res => {
  145. const existingIds = new Set(inspecionList.value.map(item => item.id));
  146. // 过滤出那些不在 existingIds 中的项,即新数据
  147. const newRows = res.rows.filter(row => !existingIds.has(row.id));
  148. // 如果有新数据,将其添加到 listData
  149. if (newRows.length > 0) {
  150. inspecionList.value = inspecionList.value.concat(newRows);
  151. original.value = original.value.concat(newRows);
  152. } else {
  153. // 如果没有新数据,更新状态表示没有更多数据
  154. status.value = false;
  155. }
  156. })
  157. }
  158. })
  159. /***************************** 定义了一些方法 *****************************/
  160. function getList() {
  161. uni.showLoading({
  162. title: '加载中'
  163. });
  164. pageNum.value = 1
  165. quer.value.startTime = startTime.value;
  166. quer.value.endTime = endTime.value
  167. // quer.value.deptId = store.curDeptDetails.deptId
  168. quer.value.type = "instrumentRoomInspection"
  169. quer.value.pageNum = pageNum.value
  170. quer.value.pageSize = pageSize.value
  171. if (!checkTime(quer.value.startTime, quer.value.endTime)) {
  172. console.log("777")
  173. uni.showToast({
  174. icon: 'none',
  175. title: "开始日期不能大于结束日期",
  176. duration: 2000
  177. })
  178. } else {
  179. getProcessInspecionList(quer.value).then(res => {
  180. console.log("res", res);
  181. if (res.code == 200) {
  182. inspecionList.value = res.rows;
  183. console.log(1111111)
  184. uni.hideLoading();
  185. }
  186. });
  187. }
  188. uni.hideLoading();
  189. }
  190. //判断开始时间是否大于结束时间
  191. function checkTime(time1, time2) {
  192. let date1 = new Date(startTime.value);
  193. let date2 = new Date(endTime.value);
  194. if (date1 > date2) {
  195. return false
  196. }
  197. return true
  198. }
  199. function handleSearch() {
  200. pageNum.value = 1
  201. status.value = true
  202. getList()
  203. }
  204. function delable(item) {
  205. if (item.creatorId === store.userInfo.userId) {
  206. return true
  207. }
  208. return false
  209. }
  210. const deleteItem = (item) => {
  211. uni.showModal({
  212. title: '确认',
  213. content: '确认删除该仪器室检查么?',
  214. success: function(res) {
  215. if (res.confirm) {
  216. delProcessInspection(item.id).then(res => {
  217. if (res.code === 200) {
  218. console.log(res)
  219. getList()
  220. } else {
  221. uni.showToast({
  222. icon: 'none',
  223. title: res.msg
  224. })
  225. }
  226. })
  227. } else if (res.cancel) {
  228. uni.showToast({
  229. title: '已取消',
  230. icon: 'none'
  231. })
  232. }
  233. }
  234. })
  235. }
  236. const changeCheckCarrier = (item) => {
  237. const openItem = {
  238. dayworkId: item.dayworkId,
  239. processInspectionId: item.id,
  240. daywork: item
  241. }
  242. uni.navigateTo({
  243. url: "/pages/changeInspectionBox/index",
  244. success: function(res) {
  245. // 通过eventChannel向被打开页面传送数据
  246. res.eventChannel.emit('outsourceFromOpenerPage', {
  247. data: openItem
  248. })
  249. }
  250. })
  251. }
  252. //H5扫码器回调
  253. function onDecodeHandler(data) {
  254. showQrCodeReader.value = false;
  255. let vehicleObj = {
  256. carrierCode: data
  257. };
  258. if (!vehicleObj.carrierCode || vehicleObj.carrierCode == "") {
  259. uni.showToast({
  260. icon: "none",
  261. title: "请扫载具码",
  262. duration: 1000
  263. })
  264. return;
  265. }
  266. quer.value.keyword = vehicleObj.carrierCode
  267. getList()
  268. }
  269. //H5扫码器关闭
  270. function qrReaderClose() {
  271. showQrCodeReader.value = false;
  272. }
  273. //扫码
  274. function handleScan() {
  275. showQrCodeReader.value = true;
  276. // 引入原生插件
  277. // const mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
  278. // if (mpaasScanModule) {
  279. // // 调用插件的 mpaasScan 方法
  280. // mpaasScanModule.mpaasScan({
  281. // // 扫码识别类型,参数可多选,qrCode、barCode,
  282. // // 如不设置,默认识别所有扫码类型,可能有些许影响识别效率
  283. // scanType: ["qrCode", "barCode"],
  284. // // 是否隐藏相册,默认false不隐藏
  285. // hideAlbum: false,
  286. // },
  287. // (ret) => {
  288. // console.log(ret);
  289. // let vehicleObj = {
  290. // carrierCode: ret.resp_result
  291. // };
  292. // if (!vehicleObj.carrierCode || vehicleObj.carrierCode == "") {
  293. // uni.showToast({
  294. // icon: "none",
  295. // title: "请扫载具码",
  296. // duration: 1000
  297. // })
  298. // return;
  299. // }
  300. // quer.value.keyword = vehicleObj.carrierCode
  301. // getList()
  302. // }
  303. // );
  304. // } else {
  305. // // 测试时用
  306. // quer.value.keyword = ""
  307. // getList()
  308. // }
  309. }
  310. //时间筛选,暂时注释,使用搜索向
  311. function timeSizer() {
  312. if (!checkTime(startTime.value, endTime.value)) {
  313. console.log("777")
  314. uni.showToast({
  315. icon: 'none',
  316. title: "开始日期不能大于结束日期",
  317. duration: 2000
  318. })
  319. } else {
  320. getList()
  321. }
  322. }
  323. // 筛选函数
  324. const filterSameDayItems = (inspectionList, startTime) => {
  325. // 使用filter方法筛选出与startTime同一天的元素
  326. const filteredList = inspectionList.filter(item => {
  327. // 将数组中每个元素的date属性转换为不包含时分秒的字符串
  328. const itemDateString = item.createTime.split(' ')[0];
  329. // 比较两个日期字符串是否相同
  330. return itemDateString === startTime;
  331. });
  332. return filteredList;
  333. };
  334. function isSameDate(date1, date2) {
  335. // 使用Date对象的toISOString()方法来格式化日期,并去除时分秒部分
  336. const formatDate = (date) => date.toISOString().split('T')[0];
  337. // 比较两个日期的年月日部分是否相同
  338. return formatDate(date1) === formatDate(date2);
  339. }
  340. //查看序捡详情
  341. function handleSelection(item) {
  342. store.processInspection = item;
  343. uni.navigateTo({
  344. url: '/pages/instrumentRoomInspection/form'
  345. })
  346. }
  347. //状态文本
  348. function selectText(item) {
  349. for (var i = 0; i < range.length; i++) {
  350. if (item.status == range[i].value) {
  351. return range[i].text
  352. }
  353. }
  354. }
  355. //状态样式
  356. function selectType(item) {
  357. for (var i = 0; i < range.length; i++) {
  358. if (item.status == range[i].value) {
  359. return range[i].type
  360. }
  361. }
  362. }
  363. const addProcessInspection = (data) => {
  364. const info = {
  365. title: data.title,
  366. standard: data.standard,
  367. result: '',
  368. number: 1
  369. }
  370. unfitInfos.value.push(info)
  371. }
  372. /***************************** 定义了一些事件 *****************************/
  373. </script>
  374. <style lang="scss">
  375. .time-controls {
  376. .title {
  377. margin: 20% auto 40% auto;
  378. }
  379. .sta {
  380. justify-content: flex-start;
  381. align-items: center;
  382. input {
  383. border: 1rpx solid gray;
  384. border-radius: 8rpx;
  385. width: 100%;
  386. // width: 400rpx;
  387. flex: 1;
  388. height: 64rpx;
  389. }
  390. }
  391. }
  392. .page-container {
  393. // height: 100%;
  394. background-color: #ececec;
  395. font-size: 28rpx;
  396. padding: 24rpx;
  397. box-sizing: border-box;
  398. }
  399. .search-container {
  400. border-radius: 12rpx;
  401. align-items: center;
  402. input {
  403. flex: 1;
  404. background-color: #ffffff;
  405. height: 64rpx;
  406. box-sizing: border-box;
  407. padding: 0 16rpx;
  408. }
  409. .btn {
  410. width: 120rpx;
  411. height: 64rpx;
  412. background-color: #1684FC;
  413. justify-content: center;
  414. font-size: 24rpx;
  415. color: #ffffff;
  416. justify-content: center;
  417. align-items: center;
  418. }
  419. }
  420. .scan-btn {
  421. height: 64rpx;
  422. color: #ffffff;
  423. background-color: #f47c3c;
  424. align-items: center;
  425. justify-content: center;
  426. border-radius: 8rpx;
  427. flex: 1;
  428. }
  429. .daywork-item {
  430. padding: 24rpx;
  431. background-color: #ffffff;
  432. margin-top: 24rpx;
  433. border-radius: 8rpx;
  434. .lot-code {
  435. align-items: center;
  436. justify-content: space-between;
  437. font-weight: 700;
  438. }
  439. .info {
  440. font-size: 24rpx;
  441. color: #767676;
  442. .info-row {
  443. margin-top: 16rpx;
  444. .label {
  445. width: 120rpx;
  446. }
  447. .value {
  448. flex: 1;
  449. }
  450. }
  451. }
  452. }
  453. </style>