index.vue 13 KB

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