index.vue 9.0 KB

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