index.vue 12 KB

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