index.vue 13 KB

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