index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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>
  146. </view>
  147. </view>
  148. </view>
  149. <!-- <dialog-lotInfo ref="lotInfo"></dialog-lotInfo> -->
  150. </template>
  151. <script setup>
  152. import {
  153. ref
  154. } from 'vue'
  155. import {
  156. onLoad,
  157. onShow
  158. } from '@dcloudio/uni-app'
  159. import {
  160. getDayWorkItemHistory
  161. } from "@/api/business/dayWorkItem.js"
  162. import {
  163. store
  164. } from '@/store/index.js'
  165. import {
  166. toHHmmss
  167. } from '@/utils/common.js'
  168. const listDaywork = ref([])
  169. const listData = ref([]) // 回显
  170. const listDataItem = ref([])
  171. const lotInfo = ref(null) // 详情弹窗
  172. const selectDate = ref('')
  173. const dateList = ref([]) // 选择的日期列表
  174. const show = ref(false)
  175. const startTime = ref('')
  176. const endTime = ref('')
  177. const total = ref(0)
  178. const editStatus = ref(false)
  179. onLoad(() => {
  180. })
  181. onShow(() => {
  182. resetPage();
  183. })
  184. function resetPage() {
  185. listData.value = [];
  186. listDataItem.value = [];
  187. selectDate.value = '';
  188. dateList.value = [];
  189. show.value = false;
  190. startTime.value = '';
  191. endTime.value = '';
  192. }
  193. function handleSearch() {
  194. let today = Date.parse(new Date());
  195. let startTimestamp = Date.parse(new Date(startTime.value));
  196. let endTimestamp = Date.parse(new Date(endTime.value));
  197. if(endTimestamp - startTimestamp < 0){
  198. uni.showToast({
  199. icon: 'none',
  200. title: '开始日期不能超过结束日期',
  201. duration: 2000
  202. })
  203. return;
  204. }
  205. if(today - endTimestamp < 0 || today - startTimestamp < 0){
  206. uni.showToast({
  207. icon: 'none',
  208. title: '开始或结束日期不能超过今日',
  209. duration: 2000
  210. })
  211. return;
  212. }
  213. if(!startTime.value || !endTime.value){
  214. uni.showToast({
  215. icon: 'none',
  216. title: '请选择开始或结束日期',
  217. duration: 2000
  218. })
  219. return;
  220. }
  221. if(endTimestamp - startTimestamp > 1000 * 60 * 60 * 24 * 30){
  222. uni.showToast({
  223. icon: 'none',
  224. title: '日期区间最长不超过31天',
  225. duration: 2000
  226. })
  227. return;
  228. }
  229. show.value = !show.value
  230. if(show.value) {
  231. init();
  232. }
  233. }
  234. function init() {
  235. uni.showLoading({
  236. title: '加载中'
  237. });
  238. console.log(startTime.value);
  239. console.log(endTime.value)
  240. getDayWorkItemHistory(startTime.value,endTime.value).then(res => {
  241. if (res.code == 200) {
  242. listData.value = res.rows || [];
  243. listDataItem.value = res.rows || [];
  244. console.log(listData.value)
  245. total.value = res.rows.length;
  246. // 时间戳转工时
  247. for (var i = 0; i < listDataItem.value.length; i++) {
  248. let timeStamp = listDataItem.value[i].workingHours;
  249. listDataItem.value[i].taskTime = toHHmmss(timeStamp);
  250. }
  251. // 转为二维数组
  252. console.log(listDataItem.value)
  253. const groupedData = listDataItem.value.reduce((accumulator, currentItem) => {
  254. // 获取当前对象的日期字符串
  255. const dateString = currentItem.startTime.split(' ')[0];
  256. // 如果有这个日期,则 push 到对应的数组中,否则创建一个新的数组
  257. if (accumulator[dateString]) {
  258. accumulator[dateString].push(currentItem);
  259. } else {
  260. accumulator[dateString] = [currentItem];
  261. }
  262. return accumulator;
  263. }, {});
  264. // 0718
  265. for (var i = 0; i < listData.value.length; i++) {
  266. var current = listData.value[i];
  267. var found = false;
  268. var endTimeStatus = "";
  269. for (var j = 0; j < listDaywork.value.length; j++) {
  270. if (listDaywork.value[j].dayworkId === current.dayworkId && listDaywork.value[j].processId === current.processId) {
  271. listDaywork.value[j].qualifiedNum += current.qualifiedNum;
  272. listDaywork.value[j].rejectSum += current.rejectSum;
  273. if(listDaywork.value[j].equipmentDetailCode != null && listDaywork.value[j].equipmentDetailCode != undefined && listDaywork.value[j].equipmentDetailCode != listDaywork.value[j].equipmentDetailCode){
  274. listDaywork.value[j].equipmentDetailCode = listDaywork.value[j].equipmentDetailCode+","+current.equipmentDetailCode
  275. }
  276. found = true;
  277. break;
  278. }
  279. }
  280. if (current.status == 3 ) {
  281. endTimeStatus = current.endTime;
  282. } else {
  283. endTimeStatus= null;
  284. }
  285. if (!found) {
  286. listDaywork.value.push({
  287. processAlias:current.process.processAlias,
  288. equipmentDetailCode:current.equipmentDetailCode,
  289. lotCode:current.lotCode,
  290. productDescription:current.productDescription,
  291. daywork:current.daywork,
  292. dayworkId: current.dayworkId,
  293. processId: current.processId,
  294. qualifiedNum: current.qualifiedNum,
  295. rejectSum: current.rejectSum,
  296. endTime: endTimeStatus
  297. });
  298. }
  299. }
  300. console.log(listData.value);
  301. console.log(listDaywork.value);
  302. // 时间下拉
  303. // for (let i = 0; i < Object.keys(groupedData).length; i++) {
  304. // dateList.value[i] = {
  305. // text: Object.keys(groupedData)[i],
  306. // value: Object.keys(groupedData)[i]
  307. // }
  308. // }
  309. // listData.value = groupedData;
  310. // if(dateList.value.length > 0){
  311. // listDataItem.value = listData.value[dateList.value[0].value]
  312. // selectDate.value = dateList.value[0].value;
  313. // }
  314. // console.log(groupedData)
  315. uni.hideLoading();
  316. } else {
  317. uni.showToast({
  318. icon: "none",
  319. title: res.message,
  320. duration: 2000
  321. })
  322. uni.hideLoading();
  323. }
  324. })
  325. }
  326. function handleCheckTab(){
  327. editStatus.value = true
  328. }
  329. function handleCheckTabHis(){
  330. editStatus.value = false
  331. }
  332. function change() {
  333. listDataItem.value = listData.value[selectDate.value]
  334. }
  335. // function handleOpenLonInfo() {
  336. // lotInfo.value.open();
  337. // }
  338. </script>
  339. <style lang="scss">
  340. .time-controls {
  341. .title {
  342. margin: 20% auto 40% auto;
  343. .first {
  344. font-size: 48rpx;
  345. margin: 0 auto;
  346. }
  347. .second {
  348. color: red;
  349. font-size: 24rpx;
  350. margin: 10rpx auto 0 auto;
  351. }
  352. }
  353. .sta {
  354. justify-content: center;
  355. align-items: center;
  356. margin-bottom: 48rpx;
  357. input {
  358. border:1rpx solid gray;
  359. border-radius: 8rpx;
  360. width: 400rpx;
  361. height: 64rpx;
  362. }
  363. }
  364. .end {
  365. justify-content: center;
  366. align-items: center;
  367. margin-bottom: 64rpx;
  368. input {
  369. border:1rpx solid gray;
  370. border-radius: 8rpx;
  371. width: 400rpx;
  372. height: 64rpx;
  373. }
  374. }
  375. button {
  376. width: 78%;
  377. background-color: #1684fc;
  378. color: white;
  379. margin: 0 auto;
  380. }
  381. }
  382. .container {
  383. height: 100%;
  384. background-color: #f5f5f5;
  385. overflow: auto;
  386. }
  387. .scroll-container {
  388. position: relative;
  389. top: 140rpx;
  390. }
  391. .selected {
  392. border: 1px solid #1684fc;
  393. }
  394. .list-item {
  395. background-color: #fff;
  396. position: relative;
  397. padding: 16rpx;
  398. padding-bottom: 24rpx;
  399. margin: 0 24rpx;
  400. margin-bottom: 24rpx;
  401. border-radius: 8rpx;
  402. .title-container {
  403. margin: 8rpx 0;
  404. width: 100%;
  405. .title {
  406. height: 48rpx;
  407. justify-content: space-between;
  408. align-items: center;
  409. flex: 7;
  410. .label {
  411. font-weight: bold;
  412. }
  413. .code {
  414. margin-left: 8rpx;
  415. }
  416. }
  417. }
  418. .item-info {
  419. margin-bottom: 8rpx;
  420. .label {
  421. font-size: 28rpx;
  422. width: 152rpx;
  423. color: #808080;
  424. &.right {
  425. flex: 1;
  426. color: #000000;
  427. }
  428. }
  429. }
  430. .right-info {
  431. .label {
  432. font-size: 28rpx;
  433. }
  434. .time {
  435. margin-left: 8rpx;
  436. color: #1684fc;
  437. }
  438. .number {
  439. margin-left: 8rpx;
  440. color: #1684fc;
  441. }
  442. }
  443. }
  444. .tab-container {
  445. display: flex;
  446. flex-direction: row;
  447. width: 100%;
  448. height: 32px;
  449. justify-content: space-around;
  450. .table-item {
  451. display: flex;
  452. flex-direction: row;
  453. flex: 1;
  454. font-size: 14px;
  455. color: #666;
  456. align-items: center;
  457. justify-content: center;
  458. }
  459. }
  460. .tab-item.active {
  461. color: rgba(25, 137, 250, 1);
  462. font-weight: 700;
  463. }
  464. </style>