form.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  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. uni.navigateTo({
  225. url: "/pages/sorting/options",
  226. success: (res) => {
  227. // 通过eventChannel向被打开页面传送数据
  228. res.eventChannel.emit('acceptDataFromOpenerPage', {
  229. data: dayworkItem.value,
  230. index: unfitInfos.value.length
  231. })
  232. }
  233. })
  234. }
  235. // 删除不合格信息
  236. const handleDelUnfit = (index) => {
  237. let tempInfo = unfitInfos.value[index]
  238. console.log(tempInfo)
  239. uni.showModal({
  240. title: '提示',
  241. content: '确定删除该项?',
  242. success: function(res) {
  243. if (res.confirm) {
  244. dayworkItem.value.rejectNum = dayworkItem.value.rejectNum - tempInfo.rejectNum
  245. dayworkItem.value.qualifiedNum = parseInt(dayworkItem.value.qualifiedNum) + parseInt(
  246. tempInfo.rejectNum)
  247. unfitInfos.value.splice(index, 1)
  248. } else if (res.cancel) {
  249. return
  250. }
  251. }
  252. })
  253. }
  254. /* 更换载具*/
  255. function handleChangeCarrier(item) {
  256. // uni.$once('refreshQuickReport', () => {
  257. // init()
  258. // })
  259. store.dayworkInfo = null
  260. uni.navigateTo({
  261. url: "/pages/changeBox/index",
  262. success: function(res) {
  263. // 通过eventChannel向被打开页面传送数据
  264. res.eventChannel.emit('sortingFromOpenerPage', {
  265. data: dayworkItem.value
  266. })
  267. }
  268. })
  269. }
  270. // 添加不合格信息
  271. const handleAddConsultation = () => {
  272. isEventTriggered.value = false; // 更新标志位状态
  273. // 监听事件
  274. uni.$once('addConsulttationEvent', (data) => {
  275. if (!isEventTriggered.value) {
  276. // 如果事件尚未触发,则执行事件触发逻辑
  277. addConsultation(data)
  278. }
  279. })
  280. uni.navigateTo({
  281. url: "/pages/sorting/consultation",
  282. success: (res) => {
  283. // 通过eventChannel向被打开页面传送数据
  284. res.eventChannel.emit('acceptDataFromOpenerPage', {
  285. data: dayworkItem.value
  286. })
  287. }
  288. })
  289. }
  290. const checkFinishable = () => {
  291. if (consultations.value.findIndex(v => v.status === 0) >= 0) {
  292. return false
  293. } else {
  294. return true
  295. }
  296. }
  297. const showStatus = (status) => {
  298. // console.log(status)
  299. switch (status) {
  300. case 0:
  301. return '未确认'
  302. case 1:
  303. return '不合格'
  304. case 2:
  305. return '合格'
  306. default:
  307. return ''
  308. }
  309. }
  310. const showStatusColor = (status) => {
  311. // console.log(status)
  312. switch (status) {
  313. case 0:
  314. return '#fcab53'
  315. case 1:
  316. return '#fc044f'
  317. case 2:
  318. return '#1deb19'
  319. default:
  320. return ''
  321. }
  322. }
  323. const rejectNumberChange = () => {
  324. let sumReject = 0
  325. unfitInfos.value.forEach(v => {
  326. sumReject += v.rejectNum == null ? 0 : Number(v.rejectNum)
  327. })
  328. dayworkItem.value.rejectNum = sumReject
  329. dayworkItem.value.qualifiedNum = dayworkItem.value.prodNum - sumReject
  330. console.log(dayworkItem.value)
  331. }
  332. const validHandle = () => {
  333. for (let i = 0; i < unfitInfos.value.length; i++) {
  334. const e = unfitInfos.value[i]
  335. if (e.rejectNum == null || e.rejectNum == 0) {
  336. uni.showToast({
  337. icon: 'none',
  338. title: `第${i + 1}条不合格信息未输入不合格数量`
  339. })
  340. return false
  341. }
  342. }
  343. if (!dayworkItem.value.qualifiedNum) {
  344. uni.showToast({
  345. icon: 'none',
  346. title: "合格数不能为空",
  347. duration: 2000
  348. })
  349. return false;
  350. }
  351. if (dayworkItem.value.qualifiedNum < 0) {
  352. uni.showToast({
  353. icon: 'none',
  354. title: "合格数不能为负数,请检查不合格信息后提交",
  355. duration: 2000
  356. })
  357. return false;
  358. }
  359. return true
  360. // unfitInfos.value.forEach((e, i) => {
  361. // if (e.name)
  362. // })
  363. }
  364. const handleFinishDaywork = () => {
  365. if (!validHandle()) {
  366. return
  367. }
  368. const saveData = {
  369. rejectList: unfitInfos.value,
  370. consult: consultations.value,
  371. id: dayworkItem.value.id,
  372. prodNum: dayworkItem.value.prodNum,
  373. rejectNum: dayworkItem.value.rejectNum,
  374. qualifiedNum: dayworkItem.value.qualifiedNum,
  375. remark: dayworkItem.value.remark
  376. }
  377. const currentTime = Date.now();
  378. // 检查是否已经过去了 2 秒
  379. if (currentTime - lastRequestTimestamp.value < 2000) {
  380. // 如果在 2 秒 内已经点击,那么不执行
  381. uni.showToast({
  382. icon: 'none',
  383. title: `请勿重复点击`,
  384. duration: 2000
  385. })
  386. return;
  387. }
  388. finish(saveData).then(res => {
  389. if (res.code === 200) {
  390. uni.navigateBack()
  391. } else {
  392. uni.showToast({
  393. icon: 'none',
  394. title: res.message
  395. })
  396. }
  397. })
  398. }
  399. const handleUpdateDaywork = () => {
  400. if (!validHandle()) {
  401. return
  402. }
  403. const saveData = {
  404. rejectList: unfitInfos.value,
  405. consult: consultations.value,
  406. id: dayworkItem.value.id,
  407. prodNum: dayworkItem.value.prodNum,
  408. rejectNum: dayworkItem.value.rejectNum,
  409. qualifiedNum: dayworkItem.value.qualifiedNum,
  410. remark: dayworkItem.value.remark
  411. }
  412. update(saveData).then(res => {
  413. if (res.code === 200) {
  414. uni.$emit("formBack")
  415. uni.navigateBack()
  416. } else {
  417. uni.showToast({
  418. icon: 'none',
  419. title: res.message
  420. })
  421. }
  422. })
  423. }
  424. </script>
  425. <style lang="scss">
  426. .page-container {
  427. height: 100%;
  428. background-color: #ececec;
  429. font-size: 28rpx;
  430. >.title {
  431. font-weight: 700;
  432. margin: 24rpx 16rpx;
  433. }
  434. }
  435. .lot-info {
  436. margin: 32rpx 16rpx 0 16rpx;
  437. padding: 24rpx;
  438. background-color: #ffffff;
  439. border-radius: 8rpx;
  440. .lot-code {
  441. font-size: 32rpx;
  442. font-weight: 700;
  443. margin-bottom: 16rpx;
  444. }
  445. .product-info {
  446. font-size: 28rpx;
  447. color: #9f9f9f;
  448. }
  449. }
  450. .unfit-title {
  451. margin-bottom: 24rpx;
  452. justify-content: space-between;
  453. align-items: center;
  454. text {
  455. font-size: 28rpx;
  456. font-weight: 700;
  457. }
  458. .add-btn {
  459. padding: 12rpx 32rpx;
  460. background-color: #a4adb3;
  461. color: #ffffff;
  462. border-radius: 12rpx;
  463. font-size: 24rpx;
  464. }
  465. }
  466. .unfit-container {
  467. padding: 24rpx;
  468. margin: 0 16rpx;
  469. background-color: #ffffff;
  470. border-radius: 12rpx;
  471. .unfit-item-container {
  472. position: relative;
  473. >* {
  474. margin-bottom: 24rpx;
  475. }
  476. .title {
  477. font-weight: 700;
  478. justify-content: space-between;
  479. align-items: center;
  480. image {
  481. width: 40rpx;
  482. height: 40rpx;
  483. }
  484. }
  485. .standard {}
  486. .result {
  487. align-items: center;
  488. border-bottom: 1px solid #9f9f9f;
  489. padding-bottom: 32rpx;
  490. .label {
  491. flex: 1;
  492. }
  493. input {
  494. width: 280rpx;
  495. height: 56rpx;
  496. border: 1px solid #9f9f9f;
  497. font-size: 28rpx;
  498. &.number {
  499. width: 104rpx;
  500. text-align: center;
  501. }
  502. }
  503. }
  504. }
  505. .unfit-item-container:last-child {
  506. .result {
  507. border-bottom: none;
  508. padding-bottom: 0;
  509. }
  510. }
  511. }
  512. .consultation-container {
  513. margin: 0 16rpx;
  514. padding: 24rpx;
  515. background-color: #ffffff;
  516. border-radius: 8rpx;
  517. .consultation-item-container {
  518. margin-bottom: 24rpx;
  519. border-bottom: 2px solid #888888;
  520. padding-bottom: 24rpx;
  521. }
  522. .consultation-item-container:last-child {
  523. margin-bottom: 0;
  524. border-bottom: 0;
  525. padding-bottom: 0;
  526. }
  527. .question,
  528. .answer {
  529. .label {
  530. justify-content: space-between;
  531. margin-bottom: 16rpx;
  532. font-weight: 700;
  533. }
  534. .content {
  535. line-height: 40rpx;
  536. }
  537. }
  538. .answer {
  539. margin-top: 24rpx;
  540. }
  541. }
  542. .daywork-container {
  543. margin-top: 24rpx;
  544. padding: 24rpx;
  545. background-color: #ffffff;
  546. border: 1px solid #bcbcbc;
  547. .result {
  548. align-items: center;
  549. .label {
  550. width: 112rpx;
  551. }
  552. input {
  553. flex: 1;
  554. height: 56rpx;
  555. border: 1px solid #9f9f9f;
  556. font-size: 28rpx;
  557. text-align: center;
  558. }
  559. }
  560. .remark {
  561. margin-top: 24rpx;
  562. .label {
  563. width: 112rpx;
  564. }
  565. textarea {
  566. flex: 1;
  567. border: 1px solid #9f9f9f;
  568. height: 168rpx;
  569. }
  570. }
  571. .btns-container {
  572. margin-top: 24rpx;
  573. .bottom-btn {
  574. display: flex;
  575. flex: 1;
  576. height: 80rpx;
  577. background-color: #5555ff;
  578. color: #ffffff;
  579. text-align: center;
  580. justify-content: center;
  581. align-items: center;
  582. border-radius: 8rpx;
  583. margin-right: 10rpx;
  584. &.left-btn {
  585. background-color: rgba(85, 85, 255, 1.0);
  586. }
  587. &.right-btn {
  588. margin-left: 24rpx;
  589. }
  590. }
  591. .finished-btn {
  592. display: flex;
  593. flex: 1;
  594. height: 80rpx;
  595. background-color: #fc6565;
  596. color: #ffffff;
  597. text-align: center;
  598. justify-content: center;
  599. align-items: center;
  600. border-radius: 8rpx;
  601. }
  602. .pause-btn {
  603. display: flex;
  604. flex: 1;
  605. height: 80rpx;
  606. background-color: #55d90d;
  607. color: #ffffff;
  608. text-align: center;
  609. justify-content: center;
  610. align-items: center;
  611. border-radius: 8rpx;
  612. }
  613. .question-btn {
  614. width: 80rpx;
  615. align-items: flex-end;
  616. image {
  617. width: 48rpx;
  618. height: 48rpx;
  619. }
  620. text {
  621. font-size: 24rpx;
  622. }
  623. }
  624. }
  625. }
  626. </style>