index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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. style="width: 200rpx;"></uni-data-select>
  29. </uni-section>
  30. <uni-section title="总数:" type="square" class="uni-row" style="justify-content: center;align-items: center;">
  31. {{ total }}
  32. </uni-section>
  33. <uni-section title="条数:" type="square" class="uni-row" style="justify-content: center;align-items: center;">
  34. {{ listDataItem.length }}
  35. </uni-section>
  36. </view>
  37. <view class="scroll-container">
  38. <view v-for="(item, index) in listDataItem" :key="index" class="list-item">
  39. <view class="title-container">
  40. <view class="title uni-row">
  41. <view class="uni-row">
  42. <text class="label">批次号:</text>
  43. <text class="label code"> {{ item['lotCode'] }}</text>
  44. </view>
  45. <!-- <view style="color: #1684fc; margin-right: 0;" @click="handleOpenLonInfo">
  46. <text>批次详情</text>
  47. </view> -->
  48. </view>
  49. <view class="uni-row" style="margin: 10rpx 0 0;">
  50. <view class="right-info uni-row"> <text class="label">工时</text>
  51. <text class="label time">{{ item['taskTime'] }}</text>
  52. </view>
  53. <view class="right-info uni-row" style="margin-left: 50rpx;"> <text class="label">合格数</text>
  54. <text class="label number ">{{ item['qualifiedNum'] }}</text>
  55. </view>
  56. </view>
  57. </view>
  58. <view class="item-info uni-row">
  59. <text class="label">产品描述</text>
  60. <text class="label right">{{ item['productDescription'] }}</text>
  61. </view>
  62. <!-- <view class="item-info uni-row">
  63. <text class="label">操作者</text>
  64. <text class="label right">{{ item['nickName'] }}</text>
  65. </view> -->
  66. <view class="item-info uni-row">
  67. <text class="label">开始时间</text>
  68. <text class="label right">{{ item['startTime'] ? item['startTime'] : '-' }}</text>
  69. </view>
  70. <view class="item-info uni-row">
  71. <text class="label">结束时间</text>
  72. <text class="label right">{{ item['endTime'] ? item['endTime'] : '-'}}</text>
  73. </view>
  74. <view class="item-info uni-row">
  75. <text class="label">废品数</text>
  76. <text class="label right">{{ item['rejectSum'] ? item['rejectSum'] : 0 }}</text>
  77. </view>
  78. <!-- <view class="item-info uni-row">
  79. <text class="label">投入数</text>
  80. <text
  81. class="label right">{{}}</text>
  82. </view> -->
  83. <view class="item-info uni-row">
  84. <text class="label">设备</text>
  85. <text class="label right">{{ item['equipmentDetailCode'] }}</text>
  86. </view>
  87. </view>
  88. </view>
  89. </view>
  90. <!-- <dialog-lotInfo ref="lotInfo"></dialog-lotInfo> -->
  91. </template>
  92. <script setup>
  93. import {
  94. ref
  95. } from 'vue'
  96. import {
  97. onLoad,
  98. onShow
  99. } from '@dcloudio/uni-app'
  100. import {
  101. getDayWorkItemHistory
  102. } from "@/api/business/dayWorkItem.js"
  103. import {
  104. store
  105. } from '@/store/index.js'
  106. import {
  107. toHHmmss
  108. } from '@/utils/common.js'
  109. const listData = ref([]) // 回显
  110. const listDataItem = ref([])
  111. const lotInfo = ref(null) // 详情弹窗
  112. const selectDate = ref('')
  113. const dateList = ref([]) // 选择的日期列表
  114. const show = ref(false)
  115. const startTime = ref('')
  116. const endTime = ref('')
  117. const total = ref(0)
  118. onLoad(() => {
  119. })
  120. onShow(() => {
  121. resetPage();
  122. })
  123. function resetPage() {
  124. listData.value = [];
  125. listDataItem.value = [];
  126. selectDate.value = '';
  127. dateList.value = [];
  128. show.value = false;
  129. startTime.value = '';
  130. endTime.value = '';
  131. }
  132. function handleSearch() {
  133. let today = Date.parse(new Date());
  134. let startTimestamp = Date.parse(new Date(startTime.value));
  135. let endTimestamp = Date.parse(new Date(endTime.value));
  136. if(endTimestamp - startTimestamp < 0){
  137. uni.showToast({
  138. icon: 'none',
  139. title: '开始日期不能超过结束日期',
  140. duration: 2000
  141. })
  142. return;
  143. }
  144. if(today - endTimestamp < 0 || today - startTimestamp < 0){
  145. uni.showToast({
  146. icon: 'none',
  147. title: '开始或结束日期不能超过今日',
  148. duration: 2000
  149. })
  150. return;
  151. }
  152. if(!startTime.value || !endTime.value){
  153. uni.showToast({
  154. icon: 'none',
  155. title: '请选择开始或结束日期',
  156. duration: 2000
  157. })
  158. return;
  159. }
  160. if(endTimestamp - startTimestamp > 1000 * 60 * 60 * 24 * 30){
  161. uni.showToast({
  162. icon: 'none',
  163. title: '日期区间最长不超过31天',
  164. duration: 2000
  165. })
  166. return;
  167. }
  168. show.value = !show.value
  169. if(show.value) {
  170. init();
  171. }
  172. }
  173. function init() {
  174. uni.showLoading({
  175. title: '加载中'
  176. });
  177. console.log(startTime.value);
  178. console.log(endTime.value)
  179. getDayWorkItemHistory(startTime.value,endTime.value).then(res => {
  180. if (res.code == 200) {
  181. listData.value = res.rows || [];
  182. total.value = res.rows.length;
  183. // 时间戳转工时
  184. for (var i = 0; i < listData.value.length; i++) {
  185. let timeStamp = listData.value[i].workingHours;
  186. listData.value[i].taskTime = toHHmmss(timeStamp);
  187. }
  188. // 转为二维数组
  189. console.log(listData.value)
  190. const groupedData = listData.value.reduce((accumulator, currentItem) => {
  191. // 获取当前对象的日期字符串
  192. const dateString = currentItem.startTime.split(' ')[0];
  193. // 如果有这个日期,则 push 到对应的数组中,否则创建一个新的数组
  194. if (accumulator[dateString]) {
  195. accumulator[dateString].push(currentItem);
  196. } else {
  197. accumulator[dateString] = [currentItem];
  198. }
  199. return accumulator;
  200. }, {});
  201. // 时间下拉
  202. for (let i = 0; i < Object.keys(groupedData).length; i++) {
  203. dateList.value[i] = {
  204. text: Object.keys(groupedData)[i],
  205. value: Object.keys(groupedData)[i]
  206. }
  207. }
  208. listData.value = groupedData;
  209. if(dateList.value.length > 0){
  210. listDataItem.value = listData.value[dateList.value[0].value]
  211. selectDate.value = dateList.value[0].value;
  212. }
  213. console.log(groupedData)
  214. uni.hideLoading();
  215. } else {
  216. uni.showToast({
  217. icon: "none",
  218. title: res.message,
  219. duration: 2000
  220. })
  221. uni.hideLoading();
  222. }
  223. })
  224. }
  225. function change() {
  226. listDataItem.value = listData.value[selectDate.value]
  227. }
  228. // function handleOpenLonInfo() {
  229. // lotInfo.value.open();
  230. // }
  231. </script>
  232. <style lang="scss">
  233. .time-controls {
  234. .title {
  235. margin: 20% auto 40% auto;
  236. .first {
  237. font-size: 48rpx;
  238. margin: 0 auto;
  239. }
  240. .second {
  241. color: red;
  242. font-size: 24rpx;
  243. margin: 10rpx auto 0 auto;
  244. }
  245. }
  246. .sta {
  247. justify-content: center;
  248. align-items: center;
  249. margin-bottom: 48rpx;
  250. input {
  251. border:1rpx solid gray;
  252. border-radius: 8rpx;
  253. width: 400rpx;
  254. height: 64rpx;
  255. }
  256. }
  257. .end {
  258. justify-content: center;
  259. align-items: center;
  260. margin-bottom: 64rpx;
  261. input {
  262. border:1rpx solid gray;
  263. border-radius: 8rpx;
  264. width: 400rpx;
  265. height: 64rpx;
  266. }
  267. }
  268. button {
  269. width: 78%;
  270. background-color: #1684fc;
  271. color: white;
  272. margin: 0 auto;
  273. }
  274. }
  275. .container {
  276. height: 100%;
  277. background-color: #f5f5f5;
  278. overflow: auto;
  279. }
  280. .scroll-container {
  281. position: relative;
  282. top: 140rpx;
  283. }
  284. .selected {
  285. border: 1px solid #1684fc;
  286. }
  287. .list-item {
  288. background-color: #fff;
  289. position: relative;
  290. padding: 16rpx;
  291. padding-bottom: 24rpx;
  292. margin: 0 24rpx;
  293. margin-bottom: 24rpx;
  294. border-radius: 8rpx;
  295. .title-container {
  296. margin: 8rpx 0;
  297. width: 100%;
  298. .title {
  299. height: 48rpx;
  300. justify-content: space-between;
  301. align-items: center;
  302. flex: 7;
  303. .label {
  304. font-weight: bold;
  305. }
  306. .code {
  307. margin-left: 8rpx;
  308. }
  309. }
  310. }
  311. .item-info {
  312. margin-bottom: 8rpx;
  313. .label {
  314. font-size: 28rpx;
  315. width: 152rpx;
  316. color: #808080;
  317. &.right {
  318. flex: 1;
  319. color: #000000;
  320. }
  321. }
  322. }
  323. .right-info {
  324. .label {
  325. font-size: 28rpx;
  326. }
  327. .time {
  328. margin-left: 8rpx;
  329. color: #1684fc;
  330. }
  331. .number {
  332. margin-left: 8rpx;
  333. color: #1684fc;
  334. }
  335. }
  336. }
  337. </style>