workOrderBom.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <template>
  2. <view>
  3. <view class="title_box rx-bc">
  4. <view class="name">工单信息 </view>
  5. <view
  6. class="btn_box rx-bc"
  7. @click="handleScan(item.workOrderId)"
  8. v-if="!isDetails"
  9. >
  10. <image class="scan" src="@/static/pda/ScanIt.svg"></image>
  11. 更换工单
  12. </view>
  13. </view>
  14. <view class="material">
  15. <view class="content_table">
  16. <view class="item">
  17. <view class="lable rx-cc">工单编号</view>
  18. <view class="content">
  19. {{ item.code }}
  20. </view>
  21. </view>
  22. <view class="item">
  23. <view class="lable rx-cc">编码</view>
  24. <view class="content">{{ item.productCode }}</view>
  25. </view>
  26. <view class="item">
  27. <view class="lable rx-cc">规格</view>
  28. <view class="content">{{ item.specification }}</view>
  29. </view>
  30. <view class="item">
  31. <view class="lable rx-cc">名称</view>
  32. <view class="content">{{ item.productName }}</view>
  33. </view>
  34. <view class="item">
  35. <view class="lable rx-cc">批次号</view>
  36. <view class="content">{{ item.batchNo }}</view>
  37. </view>
  38. <view class="item">
  39. <view class="lable rx-cc">牌号</view>
  40. <view class="content">{{
  41. item.brandNo ? item.brandNo : item.brandNum
  42. }}</view>
  43. </view>
  44. <view class="item">
  45. <view class="lable rx-cc">型号</view>
  46. <view class="content">{{
  47. item.modelType ? item.modelType : item.model
  48. }}</view>
  49. </view>
  50. <view class="item">
  51. <view class="lable rx-cc">生产编号</view>
  52. <view class="content">{{ item.productionCodes }}</view>
  53. </view>
  54. <view class="item rx-sc">
  55. <view class="rx ww55">
  56. <view class="lable rx-cc">生产数量</view>
  57. <view class="content rx-sc">
  58. <view>{{ item.formingNum }}</view>
  59. <view class="unit">{{ item.unit }}</view>
  60. </view>
  61. </view>
  62. <view class="rx ww45">
  63. <view class="lable rx-cc ww80">重量</view>
  64. <view class="content content_num">
  65. <view>{{ item.formingWeight }}</view>
  66. <view class="unit">{{ item.weightUnit }}</view>
  67. </view>
  68. </view>
  69. </view>
  70. <view class="item" v-if="isReportWork">
  71. <view class="lable rx-cc">生产要求</view>
  72. <!-- <view class="content" :disabled="isDetails">{{
  73. item.productionCodes
  74. }}</view> -->
  75. <view class="content content_num">
  76. <input
  77. style="width: 100%"
  78. :disabled="isDetails"
  79. class="uni-input"
  80. v-model="item.productionRequirements"
  81. />
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. <!-- {{ clientEnvironmentId }} {{ pType }} -->
  87. <view class="title_box mt20 rx-bc" v-if="pType == 'feed'">
  88. <view class="name"> 实际投料时间 </view>
  89. </view>
  90. <view class="material" v-if="pType == 'feed'">
  91. <view class="content_table">
  92. <view class="item">
  93. <view class="content">
  94. <uni-datetime-picker
  95. type="datetime"
  96. :value="currentExecutorTime"
  97. @change="changeTime($event, item)"
  98. />
  99. </view>
  100. </view>
  101. </view>
  102. </view>
  103. <view class="title_box mt20 rx-bc" v-if="pType == 'job' && !isReportTime">
  104. <view class="name"> 实际报工时间 </view>
  105. </view>
  106. <view class="material" v-if="pType == 'job' && !isReportTime">
  107. <view class="content_table">
  108. <view class="item">
  109. <view class="content">
  110. <uni-datetime-picker
  111. type="datetime"
  112. :value="currentExecutorTime"
  113. @change="changeTime($event, item)"
  114. />
  115. </view>
  116. </view>
  117. </view>
  118. </view>
  119. <view class="title_box mt20 rx-bc" v-if="pType == 'job' && isReportTime">
  120. <view class="name"> 实际报工时间 </view>
  121. </view>
  122. <view class="material" v-if="pType == 'job' && isReportTime">
  123. <view class="content_table">
  124. <view class="item">
  125. <view class="content">
  126. <uni-datetime-picker
  127. v-model="datetimerange"
  128. type="datetimerange"
  129. rangeSeparator="至"
  130. />
  131. </view>
  132. </view>
  133. <view class="item" v-if="isReportWork && pType == 'job'">
  134. <view class="lable rx-cc">工时</view>
  135. <view class="content content_num">
  136. <input style="width: 40%" v-model="item.workTime" />小时
  137. </view>
  138. </view>
  139. </view>
  140. </view>
  141. </view>
  142. </template>
  143. <script>
  144. import { parameterGetByCode } from "@/api/mainData/index.js";
  145. export default {
  146. props: {
  147. item: {
  148. type: Object,
  149. default: () => {},
  150. },
  151. isDetails: {
  152. type: Boolean,
  153. default: false,
  154. },
  155. isReportWork: {
  156. type: Boolean,
  157. default: false,
  158. },
  159. pType: {
  160. type: "",
  161. default: "",
  162. },
  163. taskType: {
  164. type: "",
  165. default: "",
  166. },
  167. },
  168. data() {
  169. return {
  170. clientEnvironmentId:
  171. uni.getStorageSync("userInfo") &&
  172. uni.getStorageSync("userInfo").clientEnvironmentId,
  173. currentExecutorTime: "",
  174. isReportTime: false,
  175. datetimerange: [],
  176. };
  177. },
  178. watch: {
  179. datetimerange: {
  180. deep: true,
  181. handler(val) {
  182. if (!(this.pType == "job" && this.isReportTime)) return;
  183. this.applyDateTimeRange(val);
  184. },
  185. },
  186. item: {
  187. immediate: true,
  188. deep: true,
  189. handler() {
  190. // 初始化/回显:当外部把 start/end 带进来时,同步到 range 组件
  191. if (!(this.pType == "job" && this.isReportTime)) return;
  192. const start =
  193. this.item?.workReportInfo?.executorStartTime ||
  194. this.item?.executorStartTime ||
  195. "";
  196. const end =
  197. this.item?.workReportInfo?.executorTime ||
  198. this.item?.executorTime ||
  199. "";
  200. if (start && end) {
  201. const range = [
  202. this.normalizeDateTime(start),
  203. this.normalizeDateTime(end),
  204. ];
  205. // 避免反复触发 watch 造成抖动
  206. if (
  207. !Array.isArray(this.datetimerange) ||
  208. this.datetimerange.length !== 2 ||
  209. this.datetimerange[0] !== range[0] ||
  210. this.datetimerange[1] !== range[1]
  211. ) {
  212. this.datetimerange = range;
  213. }
  214. }
  215. },
  216. },
  217. },
  218. // watch: {
  219. // item: {
  220. // immediate: true,
  221. // deep: true,
  222. // handler(newVal) {
  223. // // this.deviceList = newVal
  224. // //设备下拉框数据来源
  225. // this.getByCode();
  226. // // this.$set(this.item, "executorTime", this.currentExecutorTime);
  227. // // this.$set(
  228. // // this.item.workReportInfo,
  229. // // "executorTime",
  230. // // this.currentExecutorTime
  231. // // );
  232. // },
  233. // },
  234. // },
  235. created() {
  236. this.getByCode();
  237. this.getChooseEngrave();
  238. },
  239. methods: {
  240. changeTime(e, val) {
  241. let a = e.split(" ");
  242. console.log(a);
  243. if (a[1] !== "") {
  244. this.currentExecutorTime = e;
  245. } else {
  246. this.currentExecutorTime = `${e}00:00:00`;
  247. }
  248. this.item.executorTime = this.currentExecutorTime;
  249. },
  250. normalizeDateTime(value) {
  251. if (!value) return "";
  252. const v = String(value).trim();
  253. // yyyy-MM-dd => yyyy-MM-dd 00:00:00
  254. const dateOnly = /^\d{4}-\d{2}-\d{2}$/;
  255. if (dateOnly.test(v)) return `${v} 00:00:00`;
  256. return v;
  257. },
  258. parseDateTime(value) {
  259. const v = this.normalizeDateTime(value);
  260. if (!v) return null;
  261. // 兼容部分环境 Date("yyyy-MM-dd HH:mm:ss") 的解析问题
  262. const safe = v.replace(/-/g, "/");
  263. const d = new Date(safe);
  264. return Number.isNaN(d.getTime()) ? null : d;
  265. },
  266. hoursDiff(start, end) {
  267. const s = this.parseDateTime(start);
  268. const e = this.parseDateTime(end);
  269. if (!s || !e) return "";
  270. const ms = e.getTime() - s.getTime();
  271. if (ms < 0) return "";
  272. // 保留 2 位小数(小时)
  273. return (ms / 36e5).toFixed(2);
  274. },
  275. applyDateTimeRange(range) {
  276. // 清空时间范围时,同步清空开始/结束/工时,避免残留
  277. if (
  278. !Array.isArray(range) ||
  279. range.length !== 2 ||
  280. !range[0] ||
  281. !range[1]
  282. ) {
  283. this.clearReportTimesAndWorkTime();
  284. return;
  285. }
  286. const start = this.normalizeDateTime(range[0]);
  287. const end = this.normalizeDateTime(range[1]);
  288. if (!start || !end) {
  289. this.clearReportTimesAndWorkTime();
  290. return;
  291. }
  292. const s = this.parseDateTime(start);
  293. const e = this.parseDateTime(end);
  294. if (!s || !e) return;
  295. // 结束时间不能大于当前时间:超出则回填为当前时间
  296. const now = new Date();
  297. if (e.getTime() > now.getTime()) {
  298. const pad2 = (n) => String(n).padStart(2, "0");
  299. const nowStr = `${now.getFullYear()}-${pad2(now.getMonth() + 1)}-${pad2(now.getDate())} ${pad2(now.getHours())}:${pad2(now.getMinutes())}:${pad2(now.getSeconds())}`;
  300. this.datetimerange = [start, nowStr];
  301. uni.showToast({
  302. title: "结束时间不能大于当前时间",
  303. icon: "none",
  304. });
  305. this.setReportTimes(start, nowStr);
  306. this.setWorkTime(this.hoursDiff(start, nowStr));
  307. return;
  308. }
  309. if (e.getTime() < s.getTime()) {
  310. // 结束不能小于开始:直接把结束回填为开始,并提示
  311. this.datetimerange = [start, start];
  312. uni.showToast({
  313. title: "结束时间不能小于开始时间",
  314. icon: "none",
  315. });
  316. this.setReportTimes(start, start);
  317. this.setWorkTime(this.hoursDiff(start, start));
  318. return;
  319. }
  320. this.setReportTimes(start, end);
  321. this.setWorkTime(this.hoursDiff(start, end));
  322. },
  323. clearReportTimesAndWorkTime() {
  324. if (!this.item) return;
  325. if (!this.item.workReportInfo) {
  326. this.$set(this.item, "workReportInfo", {});
  327. }
  328. this.$set(this.item.workReportInfo, "executorStartTime", "");
  329. this.$set(this.item.workReportInfo, "executorTime", "");
  330. this.$set(this.item.workReportInfo, "workTime", "");
  331. this.$set(this.item, "executorStartTime", "");
  332. this.$set(this.item, "executorTime", "");
  333. this.$set(this.item, "workTime", "");
  334. this.$forceUpdate();
  335. },
  336. setReportTimes(start, end) {
  337. if (!this.item) return;
  338. if (!this.item.workReportInfo) {
  339. this.$set(this.item, "workReportInfo", {});
  340. }
  341. this.$set(this.item.workReportInfo, "executorStartTime", start);
  342. this.$set(this.item.workReportInfo, "executorTime", end);
  343. // 兼容页面上其他逻辑可能直接读 item 上的字段
  344. this.$set(this.item, "executorStartTime", start);
  345. this.$set(this.item, "executorTime", end);
  346. },
  347. setWorkTime(hours) {
  348. if (hours === "") return;
  349. if (!this.item) return;
  350. if (!this.item.workReportInfo) {
  351. this.$set(this.item, "workReportInfo", {});
  352. }
  353. this.$set(this.item.workReportInfo, "workTime", hours);
  354. this.$set(this.item, "workTime", hours);
  355. this.$forceUpdate();
  356. },
  357. async getByCode() {
  358. await parameterGetByCode({ code: "mes_order_feed_by_default_date" }).then(
  359. (res) => {
  360. console.log("res", res);
  361. if (res.value == "1") {
  362. if (!this.item.executorTime) {
  363. const now = new Date();
  364. const year = now.getFullYear();
  365. const month = String(now.getMonth() + 1).padStart(2, "0");
  366. const day = String(now.getDate()).padStart(2, "0");
  367. const hours = String(now.getHours()).padStart(2, "0");
  368. const minutes = String(now.getMinutes()).padStart(2, "0");
  369. const seconds = String(now.getSeconds()).padStart(2, "0");
  370. this.currentExecutorTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  371. this.item.executorTime = this.currentExecutorTime;
  372. // this.item.workReportInfo.executorTime = this.currentExecutorTime;
  373. this.$set(this.item, "executorTime", this.currentExecutorTime);
  374. // 确保 workReportInfo 对象存在后再设置属性
  375. if (!this.item.workReportInfo) {
  376. this.$set(this.item, "workReportInfo", {});
  377. }
  378. this.$set(
  379. this.item.workReportInfo,
  380. "executorTime",
  381. this.currentExecutorTime,
  382. );
  383. this.$forceUpdate();
  384. }
  385. }
  386. },
  387. );
  388. },
  389. async getChooseEngrave() {
  390. await parameterGetByCode({
  391. code: "work_hour",
  392. }).then((res) => {
  393. this.isReportTime = res.value == "1" ? true : false;
  394. if (this.isReportTime) {
  395. // 第二个时间不能为空,否则组件会显示 NAN-NAN-NAN,默认用当前时间
  396. const start = this.item.feedLastTime || "";
  397. if (start) {
  398. const now = new Date();
  399. const pad2 = (n) => String(n).padStart(2, "0");
  400. const nowStr = `${now.getFullYear()}-${pad2(now.getMonth() + 1)}-${pad2(now.getDate())} ${pad2(now.getHours())}:${pad2(now.getMinutes())}:${pad2(now.getSeconds())}`;
  401. this.datetimerange = [start, nowStr];
  402. // 赋值后计算两个时间段的时间差并写入工时
  403. this.applyDateTimeRange(this.datetimerange);
  404. } else {
  405. this.datetimerange = [];
  406. }
  407. }
  408. });
  409. },
  410. handleScan(id) {
  411. this.$emit("handleScan", id, "wordOrder");
  412. },
  413. },
  414. };
  415. </script>
  416. <style lang="scss" scoped>
  417. .title_box {
  418. .name {
  419. font-size: 28rpx;
  420. font-style: normal;
  421. font-weight: 400;
  422. color: $theme-color;
  423. padding-left: 20rpx;
  424. position: relative;
  425. &:before {
  426. position: absolute;
  427. content: "";
  428. left: 0rpx;
  429. top: 0rpx;
  430. bottom: 0rpx;
  431. width: 4rpx;
  432. height: 28rpx;
  433. background: $theme-color;
  434. margin: auto;
  435. }
  436. }
  437. .btn_box {
  438. padding: 0 18rpx;
  439. height: 60rpx;
  440. background: $theme-color;
  441. font-size: 26rpx;
  442. font-style: normal;
  443. font-weight: 400;
  444. font-size: 24rpx;
  445. color: #fff;
  446. border-radius: 4rpx;
  447. .scan {
  448. width: 34rpx;
  449. height: 34rpx;
  450. margin-right: 12rpx;
  451. }
  452. }
  453. }
  454. .material {
  455. margin-top: 10rpx;
  456. .content_table {
  457. width: 100%;
  458. border: 2rpx solid $border-color;
  459. .item {
  460. display: flex;
  461. border-bottom: 2rpx solid $border-color;
  462. .lable {
  463. width: 132rpx;
  464. text-align: center;
  465. background-color: #f7f9fa;
  466. font-size: 26rpx;
  467. border-right: 2rpx solid $border-color;
  468. flex-shrink: 0;
  469. }
  470. .lable150 {
  471. width: 156rpx !important;
  472. font-size: 24rpx;
  473. }
  474. .ww80 {
  475. width: 80rpx;
  476. }
  477. .content {
  478. width: 518rpx;
  479. min-height: 64rpx;
  480. font-size: 28rpx;
  481. line-height: 28rpx;
  482. font-style: normal;
  483. font-weight: 400;
  484. padding: 18rpx 8rpx;
  485. box-sizing: border-box;
  486. word-wrap: break-word;
  487. flex-grow: 1 !important;
  488. .unit {
  489. padding: 0 4rpx;
  490. font-size: 24rpx;
  491. color: #404446;
  492. }
  493. }
  494. .content_num {
  495. display: flex;
  496. align-items: center;
  497. padding: 0 4rpx;
  498. /deep/ .uni-input-input {
  499. border: 2rpx solid #f0f8f2;
  500. background: #f0f8f2;
  501. color: $theme-color;
  502. }
  503. }
  504. .pd4 {
  505. padding: 4rpx 8rpx;
  506. }
  507. &:last-child {
  508. border-bottom: none;
  509. }
  510. }
  511. .ww55 {
  512. width: 55%;
  513. }
  514. .ww45 {
  515. width: 45%;
  516. }
  517. }
  518. }
  519. .mt20 {
  520. margin-top: 20rpx;
  521. }
  522. </style>