index.vue 12 KB

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