index.vue 12 KB

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