index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. <template>
  2. <view v-if="!show" class="time-controls">
  3. <view class="title">
  4. <view class="first">请选择日期区间</view>
  5. <view class="second">注意日期区间最长不超过31天</view>
  6. </view>
  7. <uni-section title="开始日期:" type="square" class="uni-row sta">
  8. <input v-model="startTime" type="date"/>
  9. </uni-section>
  10. <uni-section title="结束日期:" type="square" class="uni-row end">
  11. <input v-model="endTime" type="date"/>
  12. </uni-section>
  13. <button @click="handleSearch">查询</button>
  14. </view>
  15. <view v-if="show" class="uni-column container">
  16. <view class="uni-row" style="position: fixed;
  17. top: 0;width: 100%;
  18. height: 120rpx;
  19. z-index: 2;
  20. margin:0 auto;
  21. background-color: white;
  22. flex-direction: column;
  23. justify-content: flex-start;
  24. align-items: center;
  25. border-top: 1rpx solid lightgray;
  26. border-bottom: 1rpx solid lightgray;">
  27. <!-- <uni-section title="选择日期:" type="square" class="uni-row" style="margin-left: 16rpx;">
  28. <uni-data-select v-model="selectDate" :localdata="dateList" @change="change" :clear="false"
  29. placeholder="无报工记录"
  30. style="width: 200rpx;"></uni-data-select>
  31. </uni-section> -->
  32. <view class="tab-container">
  33. <view :class="['tab-item', editStatus === false ? 'active': '']" @click="handleCheckTabHis()">历史报工</view>
  34. <view :class="['tab-item', editStatus === true ? 'active': '']" @click="handleCheckTab()">已完成报工</view>
  35. </view>
  36. <view style="width: 100%;">
  37. <uni-section title="时间范围:" type="square" class="uni-row" style="justify-content: start;align-items: center;margin-left: 20rpx;">
  38. {{ startTime }}&nbsp; ~ &nbsp;{{endTime}}
  39. </uni-section>
  40. <!-- <view style="width: 100%;font-size: 28rpx; text-align: left; margin-left: 16rpx;">时间范围:{{ startTime }}&nbsp; ~ &nbsp;{{endTime}}</view> -->
  41. <!-- <uni-section title="条数:" type="square" class="uni-row" style="justify-content: center;align-items: center;">
  42. {{ listDataItem.length }}
  43. </uni-section> -->
  44. </view>
  45. </view>
  46. <view class="scroll-container" v-if="!editStatus">
  47. <view v-for="(item, index) in listDataItem" :key="index" class="list-item">
  48. <view class="title-container">
  49. <view class="title uni-row">
  50. <view class="uni-row">
  51. <text class="label">批次号:</text>
  52. <text class="label code"> {{ item['lotCode'] }}</text>
  53. </view>
  54. <!-- <view style="color: #1684fc; margin-right: 0;" @click="handleOpenLonInfo">
  55. <text>批次详情</text>
  56. </view> -->
  57. </view>
  58. <view class="uni-row" style="margin: 10rpx 0 0;">
  59. <view class="right-info uni-row"> <text class="label">工时</text>
  60. <text class="label time">{{ item['taskTime'] }}</text>
  61. </view>
  62. <view class="right-info uni-row" style="margin-left: 50rpx;"> <text class="label">合格数</text>
  63. <text class="label number ">{{ item['qualifiedNum'] }}</text>
  64. </view>
  65. </view>
  66. </view>
  67. <view class="item-info uni-row">
  68. <text class="label">产品描述</text>
  69. <text class="label right">{{ item['productDescription'] }}</text>
  70. </view>
  71. <!-- <view class="item-info uni-row">
  72. <text class="label">操作者</text>
  73. <text class="label right">{{ item['nickName'] }}</text>
  74. </view> -->
  75. <view class="item-info uni-row">
  76. <text class="label">开始时间</text>
  77. <text class="label right">{{ item['startTime'] ? item['startTime'] : '-' }}</text>
  78. </view>
  79. <view class="item-info uni-row">
  80. <text class="label">结束时间</text>
  81. <text class="label right">{{ item['endTime'] ? item['endTime'] : '-'}}</text>
  82. </view>
  83. <view class="item-info uni-row">
  84. <text class="label">废品数</text>
  85. <text class="label right">{{ item['rejectSum'] ? item['rejectSum'] : 0 }}</text>
  86. </view>
  87. <!-- <view class="item-info uni-row">
  88. <text class="label">投入数</text>
  89. <text
  90. class="label right">{{}}</text>
  91. </view> -->
  92. <view class="item-info uni-row">
  93. <text class="label">设备</text>
  94. <text class="label right">{{ item['equipmentDetailCode'] }}</text>
  95. </view>
  96. </view>
  97. </view>
  98. <view class="scroll-container" v-if="editStatus">
  99. <view v-for="(item, index) in listDaywork" :key="index" class="list-item">
  100. <view class="title-container">
  101. <view class="title uni-row">
  102. <view class="uni-row">
  103. <text class="label">批次号:</text>
  104. <text class="label code"> {{ item['lotCode'] }}</text>
  105. </view>
  106. <!-- <view style="color: #1684fc; margin-right: 0;" @click="handleOpenLonInfo">
  107. <text>批次详情</text>
  108. </view> -->
  109. </view>
  110. <view class="uni-row" style="margin: 10rpx 0 0;">
  111. <!-- <view class="right-info uni-row"> <text class="label">工时</text>
  112. <text class="label time">{{ item['taskTime'] }}</text>
  113. </view> -->
  114. <view class="right-info uni-row"> <text class="label">工序</text>
  115. <text class="label time">{{ item['processAlias'] }}</text>
  116. </view>
  117. <view class="right-info uni-row" style="margin-left: 50rpx;"> <text class="label">合格数</text>
  118. <text class="label number ">{{ item['qualifiedNum'] }}</text>
  119. </view>
  120. </view>
  121. </view>
  122. <view class="item-info uni-row">
  123. <text class="label">产品描述</text>
  124. <text class="label right">{{ item['productDescription'] }}</text>
  125. </view>
  126. <!-- <view class="item-info uni-row">
  127. <text class="label">操作者</text>
  128. <text class="label right">{{ item['nickName'] }}</text>
  129. </view> -->
  130. <!-- <view class="item-info uni-row">
  131. <text class="label">开始时间</text>
  132. <text class="label right">{{ item['startTime'] ? item['startTime'] : '-' }}</text>
  133. </view> -->
  134. <view class="item-info uni-row">
  135. <text class="label">结束时间</text>
  136. <text class="label right">{{ item['endTime'] ? item['endTime'] : '-'}}</text>
  137. </view>
  138. <view class="item-info uni-row">
  139. <text class="label">废品数</text>
  140. <text class="label right">{{ item['rejectSum'] ? item['rejectSum'] : 0 }}</text>
  141. </view>
  142. <view class="item-info uni-row">
  143. <text class="label">设备</text>
  144. <text class="label right">{{ item['equipmentDetailCode'] }}</text>
  145. <view class="uni-row" style="justify-content: flex-end;margin-left: 20px;" v-if="item['adoptStatus'] && item['adoptStatus'] != null">
  146. <text >交检状态:</text>
  147. <text v-if="item['adoptStatus'] == 1" style="color: #67c337;" >正常</text>
  148. <text v-if="item['adoptStatus'] == 2" style="color: red;" >反选</text>
  149. </view>
  150. </view>
  151. </view>
  152. </view>
  153. </view>
  154. <!-- <dialog-lotInfo ref="lotInfo"></dialog-lotInfo> -->
  155. </template>
  156. <script setup>
  157. import {
  158. ref
  159. } from 'vue'
  160. import {
  161. onLoad,
  162. onShow
  163. } from '@dcloudio/uni-app'
  164. import {
  165. getDayWorkItemHistory
  166. } from "@/api/business/dayWorkItem.js"
  167. import {
  168. store
  169. } from '@/store/index.js'
  170. import {
  171. toHHmmss
  172. } from '@/utils/common.js'
  173. const listDaywork = ref([])
  174. const listData = ref([]) // 回显
  175. const listDataItem = ref([])
  176. const lotInfo = ref(null) // 详情弹窗
  177. const selectDate = ref('')
  178. const dateList = ref([]) // 选择的日期列表
  179. const show = ref(false)
  180. const startTime = ref('')
  181. const endTime = ref('')
  182. const total = ref(0)
  183. const editStatus = ref(false)
  184. onLoad(() => {
  185. })
  186. onShow(() => {
  187. resetPage();
  188. })
  189. function resetPage() {
  190. listData.value = [];
  191. listDataItem.value = [];
  192. selectDate.value = '';
  193. dateList.value = [];
  194. show.value = false;
  195. startTime.value = '';
  196. endTime.value = '';
  197. }
  198. function handleSearch() {
  199. let today = Date.parse(new Date());
  200. let startTimestamp = Date.parse(new Date(startTime.value));
  201. let endTimestamp = Date.parse(new Date(endTime.value));
  202. if(endTimestamp - startTimestamp < 0){
  203. uni.showToast({
  204. icon: 'none',
  205. title: '开始日期不能超过结束日期',
  206. duration: 2000
  207. })
  208. return;
  209. }
  210. if(today - endTimestamp < 0 || today - startTimestamp < 0){
  211. uni.showToast({
  212. icon: 'none',
  213. title: '开始或结束日期不能超过今日',
  214. duration: 2000
  215. })
  216. return;
  217. }
  218. if(!startTime.value || !endTime.value){
  219. uni.showToast({
  220. icon: 'none',
  221. title: '请选择开始或结束日期',
  222. duration: 2000
  223. })
  224. return;
  225. }
  226. if(endTimestamp - startTimestamp > 1000 * 60 * 60 * 24 * 30){
  227. uni.showToast({
  228. icon: 'none',
  229. title: '日期区间最长不超过31天',
  230. duration: 2000
  231. })
  232. return;
  233. }
  234. show.value = !show.value
  235. if(show.value) {
  236. init();
  237. }
  238. }
  239. function init() {
  240. uni.showLoading({
  241. title: '加载中'
  242. });
  243. console.log(startTime.value);
  244. console.log(endTime.value)
  245. getDayWorkItemHistory(startTime.value,endTime.value).then(res => {
  246. if (res.code == 200) {
  247. listData.value = res.rows || [];
  248. listDataItem.value = res.rows || [];
  249. console.log(listData.value)
  250. total.value = res.rows.length;
  251. // 时间戳转工时
  252. for (var i = 0; i < listDataItem.value.length; i++) {
  253. let timeStamp = listDataItem.value[i].workingHours;
  254. listDataItem.value[i].taskTime = toHHmmss(timeStamp);
  255. }
  256. // 转为二维数组
  257. console.log(listDataItem.value)
  258. const groupedData = listDataItem.value.reduce((accumulator, currentItem) => {
  259. // 获取当前对象的日期字符串
  260. const dateString = currentItem.startTime.split(' ')[0];
  261. // 如果有这个日期,则 push 到对应的数组中,否则创建一个新的数组
  262. if (accumulator[dateString]) {
  263. accumulator[dateString].push(currentItem);
  264. } else {
  265. accumulator[dateString] = [currentItem];
  266. }
  267. return accumulator;
  268. }, {});
  269. // 0718
  270. for (var i = 0; i < listData.value.length; i++) {
  271. var current = listData.value[i];
  272. var found = false;
  273. var endTimeStatus = "";
  274. for (var j = 0; j < listDaywork.value.length; j++) {
  275. if (listDaywork.value[j].dayworkId === current.dayworkId && listDaywork.value[j].processId === current.processId) {
  276. listDaywork.value[j].qualifiedNum += current.qualifiedNum;
  277. listDaywork.value[j].rejectSum += current.rejectSum;
  278. if(listDaywork.value[j].equipmentDetailCode != null && listDaywork.value[j].equipmentDetailCode != undefined && listDaywork.value[j].equipmentDetailCode != listDaywork.value[j].equipmentDetailCode){
  279. listDaywork.value[j].equipmentDetailCode = listDaywork.value[j].equipmentDetailCode+","+current.equipmentDetailCode
  280. }
  281. found = true;
  282. break;
  283. }
  284. }
  285. if (current.status == 3 ) {
  286. endTimeStatus = current.endTime;
  287. } else {
  288. endTimeStatus= null;
  289. }
  290. if (!found) {
  291. listDaywork.value.push({
  292. processAlias:current.process.processAlias,
  293. equipmentDetailCode:current.equipmentDetailCode,
  294. lotCode:current.lotCode,
  295. productDescription:current.productDescription,
  296. daywork:current.daywork,
  297. dayworkId: current.dayworkId,
  298. processId: current.processId,
  299. qualifiedNum: current.qualifiedNum,
  300. rejectSum: current.rejectSum,
  301. endTime: endTimeStatus,
  302. adoptStatus:current.adoptStatus == null? null:current.adoptStatus
  303. });
  304. }
  305. }
  306. console.log(listData.value);
  307. console.log(listDaywork.value);
  308. // 时间下拉
  309. // for (let i = 0; i < Object.keys(groupedData).length; i++) {
  310. // dateList.value[i] = {
  311. // text: Object.keys(groupedData)[i],
  312. // value: Object.keys(groupedData)[i]
  313. // }
  314. // }
  315. // listData.value = groupedData;
  316. // if(dateList.value.length > 0){
  317. // listDataItem.value = listData.value[dateList.value[0].value]
  318. // selectDate.value = dateList.value[0].value;
  319. // }
  320. // console.log(groupedData)
  321. uni.hideLoading();
  322. } else {
  323. uni.showToast({
  324. icon: "none",
  325. title: res.message,
  326. duration: 2000
  327. })
  328. uni.hideLoading();
  329. }
  330. })
  331. }
  332. function handleCheckTab(){
  333. editStatus.value = true
  334. }
  335. function handleCheckTabHis(){
  336. editStatus.value = false
  337. }
  338. function change() {
  339. listDataItem.value = listData.value[selectDate.value]
  340. }
  341. // function handleOpenLonInfo() {
  342. // lotInfo.value.open();
  343. // }
  344. </script>
  345. <style lang="scss">
  346. .time-controls {
  347. .title {
  348. margin: 20% auto 40% auto;
  349. .first {
  350. font-size: 48rpx;
  351. margin: 0 auto;
  352. }
  353. .second {
  354. color: red;
  355. font-size: 24rpx;
  356. margin: 10rpx auto 0 auto;
  357. }
  358. }
  359. .sta {
  360. justify-content: center;
  361. align-items: center;
  362. margin-bottom: 48rpx;
  363. input {
  364. border:1rpx solid gray;
  365. border-radius: 8rpx;
  366. width: 400rpx;
  367. height: 64rpx;
  368. }
  369. }
  370. .end {
  371. justify-content: center;
  372. align-items: center;
  373. margin-bottom: 64rpx;
  374. input {
  375. border:1rpx solid gray;
  376. border-radius: 8rpx;
  377. width: 400rpx;
  378. height: 64rpx;
  379. }
  380. }
  381. button {
  382. width: 78%;
  383. background-color: #1684fc;
  384. color: white;
  385. margin: 0 auto;
  386. }
  387. }
  388. .container {
  389. height: 100%;
  390. background-color: #f5f5f5;
  391. overflow: auto;
  392. }
  393. .scroll-container {
  394. position: relative;
  395. top: 140rpx;
  396. }
  397. .selected {
  398. border: 1px solid #1684fc;
  399. }
  400. .list-item {
  401. background-color: #fff;
  402. position: relative;
  403. padding: 16rpx;
  404. padding-bottom: 24rpx;
  405. margin: 0 24rpx;
  406. margin-bottom: 24rpx;
  407. border-radius: 8rpx;
  408. .title-container {
  409. margin: 8rpx 0;
  410. width: 100%;
  411. .title {
  412. height: 48rpx;
  413. justify-content: space-between;
  414. align-items: center;
  415. flex: 7;
  416. .label {
  417. font-weight: bold;
  418. }
  419. .code {
  420. margin-left: 8rpx;
  421. }
  422. }
  423. }
  424. .item-info {
  425. margin-bottom: 8rpx;
  426. .label {
  427. font-size: 28rpx;
  428. width: 152rpx;
  429. color: #808080;
  430. &.right {
  431. flex: 1;
  432. color: #000000;
  433. }
  434. }
  435. }
  436. .right-info {
  437. .label {
  438. font-size: 28rpx;
  439. }
  440. .time {
  441. margin-left: 8rpx;
  442. color: #1684fc;
  443. }
  444. .number {
  445. margin-left: 8rpx;
  446. color: #1684fc;
  447. }
  448. }
  449. }
  450. .tab-container {
  451. display: flex;
  452. flex-direction: row;
  453. width: 100%;
  454. height: 32px;
  455. justify-content: space-around;
  456. .table-item {
  457. display: flex;
  458. flex-direction: row;
  459. flex: 1;
  460. font-size: 14px;
  461. color: #666;
  462. align-items: center;
  463. justify-content: center;
  464. }
  465. }
  466. .tab-item.active {
  467. color: rgba(25, 137, 250, 1);
  468. font-weight: 700;
  469. }
  470. </style>