workOrderBom.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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 = [this.normalizeDateTime(start), this.normalizeDateTime(end)];
  202. // 避免反复触发 watch 造成抖动
  203. if (
  204. !Array.isArray(this.datetimerange) ||
  205. this.datetimerange.length !== 2 ||
  206. this.datetimerange[0] !== range[0] ||
  207. this.datetimerange[1] !== range[1]
  208. ) {
  209. this.datetimerange = range;
  210. }
  211. }
  212. },
  213. },
  214. },
  215. // watch: {
  216. // item: {
  217. // immediate: true,
  218. // deep: true,
  219. // handler(newVal) {
  220. // // this.deviceList = newVal
  221. // //设备下拉框数据来源
  222. // this.getByCode();
  223. // // this.$set(this.item, "executorTime", this.currentExecutorTime);
  224. // // this.$set(
  225. // // this.item.workReportInfo,
  226. // // "executorTime",
  227. // // this.currentExecutorTime
  228. // // );
  229. // },
  230. // },
  231. // },
  232. created() {
  233. this.getByCode();
  234. this.getChooseEngrave();
  235. },
  236. methods: {
  237. changeTime(e, val) {
  238. let a = e.split(" ");
  239. console.log(a);
  240. if (a[1] !== "") {
  241. this.currentExecutorTime = e;
  242. } else {
  243. this.currentExecutorTime = `${e}00:00:00`;
  244. }
  245. this.item.executorTime = this.currentExecutorTime;
  246. },
  247. normalizeDateTime(value) {
  248. if (!value) return "";
  249. const v = String(value).trim();
  250. // yyyy-MM-dd => yyyy-MM-dd 00:00:00
  251. const dateOnly = /^\d{4}-\d{2}-\d{2}$/;
  252. if (dateOnly.test(v)) return `${v} 00:00:00`;
  253. return v;
  254. },
  255. parseDateTime(value) {
  256. const v = this.normalizeDateTime(value);
  257. if (!v) return null;
  258. // 兼容部分环境 Date("yyyy-MM-dd HH:mm:ss") 的解析问题
  259. const safe = v.replace(/-/g, "/");
  260. const d = new Date(safe);
  261. return Number.isNaN(d.getTime()) ? null : d;
  262. },
  263. hoursDiff(start, end) {
  264. const s = this.parseDateTime(start);
  265. const e = this.parseDateTime(end);
  266. if (!s || !e) return "";
  267. const ms = e.getTime() - s.getTime();
  268. if (ms < 0) return "";
  269. // 保留 2 位小数(小时)
  270. return (ms / 36e5).toFixed(2);
  271. },
  272. applyDateTimeRange(range) {
  273. // 清空时间范围时,同步清空开始/结束/工时,避免残留
  274. if (
  275. !Array.isArray(range) ||
  276. range.length !== 2 ||
  277. !range[0] ||
  278. !range[1]
  279. ) {
  280. this.clearReportTimesAndWorkTime();
  281. return;
  282. }
  283. const start = this.normalizeDateTime(range[0]);
  284. const end = this.normalizeDateTime(range[1]);
  285. if (!start || !end) {
  286. this.clearReportTimesAndWorkTime();
  287. return;
  288. }
  289. const s = this.parseDateTime(start);
  290. const e = this.parseDateTime(end);
  291. if (!s || !e) return;
  292. // 结束时间不能大于当前时间:超出则回填为当前时间
  293. const now = new Date();
  294. if (e.getTime() > now.getTime()) {
  295. const pad2 = (n) => String(n).padStart(2, "0");
  296. const nowStr = `${now.getFullYear()}-${pad2(now.getMonth() + 1)}-${pad2(now.getDate())} ${pad2(now.getHours())}:${pad2(now.getMinutes())}:${pad2(now.getSeconds())}`;
  297. this.datetimerange = [start, nowStr];
  298. uni.showToast({
  299. title: "结束时间不能大于当前时间",
  300. icon: "none",
  301. });
  302. this.setReportTimes(start, nowStr);
  303. this.setWorkTime(this.hoursDiff(start, nowStr));
  304. return;
  305. }
  306. if (e.getTime() < s.getTime()) {
  307. // 结束不能小于开始:直接把结束回填为开始,并提示
  308. this.datetimerange = [start, start];
  309. uni.showToast({
  310. title: "结束时间不能小于开始时间",
  311. icon: "none",
  312. });
  313. this.setReportTimes(start, start);
  314. this.setWorkTime(this.hoursDiff(start, start));
  315. return;
  316. }
  317. this.setReportTimes(start, end);
  318. this.setWorkTime(this.hoursDiff(start, end));
  319. },
  320. clearReportTimesAndWorkTime() {
  321. if (!this.item) return;
  322. if (!this.item.workReportInfo) {
  323. this.$set(this.item, "workReportInfo", {});
  324. }
  325. this.$set(this.item.workReportInfo, "executorStartTime", "");
  326. this.$set(this.item.workReportInfo, "executorTime", "");
  327. this.$set(this.item.workReportInfo, "workTime", "");
  328. this.$set(this.item, "executorStartTime", "");
  329. this.$set(this.item, "executorTime", "");
  330. this.$set(this.item, "workTime", "");
  331. this.$forceUpdate();
  332. },
  333. setReportTimes(start, end) {
  334. if (!this.item) return;
  335. if (!this.item.workReportInfo) {
  336. this.$set(this.item, "workReportInfo", {});
  337. }
  338. this.$set(this.item.workReportInfo, "executorStartTime", start);
  339. this.$set(this.item.workReportInfo, "executorTime", end);
  340. // 兼容页面上其他逻辑可能直接读 item 上的字段
  341. this.$set(this.item, "executorStartTime", start);
  342. this.$set(this.item, "executorTime", end);
  343. },
  344. setWorkTime(hours) {
  345. if (hours === "") return;
  346. if (!this.item) return;
  347. if (!this.item.workReportInfo) {
  348. this.$set(this.item, "workReportInfo", {});
  349. }
  350. this.$set(this.item.workReportInfo, "workTime", hours);
  351. this.$set(this.item, "workTime", hours);
  352. this.$forceUpdate();
  353. },
  354. async getByCode() {
  355. await parameterGetByCode({ code: "mes_order_feed_by_default_date" }).then(
  356. (res) => {
  357. console.log("res", res);
  358. if (res.value == "1") {
  359. if (!this.item.executorTime) {
  360. const now = new Date();
  361. const year = now.getFullYear();
  362. const month = String(now.getMonth() + 1).padStart(2, "0");
  363. const day = String(now.getDate()).padStart(2, "0");
  364. const hours = String(now.getHours()).padStart(2, "0");
  365. const minutes = String(now.getMinutes()).padStart(2, "0");
  366. const seconds = String(now.getSeconds()).padStart(2, "0");
  367. this.currentExecutorTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  368. this.item.executorTime = this.currentExecutorTime;
  369. // this.item.workReportInfo.executorTime = this.currentExecutorTime;
  370. this.$set(this.item, "executorTime", this.currentExecutorTime);
  371. this.$set(
  372. this.item.workReportInfo,
  373. "executorTime",
  374. this.currentExecutorTime,
  375. );
  376. this.$forceUpdate();
  377. }
  378. }
  379. },
  380. );
  381. },
  382. async getChooseEngrave() {
  383. await parameterGetByCode({
  384. code: "work_hour",
  385. }).then((res) => {
  386. this.isReportTime = res.value == "1" ? true : false;
  387. });
  388. },
  389. handleScan(id) {
  390. this.$emit("handleScan", id, "wordOrder");
  391. },
  392. },
  393. };
  394. </script>
  395. <style lang="scss" scoped>
  396. .title_box {
  397. .name {
  398. font-size: 28rpx;
  399. font-style: normal;
  400. font-weight: 400;
  401. color: $theme-color;
  402. padding-left: 20rpx;
  403. position: relative;
  404. &:before {
  405. position: absolute;
  406. content: "";
  407. left: 0rpx;
  408. top: 0rpx;
  409. bottom: 0rpx;
  410. width: 4rpx;
  411. height: 28rpx;
  412. background: $theme-color;
  413. margin: auto;
  414. }
  415. }
  416. .btn_box {
  417. padding: 0 18rpx;
  418. height: 60rpx;
  419. background: $theme-color;
  420. font-size: 26rpx;
  421. font-style: normal;
  422. font-weight: 400;
  423. font-size: 24rpx;
  424. color: #fff;
  425. border-radius: 4rpx;
  426. .scan {
  427. width: 34rpx;
  428. height: 34rpx;
  429. margin-right: 12rpx;
  430. }
  431. }
  432. }
  433. .material {
  434. margin-top: 10rpx;
  435. .content_table {
  436. width: 100%;
  437. border: 2rpx solid $border-color;
  438. .item {
  439. display: flex;
  440. border-bottom: 2rpx solid $border-color;
  441. .lable {
  442. width: 132rpx;
  443. text-align: center;
  444. background-color: #f7f9fa;
  445. font-size: 26rpx;
  446. border-right: 2rpx solid $border-color;
  447. flex-shrink: 0;
  448. }
  449. .lable150 {
  450. width: 156rpx !important;
  451. font-size: 24rpx;
  452. }
  453. .ww80 {
  454. width: 80rpx;
  455. }
  456. .content {
  457. width: 518rpx;
  458. min-height: 64rpx;
  459. font-size: 28rpx;
  460. line-height: 28rpx;
  461. font-style: normal;
  462. font-weight: 400;
  463. padding: 18rpx 8rpx;
  464. box-sizing: border-box;
  465. word-wrap: break-word;
  466. flex-grow: 1 !important;
  467. .unit {
  468. padding: 0 4rpx;
  469. font-size: 24rpx;
  470. color: #404446;
  471. }
  472. }
  473. .content_num {
  474. display: flex;
  475. align-items: center;
  476. padding: 0 4rpx;
  477. /deep/ .uni-input-input {
  478. border: 2rpx solid #f0f8f2;
  479. background: #f0f8f2;
  480. color: $theme-color;
  481. }
  482. }
  483. .pd4 {
  484. padding: 4rpx 8rpx;
  485. }
  486. &:last-child {
  487. border-bottom: none;
  488. }
  489. }
  490. .ww55 {
  491. width: 55%;
  492. }
  493. .ww45 {
  494. width: 45%;
  495. }
  496. }
  497. }
  498. .mt20 {
  499. margin-top: 20rpx;
  500. }
  501. </style>