form.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. <template>
  2. <view class="page-container uni-column">
  3. <view class="lot-info uni-column">
  4. <view class="lot-code uni-row">
  5. <text>批次号</text>
  6. <text style="margin-left: 24rpx;">{{ dayworkItem.lotCode }}</text>
  7. </view>
  8. <view class="product-info">
  9. 产品描述: {{ dayworkItem.productDescription }}
  10. </view>
  11. <view class="product-info">
  12. 原材料厂家: {{ dayworkInfo.furnaceNoInfo.factory }}
  13. </view>
  14. <view class="product-info">
  15. 投产数量: {{ dayworkItem.prodNum }}
  16. </view>
  17. </view>
  18. <!-- 不合格信息 -->
  19. <view class="title unfit-title uni-row">
  20. <text>不合格信息</text>
  21. <view v-if="Number(dayworkItem.status) < 3" class="add-btn" @click="handleAddUnfit">添加</view>
  22. </view>
  23. <view class="unfit-container">
  24. <view class="unfit-item-container uni-column" v-for="(item, index) in unfitInfos" :key="index">
  25. <view class="title uni-row">
  26. <text>检查标准-{{ item.checkStandard }}</text>
  27. <uni-icons v-if="Number(dayworkItem.status) < 3" type="trash" size="24" color="#fc6565"
  28. @click="handleDelUnfit(index)" />
  29. </view>
  30. <!-- <view class="standard">检查标准:{{ item.checkStandard }}</view> -->
  31. <view class="result uni-row" style="display: flex;flex-direction: row;justify-content: space-between;">
  32. <!-- align-items: flex-start; -->
  33. <view class="label" style="padding-right: 16rpx;flex: 0 1 auto; min-width: 118rpx;">
  34. 检查结果</view>
  35. <input v-if="Number(dayworkItem.status) < 3" v-model="item.reason" placeholder="请输入检查结果" />
  36. <span v-else style="flex-grow: 1;">{{ item.reason }}</span>
  37. <view class="label"
  38. style="text-align: right; padding-right: 16rpx;flex: 0 1 auto; min-width: 68rpx;">数量</view>
  39. <input v-if="Number(dayworkItem.status) < 3" class="number" type="number" v-model="item.rejectNum"
  40. @blur="rejectNumberChange" />
  41. <span v-else>{{ item.rejectNum }}</span>
  42. </view>
  43. </view>
  44. </view>
  45. <!-- 咨询部分 -->
  46. <view class="title">咨询</view>
  47. <view class="consultation-container uni-column">
  48. <view class="consultation-item-container" v-for="(item, index) in consultations" :key="index">
  49. <view class="question uni-column">
  50. <view class="label uni-row">
  51. <text>问题描述</text>
  52. <text :style="{ color: showStatusColor(item.status) }">{{ showStatus(item.status) }}</text>
  53. </view>
  54. <view class="content">{{ item.content }}</view>
  55. </view>
  56. <!-- <view v-if="item.answer !== ''" class="answer"
  57. style="margin-top: 24rpx; padding-top: 24rpx; border-top: 1px dotted #aaaaaa;">
  58. <view class="label">回复</view>
  59. <view class="content">{{ item.answer }}</view>
  60. </view> -->
  61. </view>
  62. </view>
  63. <!-- 报工部分 -->
  64. <view class="daywork-container">
  65. <view class="result uni-row">
  66. <view class="label">合格量</view>
  67. <input v-if="Number(dayworkItem.status) < 3" type="number" placeholder="请输入合格量"
  68. v-model="dayworkItem.qualifiedNum" />
  69. <span v-else>{{ dayworkItem.qualifiedNum }}</span>
  70. <view class="label" style="text-align: right; padding-right: 24rpx">废品量</view>
  71. <input v-if="Number(dayworkItem.status) < 3" :disabled="true" type="number" placeholder="请输入废品量"
  72. v-model="dayworkItem.rejectNum" />
  73. <span v-else>{{ dayworkItem.rejectNum }}</span>
  74. </view>
  75. <view class="remark uni-row">
  76. <view class="label">备注</view>
  77. <textarea v-if="Number(dayworkItem.status) < 3" v-model="dayworkItem.remark" />
  78. <span v-else>{{ dayworkItem.remark }}</span>
  79. </view>
  80. <view class="btns-container uni-row">
  81. <!-- 最后一步完成不能更换载具 -->
  82. <view v-if="dayworkItem.daywork != null && dayworkItem.daywork.status != 2" class="bottom-btn left-btn "
  83. @click="handleChangeCarrier">
  84. 更换载具</view>
  85. <view v-if="checkFinishable()&&Number(dayworkItem.status) < 3" class="finished-btn"
  86. @click.stop="handleFinishDaywork">结束报工</view>
  87. <view v-if="!checkFinishable()&&Number(dayworkItem.status) < 3" class="pause-btn"
  88. @click.stop="handleUpdateDaywork">暂停</view>
  89. <view v-if="Number(dayworkItem.status) < 3" class="question-btn uni-column"
  90. @click.stop="handleAddConsultation">
  91. <uni-icons type="headphones" size="24" />
  92. <text>咨询</text>
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. </template>
  98. <script setup>
  99. import {
  100. ref
  101. } from 'vue'
  102. import {
  103. onMounted,
  104. getCurrentInstance
  105. } from 'vue';
  106. import {
  107. getSortingDayworkItem,
  108. saveConsult,
  109. finish,
  110. update
  111. } from '@/api/business/sortDaywork.js'
  112. import {
  113. onLoad,
  114. onReady,
  115. onUnload,
  116. onShow
  117. } from '@dcloudio/uni-app'
  118. import {
  119. store
  120. } from '@/store/index.js'
  121. const isEventTriggered = ref(false); // 创建一个标志位
  122. const unfitInfos = ref([])
  123. const consultations = ref([])
  124. const dayworkInfo = ref({})
  125. // 创建一个引用来存储最后一次请求的时间戳
  126. const lastRequestTimestamp = ref(0);
  127. const dayworkItem = ref({})
  128. /***************************** 页面生命周期函数 *****************************/
  129. onShow(() => {
  130. })
  131. onMounted(() => {
  132. const instance = getCurrentInstance().proxy
  133. const eventChannel = instance.getOpenerEventChannel();
  134. eventChannel.on('acceptDataFromOpenerPage', function(data) {
  135. if (data && data.data) {
  136. dayworkInfo.value = data.data
  137. init({
  138. id: data.data.id
  139. })
  140. } else {
  141. let reqParam = {
  142. id: dayworkInfo.value.id
  143. }
  144. init(reqParam);
  145. }
  146. })
  147. })
  148. /***************************** 定义了一些方法 *****************************/
  149. const init = (data) => {
  150. console.log("dayworkInfo", dayworkInfo.value);
  151. // 获取当前报工信息
  152. getSortingDayworkItem(data).then(res => {
  153. console.log(res)
  154. if (res.code === 200) {
  155. dayworkItem.value = res.data
  156. console.log(dayworkItem.value)
  157. if (dayworkItem.value.qualifiedNum === 0 && dayworkItem.value.rejectNum === 0) {
  158. dayworkItem.value.qualifiedNum = res.data.prodNum
  159. }
  160. consultations.value = res.data.consults
  161. unfitInfos.value = res.data.rejectList
  162. } else {
  163. uni.showToast({
  164. icon: none,
  165. title: res.message
  166. })
  167. }
  168. })
  169. }
  170. const addUnfitInfo = (data) => {
  171. console.log(data)
  172. if (data.index > unfitInfos.value.length) {
  173. const info = {
  174. inspectionInstructionId: data.id,
  175. title: data.title,
  176. standard: data.standard,
  177. checkStandard: data.standard,
  178. type: data.type,
  179. reason: ''
  180. }
  181. unfitInfos.value.push(info)
  182. }
  183. }
  184. const addConsultation = (data) => {
  185. const info = {
  186. dayworkItemId: dayworkItem.value.id,
  187. content: data.content,
  188. userId: store.userInfo.userId,
  189. nickName: store.userInfo.nickName,
  190. dayworkId: dayworkItem.value.dayworkId,
  191. productionPlandetailId: dayworkItem.value.productionPlandetailId,
  192. productionPlanDetailSubDetailId: dayworkItem.value.productionPlanDetailSubDetailId,
  193. lotId: dayworkItem.value.lotId,
  194. lotCode: dayworkItem.value.lotCode,
  195. productId: dayworkItem.value.productId,
  196. productDescription: dayworkItem.value.productDescription,
  197. technologicalProcessId: dayworkItem.value.technologicalProcessId,
  198. technologicalProcessDetailId: dayworkItem.value.technologicalProcessDetailId,
  199. processId: dayworkItem.value.processId,
  200. processAlias: dayworkItem.value.process.processAlias,
  201. technicianId: dayworkItem.value.technicianId
  202. }
  203. saveConsult(info).then(res => {
  204. if (res.code === 200) {
  205. consultations.value = res.data
  206. console.log(consultations.value)
  207. } else {
  208. uni.showToast({
  209. icon: 'none',
  210. title: res.message
  211. })
  212. }
  213. })
  214. isEventTriggered.value = true; // 更新标志位状态
  215. // consultations.value.push(info)
  216. }
  217. /***************************** 定义了一些事件 *****************************/
  218. // 添加不合格信息
  219. const handleAddUnfit = () => {
  220. // 监听事件
  221. uni.$once('addUnfitInfoEvent', (data) => {
  222. addUnfitInfo(data)
  223. })
  224. // console.log(dayworkItem.value)
  225. uni.navigateTo({
  226. url: "/pages/sorting/options",
  227. success: (res) => {
  228. // 通过eventChannel向被打开页面传送数据
  229. res.eventChannel.emit('acceptDataFromOpenerPage', {
  230. data: dayworkItem.value,
  231. query: {
  232. productId: dayworkItem.value.daywork.productId,
  233. processId: dayworkItem.value.process.id,
  234. technologyVersion: dayworkItem.value.technologicalProcessDetail
  235. .technologyVersion
  236. },
  237. index: unfitInfos.value.length
  238. })
  239. }
  240. })
  241. }
  242. // 删除不合格信息
  243. const handleDelUnfit = (index) => {
  244. let tempInfo = unfitInfos.value[index]
  245. console.log(tempInfo)
  246. uni.showModal({
  247. title: '提示',
  248. content: '确定删除该项?',
  249. success: function(res) {
  250. if (res.confirm) {
  251. dayworkItem.value.rejectNum = dayworkItem.value.rejectNum - tempInfo.rejectNum
  252. dayworkItem.value.qualifiedNum = parseInt(dayworkItem.value.qualifiedNum) + parseInt(
  253. tempInfo.rejectNum)
  254. unfitInfos.value.splice(index, 1)
  255. } else if (res.cancel) {
  256. return
  257. }
  258. }
  259. })
  260. }
  261. /* 更换载具*/
  262. function handleChangeCarrier(item) {
  263. // uni.$once('refreshQuickReport', () => {
  264. // init()
  265. // })
  266. store.dayworkInfo = null
  267. uni.navigateTo({
  268. url: "/pages/changeBox/index",
  269. success: function(res) {
  270. // 通过eventChannel向被打开页面传送数据
  271. res.eventChannel.emit('sortingFromOpenerPage', {
  272. data: dayworkItem.value
  273. })
  274. }
  275. })
  276. }
  277. // 添加不合格信息
  278. const handleAddConsultation = () => {
  279. isEventTriggered.value = false; // 更新标志位状态
  280. // 监听事件
  281. uni.$once('addConsulttationEvent', (data) => {
  282. if (!isEventTriggered.value) {
  283. // 如果事件尚未触发,则执行事件触发逻辑
  284. addConsultation(data)
  285. }
  286. })
  287. uni.navigateTo({
  288. url: "/pages/sorting/consultation",
  289. success: (res) => {
  290. // 通过eventChannel向被打开页面传送数据
  291. res.eventChannel.emit('acceptDataFromOpenerPage', {
  292. data: dayworkItem.value
  293. })
  294. }
  295. })
  296. }
  297. const checkFinishable = () => {
  298. if (consultations.value.findIndex(v => v.status === 0) >= 0) {
  299. return false
  300. } else {
  301. return true
  302. }
  303. }
  304. const showStatus = (status) => {
  305. // console.log(status)
  306. switch (status) {
  307. case 0:
  308. return '未确认'
  309. case 1:
  310. return '不合格'
  311. case 2:
  312. return '合格'
  313. default:
  314. return ''
  315. }
  316. }
  317. const showStatusColor = (status) => {
  318. // console.log(status)
  319. switch (status) {
  320. case 0:
  321. return '#fcab53'
  322. case 1:
  323. return '#fc044f'
  324. case 2:
  325. return '#1deb19'
  326. default:
  327. return ''
  328. }
  329. }
  330. const rejectNumberChange = () => {
  331. let sumReject = 0
  332. unfitInfos.value.forEach(v => {
  333. sumReject += v.rejectNum == null ? 0 : Number(v.rejectNum)
  334. })
  335. dayworkItem.value.rejectNum = sumReject
  336. dayworkItem.value.qualifiedNum = dayworkItem.value.prodNum - sumReject
  337. console.log(dayworkItem.value)
  338. }
  339. const validHandle = () => {
  340. for (let i = 0; i < unfitInfos.value.length; i++) {
  341. const e = unfitInfos.value[i]
  342. if (e.rejectNum == null || e.rejectNum == 0) {
  343. uni.showToast({
  344. icon: 'none',
  345. title: `第${i + 1}条不合格信息未输入不合格数量`
  346. })
  347. return false
  348. }
  349. }
  350. if (!dayworkItem.value.qualifiedNum) {
  351. uni.showToast({
  352. icon: 'none',
  353. title: "合格数不能为空",
  354. duration: 2000
  355. })
  356. return false;
  357. }
  358. if (dayworkItem.value.qualifiedNum < 0) {
  359. uni.showToast({
  360. icon: 'none',
  361. title: "合格数不能为负数,请检查不合格信息后提交",
  362. duration: 2000
  363. })
  364. return false;
  365. }
  366. return true
  367. // unfitInfos.value.forEach((e, i) => {
  368. // if (e.name)
  369. // })
  370. }
  371. const handleFinishDaywork = () => {
  372. if (!validHandle()) {
  373. return
  374. }
  375. const saveData = {
  376. rejectList: unfitInfos.value,
  377. consult: consultations.value,
  378. id: dayworkItem.value.id,
  379. prodNum: dayworkItem.value.prodNum,
  380. rejectNum: dayworkItem.value.rejectNum,
  381. qualifiedNum: dayworkItem.value.qualifiedNum,
  382. remark: dayworkItem.value.remark
  383. }
  384. const currentTime = Date.now();
  385. // 检查是否已经过去了 2 秒
  386. if (currentTime - lastRequestTimestamp.value < 2000) {
  387. // 如果在 2 秒 内已经点击,那么不执行
  388. uni.showToast({
  389. icon: 'none',
  390. title: `请勿重复点击`,
  391. duration: 2000
  392. })
  393. return;
  394. }
  395. finish(saveData).then(res => {
  396. if (res.code === 200) {
  397. uni.navigateBack()
  398. } else {
  399. uni.showToast({
  400. icon: 'none',
  401. title: res.message
  402. })
  403. }
  404. })
  405. }
  406. const handleUpdateDaywork = () => {
  407. if (!validHandle()) {
  408. return
  409. }
  410. const saveData = {
  411. rejectList: unfitInfos.value,
  412. consult: consultations.value,
  413. id: dayworkItem.value.id,
  414. prodNum: dayworkItem.value.prodNum,
  415. rejectNum: dayworkItem.value.rejectNum,
  416. qualifiedNum: dayworkItem.value.qualifiedNum,
  417. remark: dayworkItem.value.remark
  418. }
  419. update(saveData).then(res => {
  420. if (res.code === 200) {
  421. uni.$emit("formBack")
  422. uni.navigateBack()
  423. } else {
  424. uni.showToast({
  425. icon: 'none',
  426. title: res.message
  427. })
  428. }
  429. })
  430. }
  431. </script>
  432. <style lang="scss">
  433. .page-container {
  434. height: 100%;
  435. background-color: #ececec;
  436. font-size: 28rpx;
  437. >.title {
  438. font-weight: 700;
  439. margin: 24rpx 16rpx;
  440. }
  441. }
  442. .lot-info {
  443. margin: 32rpx 16rpx 0 16rpx;
  444. padding: 24rpx;
  445. background-color: #ffffff;
  446. border-radius: 8rpx;
  447. .lot-code {
  448. font-size: 32rpx;
  449. font-weight: 700;
  450. margin-bottom: 16rpx;
  451. }
  452. .product-info {
  453. font-size: 28rpx;
  454. color: #9f9f9f;
  455. }
  456. }
  457. .unfit-title {
  458. margin-bottom: 24rpx;
  459. justify-content: space-between;
  460. align-items: center;
  461. text {
  462. font-size: 28rpx;
  463. font-weight: 700;
  464. }
  465. .add-btn {
  466. padding: 12rpx 32rpx;
  467. background-color: #a4adb3;
  468. color: #ffffff;
  469. border-radius: 12rpx;
  470. font-size: 24rpx;
  471. }
  472. }
  473. .unfit-container {
  474. padding: 24rpx;
  475. margin: 0 16rpx;
  476. background-color: #ffffff;
  477. border-radius: 12rpx;
  478. .unfit-item-container {
  479. position: relative;
  480. >* {
  481. margin-bottom: 24rpx;
  482. }
  483. .title {
  484. font-weight: 700;
  485. justify-content: space-between;
  486. align-items: center;
  487. image {
  488. width: 40rpx;
  489. height: 40rpx;
  490. }
  491. }
  492. .standard {}
  493. .result {
  494. align-items: center;
  495. border-bottom: 1px solid #9f9f9f;
  496. padding-bottom: 32rpx;
  497. .label {
  498. flex: 1;
  499. }
  500. input {
  501. width: 280rpx;
  502. height: 56rpx;
  503. border: 1px solid #9f9f9f;
  504. font-size: 28rpx;
  505. &.number {
  506. width: 104rpx;
  507. text-align: center;
  508. }
  509. }
  510. }
  511. }
  512. .unfit-item-container:last-child {
  513. .result {
  514. border-bottom: none;
  515. padding-bottom: 0;
  516. }
  517. }
  518. }
  519. .consultation-container {
  520. margin: 0 16rpx;
  521. padding: 24rpx;
  522. background-color: #ffffff;
  523. border-radius: 8rpx;
  524. .consultation-item-container {
  525. margin-bottom: 24rpx;
  526. border-bottom: 2px solid #888888;
  527. padding-bottom: 24rpx;
  528. }
  529. .consultation-item-container:last-child {
  530. margin-bottom: 0;
  531. border-bottom: 0;
  532. padding-bottom: 0;
  533. }
  534. .question,
  535. .answer {
  536. .label {
  537. justify-content: space-between;
  538. margin-bottom: 16rpx;
  539. font-weight: 700;
  540. }
  541. .content {
  542. line-height: 40rpx;
  543. }
  544. }
  545. .answer {
  546. margin-top: 24rpx;
  547. }
  548. }
  549. .daywork-container {
  550. margin-top: 24rpx;
  551. padding: 24rpx;
  552. background-color: #ffffff;
  553. border: 1px solid #bcbcbc;
  554. .result {
  555. align-items: center;
  556. .label {
  557. width: 112rpx;
  558. }
  559. input {
  560. flex: 1;
  561. height: 56rpx;
  562. border: 1px solid #9f9f9f;
  563. font-size: 28rpx;
  564. text-align: center;
  565. }
  566. }
  567. .remark {
  568. margin-top: 24rpx;
  569. .label {
  570. width: 112rpx;
  571. }
  572. textarea {
  573. flex: 1;
  574. border: 1px solid #9f9f9f;
  575. height: 168rpx;
  576. }
  577. }
  578. .btns-container {
  579. margin-top: 24rpx;
  580. .bottom-btn {
  581. display: flex;
  582. flex: 1;
  583. height: 80rpx;
  584. background-color: #5555ff;
  585. color: #ffffff;
  586. text-align: center;
  587. justify-content: center;
  588. align-items: center;
  589. border-radius: 8rpx;
  590. margin-right: 10rpx;
  591. &.left-btn {
  592. background-color: rgba(85, 85, 255, 1.0);
  593. }
  594. &.right-btn {
  595. margin-left: 24rpx;
  596. }
  597. }
  598. .finished-btn {
  599. display: flex;
  600. flex: 1;
  601. height: 80rpx;
  602. background-color: #fc6565;
  603. color: #ffffff;
  604. text-align: center;
  605. justify-content: center;
  606. align-items: center;
  607. border-radius: 8rpx;
  608. }
  609. .pause-btn {
  610. display: flex;
  611. flex: 1;
  612. height: 80rpx;
  613. background-color: #55d90d;
  614. color: #ffffff;
  615. text-align: center;
  616. justify-content: center;
  617. align-items: center;
  618. border-radius: 8rpx;
  619. }
  620. .question-btn {
  621. width: 80rpx;
  622. align-items: flex-end;
  623. image {
  624. width: 48rpx;
  625. height: 48rpx;
  626. }
  627. text {
  628. font-size: 24rpx;
  629. }
  630. }
  631. }
  632. }
  633. </style>