index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <template>
  2. <view class="uni-column container">
  3. <scroll-view class="scroll-container" scroll-y>
  4. <view v-for="(item, index) in listData" :key="index" class="list-item">
  5. <view class="title-container uni-row">
  6. <view class="title uni-row">
  7. <text class="label">批次号:</text>
  8. <text class="label code"> {{ item['lotCode'] }}</text>
  9. </view>
  10. <view class="right-info " style="flex: 3;margin-right: -30rpx;">
  11. <view class="right-info uni-row"> <text class="label">工时</text>
  12. <text class="label time">{{ item['taskTime'] }}h</text>
  13. </view>
  14. <view class="right-info uni-row"> <text class="label">合格数</text>
  15. <text class="label number ">{{ item['qualifiedNum'] }}</text>
  16. </view>
  17. </view>
  18. </view>
  19. <view class="item-info uni-row">
  20. <text class="label">操作者</text>
  21. <text class="label right">{{ item['nickName'] }}</text>
  22. </view>
  23. <view class="item-info uni-row">
  24. <text class="label">开始时间</text>
  25. <text class="label right">{{ item['startTime']}}</text>
  26. </view>
  27. <view class="item-info uni-row">
  28. <text class="label">结束时间</text>
  29. <text class="label right">{{ (item['endTime'] !="")?item['endTime']:'-'}}</text>
  30. </view>
  31. <view class="item-info uni-row">
  32. <text class="label">废品数</text>
  33. <text class="label right">{{ item['rejectNum']}}</text>
  34. </view>
  35. <view class="item-info uni-row">
  36. <text class="label">废品原因</text>
  37. <text class="label right">{{ (item['reason'] != "")?item['reason']:'-'}}</text>
  38. </view>
  39. <!-- <view v-if="item['userId'] == userInfo['userId'] ? item['status'] == 0 : false" class="status-btn uni-row ">
  40. <button class="finished-turnover-tag" size="mini">开始加工</button>
  41. </view> -->
  42. <view v-if="item['userId'] == userInfo['userId'] ? item['status'] == 1 : false"
  43. class="status-btn uni-row ">
  44. <button class="finished-turnover-tag" size="mini"
  45. @click.stop="handleShowEndWorkDialog(item)">结束报工</button>
  46. </view>
  47. <view v-if="item['userId'] == userInfo['userId'] ? item['status'] == 0 : false"
  48. class="status-btn uni-row ">
  49. <button class="finished-turnover-tag" size="mini"
  50. @click.stop="handleStartProcessing(item)">开始报工</button>
  51. </view>
  52. </view>
  53. </scroll-view>
  54. <view class="bottom uni-row">
  55. <button class="bottom-btn left-btn" @click="HandleChangevehicle"><text class="label">更换载具</text></button>
  56. <button class="bottom-btn right-btn" type="primary" @click="handleStartProcessing(null)" :disabled="flag"><text
  57. class="label">开始加工</text></button>
  58. </view>
  59. <dialog-end-work ref="endWorkDialog" @sendEquipment='getEquipment' @reset="reset" />
  60. <dialog-selectEquipment ref='selectEquipment'
  61. @handleAddDayWorkItem='handleAddDayWorkItem'></dialog-selectEquipment>
  62. </view>
  63. </template>
  64. <script setup>
  65. import {
  66. ref
  67. } from 'vue'
  68. import {
  69. onLoad,
  70. onReady
  71. } from '@dcloudio/uni-app'
  72. import {
  73. getDayWorkItemList,
  74. saveDayWorkItemBatch,
  75. updateDayWorkItem
  76. } from "@/api/business/dayWorkItem.js"
  77. import {
  78. store
  79. } from '@/store/index.js'
  80. import {
  81. timestampToTime
  82. } from '@/utils/common.js'
  83. const listData = ref([]) // 回显
  84. const curSubDetails = ref({}) // 接收生产计划单信息
  85. const dayWorkInfo = ref({}) // 接收daywork信息
  86. const equipmentList = ref([]) // 设备列表
  87. const endWorkDialog = ref(null) // 组件
  88. const selectEquipment = ref(null) // 组件
  89. const dayWorkItem = ref({}) // 添加传输对象
  90. const reqParam = ref([]) // 请求参数
  91. const userInfo = ref(null) // 登录员工信息
  92. const flag = ref(true)
  93. onLoad(() => {
  94. curSubDetails.value = store.planSubDetails;
  95. dayWorkInfo.value = store.dayworkInfo;
  96. console.log(dayWorkInfo.value)
  97. init();
  98. })
  99. function init() {
  100. userInfo.value = store.userInfo;
  101. uni.showLoading({
  102. title: '加载中'
  103. });
  104. getDayWorkItemList({
  105. dayworkId: dayWorkInfo.value.id
  106. }).then(res => {
  107. listData.value = res.rows || [];
  108. console.log(listData)
  109. // 时间戳转工时
  110. for (var i = 0; i < listData.value.length; i++) {
  111. let timeStamp = Date.parse(listData.value[i].endTime) - Date.parse(listData.value[i].startTime);
  112. listData.value[i].taskTime = (timeStamp / 3600000).toFixed(2) === 'NaN' ? 0 : (timeStamp / 3600000)
  113. .toFixed(2);
  114. }
  115. // 判断是否是新批次默认生成的第一条,下面的开始加工按钮不能点(有一个为0就不能点)
  116. let arr = []
  117. for (var i = 0; i < listData.value.length; i++) {
  118. arr[i] = listData.value[i].status;
  119. }
  120. flag.value = arr.includes('0');
  121. // flag.value = listData.value.some(value => {value.status == '0'|| value.status == '3'})
  122. console.log(flag.value)
  123. })
  124. uni.hideLoading();
  125. }
  126. function reset() {
  127. init();
  128. }
  129. function handleShowEndWorkDialog(data) {
  130. // 调用子组件中的方法
  131. endWorkDialog.value.open(data)
  132. }
  133. function HandleChangevehicle() {
  134. uni.navigateTo({
  135. url: "/pages/changeBox/index"
  136. })
  137. }
  138. function getEquipment(data) {
  139. console.log(data);
  140. equipmentList.value = data;
  141. }
  142. function handleStartProcessing(item) {
  143. selectEquipment.value.open(item);
  144. }
  145. /**
  146. * 新批次默认item去报工(执行方法)
  147. * @param {Object} item
  148. */
  149. function handleStartFirstItem(item) {
  150. let reqParam = item;
  151. reqParam.status = 1;
  152. reqParam.startTime = timestampToTime(new Date());
  153. updateDayWorkItem(reqParam).then(res => {
  154. if (res.code === 200) {
  155. uni.showToast({
  156. icon: "success",
  157. title: "报工成功",
  158. duration: 2000
  159. })
  160. init();
  161. } else {
  162. uni.showToast({
  163. icon: "fail",
  164. title: "报工失败,请联系管理员",
  165. duration: 2000
  166. })
  167. }
  168. })
  169. }
  170. function handleAddDayWorkItem(data) {
  171. console.log(data)
  172. if (data[0].dayworkId) { // data里面任意一对象除了设备相关的字段存在,直接给reqParam赋值
  173. reqParam.value = data;
  174. } else {
  175. // equipmentList.value = data;
  176. dayWorkItem.value = {
  177. dayworkId: dayWorkInfo.value.id,
  178. lotId: dayWorkInfo.value.lotId,
  179. productionPlanId: curSubDetails.value.productionPlanId,
  180. productionPlanDetailId: curSubDetails.value.productionPlanDetailId,
  181. productionPlanDetailSubDetailId: curSubDetails.value.id,
  182. processId: store.dayworkInfo.currentProcess.id,
  183. technologicalProcessId: store.dayworkInfo.technologicalProcessId,
  184. status: 1,
  185. startTime: timestampToTime(new Date())
  186. }
  187. for (var i = 0; i < data.length; i++) {
  188. reqParam.value.push(dayWorkItem.value);
  189. reqParam.value[i].equipmentDetailId = data[i].equipmentDetailId;
  190. reqParam.value[i].equipmentDetailCode = data[i].equipmentDetailCode;
  191. }
  192. }
  193. console.log(reqParam.value)
  194. saveDayWorkItemBatch(reqParam.value).then(res => {
  195. if (res.code === 200) {
  196. uni.showToast({
  197. icon: 'success',
  198. title: '操作成功',
  199. duration: 2000
  200. });
  201. reqParam.value = [];
  202. init();
  203. } else {
  204. uni.showToast({
  205. icon: 'error',
  206. title: '操作失败',
  207. duration: 2000
  208. });
  209. }
  210. })
  211. }
  212. </script>
  213. <style lang="scss">
  214. .container {
  215. height: 2000rpx;
  216. background-color: #f5f5f5;
  217. overflow: auto;
  218. }
  219. .scroll-container {
  220. position: absolute;
  221. top: 24rpx;
  222. right: 0;
  223. bottom: 144rpx;
  224. left: 0;
  225. }
  226. .selected {
  227. border: 1px solid #1684fc;
  228. }
  229. .list-item {
  230. background-color: #fff;
  231. position: relative;
  232. padding: 16rpx;
  233. padding-bottom: 24rpx;
  234. margin: 0 24rpx;
  235. margin-bottom: 24rpx;
  236. border-radius: 8rpx;
  237. .title-container {
  238. justify-content: space-between;
  239. align-items: center;
  240. margin-top: 8rpx;
  241. width: 100%;
  242. .title {
  243. height: 48rpx;
  244. align-items: center;
  245. flex: 7;
  246. .label {
  247. font-size: 32rpx;
  248. font-weight: bold;
  249. }
  250. .code {
  251. margin-left: 8rpx;
  252. }
  253. }
  254. }
  255. .item-info {
  256. margin-bottom: 8rpx;
  257. .label {
  258. font-size: 28rpx;
  259. width: 152rpx;
  260. color: #808080;
  261. &.right {
  262. flex: 1;
  263. color: #000000;
  264. }
  265. }
  266. }
  267. .right-info {
  268. // justify-content: flex-end;
  269. // width:45%;
  270. // margin-top: 5rpx;
  271. .label {
  272. font-size: 28rpx;
  273. }
  274. .time {
  275. margin-left: 8rpx;
  276. color: #1684fc;
  277. }
  278. .number {
  279. margin-left: 8rpx;
  280. color: #1684fc;
  281. }
  282. }
  283. }
  284. .bottom {
  285. position: fixed;
  286. right: 0;
  287. bottom: 0;
  288. left: 0;
  289. height: 100rpx;
  290. padding: 16rpx 24rpx;
  291. align-items: center;
  292. background-color: #FFFFFF;
  293. justify-content: space-between;
  294. .bottom-btn {
  295. flex: 1;
  296. font-size: 28rpx;
  297. color: #FFFFFF;
  298. &.left-btn {
  299. background-color: rgba(0, 226, 166, 1);
  300. }
  301. &.right-btn {
  302. margin-left: 24rpx;
  303. }
  304. }
  305. }
  306. .status-btn {
  307. width: 100%;
  308. justify-content: flex-end;
  309. .finished-turnover-tag {
  310. margin: unset;
  311. border-radius: 8rpx;
  312. background-color: rgb(255, 85, 85);
  313. font-size: 28rpx;
  314. color: #FFFFFF;
  315. }
  316. }
  317. </style>