history.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <view class="history">
  3. <view class="header">
  4. <uni-datetime-picker type="date" :clear-icon="false" v-model="BeginSingle"
  5. @change='change1' />
  6. <uni-datetime-picker type="date" :clear-icon="false" v-model="FinishSingle"
  7. @change='change2' />
  8. </view>
  9. <view class="main">
  10. <view class="wu" v-if="wu">
  11. 暂无数据
  12. </view>
  13. <view class="card" v-for="(v, i) in data" :key="i">
  14. <view class="content">
  15. <view class="text1">产线名称</view>
  16. <view class="text2">{{v.name}}</view>
  17. </view>
  18. <view class="content">
  19. <view class="text1">生产油品</view>
  20. <view class="text2">{{v.typeName}}</view>
  21. </view>
  22. <view class="content">
  23. <view class="text1">产线负责人</view>
  24. <view class="text2">{{v.charger}}</view>
  25. </view>
  26. <view class="content">
  27. <view class="text1">作业工人</view>
  28. <view class="text2">{{v.member}}</view>
  29. </view>
  30. <view class="content">
  31. <view class="text1">开始时间</view>
  32. <view class="text2">{{getTime(v.startTime)}}</view>
  33. </view>
  34. <view class="content">
  35. <view class="text1">结束时间</view>
  36. <view class="text2">{{getTime(v.endTime) || '未结束'}}</view>
  37. </view>
  38. <view class="content">
  39. <view class="text1">作业时间</view>
  40. <view class="text2">{{getJob(v.endTime,v.startTime)}}</view>
  41. </view>
  42. <view class="content">
  43. <view class="text1">产量</view>
  44. <view class="text2">{{v.number}}</view>
  45. </view>
  46. <view class="content">
  47. <view class="text1">剔除量</view>
  48. <view class="text2">{{v.reject}}</view>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="filter">
  53. <text>总产量: {{TotalOutput}} 总剔除量: {{TotalelIminate || 0}}</text>
  54. </view>
  55. </view>
  56. </template>
  57. <script>
  58. import {
  59. history
  60. } from '../../api/production.js'
  61. export default {
  62. data() {
  63. return {
  64. wu: false,
  65. name: '', // 标题
  66. TotalOutput: 0, // 总产量
  67. TotalelIminate: 0, // 总剔除量
  68. data: [],
  69. BeginSingle: '', // 开始时间
  70. FinishSingle: '', // 结束时间
  71. };
  72. },
  73. onLoad(options) {
  74. this.BeginSingle = this.getTime1()
  75. this.FinishSingle = this.getTime1()
  76. this.name = options.name
  77. if (this.name) {
  78. uni.setNavigationBarTitle({
  79. title: this.name,
  80. });
  81. this.getData()
  82. }
  83. },
  84. methods: {
  85. async getData() {
  86. uni.showLoading({
  87. title: '加载中'
  88. });
  89. const res = await history({
  90. name: this.name,
  91. startTime: this.BeginSingle,
  92. endTime: this.FinishSingle,
  93. accessToken: uni.getStorageSync('tokenInfo'),
  94. account: uni.getStorageSync('account')
  95. })
  96. uni.hideLoading();
  97. this.data = res.data.list
  98. console.log(this.data);
  99. if(this.data.length === 0){
  100. this.wu = true
  101. }
  102. this.TotalOutput = res.data.outputNumber
  103. this.TotalelIminate = res.data.rejectNumber
  104. },
  105. // 切换时间
  106. change1(e){
  107. this.BeginSingle = e
  108. console.log(this.BeginSingle);
  109. this.getData()
  110. },
  111. change2(e){
  112. this.FinishSingle = e
  113. console.log(this.FinishSingle);
  114. this.getData()
  115. },
  116. // 获取时间
  117. getTime(time = new Date()) {
  118. let date = new Date(time);
  119. let year = date.getFullYear();
  120. let month = date.getMonth() + 1;
  121. let day = date.getDate();
  122. let hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours()
  123. let minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()
  124. month >= 1 && month <= 9 ? (month = "0" + month) : "";
  125. day >= 0 && day <= 9 ? (day = "0" + day) : "";
  126. let timer = year + '-' + month + '-' + day + ' ' + hour + ':'+ minute;
  127. return timer;
  128. },
  129. getTime1(){
  130. let date = new Date();
  131. let year = date.getFullYear();
  132. let month = date.getMonth() + 1;
  133. let day = date.getDate();
  134. month >= 1 && month <= 9 ? (month = "0" + month) : "";
  135. day >= 0 && day <= 9 ? (day = "0" + day) : "";
  136. let timer = year + '-' + month + '-' + day;
  137. return timer;
  138. },
  139. // 作业时间
  140. getJob(endTime,startTime){
  141. let EndTIME = endTime ? new Date(endTime).getTime() : new Date().getTime(); // 截止时间
  142. let NowTime = new Date(startTime).getTime(); // 开始时间
  143. let usedTime = EndTIME - NowTime; // 相差的毫秒数
  144. let days = Math.floor(usedTime / (24 * 3600 * 1000)); // 计算出天数
  145. let leavel = usedTime % (24 * 3600 * 1000); // 计算天数后剩余的时间
  146. let hours = Math.floor(leavel / (3600 * 1000)); // 计算剩余的小时数
  147. let leavel2 = leavel % (3600 * 1000); // 计算剩余小时后剩余的毫秒数
  148. let minutes = Math.floor(leavel2 / (60 * 1000)); // 计算剩余的分钟数
  149. return days + '天' + hours + '小时' + minutes + '分钟';
  150. }
  151. }
  152. }
  153. </script>
  154. <style lang="scss">
  155. .history {
  156. height: 100%;
  157. display: flex;
  158. flex-direction: column;
  159. justify-content: space-between;
  160. .header {
  161. padding: 20rpx;
  162. display: flex;
  163. align-items: center;
  164. }
  165. .filter {
  166. height: 100rpx;
  167. border-top: 8px solid #ebebeb;
  168. text-align: center;
  169. text {
  170. height: 100%;
  171. line-height: 100rpx;
  172. color: #e40315;
  173. }
  174. }
  175. .main {
  176. flex: 1;
  177. overflow-y: scroll;
  178. .wu{
  179. text-align: center;
  180. }
  181. .card {
  182. padding: 0 50rpx;
  183. border-bottom: 1rpx solid #ebebeb;
  184. .content {
  185. padding: 30rpx 0;
  186. display: flex;
  187. .text1 {
  188. width: 25%;
  189. text-align: right;
  190. margin-right: 40rpx;
  191. }
  192. &:nth-child(2) {
  193. .text2 {
  194. color: #2b70d4;
  195. }
  196. }
  197. }
  198. }
  199. }
  200. }
  201. </style>