index.vue 8.7 KB

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